/*
 * Copyright (c) 2018, 2025, 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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-ojcss"};ruleDef.prototype.getShortDescription=function(){return"Checks that the requirejs css! plugin is not used"};ruleDef.prototype.getDescription=function(){return"Teams should be using ojcss! in preference to css!"};ruleDef.prototype.register=function(context){return{CallExpression:this._doAudit,ImportDeclaration:this._doAuditImport}};ruleDef.prototype._doAuditImport=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent){if(node.importKind==="value"&&node.source&&node.source.type===NT.LITERAL&&node.source.value.startsWith("css!")){const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);const issue=new context.Issue(`Component ${componentInfo.fullName} uses the requireJS css! plugin. The ojcss! plugin should be used instead`);context.reporter.addIssue(issue,context)}}};ruleDef.prototype._doAudit=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();let issue;const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent&&(node.callee.name==="define"||node.callee.name==="require")){if(node.arguments[0].type===NT.ARRAY_EXPR&&node.arguments[0].elements.length>0){node.arguments[0].elements.forEach(arg=>{this._checkRequireTarget(context,withinComponent,arg)})}else if(node.arguments[0].type===NT.LITERAL){this._checkRequireTarget(context,withinComponent,node.arguments[0])}}};ruleDef.prototype._checkRequireTarget=function(context,withinComponent,node){const NT=context.utils.AstUtils.getNodeTypes();if(node.type===NT.LITERAL&&node.value.startsWith("css!")){const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);if(componentInfo){issue=new context.Issue(`Component ${componentInfo.fullName} uses the requireJS css! plugin. The ojcss! plugin should be used instead`);context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;