/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const RULENAME="oj-ts-numconv-pattern";const DESCRIPTION="Applications should not use the deprecated 'pattern' option of IntlNumberConverter because it is not locale "+"sensitive. Use other options instead like formatType, dateFormat and timeFormat, and if needed, set the "+"locale to be the preferred locale.";const SHORT_DESCRIPTION="The 'converterOptions' of IntlNumberConverter should not use the deprecated 'pattern' option.";const INTL_NUM_CONVERTER="IntlNumberConverter";const NUM_CONVERTER="NumberConverter";const NEW_EXPR="NewExpression";const PATTERN="pattern";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{MemberExpression:this._onMemExpr,CallExpression:this._onCallExpr,NewExpression:this._onNewExpr}}_onCallExpr(ruleCtx,node){var ce;if(ce=node.callee){if(ce.name===INTL_NUM_CONVERTER||ce.name===NUM_CONVERTER){this._checkConverterProps(ruleCtx,ce.name,node)}}}_onMemExpr(ruleCtx,node){if(node.property&&node.property.type==="Identifier"&&node.property.name==INTL_NUM_CONVERTER){if(node.parent&&node.parent.type===NEW_EXPR){if(node.parent.arguments){this._checkConverterProps(ruleCtx,node.property.name,node.parent)}}}}_onNewExpr(ruleCtx,node){var ce;if((ce=node.callee)&&(ce.name===INTL_NUM_CONVERTER||ce.name===NUM_CONVERTER)){this._checkConverterProps(ruleCtx,ce.name,node)}}_checkConverterProps(ruleCtx,callee,node){var args,arg,props;if((args=node.arguments)&&args.length>=1){arg=args[0];if(arg.type==="ObjectExpression"){if(props=arg.properties){let i,prop;for(i=0;i<props.length;i++){prop=props[i];if(prop.key&&prop.key.type==="Identifier"&&prop.key.name===PATTERN){this._emitIssue(ruleCtx,callee,prop)}}}}}}_emitIssue(ruleCtx,callee,prop){var md,deps,dep,since;if(md=ruleCtx.utils.metaLib._getObjectMetadata("oj.IntlNumberConverter")){if(md.typedef&&(md=md.typedef.ConverterOptions)){if(deps=md.ojdeprecated){for(let i=0;i<deps.length;i++){dep=deps[i];if(dep.for===PATTERN){if(dep.since){since=" (since "+dep.since+")"}else{since=""}break}}}}}let issue=new ruleCtx.Issue(`${callee} option 'pattern' is deprecated${since}.`);let loc=prop.key.loc;issue.setPosition(loc.start.line,loc.start.column,prop.range[0],prop.range[0]+PATTERN.length-1);ruleCtx.reporter.addIssue(issue,ruleCtx)}}module.exports=Rule;