/*
 * 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 ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-deprecated-lifecycle"};ruleDef.prototype.getShortDescription=function(){return"Checks for deprecated component lifecycle definitions"};ruleDef.prototype.getDescription=function(){return"This rule ensures that the component does not still declare deprecated lifecycle methods such as attached"};ruleDef.prototype.register=function(context){return{FunctionExpression:Utils.setupFileMethodMapping.bind(Utils),ArrowFunctionExpression:Utils.setupFileMethodMapping.bind(Utils),CallExpression:Utils.deriveViewModels.bind(Utils),MethodDefinition:Utils.setupFileMethodMappingFromMethodDefintion.bind(Utils),closedownRP:this._doAudit}};ruleDef.prototype._doAudit=function(context){let issue;if(context.rulePack.getExtension()){context.rulePack.getExtension().allComponents.forEach(compInfo=>{const vmMethods=Utils.getVMMethodsForLocalComposite(context,compInfo);if(vmMethods&&(vmMethods.has("attached")||vmMethods.has("detached")||vmMethods.has("initialize")||vmMethods.has("dispose"))){let reportSource=compInfo.fullName;if(compInfo.viewModel.resolved&&!compInfo.viewModel.skip){reportSource=compInfo.viewModel.path}issue=new context.Issue(`Component '${compInfo.fullName}' still defines one or more of the following deprecated lifecycle methods: attached(), detached(), dispose(), initialize()`);issue.setReportedFilePath(reportSource);context.reporter.addIssue(issue,context)}})}};module.exports=ruleDef;