/*
 * 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-aria-redefinition"};ruleDef.prototype.getShortDescription=function(){return"Ensure that the component does not re-define any WAI-ARIA properties"};ruleDef.prototype.getDescription=function(){return"This rule checks that a component has not overridden or tries to introduce (any custom) WAI-ARIA attributes"};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);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){let issue;if(properties){const ariaDetect=/^aria[A-Z\-].*$/;Object.keys(properties).forEach(propName=>{if(ariaDetect.test(propName)){issue=new context.Issue(`Component ${fullName} defines a WAI-ARIA property ${propName} which is not allowed`);context.reporter.addIssue(issue,context)}})}};module.exports=ruleDef;