/*
 * 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-js-ojcomp-new";const DESCRIPTION="JET custom element usage should be used instead of instantiating a JET component class via 'new'.";const SHORT_DESCRIPTION="Replace Instantiation of a JET component class via \"new\" with a custom element";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{NewExpression:this._onNew}}_onNew(ruleCtx,node){var component,issue,elem;var me,obj,start;var metaLib=ruleCtx.utils.metaLib;me=node.callee;if(me.type==="MemberExpression"){obj=me.object;if(obj&&obj.type==="Identifier"){if(obj.name==="oj"){if(me.property&&me.property.name){component="oj."+me.property.name;start=obj}}}}else if(me.type==="Identifier"){component=me.name;start=me}if(component){if(metaLib.isClassRenamed(component)||metaLib.isClassDeleted(component)){return}if(metaLib.isComponent(component)){if(component==="oj.ojTree"){elem="oj-tree-view"}else{elem=metaLib.getTagFromClass(component)}if(elem){issue=new ruleCtx.Issue("Instantiation of JET class "+component+" found. Use web component <"+elem+">.");let ft=ruleCtx.filepath.substring(ruleCtx.filepath.lastIndexOf(".")+1);start=ft==="ts"?start.range[0]:start.start;let pos=ruleCtx.utils.utils.getRowColFromIndex(ruleCtx.data,start,ft);issue.setPosition(pos.row,pos.col,start,start+component.length);ruleCtx.reporter.addIssue(issue,ruleCtx)}}}}}module.exports=Rule;