/*
 * 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 helperProp=require("../../rules/jet/helpers/bp-checkPropType");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-compjson-bp-ar"};ruleDef.prototype.getShortDescription=function(){return"Web component component.json metadata should follow best practices and avoid plain 'array' type properties"};ruleDef.prototype.getDescription=function(){return"For best practices, web components should avoid use of unqualified property type 'array', and provide a more complete definition of the API using a closure type definition"};ruleDef.prototype.register=function(context){if(context.rulePack.isRuleEnabled("oj-cca-compjson-bp-ar","JET")){return false}else{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);const componentType=Utils.getComponentType(meta);if(componentType==="composite"){this._checkProps(context,fullName,meta.properties)}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkProps(context,componentInfo.fullName,componentInfo.properties)}};ruleDef.prototype._checkProps=function(context,fullName,properties){if(properties){const arrayProps=helperProp(properties,"a");if(arrayProps){for(let i=0;i<arrayProps.length;i++){const checkProperty=arrayProps[i];const checkPropertyType=Utils.getPropertyAttributeFromPath(context,fullName,checkProperty,"type");if(checkPropertyType.toLowerCase()==="array"){if(!Utils.shouldIgnoreCheck(context,"jetwc-compjson-bp-ar",fullName,"properties",checkProperty)){const issue=new context.Issue(`property '${checkProperty}' is defined with unqualified type 'array'. Provide a more complete API definition using a closure type definition.`);context.reporter.addIssue(issue,context)}}}}}};module.exports=ruleDef;