/*
 * 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 Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-namespace"};ruleDef.prototype.getShortDescription=function(){return"Verify components are within your registered namespace"};ruleDef.prototype.getDescription=function(){return"This rule is configured with your namespace(s) in the audit configuration file and will match the naming of your component to those namespaces"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);this._checkNamespace(context,fullName)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkNamespace(context,componentInfo.fullName)}};ruleDef.prototype._checkNamespace=function(context,fullName){let issue;if(context.rulePack.getRuleCustomOption("namespaces")?.filter(ns=>fullName.startsWith(ns)).length===0){issue=new context.Issue(`Component ${fullName} is not in an assigned namespace`);context.reporter.addIssue(issue,context)}};module.exports=ruleDef;