@oracle/oraclejet-audit 16.0.5 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/AstJson.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const PROP="P";const RBRACE="}";const LBRACE="{";const LSQUARE="[";const RSQUARE="]";const NUMBER="N";const STRING="S";const BOOL="B";const NULL="NL";const COLON=":";const DQUOTE="\"";const ESCAPE="\\";const COMMA=",";const UNARY_MINUS="-";const $DIGIT="$digit";const EOF="";function AstJson(msgContext){this._msgContext=msgContext};AstJson.prototype.parse=function(data){var ret;this._data=data;this._index=-1;this._row=1;this._col=0;this._curChar=null;this._objStack=[];this._listStack=[];this._curProp=null;this._curObj=null;this._tokValue=null;ret=this._parse();return ret};AstJson.prototype._parse=function(){var tok;do{switch(tok){case STRING:case NUMBER:case BOOL:case NULL:{if(this._curProp){this._curProp.value=this._tokValue}else{this._curProp=this._tokValue}this._curList.push(this._curProp);this._curProp=null;break}case PROP:{this._curProp={name:this._tokValue.rawValue,pos:{row:this._startRow,col:this._startCol,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,"string"),index:this._startIndex}};this._next(COLON);break}case LBRACE:{if(this._curProp){this._curProp.value=this._tokValue}if(this._curObj){this._objStack.push(this._curObj)}this._curObj=this._tokValue;this._curObj.members=[];if(this._curList){if(this._curProp)this._curList.push(this._curProp);else this._curList.push(this._curObj)}this._listStack.push(this._curList);this._curList=this._curObj.members;break}case RBRACE:{if(this._objStack.length){this._curObj=this._objStack.pop()}if(this._listStack.length){this._curList=this._listStack.pop()}break}case LSQUARE:{if(this._curList){this._listStack.push(this._curList)}if(this._curProp){this._curProp.value=this._tokValue;this._curList.push(this._curProp)}else if(this._curList){this._curList.push(this._tokValue)}this._curList=this._tokValue.members;this._curProp=null;break}case RSQUARE:{this._curList=this._listStack.pop();break}}}while((tok=this._getToken())!==EOF);return this._startToken===LBRACE?this._curObj:this._curList};AstJson.prototype._getToken=function(){var s;while(true){s=this._getNextChar();if(s===DQUOTE){this._tokValue=this._getString();this._getTokValue("string",this._tokValue,true);return this._peekNext(COLON)?PROP:STRING}else if(this._isNumber(s)){this._tokValue=this._getNumber(s);this._getTokValue("number",this._tokValue,true);return NUMBER}else if(s==="t"||s==="f"){this._tokValue=this._getBoolean(s);this._getTokValue("boolean",this._tokValue,true);return BOOL}else if(s==="n"){this._tokValue=this._getNull();this._getTokValue("null",this._tokValue,true);return NULL}else if(s===LBRACE){this._tokValue={type:"Object",value:"{",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index}};if(!this._startToken){this._startToken=LBRACE}return LBRACE}else if(s===RBRACE){return RBRACE}else if(s===LSQUARE){this._tokValue={type:"array",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index},members:[]};if(!this._startToken){this._startToken=LSQUARE}return LSQUARE}else if(s===RSQUARE){return RSQUARE}else if(s===EOF){return EOF}else if(s===COMMA){continue}else{if(this._msgContext){this._msgContext.assert("JSON -> AST - unexpected char '"+s+"'")}return s}}};AstJson.prototype._getString=function(){var str="",s,inEscape;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while((s=this._getChar())!==EOF){if(s===ESCAPE&&!inEscape){inEscape=true;continue}if(inEscape){inEscape=false;if(s==="n"){str+"\n"}else if(s==="\""){str+="\""}else if(s==="t"){str+="\t"}else{str+=" "+s}continue}if(s===DQUOTE){break}str+=s}return{value:str,rawValue:str}};AstJson.prototype._getNumber=function(s){var str=s;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(this._isNumber(s)){if(s!==UNARY_MINUS){str+=s;continue}}this._unget();break}return{value:parseInt(str),rawValue:str}};AstJson.prototype._getBoolean=function(s){var ret={};this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;if(s==="t"){this._next("r");this._next("u");this._next("e");ret.value=true;ret.rawValue="true"}else{this._next("a");this._next("l");this._next("s");this._next("e");ret.value=false;ret.rawValue="false"}return ret};AstJson.prototype._getNull=function(){this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;this._next("u");this._next("l");this._next("l");return{value:null,rawValue:"null"}};AstJson.prototype._getTokValue=function(type,tokValue,startRc){this._tokValue={type:type,value:this._tokValue.value,rawValue:this._tokValue.rawValue,pos:{row:startRc?this._startRow:this._row,col:startRc?this._startCol:this._col,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,type),index:this._startIndex}}};AstJson.prototype._next=function(s){while(true){if(this._getNextChar()===s){break}}};AstJson.prototype._peekNext=function(s){var n,r,c,val,ret=false;n=this._index;r=this._row;c=this._col;if(s===$DIGIT){val=this._getNextChar();ret=!isNaN(parseInt(val,10))}else{ret=this._getNextChar()===s}this._index=n;this._row=r;this._col=c;return ret};AstJson.prototype._getNextChar=function(){var s;while(true){s=this._getChar();if(s===EOF){return EOF}if(!_isWhite(s)){return s}}};AstJson.prototype._getChar=function(){if(!this._doNotadvance){this._index=this._index>=0?++this._index:0}else{this._unget=false}if(this._index<this._data.length){this._curChar=this._data.substr(this._index,1);if(this._curChar==="\n"){this._row++;this._col=0}else if(this._curChar!=="\r"){this._col++}return this._curChar}return EOF};AstJson.prototype._unget=function(){this._doNotAdvance=true};AstJson.prototype._getTokEndIndex=function(s,start,type){var end=start;if(type==="string"){end+=2}return end+s.length-1};AstJson.prototype._isNumber=function(s){var num;if(s===UNARY_MINUS){num=this._peekNext($DIGIT);return num>="0"&&num<="9"}return!isNaN(parseInt(s,10))};function _isWhite(s){return s==" "||s==="\n"||s==="\r"||s==="\t"};module.exports=AstJson;
6
+ const PROP="P";const RBRACE="}";const LBRACE="{";const LSQUARE="[";const RSQUARE="]";const NUMBER="N";const STRING="S";const BOOL="B";const NULL="NL";const COLON=":";const DQUOTE="\"";const ESCAPE="\\";const COMMA=",";const UNARY_MINUS="-";const $DIGIT="$digit";const EOF="";function AstJson(msgContext){this._msgContext=msgContext};AstJson.prototype.parse=function(data){var ret;this._data=data;this._index=-1;this._row=1;this._col=0;this._curChar=null;this._objStack=[];this._listStack=[];this._curProp=null;this._curObj=null;this._tokValue=null;ret=this._parse();return ret};AstJson.prototype._parse=function(){var tok;do{switch(tok){case STRING:case NUMBER:case BOOL:case NULL:{if(this._curProp){this._curProp.value=this._tokValue}else{this._curProp=this._tokValue}this._curList.push(this._curProp);this._curProp=null;break}case PROP:{this._curProp={name:this._tokValue.rawValue,pos:{row:this._startRow,col:this._startCol,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,"string"),index:this._startIndex}};this._next(COLON);break}case LBRACE:{if(this._curProp){this._curProp.value=this._tokValue}if(this._curObj){this._objStack.push(this._curObj)}this._curObj=this._tokValue;this._curObj.members=[];if(this._curList){if(this._curProp)this._curList.push(this._curProp);else this._curList.push(this._curObj)}this._listStack.push(this._curList);this._curList=this._curObj.members;break}case RBRACE:{if(this._objStack.length){this._curObj=this._objStack.pop()}if(this._listStack.length){this._curList=this._listStack.pop()}break}case LSQUARE:{if(this._curList){this._listStack.push(this._curList)}if(this._curProp){this._curProp.value=this._tokValue;this._curList.push(this._curProp)}else if(this._curList){this._curList.push(this._tokValue)}this._curList=this._tokValue.members;this._curProp=null;break}case RSQUARE:{this._curList=this._listStack.pop();break}}}while((tok=this._getToken())!==EOF);return this._startToken===LBRACE?this._curObj:this._curList};AstJson.prototype._getToken=function(){var s;while(true){s=this._getNextChar();if(s===DQUOTE){this._tokValue=this._getString();this._getTokValue("string",this._tokValue,true);return this._peekNext(COLON)?PROP:STRING}else if(this._isNumber(s)){this._tokValue=this._getNumber(s);this._getTokValue("number",this._tokValue,true);return NUMBER}else if(s==="t"||s==="f"){this._tokValue=this._getBoolean(s);this._getTokValue("boolean",this._tokValue,true);return BOOL}else if(s==="n"){this._tokValue=this._getNull();this._getTokValue("null",this._tokValue,true);return NULL}else if(s===LBRACE){this._tokValue={type:"Object",value:"{",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index}};if(!this._startToken){this._startToken=LBRACE}return LBRACE}else if(s===RBRACE){return RBRACE}else if(s===LSQUARE){this._tokValue={type:"array",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index},members:[]};if(!this._startToken){this._startToken=LSQUARE}return LSQUARE}else if(s===RSQUARE){return RSQUARE}else if(s===EOF){return EOF}else if(s===COMMA){continue}else{if(this._msgContext){this._msgContext.assert("JSON -> AST - unexpected char '"+s+"'")}return s}}};AstJson.prototype._getString=function(){var str="",s,inEscape;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(s===ESCAPE){inEscape=true;continue}if(!inEscape){if(s===DQUOTE){return{value:str,rawValue:str}}}inEscape=false;str+=s}};AstJson.prototype._getNumber=function(s){var str=s;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(this._isNumber(s)){if(s!==UNARY_MINUS){str+=s;continue}}this._unget();break}return{value:parseInt(str),rawValue:str}};AstJson.prototype._getBoolean=function(s){var ret={};this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;if(s==="t"){this._next("r");this._next("u");this._next("e");ret.value=true;ret.rawValue="true"}else{this._next("a");this._next("l");this._next("s");this._next("e");ret.value=false;ret.rawValue="false"}return ret};AstJson.prototype._getNull=function(){this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;this._next("u");this._next("l");this._next("l");return{value:null,rawValue:"null"}};AstJson.prototype._getTokValue=function(type,tokValue,startRc){this._tokValue={type:type,value:this._tokValue.value,rawValue:this._tokValue.rawValue,pos:{row:startRc?this._startRow:this._row,col:startRc?this._startCol:this._col,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,type),index:this._startIndex}}};AstJson.prototype._next=function(s){while(true){if(this._getNextChar()===s){break}}};AstJson.prototype._peekNext=function(s){var n,r,c,val,ret=false;n=this._index;r=this._row;c=this._col;if(s===$DIGIT){val=this._getNextChar();ret=!isNaN(parseInt(val,10))}else{ret=this._getNextChar()===s}this._index=n;this._row=r;this._col=c;return ret};AstJson.prototype._getNextChar=function(){var s;while(true){s=this._getChar();if(s===EOF){return EOF}if(!_isWhite(s)){return s}}};AstJson.prototype._getChar=function(){if(!this._doNotadvance){this._index=this._index>=0?++this._index:0}else{this._unget=false}if(this._index<this._data.length){this._curChar=this._data.substr(this._index,1);if(this._curChar==="\n"){this._row++;this._col=0}else if(this._curChar!=="\r"){this._col++}return this._curChar}return EOF};AstJson.prototype._unget=function(){this._doNotAdvance=true};AstJson.prototype._getTokEndIndex=function(s,start,type){var end=start;if(type==="string"){end+=2}return end+s.length-1};AstJson.prototype._isNumber=function(s){var num;if(s===UNARY_MINUS){num=this._peekNext($DIGIT);return num>="0"&&num<="9"}return!isNaN(parseInt(s,10))};function _isWhite(s){return s==" "||s==="\n"||s==="\r"||s==="\t"};module.exports=AstJson;
package/lib/RuleSet.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const REG=require("./RegTypes");const FILETYPE=require("./filetypes");const RULE_FILE="rules.json";const BUILTIN_RULES_PATH="../rules/";const BUILTIN_RULEPACK_PATH="../rulepacks/";const JAF_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jaf";const JET_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jet";const SPOC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"spoc";const OJC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"ojc";const VDOM_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"vdom";const JETVDOM_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetvdom";const CSP_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"csp";const JETWC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwc";const JETWCO_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwco";const VCOMPMIG_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"ojcmig";const WEBDRIVER_TEST_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"wdt";const JET_MIN_VERSION="5.2.0";const TEMP_FILE_TEMPLATE="@@rpziptmp-XXXXXX";const PROP_$BUILTIN="$builtin";const PROP_$REQUIRED="$required";const RESERVED_RULE_PREFIX=["oj-","jaf-","csp-","spoc-","jetwc-","jetwco-","wdt-","vdom-","jetvdom-","exch-","demo-"];const RESERVED_PACK_PREFIX=["JAF","JET","SPOC","CSP","JETWC","JETWCO","VDOM","JETVDOM","WDT","DEMO"];const NO_MSGID_PACKS=[];const RULE_STATUS=["prod","production","ready","beta","alpha","deprecated"];const RULE_OPTS_JAF=["enabled","severity","status","filetype","group","jetver","theme","inservice","amd","customopts","issuetag"];const OPT_SEVERITY="severity";const FUNCTION="function";const COLON=":";const RULE_RE=new RegExp(/[~`!#$%\^&*+\[\]\\';,/{}|\\"\?]/,"g");const JAF_RULEOPT_RE=RegExp(/^(\$|jet|jaf|oj|vdom|spoc|wdt|csp|_)/);const RulePack=require("./RulePack");const Registry=require("./Registry");const SemVer=require("./SemVer");const CssUtils=require("./CssUtils");const AstNodeTypes=require("./AstNodeTypes");const clone=require("./clone");var RuleSet=function(config,nodeDeps,appCtx,msgCtx,AMDRulePacks){this._config=config;this._ruleSets=config.getRulePacks();this._ruleMods=config.getRuleMods();this._ruleCount=0;this._AmdPacks=AMDRulePacks;this._appCtx=appCtx;this._nd=nodeDeps;this._isAMD=!!nodeDeps.AmdRulePackLoader;this._isCLI=appCtx.runMode==="cli";this._isCliOrApi=!this._isAMD;this._metaLib=appCtx.metaLib;this._utils=appCtx.utils;this._fsUtils=appCtx.fsUtils;this._tsxUtils=appCtx.tsxUtils;this._severity=appCtx.severity;this._tmpDir=appCtx.tmpDir;this._semVer=new SemVer;this._targFiletypes=[];this._msgIds=null;this._useBuiltinRules=config._config.builtinJetRules;this._rulePacks=null;this._shadowRulePacks=null;this._rulesetSummary=[];this._RSI={};this._registerCtx={sysOpts:{verboseMode:this._appCtx.verboseMode,debugMode:this._appCtx.debugMode}};this._registerCtx.utils={};this._registerCtx.utils.metaLib=this._metaLib.getPublicInterface();this._registerCtx.runMode=appCtx.runMode;this._registerCtx.VsCodeExtHint=appCtx.VsCodeExtHint;this._registerCtx.utils.semVerUtils=this._semVer;this._registerCtx.utils.utils=this._utils;this._registerCtx.utils.CssUtils=CssUtils;this._registerCtx.config=JSON.parse(JSON.stringify(this._config._config));this._registerCtx.utils.msgLib={msg:msgCtx.msg,error:msgCtx.error,info:msgCtx.info,debug:msgCtx.debug,assert:msgCtx.assert};this._registerCtx.utils.sevLib=this._severity.getSevLib();this._registerCtx.utils.OjetLib=appCtx.ojetLib;this._registerCtx.utils.pluginLib=appCtx.plugin.getPluginLib();this._msgCtx=msgCtx;this._msg=msgCtx.msg;this._info=msgCtx.info;this._debug=msgCtx.debug;this._error=msgCtx.error;this._warn=msgCtx.warn;this._assert=msgCtx.assert;this._debugMode=msgCtx.isDebug;this._verboseMode=msgCtx.isVerbose;if(!this._ruleSets){this._ruleSets=[]}let rsi=this._RSI.JAF=0;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JAF_BUILTIN_RULES_PATH):null,"builtin":true});if(config._config.builtinJetRules){this._RSI.JET=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JET_BUILTIN_RULES_PATH):null,"builtin":true});this._RSI.OJC=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,OJC_BUILTIN_RULES_PATH):null,"builtin":true});this._RSI.VDOM=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,VDOM_BUILTIN_RULES_PATH):null,"builtin":true});this._RSI.JETVDOM=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JETVDOM_BUILTIN_RULES_PATH):null,"builtin":true})}if(config._config.builtinCspRules){this._RSI.CSP=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,CSP_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcRules){this._RSI.JETWC=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWC_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcOracleRules){this._RSI.JETWCO=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWCO_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinSpocRules){this._RSI.SPOC=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,SPOC_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinOjcMigrationRules){this._RSI.OJCMIG=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,VCOMPMIG_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinWebDriverTestRules){this._RSI.WEBDT=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,WEBDRIVER_TEST_BUILTIN_RULES_PATH),"builtin":true})}if(this._isAMD&&this._AmdPacks){let i,apack;for(i=0;i<this._AmdPacks.length;i++){if(apack=this._AmdPacks[i]){let amdpref=apack.rulesJson.prefix;if(amdpref){this._RSI[amdpref]=rsi}this._ruleSets.splice(rsi++,0,{enabled:true,path:null,builtin:false,amdpack:apack})}}}};RuleSet.prototype.loadRulePacks=function(config,isDryRun,isRuleDump,fnSetJafMsgIds){var ruleSet,rulePath,rulesJson,rulePack,rsi,rule,prefix,groups,gname,arules,j,k,s="",rulesetSummaryIndex=-1,spocFound,demoFound,errors=false,rc,ruleName,jetVersion;this._config=config;this._confSeverity=config._sev;this._confNamedRules=config.ruleNames;jetVersion=this._metaLib.getRevisionInfo().jetVersion.split("-")[0];if(!this._semVer.setReference(jetVersion,JET_MIN_VERSION)){this._error(`JET metadata version ${jetVersion} not supported (less than ${JET_MIN_VERSION})`);return false}if(this._debugMode){this._debug(this._ruleSets?"Processing "+this._ruleSets.length+" Rule Sets":"No Rule Sets defined")}if(!this._ruleSets){return false}this._rulePacks=[];this._shadowRulePacks=[];for(rsi=0;rsi<this._ruleSets.length;rsi++){ruleSet=this._ruleSets[rsi];groups=null;try{if(typeof ruleSet.enabled==="boolean"&&!ruleSet.enabled){s+=(rsi?"\n":"")+" "+(rsi+1)+") "+"Disabled ruleSet at '"+ruleSet.path;continue}if(!ruleSet.status){ruleSet.status=["all"]}if(!this._isAMD){if(this._debugMode){let rname=this._nd.path.basename(ruleSet.path);switch(rname){case"jaf":case"jet":case"spoc":rname=rname.toUpperCase();break;default:rname=ruleSet.name;break}this._debug(`Ruleset ${rname?"'rname'":""}path->'${ruleSet.path}'`)}if(ruleSet.path.endsWith(".zip")){ruleSet.container=ruleSet.path;let tmpFile=this._fsUtils.getUniqueFileName(TEMP_FILE_TEMPLATE);let tmpDir=this._nd.path.join(this._tmpDir,tmpFile);rc=this._fsUtils.createFolder(tmpDir);if(typeof rc!=="boolean"){this._error(`Unable to create folder ${rc.message}`);break}var zipUtils=new this._nd.zipUtils;;rc=zipUtils.extractAll(tmpDir,ruleSet.container,true);if(typeof rc!=="boolean"){this._error(`Unable to extract from zip ('${rc.message}') : "${ruleSet.container}"`);break}ruleSet.path=tmpDir}rulePath=this._nd.path.join(ruleSet.path,RULE_FILE);rulesJson=this._loadJson(rulePath)}else{if(ruleSet.builtin){rulesJson=this._nd.AmdRulePackLoader(this._nd,rsi,ruleSet,this._RSI,this._error)}else if(ruleSet.amdpack){rulesJson=ruleSet.amdpack.rulesJson;rulesJson=JSON.parse(JSON.stringify(rulesJson))}}if(!rulesJson){continue}if(!rulesJson.title){rulesJson.title="unknown"}if(!rulesJson.version){rulesJson.version="0.0.0"}prefix=rulesJson.prefix;ruleSet.prefix=prefix;s+=(rsi?"\n":"")+" "+(rsi+1)+") "+rulesJson.title+"\n "+rulesJson.version+" : "+prefix+(ruleSet.builtin||ruleSet.amdpack?"":" -> "+(ruleSet.container?ruleSet.container:ruleSet.path));if(this._appCtx.isUnitTest&&!spocFound&&prefix==="SPOC"){ruleSet.builtin=true;if(prefix==="SPOC"){spocFound=true}if(prefix==="DEMO"){demoFound=true}}if(!demoFound&&prefix==="DEMO"){ruleSet.builtin=true;if(prefix==="DEMO"){demoFound=true}}if(!ruleSet.builtin){if(RESERVED_PACK_PREFIX.includes(prefix)){let rspath=rulePath?` at '${rulePath}'`:"";this._error(`Rule pack${rspath} cannot use use reserved prefix '${prefix}'!`);break}}for(j=0;j<this._rulesetSummary.length;j++){if(this._rulesetSummary[j].prefix===prefix){let rspath,rpath;if(rspath=this._rulesetSummary[j].path){rspath=` at '${this._rulesetSummary[j].path}'`}else{rspath=" by another rulepack"}rpath=rulePath?` at '${rulePath}'`:"";this._error(`Rule pack prefix '${prefix}'${rpath} ignored - previously defined${rspath}.`);break}}if(j<this._rulesetSummary.length){continue}this._rulesetSummary.push({title:rulesJson.title,path:ruleSet.path,version:rulesJson.version,prefix:rulesJson.prefix,status:ruleSet.status,packData:ruleSet.packData});++rulesetSummaryIndex;var reorder,nonReq,reqList=[];reorder=nonReq=false;reqList.length=0;for(ruleName in rulesJson.rules){rule=rulesJson.rules[ruleName];rule._rsi=rulesetSummaryIndex;if(this._ruleSets[rulesetSummaryIndex].builtin){rule[PROP_$BUILTIN]=true;if(!rule.hasOwnProperty("inservice")||rule.inservice){if(!Array.isArray(rule.group)){rule.group=[rule.group]}rule.group.push("jet-inservice")}}if(rule[PROP_$REQUIRED]){if(!reorder){reorder=nonReq}reqList.push(ruleName)}else{nonReq=true}if(rule.group){groups=groups||{};let rg=rule.group;if(typeof rg==="string"){arules=groups[rg];if(!arules){groups[rg]=arules=[]}arules.push(ruleName)}else if(Array.isArray(rg)){for(k=0;k<rg.length;k++){gname=rg[k];arules=groups[gname];if(!arules){groups[gname]=arules=[]}arules.push(ruleName)}}}if(rule.issueTag){if(typeof rule.issueTag!=="string"){this._error(`Syntax - rules.json for pack '${prefix}' rule '${ruleName}' : 'issueTag' is not a string.`);break}}}if(reorder){rulesJson.rules=this._promoteRequired(rulesJson.rules,rulesJson.prefix,reqList)}this._rulePacks.push({path:ruleSet.path,rulesJson:rulesJson});ruleSet.groupMap=groups;this._mergeRuleOptions(rulesJson,ruleSet.builtin)}catch(e){this._error(`Failure processing ruleset at '${rulePath}' (${e.message})`);errors=true}}if(s.length){let n=this._rulePacks.length;this._info(`[info]: ------ ${n} Built-in Rulepack${n===1?"":"s"} Loaded: --------`);this._info(s)}if(this._debugMode){this._debug("------ Group Mappings : --------");let self=this;this._ruleSets.forEach(s=>{self._debug(s.prefix+": "+(s.groupMap?JSON.stringify(s.groupMap,null,3):"none"))})}if(errors){return false}this._registry=new Registry(this._appCtx);this._postProcess_RuleMods_EnableDisable();this._postProcess_RuleNames();if(!this._processRuleSets(fnSetJafMsgIds)){return false}if(config.options.debug&&!isRuleDump||config.options.verbose&&!isRuleDump||isDryRun){var f=isDryRun||config.options.verbose?this._info:this._debug;var rules,opts;if(this._ruleCount){f("\n-------- Active Rule Summmary --------");for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];f("\n ["+(rsi+1)+"] Rule Set '"+rulePack.rulesJson.title+"'");rules=rulePack.rulesJson.rules;let n=0;for(ruleName in rules){opts=rules[ruleName];if(opts.enabled){f("\n "+ruleName+" : "+JSON.stringify(this._utils.extend(opts)));n++}}if(!n){f("\n "+"No rules enabled in pack.")}}}}return!errors};RuleSet.prototype._postProcess_RuleMods_EnableDisable=function(){var rs,rm,are,ard,count=0,n;rm=this._config.ruleMods;if(rm&&(rm.enable||rm.disable)){rs=this._ruleSets;if(are=rm.enable){n=_replaceGroups(are,rs);if(n){are=_removeDups(are);count+=n}}if(ard=rm.disable){n=_replaceGroups(ard,rs);if(n){ard=_removeDups(ard);count+=n}}this._enableDisableGroupRules(are,ard)}return count};RuleSet.prototype._enableDisableGroupRules=function(are,ard){var ar,rname,packs,rules,rule,enable,m1,i,j,k;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Enabling rules found in ruleMods.enable ---");if(!are){this._info("* None found")}}packs=this._rulePacks;i=2;ar=are;enable=true;m1="enabled";while(i){if(ar){for(j=0;j<ar.length;j++){rname=ar[j];for(k=0;k<packs.length;k++){rules=packs[k];if(rules){rules=rules.rulesJson;if(rules){rule=rules.rules[rname];if(rule){if(!enable&&rule.$required){this._error(`rule '${rname}' is mandatory and cannot be disabled using config 'ruleMods.disable' property.`);continue}rule.enabled=enable;if(this._verboseMode||this._debugMode){this._info(` Rule ${rname} ${m1}`)}break}}}}}}if(enable){ar=ard;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Disabling rules found in ruleMods.disable ---");m1="disabled";if(!ard){this._info("* None found")}}if(!ard){return}}enable=false;i--}};RuleSet.prototype._postProcess_RuleNames=function(){var ret=0;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Processing config ruleNames entries ---")}if(this._config.ruleNames){ret=_replaceGroups(this._config.ruleNames,this._ruleSets);this._config.ruleNames=_removeDups(this._config.ruleNames)}if(this._verboseMode||this._debugMode){this._info(`\n[Info]: ${ret} ruleNames group entr${ret===1?"y":"ies"} replaced ---`)}return ret};function _replaceGroups(ar,rs){var val,o,group,grules,rc=0,rsi,i;var replaced=[];for(i=0;i<ar.length;i++){val=ar[i];replaced.length=0;for(rsi=0;rsi<rs.length;rsi++){o=rs[rsi];if(o.groupMap){for(group in o.groupMap){if(group===val){grules=o.groupMap[group];replaced.push(...grules);break}}}}if(replaced.length){ar.splice(i,1,...replaced);i+=replaced.length-1;rc++}}return rc};RuleSet.prototype._promoteRequired=function(rules,prefix,reqList){var ret={},keys,rule,n;for(rule of reqList){ret[rule]=rules[rule]}keys=Object.keys(rules);for(rule of keys){if(!rules[rule][PROP_$REQUIRED]){ret[rule]=rules[rule]}}if(this._debugMode||this._verboseMode){this._info(`\n[Info]: Rulepack '${prefix}' - ${reqList.length} rule${reqList.length===1?"":"s"} promoted to top for early $required loading`);let s="";for(n=0;n<reqList.length;n++){s+=" "+(n+1)+"] "+reqList[n]+"\n"}this._info(s+"\n");if(this._debugMode){this._info(`\n[Info]: Rulepack '${prefix}' - Loading Order`);n=0;s="";for(rule in ret){s+=" "+(n+1)+"] "+rule+"\n";n++}this._info(s+"\n")}}return ret?ret:rules};function _removeDups(ar){return[...new Set(ar)]};RuleSet.prototype.dumpRegistry=function(){if(this._registry.isEmpty()){console.log("\n--reg : Nothing to report, no rules active")}else{console.log("\n-------- Active Rule Type Listener Types --------");console.log(this._registry.dump())}};RuleSet.prototype.getRulePacks=function(){return this._rulePacks};RuleSet.prototype.getRuleSets=function(){return this._ruleSets};RuleSet.prototype.getRulePacksSummary=function(){return this._rulesetSummary};RuleSet.prototype.getShadowRulePacks=function(){return this._shadowRulePacks};RuleSet.prototype.getActiveRuleCount=function(){return this._ruleCount};RuleSet.prototype.getActiveFiletypes=function(){return this._targFiletypes?this._targFiletypes:[]};RuleSet.prototype.getRegistry=function(){return this._registry};RuleSet.prototype.getRulesetSummary=function(){return this._rulesetSummary};RuleSet.prototype.getRsiFromMsgId=function(msgId){var i,prefix,ret=-1;i=msgId.indexOf("-");prefix=i>=0?msgId.substring(0,i):msgId;if(this._rulesetSummary){for(i=0;i<this._rulesetSummary.length;i++){if(this._rulesetSummary[i].prefix===prefix){ret=i;break}}}return ret};RuleSet.prototype.loadMsgIds=function(coreLoad,jafLoad){var msgObj,rp,rs,o,rsi,fpath,err;if(coreLoad){this._msgIds=null}if(!coreLoad&&!jafLoad){if(this._msgIds){return this._msgIds}}if(this._rulePacks&&this._rulePacks.length){for(rsi=0;rsi<this._rulePacks.length;rsi++){rp=this._rulePacks[rsi];rs=this._ruleSets[rsi];if(rs.builtin&&NO_MSGID_PACKS.includes(rs.prefix)){continue}if(rs.enabled){if(!msgObj){msgObj={}}o=null;try{if(this._isCliOrApi){fpath=this._nd.path.join(rp.path,"msgid.json");if(rs.builtin||this._fsUtils.fileExists(fpath)){o=this._nd.msgidLoader(fpath,this._nd,this._RSI,this._appCtx)}}else{if(rs.builtin){o=this._nd.msgidLoader(this._nd,rsi,this._ruleSets[rsi],this._RSI,this._error)}else if(rs.amdpack&&rs.amdpack.msgid){o=rs.amdpack.msgid}}}catch(e){this._error(`'Failed to load ${rs.builtin?"built-in":"external"} rulepack msgid file : ${e.message}`);err=true;o=null}msgObj[rp.rulesJson.prefix]=o}if(jafLoad){break}}}return err?-1:this._msgIds=msgObj};RuleSet.prototype.getMsgIds=function(){return this._msgIds};RuleSet.prototype.getLoadedRule=function(rsi,ruleName){return this._shadowRulePacks[rsi][ruleName]};RuleSet.prototype.getSemVer=function(){return this._semVer};RuleSet.prototype._processRuleSets=function(fnSetJafMsgIds){var ruleName,ruleNamesWild,rulePack,rules,opts,opt,ruleJS,rule,rulePath,packStat,rset,callbacks,callback,atLine,rn,rsi,temp,s,i,j;for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];rules=rulePack.rulesJson.rules;rulePack.rulePack=new RulePack(this._rulesetSummary,this._rulePacks,this._shadowRulePacks,rsi,this._appCtx);this._registerCtx.rulePack=rulePack.rulePack;packStat=this._rulesetSummary[rsi].status;for(ruleName in rules){opts=rules[ruleName];if(this._debugMode){this._debug(`Loading rule '${ruleName}'`)}if(opts.hasOwnProperty("inservice")){if(!opts.inservice){this._showIgnoredRule(`rule '${ruleName}' is not in service - ignored`);opts.enabled=false;continue}}try{if(this._isAMD){if(!_isAMDRule(opts)){this._showIgnoredRule(`rule '${ruleName}' is not supported in AMD mode - ignored`);opts.enabled=false;continue}}opts.enabled=typeof opts.enabled==="boolean"?opts.enabled:true;if(!opts.enabled){this._showIgnoredRule(`rule '${ruleName}' is disabled - ignored`);continue}if(opts._rsi===undefined){this._showIgnoredRule(`rule '${ruleName}' does not belong to an active ruleset - ignored`);opts.enabled=false;continue}if(opts.severity){if(typeof opts.severity!=="string"||!this._severity.isValidRuleSeverity(opts.severity)){this._showIgnoredRule(`rule '${ruleName}' has invalid 'severity' of ${opts.severity} - assuming default of '${this._severity.DEFAULT}'`,true);opts.severity=this._severity.DEFAULT;opts.enabled=false}}else{opts.severity=this._severity.DEFAULT}if(opts.group){if(rsi&&!this._isGroupActive(opts.group)){this._showIgnoredRule(`rule '${ruleName}' ignored by group`);opts.enabled=false;continue}}if(!opts.status){opts.status="production"}if(!RULE_STATUS.includes(opts.status)){this._showIgnoredRule(`rule '${ruleName}' invalid 'status' (i.e. not 'production', 'prod', 'ready', 'deprecated', 'beta', 'alpha'`,true);opts.enabled=false;continue}if(!_isStatEnabledByPack(packStat,opts.status)){this._showIgnoredRule(`rule '${ruleName}' status does not match rulepack status - ignored`);opts.enabled=false;continue}if(opts.filetype){var __self=this;function _unsupFileType(opts,isArray){let ft=isArray?opts.filetype.join("', '"):opts.filetype;__self._showIgnoredRule(`rule '${ruleName}' ignored by 'filetype' value${isArray?"s":""} '${ft}'`);opts.enabled=false};if(Array.isArray(opts.filetype)){let ftcount=0;for(j=0;j<opts.filetype.length;j++){opts.filetype[j]=opts.filetype[j].toLowerCase();if(!FILETYPE.isFileTypeSupported(opts.filetype[j])){ftcount++;continue}}if(ftcount===opts.filetype.length){if(!opts.$required){_unsupFileType(opts,true);continue}}}else{if(!FILETYPE.isFileTypeSupported(opts.filetype)){if(!opts.$required){_unsupFileType(opts,false);continue}}}}if(!ruleName.startsWith("jaf-")&&this._confNamedRules&&this._confNamedRules.length){if(!ruleNamesWild){ruleNamesWild=[];for(j=0;j<this._confNamedRules.length;j++){rn=this._confNamedRules[j];ruleNamesWild.push(_isRE(rn)?new RegExp(rn):null)}}for(j=0;j<this._confNamedRules.length;j++){if(this._confNamedRules.includes(ruleName)){break}rn=ruleNamesWild[j];if(rn){if(rn.test(ruleName)){break}}}if(j>=this._confNamedRules.length){if(opts.$required){this._showIgnoredRule(`rule '${ruleName}' not excluded by config 'ruleNames'- rule is mandatory`)}else{this._showIgnoredRule(`rule '${ruleName}' ignored - excluded by config 'ruleNames'`);opts.enabled=false}continue}}if(opts.jetver){if(!this._semVer.match(opts.jetver)){this._showIgnoredRule(`rule '${ruleName}' ignored : 'jetVer' option is '${opts.jetver}' but metadata is '${this._semVer.getReference()}'`);opts.enabled=false;continue}}if(opts.theme){temp=opts.theme;if(typeof temp==="string"){temp=opts.theme.toLowerCase();if(temp==="redwood"||temp==="alta"){opts.theme=temp.charAt(0).toUpperCase()+temp.substring(1);if(this._config.theme!==opts.theme){this._showIgnoredRule(`rule '${ruleName}' ignored : 'theme' option '${opts.theme}' excluded by config '${this._config.theme}'`);opts.enabled=false;continue}}else{this._showIgnoredRule(`rule '${ruleName}' theme option '${opts.theme}' - must be 'Redwood' or 'Alta'`,true);opts.enabled=false}}else{if(!Array.isArray(temp)){this._showIgnoredRule(`rule '${ruleName}' theme option - must be a string or a string array`,true);opts.enabled=false;continue}temp.forEach((theme,idx)=>{theme=theme.toLowerCase();if(theme==="redwood"||theme==="alta"){theme=theme.charAt(0).toUpperCase()+theme.substring(1);temp[idx]=theme}else{this._showIgnoredRule(`rule '${ruleName}' theme option '${theme}' - must be 'Redwood' or 'Alta'`,true);opts.enabled=false}});if(opts.enabled&&!opts.theme.includes(this._config.theme)){this._showIgnoredRule(`rule '${ruleName}' ignored : 'theme' option '${opts.theme}' excluded by config '${this._config.theme}'`);opts.enabled=false}}}if(opts.hasOwnProperty("customOpts")){if(!this._utils.isObject(opts.customOpts)){this._error(`rule '${ruleName}' - rule option 'customOpts' is not an object`);opts.enabled=false;continue}}if(opts.enabled){for(opt in opts){let custOpts;if(!this._isJafRuleOption(opt)){if(RESERVED_PACK_PREFIX.indexOf(rulePack.rulesJson.prefix)<0){this._msgCtx.jafMsg("jaf-sys-rule-opt",`Warning - rule '${ruleName}' user option property '${opt}' should be moved to the rule's 'customOpts' property.`,"W")}if(opts.hasOwnProperty("customOpts")){custOpts=opts.customOpts}else{opts.customOpts=custOpts={}}if(!custOpts.hasOwnProperty(opt)){custOpts[opt]=opts[opt]}}}}if(this._isCliOrApi){rulePath=this._rulesetSummary[opts._rsi].path;rulePath=this._nd.path.join(rulePath,ruleName+".js");ruleJS=this._nd.ruleLoader(rulePath)}else{rset=this._ruleSets[opts._rsi];if(rset.builtin){ruleJS=this._nd.ruleLoader(ruleName,opts._rsi,this._error)}else if(rset.amdpack){ruleJS=rset.amdpack.rules[ruleName]}}if(!ruleJS){continue}rule=ruleJS;if(rset&&rset.amdpack){try{rule=new ruleJS.default}catch(e){this._showIgnoredRule(`AMD rule '${ruleName}' ${e.message}`,true);rule=null;continue}}else{if(ruleJS.prototype||!ruleJS.getName){try{rule=new ruleJS}catch(e){this._showIgnoredRule(`rule '${ruleName}' ${e.message}`,true);rule=null;continue}}}if(!opts.$internal){if(typeof rule.register!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no register() method`,true);opts.enabled=false;continue}}if(typeof rule.getName!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getName() method`,true);opts.enabled=false;continue}if(typeof rule.getDescription!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getDescription() method`,true);opts.enabled=false;continue}if(typeof rule.getShortDescription!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getShortDescription() method`,true);opts.enabled=false;continue}if(ruleName!==rule.getName()){this._showIgnoredRule(`rule '${ruleName}' ignored - name '${rule.getName()}' does not match external name '${ruleName}`,true);opts.enabled=false;continue}if(!opts.$internal){this._registerCtx.ruleOpts=clone.cloneOptions(opts);if(opts.filetype){let FTypeIsArray=Array.isArray(opts.filetype);if(FTypeIsArray||typeof opts.filetype==="string"){if(opts.filetype==="js"||FTypeIsArray&&opts.filetype.includes("js")){this._registerCtx.jsNodeTypes=AstNodeTypes}else if(opts.filetype==="ts"||FTypeIsArray&&opts.filetype.includes("ts")){this._registerCtx.tsNodeTypes=AstNodeTypes}else if(opts.filetype==="tsx"||FTypeIsArray&&opts.filetype.includes("tsx")){this._registerCtx.tsNodeTypes=AstNodeTypes;this._registerCtx.utils.tsxUtils=this._tsxUtils}}}if(this._isCliOrApi){this._registerCtx.utils.fsUtils=this._fsUtils;if(ruleName==="oj-html-cspexpr"){this._registerCtx.decache=this._nd.decache}}this._registerCtx.ruleName=ruleName;this._registerCtx.rulePack._setCBCtx(this._registerCtx);callbacks=rule.register(this._registerCtx);if(!callbacks){this._showIgnoredRule(`rule '${ruleName}' has disabled itself during registration`);opts.enabled=false;continue}for(callback in callbacks){if(callbacks[callback]){callbacks[callback]=callbacks[callback].bind(rule)}else{s=`rule '${ruleName}': listener for '${callback}' in register() is not defined - rule is disabled`;this._error(s);this._showIgnoredRule(s);opts.enabled=false;continue}}if(_isHookRule(callbacks)){opts.$hook=true}else{if(!this._checkRuleSeverity(opts)){this._showIgnoredRule(`rule '${ruleName}' ignored by severity`);opts.enabled=false;continue}}}this._addToShadowRulePacks(ruleName,rule,opts);if(!opts.$internal){this._registry.setRuleCallback(ruleName,callbacks,opts._rsi)}this._ruleCount++;this._updateTargetFiletypes(opts)}catch(e){atLine=e.stack.replace(rulePath,"").trim();i=NaN;if(atLine.startsWith(COLON)){i=parseInt(atLine.substr(1))}if(!isNaN(i)){atLine=" line "+i+": "}else{i=atLine.indexOf(COLON);if(i<0){atLine=""}else{atLine=this._utils.eatLine(atLine,i);i=atLine.indexOf(COLON);if(i>=0){atLine=atLine.substring(i+1);i=atLine.indexOf(")");if(i>=0){atLine="("+atLine.substring(0,i).replace(COLON,",")+") - "}}else{atLine=""}};}this._showIgnoredRule(`Cannot load rule ${ruleName} [${atLine} '${e.message}']`,true)}}if(rsi===0){fnSetJafMsgIds(this.loadMsgIds(false,true))}}this._showIgnoredRule(null);return true};RuleSet.prototype._isJafRuleOption=function(prop){var prop_lc=prop.toLowerCase();return RULE_OPTS_JAF.includes(prop_lc)||JAF_RULEOPT_RE.test(prop_lc)};RuleSet.prototype._showIgnoredRule=function(msg,isError){if(msg){if(!this._ignoredRulesShown){this._info("\n--------- Start-up Rule analysis ---------");this._ignoredRulesShown=true}isError?this._error(msg):this._info(msg)}else if(this._ignoredRulesShown){this._info("------------ End Rule analysis -------------")}};RuleSet.prototype._mergeRuleOptions=function(rulesJson,isBuiltinRules){var prefix,rules,overrides,ruleName,opts,error,x;this._debug("Augmenting config defined rules in rulePack from ruleMods...");prefix=rulesJson.prefix;rules=rulesJson.rules;overrides=this._getRuleModsByPrefix(prefix);for(ruleName in rules){error=false;if(!isBuiltinRules){x=RESERVED_RULE_PREFIX.indexOf(ruleName.toLowerCase());if(x>=0){this._showIgnoredRule(`rule '${ruleName}' in rulepack (prefix: '${prefix}') must not use JET reserved prefix '${RESERVED_RULE_PREFIX[x]}'`,true);error=true}}if(overrides){if(error){continue}if(overrides.hasOwnProperty(ruleName)&&rules[ruleName]){if(this._isAMD){opts=rules[ruleName];if(!_isAMDRule(opts)){if(this._debugMode){this._debug(`Rule options override ignored for non-AMD ${ruleName} in AMD mode`)}continue}if(!this._nd.ruleLoader(ruleName,opts._rsi,this._error)){continue}}if(this._debugMode){this._debug(`Merging rule props of ${ruleName}`)}this._mergeOverrideProps(ruleName,overrides[ruleName],rules[ruleName],isBuiltinRules)}}}};RuleSet.prototype._mergeOverrideProps=function(ruleName,configOpts,ruleOpts){var prop;function _mergeCustomOpts(ruleCustomOpts,modCustomOpts){var p;for(p in modCustomOpts){ruleCustomOpts[p]=modCustomOpts[p]}};for(prop in configOpts){if(prop.charAt(0)==="$"){delete configOpts[prop];this._showIgnoredRule(`rule '${ruleName}' : '${prop}' in config 'rulesMod' cannot use reserved '$' prefix`,true);continue}if(prop==="enabled"&&!configOpts[prop]&&ruleOpts["$required"]){this._showIgnoredRule(`rule '${ruleName}' is mandatory and cannot be disabled using config 'ruleMods' property.`,true);continue}if(prop==="customOpts"){if(!ruleOpts.customOpts){ruleOpts[prop]=configOpts[prop]}else{_mergeCustomOpts(ruleOpts.customOpts,configOpts.customOpts)}}else{ruleOpts[prop]=configOpts[prop];if(prop===OPT_SEVERITY){ruleOpts.$sevLocked=true}}}};RuleSet.prototype._addToShadowRulePacks=function(ruleName,loadedRule,ruleOpts){var rsi=ruleOpts._rsi;var srp=this._shadowRulePacks;while(rsi>=srp.length){srp.push({})}srp[rsi][ruleName]=loadedRule};RuleSet.prototype._updateTargetFiletypes=function(opts){var ft=opts.filetype;if(ft){if(typeof ft==="string"){ft=[ft]}ft.forEach(t=>{if(!opts.$internal){if(!this._targFiletypes.includes(t)){this._targFiletypes.push(t)}}},this)}};RuleSet.prototype._getRuleModsByPrefix=function(prefix){var modPrefix,ret;if(this._ruleMods){prefix=prefix.toLowerCase();for(modPrefix in this._ruleMods){if(prefix===modPrefix.toLowerCase()){ret=this._ruleMods[modPrefix];break}}}return ret};RuleSet.prototype._isGroupActive=function(group){var groups,defs,def,i;groups=this._config.groups;defs=this._config.defGroups;if(this._checkGroups(groups,group)){return true}if(!defs){return false}for(i=0;i<groups.length;i++){def=groups[i];if(this._checkDefGroup(defs,def,group)){return true}}return false};RuleSet.prototype._checkGroups=function(cfgGroups,ruleGroup){var theGroup,i;if(Array.isArray(ruleGroup)){for(i=0;i<ruleGroup.length;i++){theGroup=ruleGroup[i];if(this._checkGroup(cfgGroups,theGroup)){return true}}}else if(this._checkGroup(cfgGroups,ruleGroup)){return true}return false};RuleSet.prototype._checkGroup=function(cfgGroups,group){return!cfgGroups||cfgGroups.includes(group)||cfgGroups.includes(this._severity.ALL)};RuleSet.prototype._isJetInRuleSet=function(jetPrefix){var i,ret=false;if(this._ruleSets&&this._ruleSets.length){for(i=0;i<this._ruleSets.length;i++){if(this._ruleSets[i].prefix===jetPrefix){ret=true;break}}}return ret};RuleSet.prototype._checkRuleSeverity=function(opts){var severities,severity,_sev,i,ret=false;severities=this._config.severity;severity=opts.severity;if(typeof severities==="string"){_sev=this._severity.getConfigSevExpr();if(_sev){ret=true}else{ret=severity===severities||severities===this._severity.ALL}}else{for(var i=0;i<severities.length;i++){if(severity===severities[i]||severities[i]===this._severity.ALL){ret=true;break}}}return ret};RuleSet.prototype._loadJson=function(filepath){var data,stats,msg;try{stats=this._nd.fs.lstatSync(filepath);if(!stats.isFile()){this._error(`RuleSet '${filepath}' not found!`);return null}else{data=this._nd.fs.readFileSync(filepath,"utf8");data=JSON.parse(this._nd.decomment(data))}}catch(e){if(e.code){if(e.message.startsWith("ENOENT:")){this._error(`RuleSet error - '${filepath}' not found!`)}}else if(e.toString().startsWith("SyntaxError")){msg=_convertMsgToRowCol(e.message,data,this._utils)}else{msg=e.message}if(msg){this._error(`JSON load error '${filepath}' - ${msg}`)}data=null}return data};function _isStatEnabledByPack(pstat,rstat){var ret=false;if(pstat.includes("all")||pstat.includes(rstat)){ret=true}else{if(rstat==="ready"||rstat.startsWith("prod")){ret=pstat.includes("ready")||pstat.includes("production")||pstat.includes("prod")}}return ret};function _isHookRule(callbacks){return callbacks[REG.PHASE_STARTUP]||callbacks[REG.PHASE_CLOSEDOWN]||callbacks[REG.PHASE_FILE]?true:false};function _isAMDRule(opts){return opts.hasOwnProperty("amd")?!!opts.amd:true};function _convertMsgToRowCol(msg,data,utils){var x,n,rc;x=msg.indexOf("position");if(x<0){return msg}n=parseInt(msg.substr(x+8).trim());rc=utils.getRowColFromIndex(data,n);return msg.substr(0,x)+"line "+rc.row+", col "+rc.col};function _isRE(s){return RULE_RE.test(s)};module.exports=RuleSet;
6
+ const REG=require("./RegTypes");const FILETYPE=require("./filetypes");const RULE_FILE="rules.json";const BUILTIN_RULES_PATH="../rules/";const BUILTIN_RULEPACK_PATH="../rulepacks/";const JAF_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jaf";const JET_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jet";const SPOC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"spoc";const OJC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"ojc";const VDOM_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"vdom";const JETVDOM_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetvdom";const CSP_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"csp";const JETWC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwc";const JETWCO_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwco";const VCOMPMIG_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"ojcmig";const WEBDRIVER_TEST_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"wdt";const JET_MIN_VERSION="5.2.0";const TEMP_FILE_TEMPLATE="@@rpziptmp-XXXXXX";const PROP_$BUILTIN="$builtin";const PROP_$REQUIRED="$required";const RESERVED_RULE_PREFIX=["oj-","jaf-","csp-","spoc-","jetwc-","jetwco-","wdt-","vdom-","jetvdom-","exch-","demo-"];const RESERVED_PACK_PREFIX=["JAF","JET","SPOC","CSP","JETWC","JETWCO","VDOM","JETVDOM","WDT","DEMO"];const NO_MSGID_PACKS=[];const RULE_STATUS=["prod","production","ready","beta","alpha","deprecated"];const RULE_OPTS_JAF=["enabled","severity","status","filetype","group","jetver","theme","inservice","amd","customopts","issuetag"];const OPT_SEVERITY="severity";const FUNCTION="function";const COLON=":";const RULE_RE=new RegExp(/[~`!#$%\^&*+\[\]\\';,/{}|\\"\?]/,"g");const JAF_RULEOPT_RE=RegExp(/^(\$|jet|jaf|oj|vdom|spoc|wdt|csp|_)/);const RulePack=require("./RulePack");const Registry=require("./Registry");const SemVer=require("./SemVer");const CssUtils=require("./CssUtils");const AstNodeTypes=require("./AstNodeTypes");const clone=require("./clone");var RuleSet=function(config,nodeDeps,appCtx,msgCtx,AMDRulePacks){this._config=config;this._ruleSets=config.getRulePacks();this._ruleMods=config.getRuleMods();this._ruleCount=0;this._AmdPacks=AMDRulePacks;this._appCtx=appCtx;this._nd=nodeDeps;this._isAMD=!!nodeDeps.AmdRulePackLoader;this._isCLI=appCtx.runMode==="cli";this._isCliOrApi=!this._isAMD;this._metaLib=appCtx.metaLib;this._utils=appCtx.utils;this._fsUtils=appCtx.fsUtils;this._tsxUtils=appCtx.tsxUtils;this._severity=appCtx.severity;this._tmpDir=appCtx.tmpDir;this._semVer=new SemVer;this._targFiletypes=[];this._msgIds=null;this._useBuiltinRules=config._config.builtinJetRules;this._rulePacks=null;this._shadowRulePacks=null;this._rulesetSummary=[];this._RSI={};this._registerCtx={sysOpts:{verboseMode:this._appCtx.verboseMode,debugMode:this._appCtx.debugMode}};this._registerCtx.utils={};this._registerCtx.utils.metaLib=this._metaLib.getPublicInterface();this._registerCtx.runMode=appCtx.runMode;this._registerCtx.VsCodeExtHint=appCtx.VsCodeExtHint;this._registerCtx.utils.semVerUtils=this._semVer;this._registerCtx.utils.utils=this._utils;this._registerCtx.utils.CssUtils=CssUtils;this._registerCtx.config=JSON.parse(JSON.stringify(this._config._config));this._registerCtx.utils.msgLib={msg:msgCtx.msg,error:msgCtx.error,info:msgCtx.info,debug:msgCtx.debug,assert:msgCtx.assert};this._registerCtx.utils.sevLib=this._severity.getSevLib();this._registerCtx.utils.OjetLib=appCtx.ojetLib;this._registerCtx.utils.pluginLib=appCtx.plugin.getPluginLib();this._msgCtx=msgCtx;this._msg=msgCtx.msg;this._info=msgCtx.info;this._debug=msgCtx.debug;this._error=msgCtx.error;this._warn=msgCtx.warn;this._assert=msgCtx.assert;this._debugMode=msgCtx.isDebug;this._verboseMode=msgCtx.isVerbose;if(!this._ruleSets){this._ruleSets=[]}let rsi=this._RSI.JAF=0;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JAF_BUILTIN_RULES_PATH):null,"builtin":true});if(config._config.builtinJetRules){this._RSI.JET=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JET_BUILTIN_RULES_PATH):null,"builtin":true});this._RSI.OJC=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,OJC_BUILTIN_RULES_PATH):null,"builtin":true});this._RSI.VDOM=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,VDOM_BUILTIN_RULES_PATH):null,"builtin":true});this._RSI.JETVDOM=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JETVDOM_BUILTIN_RULES_PATH):null,"builtin":true})}if(config._config.builtinCspRules){this._RSI.CSP=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,CSP_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcRules){this._RSI.JETWC=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWC_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcOracleRules){this._RSI.JETWCO=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWCO_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinSpocRules){this._RSI.SPOC=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,SPOC_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinOjcMigrationRules){this._RSI.OJCMIG=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,VCOMPMIG_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinWebDriverTestRules){this._RSI.WEBDT=rsi;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,WEBDRIVER_TEST_BUILTIN_RULES_PATH),"builtin":true})}if(this._isAMD&&this._AmdPacks){let i,apack;for(i=0;i<this._AmdPacks.length;i++){if(apack=this._AmdPacks[i]){let amdpref=apack.rulesJson.prefix;if(amdpref){this._RSI[amdpref]=rsi}this._ruleSets.splice(rsi++,0,{enabled:true,path:null,builtin:false,amdpack:apack})}}}};RuleSet.prototype.loadRulePacks=function(config,isDryRun,isRuleDump,fnSetJafMsgIds){var ruleSet,rulePath,rulesJson,rulePack,rsi,rule,prefix,groups,gname,arules,j,k,s="",rulesetSummaryIndex=-1,spocFound,demoFound,errors=false,rc,ruleName,jetVersion;this._config=config;this._confSeverity=config._sev;this._confNamedRules=config.ruleNames;jetVersion=this._metaLib.getRevisionInfo().jetVersion.split("-")[0];if(!this._semVer.setReference(jetVersion,JET_MIN_VERSION)){this._error(`JET metadata version ${jetVersion} not supported (less than ${JET_MIN_VERSION})`);return false}if(this._debugMode){this._debug(this._ruleSets?"Processing "+this._ruleSets.length+" Rule Sets":"No Rule Sets defined")}if(!this._ruleSets){return false}this._rulePacks=[];this._shadowRulePacks=[];for(rsi=0;rsi<this._ruleSets.length;rsi++){ruleSet=this._ruleSets[rsi];groups=null;try{if(typeof ruleSet.enabled==="boolean"&&!ruleSet.enabled){s+=(rsi?"\n":"")+" "+(rsi+1)+") "+"Disabled ruleSet at '"+ruleSet.path;continue}if(!ruleSet.status){ruleSet.status=["all"]}if(!this._isAMD){if(this._debugMode){let rname=this._nd.path.basename(ruleSet.path);switch(rname){case"jaf":case"jet":case"spoc":rname=rname.toUpperCase();break;default:rname=ruleSet.name;break}this._debug(`Ruleset ${rname?"'rname'":""}path->'${ruleSet.path}'`)}if(ruleSet.path.endsWith(".zip")){ruleSet.container=ruleSet.path;let tmpFile=this._fsUtils.getUniqueFileName(TEMP_FILE_TEMPLATE);let tmpDir=this._nd.path.join(this._tmpDir,tmpFile);rc=this._fsUtils.createFolder(tmpDir);if(typeof rc!=="boolean"){this._error(`Unable to create folder ${rc.message}`);break}var zipUtils=new this._nd.zipUtils;;rc=zipUtils.extractAll(tmpDir,ruleSet.container,true);if(typeof rc!=="boolean"){this._error(`Unable to extract from zip ('${rc.message}') : "${ruleSet.container}"`);break}ruleSet.path=tmpDir}rulePath=this._nd.path.join(ruleSet.path,RULE_FILE);rulesJson=this._loadJson(rulePath)}else{if(ruleSet.builtin){rulesJson=this._nd.AmdRulePackLoader(this._nd,rsi,ruleSet,this._RSI,this._error)}else if(ruleSet.amdpack){rulesJson=ruleSet.amdpack.rulesJson;rulesJson=JSON.parse(JSON.stringify(rulesJson))}}if(!rulesJson){continue}if(!rulesJson.title){rulesJson.title="unknown"}if(!rulesJson.version){rulesJson.version="0.0.0"}prefix=rulesJson.prefix;ruleSet.prefix=prefix;s+=(rsi?"\n":"")+" "+(rsi+1)+") "+rulesJson.title+"\n "+rulesJson.version+" : "+prefix+(ruleSet.builtin||ruleSet.amdpack?"":" -> "+(ruleSet.container?ruleSet.container:ruleSet.path));if(this._appCtx.isUnitTest&&!spocFound&&prefix==="SPOC"){ruleSet.builtin=true;if(prefix==="SPOC"){spocFound=true}if(prefix==="DEMO"){demoFound=true}}if(!demoFound&&prefix==="DEMO"){ruleSet.builtin=true;if(prefix==="DEMO"){demoFound=true}}if(!ruleSet.builtin){if(RESERVED_PACK_PREFIX.includes(prefix)){let rspath=rulePath?` at '${rulePath}'`:"";this._error(`Rule pack${rspath} cannot use use reserved prefix '${prefix}'!`);break}}for(j=0;j<this._rulesetSummary.length;j++){if(this._rulesetSummary[j].prefix===prefix){let rspath,rpath;if(rspath=this._rulesetSummary[j].path){rspath=` at '${this._rulesetSummary[j].path}'`}else{rspath=" by another rulepack"}rpath=rulePath?` at '${rulePath}'`:"";this._error(`Rule pack prefix '${prefix}'${rpath} ignored - previously defined${rspath}.`);break}}if(j<this._rulesetSummary.length){continue}this._rulesetSummary.push({title:rulesJson.title,path:ruleSet.path,version:rulesJson.version,prefix:rulesJson.prefix,status:ruleSet.status,packData:ruleSet.packData});++rulesetSummaryIndex;var reorder,nonReq,reqList=[];reorder=nonReq=false;reqList.length=0;for(ruleName in rulesJson.rules){rule=rulesJson.rules[ruleName];rule._rsi=rulesetSummaryIndex;if(this._ruleSets[rulesetSummaryIndex].builtin){rule[PROP_$BUILTIN]=true;if(!rule.hasOwnProperty("inservice")||rule.inservice){if(!Array.isArray(rule.group)){rule.group=[rule.group]}rule.group.push("jet-inservice")}}if(rule[PROP_$REQUIRED]){if(!reorder){reorder=nonReq}reqList.push(ruleName)}else{nonReq=true}if(rule.group){groups=groups||{};let rg=rule.group;if(typeof rg==="string"){arules=groups[rg];if(!arules){groups[rg]=arules=[]}arules.push(ruleName)}else if(Array.isArray(rg)){for(k=0;k<rg.length;k++){gname=rg[k];arules=groups[gname];if(!arules){groups[gname]=arules=[]}arules.push(ruleName)}}}if(rule.issueTag){if(typeof rule.issueTag!=="string"){this._error(`Syntax - rules.json for pack '${prefix}' rule '${ruleName}' : 'issueTag' is not a string.`);break}}}if(reorder){rulesJson.rules=this._promoteRequired(rulesJson.rules,rulesJson.prefix,reqList)}this._rulePacks.push({path:ruleSet.path,rulesJson:rulesJson});ruleSet.groupMap=groups;this._mergeRuleOptions(rulesJson,ruleSet.builtin)}catch(e){this._error(`Failure processing ruleset at '${rulePath}' (${e.message})`);errors=true}}if(s.length){let n=this._rulePacks.length;this._info(`[info]: ------ ${n} Built-in Rulepack${n===1?"":"s"} Loaded: --------`);this._info(s)}if(this._debugMode){this._debug("------ Group Mappings : --------");let self=this;this._ruleSets.forEach(s=>{self._debug(s.prefix+": "+(s.groupMap?JSON.stringify(s.groupMap,null,3):"none"))})}if(errors){return false}this._registry=new Registry(this._appCtx);this._postProcess_RuleMods_EnableDisable();this._postProcess_RuleNames();if(!this._processRuleSets(fnSetJafMsgIds)){return false}if(config.options.debug&&!isRuleDump||config.options.verbose&&!isRuleDump||isDryRun){var f=isDryRun||config.options.verbose?this._info:this._debug;var rules,opts;if(this._ruleCount){f("\n-------- Active Rule Summmary --------");for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];f("\n ["+(rsi+1)+"] Rule Set '"+rulePack.rulesJson.title+"'");rules=rulePack.rulesJson.rules;let n=0;for(ruleName in rules){opts=rules[ruleName];if(opts.enabled){f("\n "+ruleName+" : "+JSON.stringify(this._utils.extend(opts)));n++}}if(!n){f("\n "+"No rules enabled in pack.")}}}}return!errors};RuleSet.prototype._postProcess_RuleMods_EnableDisable=function(){var rs,rm,are,ard,count=0,n;rm=this._config.ruleMods;if(rm&&(rm.enable||rm.disable)){rs=this._ruleSets;if(are=rm.enable){n=_replaceGroups(are,rs);if(n){are=_removeDups(are);count+=n}}if(ard=rm.disable){n=_replaceGroups(ard,rs);if(n){ard=_removeDups(ard);count+=n}}this._enableDisableGroupRules(are,ard)}return count};RuleSet.prototype._enableDisableGroupRules=function(are,ard){var ar,rname,packs,rules,rule,enable,m1,i,j,k;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Enabling rules found in ruleMods.enable ---");if(!are){this._info("* None found")}}packs=this._rulePacks;i=2;ar=are;enable=true;m1="enabled";while(i){if(ar){for(j=0;j<ar.length;j++){rname=ar[j];for(k=0;k<packs.length;k++){rules=packs[k];if(rules){rules=rules.rulesJson;if(rules){rule=rules.rules[rname];if(rule){if(!enable&&rule.$required){this._error(`rule '${rname}' is mandatory and cannot be disabled using config 'ruleMods.disable' property.`);continue}rule.enabled=enable;if(this._verboseMode||this._debugMode){this._info(` Rule ${rname} ${m1}`)}break}}}}}}if(enable){ar=ard;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Disabling rules found in ruleMods.disable ---");m1="disabled";if(!ard){this._info("* None found")}}if(!ard){return}}enable=false;i--}};RuleSet.prototype._postProcess_RuleNames=function(){var ret=0;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Processing config ruleNames entries ---")}if(this._config.ruleNames){ret=_replaceGroups(this._config.ruleNames,this._ruleSets);this._config.ruleNames=_removeDups(this._config.ruleNames)}if(this._verboseMode||this._debugMode){this._info(`\n[Info]: ${ret} ruleNames group entr${ret===1?"y":"ies"} replaced ---`)}return ret};function _replaceGroups(ar,rs){var val,o,group,grules,rc=0,rsi,i;var replaced=[];for(i=0;i<ar.length;i++){val=ar[i];replaced.length=0;for(rsi=0;rsi<rs.length;rsi++){o=rs[rsi];if(o.groupMap){for(group in o.groupMap){if(group===val){grules=o.groupMap[group];replaced.push(...grules);break}}}}if(replaced.length){ar.splice(i,1,...replaced);i+=replaced.length-1;rc++}}return rc};RuleSet.prototype._promoteRequired=function(rules,prefix,reqList){var ret={},keys,rule,n;for(rule of reqList){ret[rule]=rules[rule]}keys=Object.keys(rules);for(rule of keys){if(!rules[rule][PROP_$REQUIRED]){ret[rule]=rules[rule]}}if(this._debugMode||this._verboseMode){this._info(`\n[Info]: Rulepack '${prefix}' - ${reqList.length} rule${reqList.length===1?"":"s"} promoted to top for early $required loading`);let s="";for(n=0;n<reqList.length;n++){s+=" "+(n+1)+"] "+reqList[n]+"\n"}this._info(s+"\n");if(this._debugMode){this._info(`\n[Info]: Rulepack '${prefix}' - Loading Order`);n=0;s="";for(rule in ret){s+=" "+(n+1)+"] "+rule+"\n";n++}this._info(s+"\n")}}return ret?ret:rules};function _removeDups(ar){return[...new Set(ar)]};RuleSet.prototype.dumpRegistry=function(){if(this._registry.isEmpty()){console.log("\n--reg : Nothing to report, no rules active")}else{console.log("\n-------- Active Rule Type Listener Types --------");console.log(this._registry.dump())}};RuleSet.prototype.getRulePacks=function(){return this._rulePacks};RuleSet.prototype.getRuleSets=function(){return this._ruleSets};RuleSet.prototype.getRulePacksSummary=function(){return this._rulesetSummary};RuleSet.prototype.getShadowRulePacks=function(){return this._shadowRulePacks};RuleSet.prototype.getActiveRuleCount=function(){return this._ruleCount};RuleSet.prototype.getActiveFiletypes=function(){return this._targFiletypes?this._targFiletypes:[]};RuleSet.prototype.getRegistry=function(){return this._registry};RuleSet.prototype.getRulesetSummary=function(){return this._rulesetSummary};RuleSet.prototype.getRsiFromMsgId=function(msgId){var i,prefix,ret=-1;i=msgId.indexOf("-");prefix=i>=0?msgId.substring(0,i):msgId;if(this._rulesetSummary){for(i=0;i<this._rulesetSummary.length;i++){if(this._rulesetSummary[i].prefix===prefix){ret=i;break}}}return ret};RuleSet.prototype.loadMsgIds=function(coreLoad,jafLoad){var msgObj,rp,rs,o,rsi,fpath,err;if(coreLoad){this._msgIds=null}if(!coreLoad&&!jafLoad){if(this._msgIds){return this._msgIds}}if(this._rulePacks&&this._rulePacks.length){for(rsi=0;rsi<this._rulePacks.length;rsi++){rp=this._rulePacks[rsi];rs=this._ruleSets[rsi];if(rs.builtin&&NO_MSGID_PACKS.includes(rs.prefix)){continue}if(rs.enabled){if(!msgObj){msgObj={}}o=null;try{if(this._isCliOrApi){fpath=this._nd.path.join(rp.path,"msgid.json");if(rs.builtin||this._fsUtils.fileExists(fpath)){o=this._nd.msgidLoader(fpath,this._nd,this._RSI,this._appCtx)}}else{if(rs.builtin){o=this._nd.msgidLoader(this._nd,rsi,this._ruleSets[rsi],this._RSI,this._error)}else if(rs.amdpack&&rs.amdpack.msgid){o=rs.amdpack.msgid}}}catch(e){this._error(`'Failed to load ${rs.builtin?"built-in":"external"} rulepack msgid file : ${e.message}`);err=true;o=null}msgObj[rp.rulesJson.prefix]=o}if(jafLoad){break}}}return err?-1:this._msgIds=msgObj};RuleSet.prototype.getMsgIds=function(){return this._msgIds};RuleSet.prototype.getLoadedRule=function(rsi,ruleName){return this._shadowRulePacks[rsi][ruleName]};RuleSet.prototype.getSemVer=function(){return this._semVer};RuleSet.prototype._processRuleSets=function(fnSetJafMsgIds){var ruleName,ruleNamesWild,rulePack,rules,opts,opt,ruleJS,rule,rulePath,packStat,rset,callbacks,callback,atLine,rn,rsi,temp,s,i,j;for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];rules=rulePack.rulesJson.rules;rulePack.rulePack=new RulePack(this._rulesetSummary,this._rulePacks,this._shadowRulePacks,rsi,this._appCtx);this._registerCtx.rulePack=rulePack.rulePack;packStat=this._rulesetSummary[rsi].status;for(ruleName in rules){opts=rules[ruleName];if(this._debugMode){this._debug(`Loading rule '${ruleName}'`)}if(opts.hasOwnProperty("inservice")){if(!opts.inservice){this._showIgnoredRule(`rule '${ruleName}' is not in service - ignored`);opts.enabled=false;continue}}try{if(this._isAMD){if(!_isAMDRule(opts)){this._showIgnoredRule(`rule '${ruleName}' is not supported in AMD mode - ignored`);opts.enabled=false;continue}}opts.enabled=typeof opts.enabled==="boolean"?opts.enabled:true;if(!opts.enabled){this._showIgnoredRule(`rule '${ruleName}' is disabled - ignored`);continue}if(opts._rsi===undefined){this._showIgnoredRule(`rule '${ruleName}' does not belong to an active ruleset - ignored`);opts.enabled=false;continue}if(opts.severity){if(typeof opts.severity!=="string"||!this._severity.isValidRuleSeverity(opts.severity)){this._showIgnoredRule(`rule '${ruleName}' has invalid 'severity' of ${opts.severity} - assuming default of '${this._severity.DEFAULT}'`,true);opts.severity=this._severity.DEFAULT;opts.enabled=false}}else{opts.severity=this._severity.DEFAULT}if(opts.group){if(rsi&&!this._isGroupActive(opts.group)){this._showIgnoredRule(`rule '${ruleName}' ignored by group`);opts.enabled=false;continue}}if(!opts.status){opts.status="production"}if(!RULE_STATUS.includes(opts.status)){this._showIgnoredRule(`rule '${ruleName}' invalid 'status' (i.e. not 'production', 'prod', 'ready', 'deprecated', 'beta', 'alpha'`,true);opts.enabled=false;continue}if(!_isStatEnabledByPack(packStat,opts.status)){this._showIgnoredRule(`rule '${ruleName}' status does not match rulepack status - ignored`);opts.enabled=false;continue}if(opts.filetype){var __self=this;function _unsupFileType(opts,isArray){let ft=isArray?opts.filetype.join("', '"):opts.filetype;__self._showIgnoredRule(`rule '${ruleName}' ignored by 'filetype' value${isArray?"s":""} '${ft}'`);opts.enabled=false};if(Array.isArray(opts.filetype)){let ftcount=0;for(j=0;j<opts.filetype.length;j++){opts.filetype[j]=opts.filetype[j].toLowerCase();if(!FILETYPE.isFileTypeSupported(opts.filetype[j])){ftcount++;continue}}if(ftcount===opts.filetype.length){if(!opts.$required){_unsupFileType(opts,true);continue}}}else{if(!FILETYPE.isFileTypeSupported(opts.filetype)){if(!opts.$required){_unsupFileType(opts,false);continue}}}}if(!ruleName.startsWith("jaf-")&&this._confNamedRules&&this._confNamedRules.length){if(!ruleNamesWild){ruleNamesWild=[];for(j=0;j<this._confNamedRules.length;j++){rn=this._confNamedRules[j];ruleNamesWild.push(_isRE(rn)?new RegExp(rn):null)}}for(j=0;j<this._confNamedRules.length;j++){if(this._confNamedRules.includes(ruleName)){break}rn=ruleNamesWild[j];if(rn){if(rn.test(ruleName)){break}}}if(j>=this._confNamedRules.length){if(opts.$required){this._showIgnoredRule(`rule '${ruleName}' not excluded by config 'ruleNames'- rule is mandatory`)}else{this._showIgnoredRule(`rule '${ruleName}' ignored - excluded by config 'ruleNames'`);opts.enabled=false}continue}}if(opts.jetver){if(!this._semVer.match(opts.jetver)){this._showIgnoredRule(`rule '${ruleName}' ignored : 'jetVer' option is '${opts.jetver}' but metadata is '${this._semVer.getReference()}'`);opts.enabled=false;continue}}if(opts.theme){temp=opts.theme;if(typeof temp==="string"){temp=opts.theme.toLowerCase();if(temp==="redwood"||temp==="alta"){opts.theme=temp.charAt(0).toUpperCase()+temp.substring(1);if(this._config.theme!==opts.theme){this._showIgnoredRule(`rule '${ruleName}' ignored : 'theme' option '${opts.theme}' excluded by config '${this._config.theme}'`);opts.enabled=false;continue}}else{this._showIgnoredRule(`rule '${ruleName}' theme option '${opts.theme}' - must be 'Redwood' or 'Alta'`,true);opts.enabled=false}}else{if(!Array.isArray(temp)){this._showIgnoredRule(`rule '${ruleName}' theme option - must be a string or a string array`,true);opts.enabled=false;continue}temp.forEach((theme,idx)=>{theme=theme.toLowerCase();if(theme==="redwood"||theme==="alta"){theme=theme.charAt(0).toUpperCase()+theme.substring(1);temp[idx]=theme}else{this._showIgnoredRule(`rule '${ruleName}' theme option '${theme}' - must be 'Redwood' or 'Alta'`,true);opts.enabled=false}});if(opts.enabled&&!opts.theme.includes(this._config.theme)){this._showIgnoredRule(`rule '${ruleName}' ignored : 'theme' option '${opts.theme}' excluded by config '${this._config.theme}'`);opts.enabled=false}}}if(opts.hasOwnProperty("customOpts")){if(!this._utils.isObject(opts.customOpts)){this._error(`rule '${ruleName}' - rule option 'customOpts' is not an object`);opts.enabled=false;continue}}if(opts.enabled){for(opt in opts){let custOpts;if(!this._isJafRuleOption(opt)){if(RESERVED_PACK_PREFIX.indexOf(rulePack.rulesJson.prefix)<0){this._msgCtx.jafMsg("jaf-sys-rule-opt",`Warning - rule '${ruleName}' user option property '${opt}' should be moved to the rule's 'customOpts' property.`,"W")}if(opts.hasOwnProperty("customOpts")){custOpts=opts.customOpts}else{opts.customOpts=custOpts={}}if(!custOpts.hasOwnProperty(opt)){custOpts[opt]=opts[opt]}}}}if(this._isCliOrApi){rulePath=this._rulesetSummary[opts._rsi].path;rulePath=this._nd.path.join(rulePath,ruleName+".js");ruleJS=this._nd.ruleLoader(rulePath)}else{rset=this._ruleSets[opts._rsi];if(rset.builtin){ruleJS=this._nd.ruleLoader(ruleName,opts._rsi,this._error)}else if(rset.amdpack){ruleJS=rset.amdpack.rules[ruleName]}}if(!ruleJS){continue}rule=ruleJS;if(rset&&rset.amdpack){try{rule=new ruleJS.default}catch(e){this._showIgnoredRule(`AMD rule '${ruleName}' ${e.message}`,true);rule=null;continue}}else{if(ruleJS.prototype||!ruleJS.getName){try{rule=new ruleJS}catch(e){this._showIgnoredRule(`rule '${ruleName}' ${e.message}`,true);rule=null;continue}}}if(!opts.$internal){if(typeof rule.register!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no register() method`,true);opts.enabled=false;continue}}if(typeof rule.getName!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getName() method`,true);opts.enabled=false;continue}if(typeof rule.getDescription!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getDescription() method`,true);opts.enabled=false;continue}if(typeof rule.getShortDescription!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getShortDescription() method`,true);opts.enabled=false;continue}if(ruleName!==rule.getName()){this._showIgnoredRule(`rule '${ruleName}' ignored - name '${rule.getName()}' does not match external name '${ruleName}`,true);opts.enabled=false;continue}if(!opts.$internal){this._registerCtx.ruleOpts=clone.cloneOptions(opts);if(opts.filetype){let FTypeIsArray=Array.isArray(opts.filetype);if(FTypeIsArray||typeof opts.filetype==="string"){if(opts.filetype==="js"||FTypeIsArray&&opts.filetype.includes("js")){this._registerCtx.jsNodeTypes=AstNodeTypes}else if(opts.filetype==="ts"||FTypeIsArray&&opts.filetype.includes("ts")){this._registerCtx.tsNodeTypes=AstNodeTypes}else if(opts.filetype==="tsx"||FTypeIsArray&&opts.filetype.includes("tsx")){this._registerCtx.tsNodeTypes=AstNodeTypes;this._registerCtx.utils.tsxUtils=this._tsxUtils}}}if(this._isCliOrApi){this._registerCtx.utils.fsUtils=this._fsUtils;if(ruleName==="oj-html-cspexpr"){this._registerCtx.decache=this._nd.decache}}this._registerCtx.ruleName=ruleName;this._registerCtx.rulePack._setCBCtx(this._registerCtx);callbacks=rule.register(this._registerCtx);if(!callbacks){this._showIgnoredRule(`rule '${ruleName}' has disabled itself during registration`);opts.enabled=false;continue}for(callback in callbacks){if(callbacks[callback]){callbacks[callback]=callbacks[callback].bind(rule)}else{s=`rule '${ruleName}': listener for '${callback}' in register() is not defined - rule is disabled`;this._error(s);this._showIgnoredRule(s);opts.enabled=false;continue}}if(_isHookRule(callbacks)){opts.$hook=true}else{if(!this._checkRuleSeverity(opts)){this._showIgnoredRule(`rule '${ruleName}' ignored by severity`);opts.enabled=false;continue}}}this._addToShadowRulePacks(ruleName,rule,opts);if(!opts.$internal){this._registry.setRuleCallback(ruleName,callbacks,opts._rsi)}this._ruleCount++;this._updateTargetFiletypes(opts)}catch(e){atLine=e.stack.replace(rulePath,"").trim();i=NaN;if(atLine.startsWith(COLON)){i=parseInt(atLine.substr(1))}if(!isNaN(i)){atLine=" line "+i+": "}else{i=atLine.indexOf(COLON);if(i<0){atLine=""}else{atLine=this._utils.eatLine(atLine,i);i=atLine.indexOf(COLON);if(i>=0){atLine=atLine.substring(i+1);i=atLine.indexOf(")");if(i>=0){atLine="("+atLine.substring(0,i).replace(COLON,",")+") - "}}else{atLine=""}};}this._showIgnoredRule(`Cannot load rule ${ruleName} [${atLine} '${e.message}']`,true)}}if(rsi===0){fnSetJafMsgIds(this.loadMsgIds(false,true))}}this._showIgnoredRule(null);return true};RuleSet.prototype._isJafRuleOption=function(prop){var prop_lc=prop.toLowerCase();return RULE_OPTS_JAF.includes(prop_lc)||JAF_RULEOPT_RE.test(prop_lc)};RuleSet.prototype._showIgnoredRule=function(msg,isError){if(msg){if(!this._ignoredRulesShown){this._info("\n--------- Start-up Rule analysis ---------");this._ignoredRulesShown=true}isError?this._error(msg):this._info(msg)}else if(this._ignoredRulesShown){this._info("------------ End Rule analysis -------------")}};RuleSet.prototype._mergeRuleOptions=function(rulesJson,isBuiltinRules){var prefix,rules,overrides,ruleName,opts,error,x;this._debug("Augmenting config defined rules in rulePack from ruleMods...");prefix=rulesJson.prefix;rules=rulesJson.rules;overrides=this._getRuleModsByPrefix(prefix);for(ruleName in rules){error=false;if(!isBuiltinRules){x=RESERVED_RULE_PREFIX.indexOf(ruleName.toLowerCase());if(x>=0){this._showIgnoredRule(`rule '${ruleName}' in rulepack (prefix: '${prefix}') must not use JET reserved prefix '${RESERVED_RULE_PREFIX[x]}'`,true);error=true}}if(overrides){if(error){continue}if(overrides.hasOwnProperty(ruleName)&&rules[ruleName]){if(this._isAMD){opts=rules[ruleName];if(!_isAMDRule(opts)){if(this._debugMode){this._debug(`Rule options override ignored for non-AMD ${ruleName} in AMD mode`)}continue}if(isBuiltinRules){if(!this._nd.ruleLoader(ruleName,opts._rsi,this._error)){continue}}}if(this._debugMode){this._debug(`Merging rule props of ${ruleName}`)}this._mergeOverrideProps(ruleName,overrides[ruleName],rules[ruleName],isBuiltinRules)}}}};RuleSet.prototype._mergeOverrideProps=function(ruleName,configOpts,ruleOpts){var prop;function _mergeCustomOpts(ruleCustomOpts,modCustomOpts){var p;for(p in modCustomOpts){ruleCustomOpts[p]=modCustomOpts[p]}};for(prop in configOpts){if(prop.charAt(0)==="$"){delete configOpts[prop];this._showIgnoredRule(`rule '${ruleName}' : '${prop}' in config 'rulesMod' cannot use reserved '$' prefix`,true);continue}if(prop==="enabled"&&!configOpts[prop]&&ruleOpts["$required"]){this._showIgnoredRule(`rule '${ruleName}' is mandatory and cannot be disabled using config 'ruleMods' property.`,true);continue}if(prop==="customOpts"){if(!ruleOpts.customOpts){ruleOpts[prop]=configOpts[prop]}else{_mergeCustomOpts(ruleOpts.customOpts,configOpts.customOpts)}}else{ruleOpts[prop]=configOpts[prop];if(prop===OPT_SEVERITY){ruleOpts.$sevLocked=true}}}};RuleSet.prototype._addToShadowRulePacks=function(ruleName,loadedRule,ruleOpts){var rsi=ruleOpts._rsi;var srp=this._shadowRulePacks;while(rsi>=srp.length){srp.push({})}srp[rsi][ruleName]=loadedRule};RuleSet.prototype._updateTargetFiletypes=function(opts){var ft=opts.filetype;if(ft){if(typeof ft==="string"){ft=[ft]}ft.forEach(t=>{if(!opts.$internal){if(!this._targFiletypes.includes(t)){this._targFiletypes.push(t)}}},this)}};RuleSet.prototype._getRuleModsByPrefix=function(prefix){var modPrefix,ret;if(this._ruleMods){prefix=prefix.toLowerCase();for(modPrefix in this._ruleMods){if(prefix===modPrefix.toLowerCase()){ret=this._ruleMods[modPrefix];break}}}return ret};RuleSet.prototype._isGroupActive=function(group){var groups,defs,def,i;groups=this._config.groups;defs=this._config.defGroups;if(this._checkGroups(groups,group)){return true}if(!defs){return false}for(i=0;i<groups.length;i++){def=groups[i];if(this._checkDefGroup(defs,def,group)){return true}}return false};RuleSet.prototype._checkGroups=function(cfgGroups,ruleGroup){var theGroup,i;if(Array.isArray(ruleGroup)){for(i=0;i<ruleGroup.length;i++){theGroup=ruleGroup[i];if(this._checkGroup(cfgGroups,theGroup)){return true}}}else if(this._checkGroup(cfgGroups,ruleGroup)){return true}return false};RuleSet.prototype._checkGroup=function(cfgGroups,group){return!cfgGroups||cfgGroups.includes(group)||cfgGroups.includes(this._severity.ALL)};RuleSet.prototype._isJetInRuleSet=function(jetPrefix){var i,ret=false;if(this._ruleSets&&this._ruleSets.length){for(i=0;i<this._ruleSets.length;i++){if(this._ruleSets[i].prefix===jetPrefix){ret=true;break}}}return ret};RuleSet.prototype._checkRuleSeverity=function(opts){var severities,severity,_sev,i,ret=false;severities=this._config.severity;severity=opts.severity;if(typeof severities==="string"){_sev=this._severity.getConfigSevExpr();if(_sev){ret=true}else{ret=severity===severities||severities===this._severity.ALL}}else{for(var i=0;i<severities.length;i++){if(severity===severities[i]||severities[i]===this._severity.ALL){ret=true;break}}}return ret};RuleSet.prototype._loadJson=function(filepath){var data,stats,msg;try{stats=this._nd.fs.lstatSync(filepath);if(!stats.isFile()){this._error(`RuleSet '${filepath}' not found!`);return null}else{data=this._nd.fs.readFileSync(filepath,"utf8");data=JSON.parse(this._nd.decomment(data))}}catch(e){if(e.code){if(e.message.startsWith("ENOENT:")){this._error(`RuleSet error - '${filepath}' not found!`)}}else if(e.toString().startsWith("SyntaxError")){msg=_convertMsgToRowCol(e.message,data,this._utils)}else{msg=e.message}if(msg){this._error(`JSON load error '${filepath}' - ${msg}`)}data=null}return data};function _isStatEnabledByPack(pstat,rstat){var ret=false;if(pstat.includes("all")||pstat.includes(rstat)){ret=true}else{if(rstat==="ready"||rstat.startsWith("prod")){ret=pstat.includes("ready")||pstat.includes("production")||pstat.includes("prod")}}return ret};function _isHookRule(callbacks){return callbacks[REG.PHASE_STARTUP]||callbacks[REG.PHASE_CLOSEDOWN]||callbacks[REG.PHASE_FILE]?true:false};function _isAMDRule(opts){return opts.hasOwnProperty("amd")?!!opts.amd:true};function _convertMsgToRowCol(msg,data,utils){var x,n,rc;x=msg.indexOf("position");if(x<0){return msg}n=parseInt(msg.substr(x+8).trim());rc=utils.getRowColFromIndex(data,n);return msg.substr(0,x)+"line "+rc.row+", col "+rc.col};function _isRE(s){return RULE_RE.test(s)};module.exports=RuleSet;
package/lib/checkage.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const BUILT="2024-04-27T00:34:55.012Z";const MAJOR_RELS=2;function CheckAge(burnedInJetVer,msgCtx){this._jetRels=-1;this._msgCtx=msgCtx;this._burnedInMajor=parseInt(burnedInJetVer.split(".")[0])};CheckAge.prototype.checkAge=function(){var curDate;var buildDate;var buildMonth;var monthsToNow;curDate=new Date;buildDate=BUILT==="@BUILT@"?curDate:new Date(BUILT);buildMonth=buildDate.getMonth()+1;monthsToNow=_getElapsedMonths(buildDate,curDate);if(!monthsToNow){this._jetRels=0}else{this._jetRels=_getReleases(buildMonth,monthsToNow);if(this._jetRels>MAJOR_RELS){this._emitMsg(monthsToNow)}}return this._jetRels};CheckAge.prototype.getJafReleaseCount=function(){return this._jetRels};CheckAge.prototype.getMajorReleaseCount=function(major){if(typeof major==="string"){let a=major.split(".");major=parseInt(a[0])}if(isNaN(major)){return this._jetRels}let estimatedMajor=this._burnedInMajor+this._jetRels;return estimatedMajor-major};CheckAge.prototype._emitMsg=function(old){var INDENT=" ".repeat(12);var s,h,p;if(this._jetRels){s=""+this._jetRels;if(this._jetRels===1){h="has";p=""}else{h="have";p="s"}}else{s="at least one";h="has";p=""}var s=`\nThis version of JAF is ${old} month${old===1?"":"s"} old, and there ${h} been ${s} scheduled public\n`+`${INDENT}major JET release${p}, together with JAF updates and fixes. It is strongly\n`+INDENT+"recommended that you install the latest version of JAF. [JAF-9100]\n";this._msgCtx.warn(s,"JAF-9100",true)};function _getElapsedMonths(start,end){return end.getMonth()-start.getMonth()+12*(end.getFullYear()-start.getFullYear())};function _getReleases(buildMonth,months){var toNextRel,releases=0;if(buildMonth===1){toNextRel=0}else if(buildMonth>1&&buildMonth<7){toNextRel=7-buildMonth}else if(buildMonth===7){toNextRel=0}else{toNextRel=13-buildMonth}if((releases=months-toNextRel)>=0){releases=1+Math.floor(releases/6)}else{releases=0}return releases};module.exports=CheckAge;
6
+ const BUILT="2024-05-03T18:14:11.028Z";const MAJOR_RELS=2;function CheckAge(burnedInJetVer,msgCtx){this._jetRels=-1;this._msgCtx=msgCtx;this._burnedInMajor=parseInt(burnedInJetVer.split(".")[0])};CheckAge.prototype.checkAge=function(){var curDate;var buildDate;var buildMonth;var monthsToNow;curDate=new Date;buildDate=BUILT==="@BUILT@"?curDate:new Date(BUILT);buildMonth=buildDate.getMonth()+1;monthsToNow=_getElapsedMonths(buildDate,curDate);if(!monthsToNow){this._jetRels=0}else{this._jetRels=_getReleases(buildMonth,monthsToNow);if(this._jetRels>MAJOR_RELS){this._emitMsg(monthsToNow)}}return this._jetRels};CheckAge.prototype.getJafReleaseCount=function(){return this._jetRels};CheckAge.prototype.getMajorReleaseCount=function(major){if(typeof major==="string"){let a=major.split(".");major=parseInt(a[0])}if(isNaN(major)){return this._jetRels}let estimatedMajor=this._burnedInMajor+this._jetRels;return estimatedMajor-major};CheckAge.prototype._emitMsg=function(old){var INDENT=" ".repeat(12);var s,h,p;if(this._jetRels){s=""+this._jetRels;if(this._jetRels===1){h="has";p=""}else{h="have";p="s"}}else{s="at least one";h="has";p=""}var s=`\nThis version of JAF is ${old} month${old===1?"":"s"} old, and there ${h} been ${s} scheduled public\n`+`${INDENT}major JET release${p}, together with JAF updates and fixes. It is strongly\n`+INDENT+"recommended that you install the latest version of JAF. [JAF-9100]\n";this._msgCtx.warn(s,"JAF-9100",true)};function _getElapsedMonths(start,end){return end.getMonth()-start.getMonth()+12*(end.getFullYear()-start.getFullYear())};function _getReleases(buildMonth,months){var toNextRel,releases=0;if(buildMonth===1){toNextRel=0}else if(buildMonth>1&&buildMonth<7){toNextRel=7-buildMonth}else if(buildMonth===7){toNextRel=0}else{toNextRel=13-buildMonth}if((releases=months-toNextRel)>=0){releases=1+Math.floor(releases/6)}else{releases=0}return releases};module.exports=CheckAge;
package/lib/defaults.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- const defaults={JETVER:"16.0.5".replace(/(\d*\.\d*)(\.\d*)+$/g,"$1")+".0",THEME:"Alta",ECMAVER:14};module.exports=defaults;
6
+ const defaults={JETVER:"16.1.0".replace(/(\d*\.\d*)(\.\d*)+$/g,"$1")+".0",THEME:"Alta",ECMAVER:14};module.exports=defaults;
package/lib/schema.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * Licensed under The Universal Permissive License (UPL), Version 1.0
4
4
  * as shown at https://oss.oracle.com/licenses/upl/
5
5
  */
6
- var _validate;const DOT=".";function validateComponentJson(obj){var errors,error,s,i,ret=null;if(!_validate){_init()}if(!_validate(obj)){ret=[];errors=_validate.errors;for(i=0;i<errors.length;i++){error=errors[i];s=_cleanAjvMessages(error);if(s&&!s.includes("(if)")){ret.push({msg:s,error:error})}}}return ret};function _cleanAjvMessages(error){var prop,propType,msg,param,ret;var instPath=_convertJsonPointer(error.instancePath);if(instPath===""){instPath="JSON top-level"};switch(error.keyword){case"required":ret=`${error.message} at ${instPath}`;break;case"enum":ret=`bad property '${instPath}' value : ${error.message}} [${error.params.allowedValues}]`;break;case"additionalProperties":if(error.params){param=error.params["additionalProperty"];param=param?` '${param}'`:"";if(error.instancePath.includes(DOT)){ret=`unexpected metadata property'${param}' in '${instPath}`}else{ret=`invalid property'${param}' in '${instPath}'`}}else{ret=`"unexpected property (unknown) at '${instPath}'`}break;case"type":ret=`${instPath} - ${error.message}`;break;case"not":msg=error.message;msg=msg.replace("must NOT be valid","is not permitted");if(instPath){propType=instPath.startsWith("prop")?"property":instPath.startsWith("events")?"events":instPath.startsWith("name")?"name":""}prop=error.propertyName?error.propertyName:"";ret=propType+(propType.length?" ":"")+(prop?"'"+prop+"'":"")+" at '"+instPath+"' "+msg;break;case"propertyNames":ret=error.message+(error.params&&error.params.propertyName?" - '"+error.params.propertyName+"'":"")+" at '"+instPath+"'";break;case"pattern":return`property '${instPath}' failed a schema format pattern match`;break;case"format":return`property '${instPath}' format - ${error.message}`;break;case"anyOf":return`property ${instPath} - ${error.message}`;break;case"if":break;default:ret=`unknown error ('${error.keyword}', '${error.message}')`}return ret};function _convertJsonPointer(ip){if(ip){if(ip.startsWith("/")){ip=ip.substring(1)}let elems=ip.split("/");for(let i=0;i<elems.length;i++){let elem=elems[i];if(elem!==DOT&&!isNaN(elem)){elems[i]="["+elem+"]"}}ip=elems.join(".");ip=ip.replace(/\.\[/g,"[")}return ip};function _init(){const schema=require("../schema/component-schema.json");const Ajv=require("ajv");const AjvFormats=require("ajv-formats");const _ajv=new Ajv({allErrors:true,strictTypes:false});AjvFormats(_ajv,{mode:"fast"});_validate=_ajv.compile(schema)};module.exports.validateComponentJson=validateComponentJson;
6
+ var _validate;const DOT=".";function validateComponentJson(obj){var errors,error,s,i,ret=null;if(!_validate){_init()}if(!_validate(obj)){ret=[];errors=_validate.errors;for(i=0;i<errors.length;i++){error=errors[i];s=_cleanAjvMessages(error);if(s&&!s.includes("(if)")){ret.push({msg:s,error:error})}}}return ret};function _cleanAjvMessages(error){var prop,propType,msg,param,ret;var instPath=_convertJsonPointer(error.instancePath);if(instPath===""){instPath="JSON top-level"};switch(error.keyword){case"required":ret=`${error.message} at ${instPath}`;break;case"enum":ret=`bad property '${instPath}' value : ${error.message}} [${error.params.allowedValues}]`;break;case"additionalProperties":if(error.params){param=error.params["additionalProperty"];param=param?` '${param}'`:"";if(error.instancePath.includes(DOT)){ret=`unexpected metadata property'${param}' in '${instPath}`}else{ret=`invalid property'${param}' in '${instPath}'`}}else{ret=`"unexpected property (unknown) at '${instPath}'`}break;case"type":ret=`${instPath} - ${error.message}`;break;case"not":msg=error.message;msg=msg.replace("must NOT be valid","is not permitted");if(instPath){propType=instPath.startsWith("prop")?"property":instPath.startsWith("events")?"events":instPath.startsWith("name")?"name":""}prop=error.propertyName?error.propertyName:"";ret=propType+(propType.length?" ":"")+(prop?"'"+prop+"'":"")+" at '"+instPath+"' "+msg;break;case"propertyNames":ret=error.message+(error.params&&error.params.propertyName?" - '"+error.params.propertyName+"'":"")+" at '"+instPath+"'";break;case"pattern":return`property '${instPath}' failed a schema format pattern match`;break;case"format":return`property '${instPath}' format - ${error.message}`;break;case"anyOf":return`property ${instPath} - ${error.message}`;break;case"if":break;default:ret=`unknown error ('${error.keyword}', '${error.message}')`}return ret};function _convertJsonPointer(ip){if(ip){if(ip.startsWith("/")){ip=ip.substring(1)}let elems=ip.split("/");for(let i=0;i<elems.length;i++){let elem=elems[i];if(elem!==DOT&&!isNaN(elem)){elems[i]="["+elem+"]"}}ip=elems.join(".");ip=ip.replace(/\.\[/g,"[")}return ip};const FAST_URI=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i;const Z_ANCHOR=/[^\\]\\Z/;function isValidJSRegex(str){if(Z_ANCHOR.test(str))return false;try{new RegExp(str);return true}catch(e){return false}}function _init(){const schema=require("../schema/component-schema.json");const Ajv=require("ajv");const _ajv=new Ajv({allErrors:true,strictTypes:false,formats:{uri:FAST_URI,regex:isValidJSRegex}});_validate=_ajv.compile(schema)};module.exports.validateComponentJson=validateComponentJson;