/*
 * Copyright (c) 2018, 2026, 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 path=require("path");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vcomponent-version"};ruleDef.prototype.getShortDescription=function(){return"Verify that a VComponent .tsx file defines a version number for the component"};ruleDef.prototype.getDescription=function(){return"This rule checks that a vcomponent either directly, or indirectly provides the version metadata needed for managing dependencies"};ruleDef.prototype.register=function(context){return{startaudit:this._checkForApplicability,Program:this._doVComponentAudit}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);let issue;if(componentInfo){if(componentInfo.version){if(!context.utils.semVerUtils.isValid(componentInfo.version)){if(componentInfo.pack&&componentInfo.inferredVersion){issue=new context.Issue(`Component ${componentInfo.fullName} inherits an invalid version number format (${componentInfo.version}) from its pack definition`)}else{issue=new context.Issue(`Component ${componentInfo.fullName} defines a version number using an invalid format (${componentInfo.version})`)}issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}else if(componentInfo.pack&&componentInfo.inferredVersion){issue=new context.Issue(`Component ${componentInfo.fullName} is inheriting a version number from its pack`);issue.setMsgKey(context.ruleName+"_3");context.reporter.addIssue(issue,context,"info")}}else{issue=new context.Issue(`Component ${componentInfo?componentInfo.fullName:context.filepath.split("/").reverse()[0]} does not define a version number`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;