/*
 * 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 path=require("path");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vcomponent-jetversion"};ruleDef.prototype.getShortDescription=function(){return"Verify that a VComponent .tsx file includes the supported JET version"};ruleDef.prototype.getDescription=function(){return"This rule checks that a vcomponent either directly, or indirectly provides the jetVersion metadata needed to indicate the support range"};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);if(componentInfo){let checkVersion=componentInfo.jetVersion;if(!context.utils.semVerUtils.isValidRange(checkVersion)){if(componentInfo.inferredJetVersion){issue=new context.Issue(`Component ${componentInfo.fullName} inherits a JET version dependency from its pack that is using an invalid format (${checkVersion})`)}else{issue=new context.Issue(`Component ${componentInfo.fullName} defines a JET version dependency using an invalid format (${checkVersion})`)}issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}else{if(componentInfo.inferredJetVersion){issue=new context.Issue(`Component ${componentInfo.fullName} is using an inferred / defaulted JET version range`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context,"info")}}}};module.exports=ruleDef;