/*
 * 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 ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-prerelease-pattern"};ruleDef.prototype.getShortDescription=function(){return"Checks pattern of any pre-release version number"};ruleDef.prototype.getDescription=function(){return"This rule ensures that if a component has a pre-release version number it is one that conforms to one of the recommended patterns, e.g. -alpha|beta|rc.1 (keyword, incremented), -1 (incremented numerical), or -20190412T060000 (timestamp)"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){let issue;const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);this._checkPrereleasePattern(context,fullName,meta.version)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkPrereleasePattern(context,componentInfo.fullName,componentInfo.version)}};ruleDef.prototype._checkPrereleasePattern=function(context,fullName,version){const prereleases=context.utils.semVerUtils.prerelease(version);if(prereleases&&prereleases.length>0){const patterns=[/^alpha|beta|rc$/i,/^\d*$/,/^20\d{6}T\d*$/];if(!(patterns[0].test(prereleases[0])||patterns[1].test(prereleases[0])||patterns[2].test(prereleases[0]))){issue=new context.Issue(`Component ${fullName} has a pre-release version number that does not use a recommended pattern`);context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;