@oracle/oraclejet-audit 15.1.8 → 16.0.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/corePackMigrator/corePackMigrator.js +2 -2
- package/corePackMigrator/metadata/actionCardMetadata.json +8 -0
- package/corePackMigrator/metadata/avatarMetadata.json +0 -12
- package/corePackMigrator/metadata/drawerPopupMetadata.json +16 -0
- package/corePackMigrator/metadata/formLayoutMetadata.json +34 -0
- package/corePackMigrator/metadata/highlightTextMetadata.json +8 -0
- package/corePackMigrator/metadata/inputNumberMetadata.json +26 -2
- package/corePackMigrator/metadata/inputPasswordMetadata.json +32 -2
- package/corePackMigrator/metadata/inputTextMetadata.json +26 -2
- package/corePackMigrator/metadata/legendItemMetadata.json +1 -5
- package/corePackMigrator/metadata/legendMetadata.json +42 -0
- package/corePackMigrator/metadata/legendSectionMetadata.json +6 -4
- package/corePackMigrator/metadata/listviewMetadata.json +61 -2
- package/corePackMigrator/metadata/messageBannerMetadata.json +8 -0
- package/corePackMigrator/metadata/messagesMetadata.json +17 -5
- package/corePackMigrator/metadata/radiosetMetadata.json +86 -0
- package/corePackMigrator/metadata/ratingGaugeMetadata.json +29 -17
- package/corePackMigrator/metadata/selectManyMetadata.json +9 -3
- package/corePackMigrator/metadata/selectSingleMetadata.json +16 -5
- package/corePackMigrator/metadata/selectorMetadata.json +37 -0
- package/corePackMigrator/metadata/statusMeterGaugeMetadata.json +21 -9
- package/corePackMigrator/metadata/tagCloudMetadata.json +8 -0
- package/corePackMigrator/metadata/textAreaMetadata.json +8 -2
- package/corePackMigrator/resource/astUtils.js +1 -1
- package/corePackMigrator/resource/componentMigrator.js +1 -1
- package/corePackMigrator/resource/fileScanner.js +1 -1
- package/corePackMigrator/resource/htmlUtils.js +1 -1
- package/corePackMigrator/resource/manifest.json +25 -10
- package/corePackMigrator/resource/migrationConfig.json +3 -0
- package/corePackMigrator/templates/componentMetaData.json +18 -4
- package/corePackMigrator/templates/migrationConfig.json +15 -3
- package/corePackMigrator/utilities/logging.js +1 -1
- package/jaf-amd.js +1 -1
- package/jaf.js +1 -1
- package/jafapi.js +1 -1
- package/lib/AST_Ts.js +1 -1
- package/lib/AstNodeTypes.js +1 -1
- package/lib/Components.js +1 -1
- package/lib/DomUtils.js +1 -1
- package/lib/FsUtils.js +1 -1
- package/lib/HtmlUtils.js +1 -1
- package/lib/JafLib.js +1 -1
- package/lib/MetaLib.js +1 -1
- package/lib/OjCPack.js +1 -1
- package/lib/Registry.js +1 -1
- package/lib/RulePack.js +1 -1
- package/lib/RuleSet.js +1 -1
- package/lib/Rules.js +1 -1
- package/lib/Stats.js +1 -1
- package/lib/Ts.js +1 -1
- package/lib/TsUtils.js +6 -0
- package/lib/TsxUtils.js +1 -1
- package/lib/TsxUtils2.js +1 -1
- package/lib/Utils.js +1 -1
- package/lib/checkage.js +1 -1
- package/lib/defaults.js +1 -1
- package/lib/jsx.js +1 -1
- package/lib/migrator.js +1 -1
- package/lib/scaffold.js +1 -1
- package/lib/sublib/precomp/ComponentFinder.js +6 -0
- package/lib/sublib/precomp/Precompiler.js +6 -0
- package/lib/sublib/precomp/TsxUtils.js +6 -0
- package/lib/sublib/precomp/Utils.js +6 -0
- package/meta/15.0.0/jetauditmeta.js +1 -1
- package/meta/15.1.0/jetauditmeta.js +1 -1
- package/meta/16.0.0/jetauditmeta.js +9 -0
- package/meta/metaverlist.json +1 -1
- package/package.json +10 -7
- package/profiles/best-practice.json +1 -0
- package/rulepacks/csp/csp-json-unsafe-expr.js +1 -1
- package/rulepacks/jetwc/jetwc-bootstrap.js +1 -1
- package/rulepacks/jetwc/jetwc-require-paths.js +1 -1
- package/rulepacks/jetwc/jetwc-schema.js +1 -1
- package/rulepacks/jetwc/jetwc-well-formed-description.js +6 -0
- package/rulepacks/jetwc/msgid.json +1 -1
- package/rulepacks/jetwc/rules.json +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-componentAuditUtils.js +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-componentFinder.js +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-tsxUtils.js +1 -1
- package/rulepacks/jetwco/jetwco-bootstrap.js +1 -1
- package/rulepacks/jetwco/jetwco-cacc-methodParamTypes.js +1 -1
- package/rulepacks/jetwco/jetwco-cacc-methodReturnType.js +1 -1
- package/rulepacks/jetwco/jetwco-description-standards.js +1 -1
- package/rulepacks/jetwco/jetwco-license-info.js +1 -1
- package/rulepacks/jetwco/jetwco-validate-applied-audits.js +6 -0
- package/rulepacks/jetwco/msgid.json +1 -1
- package/rulepacks/jetwco/rules.json +1 -1
- package/rulepacks/ojc/msgid.json +1 -1
- package/rulepacks/ojc/ojc-html-button-defslot.js +6 -0
- package/rulepacks/ojc/ojc-tsx-button-defslot.js +6 -0
- package/rulepacks/ojc/rules.json +1 -1
- package/rules/jaf/jaf-css-diagnose.js +1 -1
- package/rules/jaf/jaf-js-diagnose.js +1 -1
- package/rules/jaf/jaf-sys-dup-component.js +6 -0
- package/rules/jaf/jaf-sys-rule-opt.js +6 -0
- package/rules/jaf/jaf-ts-precompile.js +6 -0
- package/rules/jaf/msgid.json +1 -1
- package/rules/jaf/rules.json +1 -1
- package/rules/jet/helpers/has-slot-name.js +1 -1
- package/rules/jet/msgid.json +1 -1
- package/rules/jet/oj-cca-compjson-bp-jetver.js +1 -1
- package/rules/jet/oj-html-alta-deprecated.js +1 -1
- package/rules/jet/oj-html-attr-expr-writeback.js +6 -0
- package/rules/jet/oj-html-binding-as-slot-child.js +6 -0
- package/rules/jet/oj-html-event-focus-blur.js +6 -0
- package/rules/jet/oj-html-form-bindif.js +1 -1
- package/rules/jet/oj-html-ojattr-deprecated.js +1 -1
- package/rules/jet/oj-html-ojattr-enum-deprecated.js +1 -1
- package/rules/jet/oj-html-ojattr.js +1 -1
- package/rules/jet/oj-html-ojtag-deprecated.js +1 -1
- package/rules/jet/oj-html-ojtag-nonglobattr-prefix.js +1 -1
- package/rules/jet/oj-html-prop-anti-pattern.js +6 -0
- package/rules/jet/oj-html-slot-default.js +6 -0
- package/rules/jet/oj-html-slot-deprecated.js +1 -1
- package/rules/jet/oj-html-slot-name.js +1 -1
- package/rules/jet/oj-html-slot-pref-content.js +1 -1
- package/rules/jet/oj-html-style-deprecated.js +1 -1
- package/rules/jet/oj-html-treeview-actionable-content.js +6 -0
- package/rules/jet/oj-html-wctag-anti-pattern.js +6 -0
- package/rules/jet/oj-html-wctag-maintenance.js +1 -1
- package/rules/jet/oj-html-wctag-supersedes.js +1 -1
- package/rules/jet/oj-js-ojcomp-exist.js +1 -1
- package/rules/jet/oj-ts-ojcomp-exist.js +1 -1
- package/rules/jet/oj-tsx-aria-ojselector-labelledby.js +1 -1
- package/rules/jet/oj-tsx-aria-prop.js +1 -1
- package/rules/jet/oj-tsx-event.js +6 -0
- package/rules/jet/oj-tsx-ojattr-deprecated.js +1 -1
- package/rules/jet/oj-tsx-ojattr-enum-deprecated.js +1 -1
- package/rules/jet/oj-tsx-ojattr-value.js +1 -1
- package/rules/jet/oj-tsx-ojattr.js +1 -1
- package/rules/jet/oj-tsx-ojtag-deprecated.js +1 -1
- package/rules/jet/oj-tsx-pageopts-type.js +1 -1
- package/rules/jet/oj-tsx-picker-attrs.js +1 -1
- package/rules/jet/oj-tsx-popup-sibling.js +6 -0
- package/rules/jet/oj-tsx-prop-anti-pattern.js +6 -0
- package/rules/jet/oj-tsx-rating-gauge-size.js +1 -1
- package/rules/jet/oj-tsx-rating-gauge-track-resize.js +1 -1
- package/rules/jet/oj-tsx-slot-deprecated.js +1 -1
- package/rules/jet/oj-tsx-slot-pref-content.js +1 -1
- package/rules/jet/oj-tsx-treeview-actionable-content.js +6 -0
- package/rules/jet/oj-tsx-unsup-theme.js +1 -1
- package/rules/jet/oj-tsx-wctag-anti-pattern.js +6 -0
- package/rules/jet/oj-tsx-wctag-maintenance.js +1 -1
- package/rules/jet/rules.json +1 -1
- package/schema/component-schema.json +1 -1
- package/src/JafCore.js +1 -1
- package/types/index.d.ts +1 -0
- package/rulepacks/jetwc-lib/jetwcutils-preCompiler.js +0 -6
- package/rules/jet/oj-html-combo-converter.js +0 -6
- package/rules/jet/oj-tsx-combo-converter.js +0 -6
package/meta/metaverlist.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"metaList":{"8.3.0":{"version":"8.3.0","date":"Monday May 04, 2020","time":"4:34pm edt"},"9.0.0":{"version":"9.0.0","date":"Friday Jun 12, 2020","time":"1:57am utc"},"9.1.0":{"version":"9.1.0","date":"Thursday Aug 06, 2020","time":"2:13am utc"},"9.2.0":{"version":"9.2.0","date":"Wednesday Oct 07, 2020","time":"5:41pm utc"},"10.0.0":{"version":"10.0.0","date":"Thursday Jan 07, 2021","time":"9:20pm utc"},"10.1.0":{"version":"10.1.0","date":"Saturday Apr 17, 2021","time":"4:01pm utc"},"11.0.0":{"version":"11.0.0","date":"Friday Jul 02, 2021","time":"3:02am utc"},"11.1.0":{"version":"11.1.0","date":"Thursday Sep 30, 2021","time":"9:33pm utc"},"12.0.0":{"version":"12.0.0","date":"Friday Feb 04, 2022","time":"2:29am utc"},"12.1.0":{"version":"12.1.0","date":"Saturday Apr 09, 2022","time":"7:54am utc"},"13.0.0":{"version":"13.0.4","date":"Thursday Sep 22, 2022","time":"3:14am utc"},"13.1.0":{"version":"13.1.0","date":"Sunday Oct 02, 2022","time":"3:37am utc"},"14.0.0":{"version":"14.0.0","date":"Tuesday Jan 03, 2023","time":"8:54pm utc"},"14.1.0":{"version":"14.1.0","date":"Thursday Apr 06, 2023","time":"7:55pm utc"},"15.0.0":{"version":"15.0.0","date":"
|
|
1
|
+
{"metaList":{"8.3.0":{"version":"8.3.0","date":"Monday May 04, 2020","time":"4:34pm edt"},"9.0.0":{"version":"9.0.0","date":"Friday Jun 12, 2020","time":"1:57am utc"},"9.1.0":{"version":"9.1.0","date":"Thursday Aug 06, 2020","time":"2:13am utc"},"9.2.0":{"version":"9.2.0","date":"Wednesday Oct 07, 2020","time":"5:41pm utc"},"10.0.0":{"version":"10.0.0","date":"Thursday Jan 07, 2021","time":"9:20pm utc"},"10.1.0":{"version":"10.1.0","date":"Saturday Apr 17, 2021","time":"4:01pm utc"},"11.0.0":{"version":"11.0.0","date":"Friday Jul 02, 2021","time":"3:02am utc"},"11.1.0":{"version":"11.1.0","date":"Thursday Sep 30, 2021","time":"9:33pm utc"},"12.0.0":{"version":"12.0.0","date":"Friday Feb 04, 2022","time":"2:29am utc"},"12.1.0":{"version":"12.1.0","date":"Saturday Apr 09, 2022","time":"7:54am utc"},"13.0.0":{"version":"13.0.4","date":"Thursday Sep 22, 2022","time":"3:14am utc"},"13.1.0":{"version":"13.1.0","date":"Sunday Oct 02, 2022","time":"3:37am utc"},"14.0.0":{"version":"14.0.0","date":"Tuesday Jan 03, 2023","time":"8:54pm utc"},"14.1.0":{"version":"14.1.0","date":"Thursday Apr 06, 2023","time":"7:55pm utc"},"15.0.0":{"version":"15.0.0","date":"Saturday Jul 01, 2023","time":"2:08pm utc"},"15.1.0":{"version":"15.1.0","date":"Thursday Jul 06, 2023","time":"8:04pm utc"},"16.0.0":{"version":"16.0.0","date":"Saturday Feb 10, 2024","time":"4:36pm utc"}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oracle/oraclejet-audit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"description": "JET AUDIT FRAMEWORK",
|
|
5
5
|
"main": "jaf.js",
|
|
6
6
|
"files": [
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
"lint"
|
|
45
45
|
],
|
|
46
46
|
"Jaf": {
|
|
47
|
-
"version": "
|
|
47
|
+
"version": "8.13.5"
|
|
48
48
|
},
|
|
49
49
|
"license": "UPL-1.0",
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@babel/generator": "^7.19.5",
|
|
52
52
|
"@babel/parser": "^7.19.4",
|
|
53
|
-
"@typescript-eslint/typescript-estree": "
|
|
53
|
+
"@typescript-eslint/typescript-estree": "6.13.2",
|
|
54
54
|
"adm-zip": "0.4.16",
|
|
55
|
-
"ajv": "8.
|
|
55
|
+
"ajv": "8.12.0",
|
|
56
56
|
"ajv-formats": "2.1.1",
|
|
57
57
|
"ast-traverse": "^0.1.1",
|
|
58
58
|
"astring": "^1.8.3",
|
|
59
|
-
"css-tree": "
|
|
59
|
+
"css-tree": "2.3.1",
|
|
60
60
|
"decache": "4.6.0",
|
|
61
61
|
"es-abstract": "1.20.5",
|
|
62
62
|
"espree": "9.5.2",
|
|
@@ -73,11 +73,14 @@
|
|
|
73
73
|
"strip-json-comments": "2.0.1",
|
|
74
74
|
"sync-request": "6.1.0",
|
|
75
75
|
"tmp": "0.0.33",
|
|
76
|
-
"typescript": "
|
|
76
|
+
"typescript": "5.3.2"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/traverse": "^7.19.6",
|
|
80
|
-
"chai": "~4.3.
|
|
80
|
+
"chai": "~4.3.10",
|
|
81
81
|
"mocha": "^7.2.0"
|
|
82
|
+
},
|
|
83
|
+
"resolutions": {
|
|
84
|
+
"fsevents": "2.2.1"
|
|
82
85
|
}
|
|
83
86
|
}
|
|
@@ -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 RULE_NAME="csp-json-unsafe-expr";const LONG_DESCRIPT="A JSON member value contains an expression that violates the Content Security Policy, and is not supported. Execution of the expression will be blocked.";const SHORT_DESCRIPT=LONG_DESCRIPT;const CHARACTER="character";const VB_ASSET_TOKEN_MATCHER=/\@{2}(?<tokenRef>[A-Z\d\-\$]*)@{2}/gmi;function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT_DESCRIPT};Rule.prototype.getDescription=function(){return LONG_DESCRIPT};Rule.prototype.register=function(regCtx){if(regCtx.runMode==="api"&®Ctx.VsCodeExtHint){if(this._exprEval){regCtx.decache(this._exprEval)}}this._exprEval=require("../../libext/expparser");this._exprEval=new this._exprEval;return{"json":this._onJson}};Rule.prototype._onJson=function(ruleCtx,ast){if(!ast){_onSyntaxError(ruleCtx);return false}this._walk(ruleCtx,ast)};Rule.prototype._walk=function(ruleCtx,ast,members){if(members=members||ast.members){members.forEach(member=>{let val,subMems;if(val=member.value){if(val?.type==="string"&&_isExpr(val?.value)){this._checkExpr(ruleCtx,member)}else if(val?.type==="array"){this._checkArrayExpr(ruleCtx,ast,member)}if(val?.members){if(subMems=val.members){this._walk(ruleCtx,ast,subMems)};}}})}};Rule.prototype._checkArrayExpr=function(ruleCtx,ast,member){var arrayMems,mem,i;if(arrayMems=member.value.members){for(i=0;i<arrayMems.length;i++){if(mem=arrayMems[i]){if(mem.type==="Object"&&mem.members){this._walk(ruleCtx,ast,mem.members)}}}}};Rule.prototype._checkExpr=function(ruleCtx,member){var value,issue,p;value=member.value.value.trim();value=value.substring(2,value.length-2).trim();value=value.replace(VB_ASSET_TOKEN_MATCHER,"$<tokenRef>");try{p=this._exprEval.parse(value)}catch(e){let o=_cleanUp(e.message,member);issue=new ruleCtx.Issue(`Member '${member.name}' contains an expression that may not be compatible with all Content Security policies: "${o.msg}"`);if(o.pos>=0){let pos=member.value.pos;issue.setPosition(pos.line,pos.col+o.pos+3,pos.start+o.pos+3,pos.end+o.pos+3)}else{issue.setPosition(member.value.pos)}ruleCtx.reporter.addIssue(issue,ruleCtx)}};function _cleanUp(msg,member){var pos=-1,x;if((x=msg.indexOf(CHARACTER))>=0){let posChars=msg.substring(x+CHARACTER.length+1);pos=parseInt(posChars);if(!isNaN(pos)){msg=msg.replace(CHARACTER,"column");msg=msg.replace(posChars,""+(pos+member.value.pos.col+3))}}return{msg:msg,pos:pos}};function _onSyntaxError(ruleCtx){if(ruleCtx.suppData){if(!ruleCtx.rulePack.isRuleEnabled("oj-json-syntax","JET")){let issue=new ruleCtx.Issue(ruleCtx.suppData.msg);issue.setPosition(ruleCtx.suppData.line,ruleCtx.suppData.col,ruleCtx.suppData.position,ruleCtx.suppData.position+3);issue.setMsgKey(RULE_NAME+"_1");issue.setSeverity("critical");ruleCtx.reporter.addIssue(issue,ruleCtx)}}};function _isExpr(s){s=s.trimStart();return s.startsWith("[[")||s.startsWith("{{")};module.exports=Rule;
|
|
6
|
+
const RULE_NAME="csp-json-unsafe-expr";const LONG_DESCRIPT="A JSON member value contains an expression that violates the Content Security Policy, "+"and is not supported. Execution of the expression will be blocked.";const SHORT_DESCRIPT=LONG_DESCRIPT;const CHARACTER="character";const VB_ASSET_TOKEN_MATCHER=/\@{2}(?<tokenRef>[A-Z\d\-\$]*)@{2}/gmi;function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT_DESCRIPT};Rule.prototype.getDescription=function(){return LONG_DESCRIPT};Rule.prototype.register=function(regCtx){if(regCtx.runMode==="api"&®Ctx.VsCodeExtHint){if(this._exprEval){regCtx.decache(this._exprEval)}}this._exprEval=require("../../libext/expparser");this._exprEval=new this._exprEval;return{"json":this._onJson}};Rule.prototype._onJson=function(ruleCtx,ast){if(!ast){_onSyntaxError(ruleCtx);return false}this._walk(ruleCtx,ast)};Rule.prototype._walk=function(ruleCtx,ast,members){if(members=members||ast.members){members.forEach(member=>{let val,subMems;if(val=member.value){if(val?.type==="string"&&_isExpr(val?.value)){this._checkExpr(ruleCtx,member)}else if(val?.type==="array"){this._checkArrayExpr(ruleCtx,ast,member)}if(val?.members){if(subMems=val.members){this._walk(ruleCtx,ast,subMems)};}}})}};Rule.prototype._checkArrayExpr=function(ruleCtx,ast,member){var arrayMems,mem,i;if(arrayMems=member.value.members){for(i=0;i<arrayMems.length;i++){if(mem=arrayMems[i]){if(mem.type==="Object"&&mem.members){this._walk(ruleCtx,ast,mem.members)}}}}};Rule.prototype._checkExpr=function(ruleCtx,member){var value,issue,p;value=member.value.value.trim();value=value.substring(2,value.length-2).trim();value=value.replace(VB_ASSET_TOKEN_MATCHER,"$<tokenRef>");try{p=this._exprEval.parse(value)}catch(e){let o=_cleanUp(e.message,member);issue=new ruleCtx.Issue(`Member '${member.name}' contains an expression that may not be compatible with all Content Security policies: "${o.msg}"`);if(o.pos>=0){let pos=member.value.pos;issue.setPosition(pos.line,pos.col+o.pos+3,pos.start+o.pos+3,pos.end+o.pos+3)}else{issue.setPosition(member.value.pos)}ruleCtx.reporter.addIssue(issue,ruleCtx)}};function _cleanUp(msg,member){var pos=-1,x;if((x=msg.indexOf(CHARACTER))>=0){let posChars=msg.substring(x+CHARACTER.length+1);pos=parseInt(posChars);if(!isNaN(pos)){msg=msg.replace(CHARACTER,"column");msg=msg.replace(posChars,""+(pos+member.value.pos.col+3))}}return{msg:msg,pos:pos}};function _onSyntaxError(ruleCtx){if(ruleCtx.suppData){if(!ruleCtx.rulePack.isRuleEnabled("oj-json-syntax","JET")){let issue=new ruleCtx.Issue(ruleCtx.suppData.msg);issue.setPosition(ruleCtx.suppData.line,ruleCtx.suppData.col,ruleCtx.suppData.position,ruleCtx.suppData.position+3);issue.setMsgKey(RULE_NAME+"_1");issue.setSeverity("critical");ruleCtx.reporter.addIssue(issue,ruleCtx)}}};function _isExpr(s){s=s.trimStart();return s.startsWith("[[")||s.startsWith("{{")};module.exports=Rule;
|
|
@@ -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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const componentFinder=require("../jetwc-lib/jetwcutils-componentFinder");const
|
|
6
|
+
const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const componentFinder=require("../jetwc-lib/jetwcutils-componentFinder");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-bootstrap"};ruleDef.prototype.getShortDescription=function(){return"Bootstrap processing for the JETWC rulset"};ruleDef.prototype.getDescription=function(){return"This rule is for internal use by the ruleset and should not be disabled"};ruleDef.prototype.register=function(context){this.componentRoots=context.config.components;this.auditBase=context.config.base;this.typeScriptCompile=context.config.typescript&&context.config.typescript.compile;return{startupRP:this._getAllVisibleComponents,closedownRP:this._reportDiagnostics}};ruleDef.prototype._getAllVisibleComponents=function(context){const{msgLib}=context.utils;msgLib.info(`builtinJetWcRules (${context.rulePack.getPackInfo().prefix}): ${context.rulePack.getPackInfo().version}`);const projectPathInfo=Utils.getKeyPathInfoForRulepack(context,this.auditBase);const componentRootFolder=context.rulePack.getRuleOptions().componentRoot||projectPathInfo.componentRootFolder;const masterComponentList=componentFinder.findAllComponents(context,this.auditBase,projectPathInfo,this.componentRoots);if(masterComponentList&&masterComponentList.length>0){const allComponentsMap=masterComponentList.reduce((wmap,component)=>{if(!projectPathInfo.isBuiltOutput||projectPathInfo.isBuiltOutput&&!wmap.has(component.fullName)){wmap.set(component.fullName,component)}return wmap},new Map);const referenceComponents=new Map;const componentPaths=new Map;allComponentsMap.forEach(component=>{component.language=Utils.detectComponentSourceType(context,component.rootFolder,component.vcomponent);switch(component.type){case"reference":referenceComponents.set(component.fullName,component.ba);break;case"composite":case"resource":if(component.local){if(component.dependencies){Object.values(component.dependencies).forEach(dependency=>{if(allComponentsMap.has(dependency.name)){const proxyPaths=allComponentsMap.get(dependency.name).requirePaths;proxyPaths.forEach(path=>{component.requirePaths.add(path)})}else{msgLib.debug(`JETWC: missing dependency lookup for ${dependency.name} when resolving requirePaths`)}})}componentPaths.set(component.rootFolder,component.fullName)}break}});context.rulePack.setExtension({rulepackVersion:context.rulePack.getPackInfo().version,bootStrap:true,platform:Utils.isWindows?"Windows":"Unix-like",precompiled:this.typeScriptCompile,componentHome:`/${componentRootFolder}/`,auditBuildOutput:projectPathInfo.isBuiltOutput,discoveredPaths:projectPathInfo,componentRoots:this.componentRoots,allReferenceComponents:referenceComponents,allComponents:allComponentsMap,auditableComponentPaths:componentPaths,allAuditableFilePaths:new Map})}else{msgLib.error(`No components have been discovered from the JAF configuration for the ${context.rulePack.getPackInfo().prefix} ruleset to process. You will need to configure the "components" array to point at your component root folder`);Utils.disableRulePack(context)}};ruleDef.prototype._reportDiagnostics=function(context){const msgLib=context.utils.msgLib;const opts=context.rulePack.getRuleOptions();const diagnostics=context.rulePack.getExtension();if(opts.debug){msgLib.msg("The custom component specific audits discovered the following components:");diagnostics.allComponents.forEach(component=>{msgLib.msg(` ${component.fullName}`)})}if(!opts.testMode){let foundVMMapping=0;let candidateLocal=0;if(diagnostics&&diagnostics.allComponents&&diagnostics.allComponents.length>0){diagnostics.allComponents.forEach(component=>{if(component.local&&component.type==="composite"){candidateLocal++;if(component.viewModel&&component.viewModel.resolved){foundVMMapping++}}});if(foundVMMapping!==candidateLocal){msgLib.error(`Error: Audit was only able to map ${foundVMMapping} out of ${candidateLocal} components to their viewModels. Some audits will be unable to operate.`)}}}if(opts.debug&&opts.diagnosticFile&&diagnostics){msgLib.msg(`Writing JETWC diagnostics to ${opts.diagnosticFile}.json`);const dFile=Utils.toJAFPath(path.join(path.resolve("."),opts.diagnosticFile+".json"));context.utils.fsUtils.writeJsonSync(diagnostics,dFile,{spaces:2,replacer:Utils.diagnosticReplacer})}};module.exports=ruleDef;
|
|
@@ -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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-require-paths"};ruleDef.prototype.getShortDescription=function(){return"Checks that any import paths used are valid"};ruleDef.prototype.getDescription=function(){return"This rule ensures that all path references (define, require or import) use paths that are valid in the context of the component. This list of valid paths will be constructed based on the declared and implicit dependencies of the component, combined with the standardPaths configuration property of the jetwc-require-paths rule which you can add to if needs be. The path \".\" is always valid. The path .. should not be used outside of the boundary of a given component, use the pack root instead."};ruleDef.prototype.register=function(context){return{CallExpression:this._doAuditRequireStyle,ImportDeclaration:this._doAuditImport,TSImportEqualsDeclaration:this._doAuditImportRequire}};ruleDef.prototype._doAuditRequireStyle=function(context,node){const ruleOptions=context.rulePack.getRuleOptions();const NT=context.utils.AstUtils.getNodeTypes();
|
|
6
|
+
const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-require-paths"};ruleDef.prototype.getShortDescription=function(){return"Checks that any import paths used are valid"};ruleDef.prototype.getDescription=function(){return"This rule ensures that all path references (define, require or import) use paths that are valid in the context of the component. This list of valid paths will be constructed based on the declared and implicit dependencies of the component, combined with the standardPaths configuration property of the jetwc-require-paths rule which you can add to if needs be. The path \".\" is always valid. The path .. should not be used outside of the boundary of a given component, use the pack root instead."};ruleDef.prototype.register=function(context){return{CallExpression:this._doAuditRequireStyle,ImportDeclaration:this._doAuditImport,TSImportEqualsDeclaration:this._doAuditImportRequire}};ruleDef.prototype._doAuditRequireStyle=function(context,node){const ruleOptions=context.rulePack.getRuleOptions().customOpts;const NT=context.utils.AstUtils.getNodeTypes();if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);if(withinComponent&&node.callee.type===NT.IDENTIFIER&&(node.callee.name==="define"||node.callee.name==="require")){if(node.arguments[0].type===NT.ARRAY_EXPR&&node.arguments[0].elements.length>0){node.arguments[0].elements.forEach(arg=>{if(arg.value){this._verifyPath(context,arg.value,componentInfo,node.callee.name)}})}else if(node.arguments[0].type===NT.LITERAL&&node.arguments[0].value){this._verifyPath(context,node.arguments[0].value,componentInfo,node.callee.name)}}}else{Utils.reportMissingBootstrapInfo(context,"allComponents")}};ruleDef.prototype._doAuditImport=function(context,node){if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){const NT=context.utils.AstUtils.getNodeTypes();const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);if(componentInfo){if(node.source&&node.source.type===NT.LITERAL){const sourcePath=node.source.value;this._verifyPath(context,sourcePath,componentInfo,"import")}}}else{Utils.reportMissingBootstrapInfo(context,"allComponents")}};ruleDef.prototype._doAuditImportRequire=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);if(componentInfo){if(node.moduleReference&&node.moduleReference.type===NT.EXTERN_MOD_REF&&node.moduleReference.expression){const sourcePath=node.moduleReference.expression.value;this._verifyPath(context,sourcePath,componentInfo,"importRequire")}}}else{Utils.reportMissingBootstrapInfo(context,"allComponents")}};ruleDef.prototype._verifyPath=function(context,pathToCheck,componentInfo,importType){if(pathToCheck&&typeof pathToCheck==="string"){let pathVerified=false;const allValidPaths=context.rulePack.getRuleOptions().customOpts.standardPaths.slice(0);const additionalPaths=context.rulePack.getRuleOptions().customOpts.additionalPaths;if(additionalPaths&&Array.isArray(additionalPaths)){additionalPaths.forEach(addPath=>{allValidPaths.push(addPath)})}if(componentInfo.requirePaths){componentInfo.requirePaths.forEach(depPath=>{allValidPaths.push(depPath)})}let targetPath=pathToCheck;const pluginPos=targetPath.indexOf("!");if(pluginPos>=0){targetPath=targetPath.substring(pluginPos+1)}const targetPathParts=targetPath.split("/");if(targetPathParts[0]!==".."){if(allValidPaths.includes(targetPathParts[0])){pathVerified=true}else{if(targetPathParts[1]){const packCompPath=targetPathParts[0]+"/"+targetPathParts[1];if(allValidPaths.includes(packCompPath)){pathVerified=true}}}}else{let walkBackDepth=0;let examineSegment="..";while(examineSegment===".."){examineSegment=targetPathParts.shift();if(examineSegment===".."){walkBackDepth++}}const compRootPathParts=componentInfo.rootFolder.split("/");const importingFileParts=context.filepath.split("/");for(let i=walkBackDepth;i>=0;i--){importingFileParts.pop()}if(importingFileParts.length>=compRootPathParts.length){if(importingFileParts.slice(0,compRootPathParts.length).join("/")===componentInfo.rootFolder){pathVerified=true}}}if(!pathVerified){let sourceInfo;switch(importType){case"import":sourceInfo="Import";break;case"importRequire":sourceInfo="Import via require()";break;case"define":sourceInfo="Import via define()";break;case"require":sourceInfo="Import via require()";break};issue=new context.Issue(`${sourceInfo} for component ${componentInfo.fullName} is not based on a valid path in that component context. Valid paths would be [${allValidPaths.join(",")}] encountered: '${pathToCheck}'`);context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;
|
|
@@ -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
|
|
6
|
+
const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-schema"};ruleDef.prototype.getShortDescription=function(){return"Validate component json definition against the schema"};ruleDef.prototype.getDescription=function(){return"This rule checks verifies the component.json file included by or generated from the component against the schema supplied for this purpose"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context,obj){let issue;if(context.suppData.obj){const jsonToValidate=obj.obj.component?obj.obj.component:obj.obj;const schemaErrors=context.utils.metaLib.applySchema(jsonToValidate);if(schemaErrors){schemaErrors.forEach(error=>{issue=new context.Issue(`component.json schema violation: ${this._formatViolation(error)}`);context.reporter.addIssue(issue,context)})}}};ruleDef.prototype._doVComponentAudit=function(context){const customOpts=context.rulePack.getRuleOptions().customOpts;let lenient=false;if(customOpts){lenient=customOpts.ignoreAdditionalProperties}const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo&&componentInfo.compiledMetadata){const jsonToValidate=componentInfo.compiledMetadata;const schemaErrors=context.utils.metaLib.applySchema(jsonToValidate);if(schemaErrors){const encounteredErrors=new Set;schemaErrors.forEach(report=>{const skip=lenient&&report.error&&report.error.keyword==="additionalProperties";if(!skip){const formattedError=this._formatViolation(report);if(!encounteredErrors.has(formattedError)){encounteredErrors.add(formattedError);issue=new context.Issue(`Generated component.json has schema violation: ${formattedError}`);context.reporter.addIssue(issue,context)}}})}}};ruleDef.prototype._formatViolation=function(report){let formattedMsg;switch(report.error.keyword){case"required":const jsonErrorPath=report.error.dataPath?report.error.dataPath:report.error.instancePath;const formattedPath=this._transformViolationDataPath(jsonErrorPath);formattedMsg=`${formattedPath} ${report.msg}`;break;default:formattedMsg=report.msg}return formattedMsg};ruleDef.prototype._transformViolationDataPath=function(dataPath){let formatted=dataPath;;const parser=/\.(\w*)\['(\w*)'\]/g;const segparser=/\.(\w*)\['(\w*)'\]/;const instancePathParser=/\/(\w*)\/(\w*)/g;const instancePathSegParser=/\/(\w*)\/(\w*)/;let segments=dataPath.match(parser);let deconstructed;if(segments!==null){deconstructed=segments.map(seg=>{subParts=seg.match(segparser);return{segment:subParts[0],type:subParts[1],context:subParts[2]}})}else{segments=dataPath.match(instancePathParser);deconstructed=segments.map(seg=>{subParts=seg.match(instancePathSegParser);return{segment:subParts[0],type:subParts[1],context:subParts[2]}})}if(deconstructed&&deconstructed.length>0){if(deconstructed[0].type==="properties"){formatted=`Property ${deconstructed[0].context}`;if(deconstructed.length>1){for(let i=1;i<deconstructed.length;i++){if(deconstructed[i].type==="properties"){formatted+=`.${deconstructed[i].context}`}else{formatted+=` ${deconstructed[i].type}:${deconstructed[i].context}`}}}}}return formatted};module.exports=ruleDef;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
|
|
3
|
+
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
|
+
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
|
+
*/
|
|
6
|
+
const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-well-formed-description"};ruleDef.prototype.getShortDescription=function(){return"Ensure that description text is defined as complete sentences"};ruleDef.prototype.getDescription=function(){return"This rule checks that any description text defined as part of a components metadata is expressed as well formed sentences with a leading capital and terminating period / full stop"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){this._checkAllDescriptions(context,context.suppData.obj)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkAllDescriptions(context,componentInfo)}};ruleDef.prototype._checkAllDescriptions=function(context,meta){const descriptionInstances=this._gatherDescriptions(meta);descriptionInstances.forEach(({description,locator})=>{if(!this._isValidSentenceForm(description)){issue=new context.Issue(`${locator} description is not well formed. Sentences should begin with a capital and be terminated with a period / full stop.`);context.reporter.addIssue(issue,context)}})};ruleDef.prototype._gatherDescriptions=function(meta){let allDescriptions=[];if(meta.description){allDescriptions.push({description:meta.description,locator:"Component level"})}const propertyList=Utils.flattenComponentProperties(meta,"description");allDescriptions=allDescriptions.concat(propertyList.map(({key,value})=>{return{description:value,locator:`Property ${key}`}}));if(meta.events){Object.entries(meta.events).forEach(([key,value])=>{if(value?.description?.length>0){allDescriptions.push({description:value.description,locator:`Event ${key}`})}if(value?.detail){Object.entries(value.detail).forEach(([detailKey,detailValue])=>{if(detailValue?.description?.length>0){allDescriptions.push({description:detailValue.description,locator:`Event ${key} detail entry ${detailKey}`})}})}})}if(meta.methods){Object.entries(meta.methods).forEach(([key,value])=>{if(value?.description?.length>0){allDescriptions.push({description:value.description,locator:`Method ${key}`})}if(value?.params){value.params.forEach(parameter=>{if(parameter.description?.length>0){allDescriptions.push({description:parameter.description,locator:`Method ${key} ${parameter.name} parameter`})}})}})}if(meta.slots){Object.entries(meta.slots).forEach(([key,value])=>{if(value?.description?.length>0){const slotId=key.length===0?"Default slot":`Slot ${key}`;allDescriptions.push({description:value.description,locator:slotId})}if(value?.data){Object.entries(value.data).forEach(([dataKey,dataValue])=>{if(dataValue?.description?.length>0){allDescriptions.push({description:dataValue.description,locator:`Template Slot ${key} data entry ${dataKey}`})}})}})}return allDescriptions};ruleDef.prototype._isValidSentenceForm=function(description){let wellFormed=true;if(description){const baseDesc=description.trim();const decomposed=baseDesc.split(/\.(?=\s)/).reverse();if(decomposed[0].endsWith(".")){decomposed.forEach(description=>{if(!description.trimStart().match(/^[A-Z].*/)){wellFormed=false}})}else{wellFormed=false}}return wellFormed};module.exports=ruleDef;
|
|
@@ -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
|
-
{"jetwc-component-foldername":"0010","jetwc-component-location_1":"0011","jetwc-component-location_2":"0012","jetwc-pack-children_1":"0013","jetwc-pack-children_2":"0014","jetwc-pack-children_3":"0015","jetwc-pack-children_4":"0016","jetwc-packable-components_1":"0017","jetwc-packable-components_2":"0018","jetwc-packable-components_3":"0019","jetwc-component-dependencies_1":"0021","jetwc-component-dependencies_2":"0022","jetwc-component-dependencies_3":"0023","jetwc-component-dependencies_4":"0024","jetwc-component-dependencies_5":"0025","jetwc-prerelease-version":"0026","jetwc-prerelease-dependencies":"0027","jetwc-namespace":"0029","jetwc-vb-category_1":"0030","jetwc-vb-category_2":"0031","jetwc-jet-version_1":"0033","jetwc-jet-version_2":"0034","jetwc-absolute-jetversion":"0035","jetwc-semantic-version":"0040","jetwc-standard-files":"0041","jetwc-loader-file_1":"0044","jetwc-loader-file_2":"0045","jetwc-loader-file_3":"0046","jetwc-loader-file_4":"0047","jetwc-version-openrange_1":"0048","jetwc-version-openrange_2":"0049","jetwc-displayname_1":"0050","jetwc-displayname_2":"0051","jetwc-nls-root":"0052","jetwc-require-paths":"0053","jetwc-vb-icon_1":"0054","jetwc-vb-icon_2":"0055","jetwc-vb-icon_3":"0056","jetwc-vb-icon_4":"0057","jetwc-vb-icon_5":"0058","jetwc-vb-icon_6":"0059","jetwc-vb-icon_7":"0060","jetwc-vb-icon_8":"0061","jetwc-template-slots_1":"0062","jetwc-template-slots_2":"0063","jetwc-template-slots_3":"0064","jetwc-template-slots_4":"0065","jetwc-template-slots_5":"0066","jetwc-slots_1":"0067","jetwc-slots_2":"0068","jetwc-events_1":"0069","jetwc-events_2":"0070","jetwc-property-nesting":"0071","jetwc-nls-languages_1":"0072","jetwc-nls-languages_2":"0073","jetwc-nls-languages_3":"0074","jetwc-nls-languages_4":"0075","jetwc-event-displayname":"0076","jetwc-methods_1":"0077","jetwc-methods_2":"0078","jetwc-property-changed":"0079","jetwc-writeback-required_1":"0080","jetwc-writeback-required_2":"0081","jetwc-writeback-required_3":"0082","jetwc-writeback-required_4":"0083","jetwc-oj-register":"0084","jetwc-register-with-promises":"0085","jetwc-register-css":"0086","jetwc-deprecated-lifecycle":"0087","jetwc-aria-redefinition":"0088","jetwc-public-modules_1":"0089","jetwc-public-modules_2":"0090","jetwc-disabled-property":"0091","jetwc-reserved-property":"0092","jetwc-prerelease-pattern":"0093","jetwc-ojcss":"0094","jetwc-vb-icon_9":"0095","jetwc-component-location_3":"0096","jetwc-dynamic-slot-context":"0097","jetwc-dynamic-slots-naming":"0098","jetwc-unused-slots":"0099","jetwc-unused-events":"0100","jetwc-compjson-bp-obj":"0101","jetwc-compjson-bp-ar":"0102","jetwc-method-displayname":"0103","jetwc-slot-displayname":"0104","jetwc-component-displayname":"0105","jetwc-property-displayname":"0106","jetwc-data-property-prefix":"0107","jetwc-schema":"0108","jetwc-component-type":"0109","jetwc-subproperty-writeback":"0111","jetwc-nested-defaults":"0112","jetwc-required-subproperty":"0113","jetwc-vcomponent-jetversion_1":"0120","jetwc-vcomponent-jetversion_2":"0121","jetwc-vcomponent-version_1":"0130","jetwc-vcomponent-version_2":"0131","jetwc-vcomponent-version_3":"0132","jetwc-vcomponent-loader_1":"0140","jetwc-vcomponent-loader_2":"0141","jetwc-markdown-link_1":"0150","jetwc-markdown-link_2":"0151","jetwc-css-oj-complete":"0160","jetwc-supproperty-propagation":"0170","jetwc-css-scoping":"0180","jetwc-exchange-images_1":"0190","jetwc-exchange-images_2":"0191","jetwc-property-translatable":"0200","jetwc-status-since_1":"0210","jetwc-status-since_2":"0211","jetwc-status-since_3":"0212","jetwc-reference-npm-path":"0220","jetwc-css-pack-load-path":"0230"}
|
|
6
|
+
{"jetwc-component-foldername":"0010","jetwc-component-location_1":"0011","jetwc-component-location_2":"0012","jetwc-pack-children_1":"0013","jetwc-pack-children_2":"0014","jetwc-pack-children_3":"0015","jetwc-pack-children_4":"0016","jetwc-packable-components_1":"0017","jetwc-packable-components_2":"0018","jetwc-packable-components_3":"0019","jetwc-component-dependencies_1":"0021","jetwc-component-dependencies_2":"0022","jetwc-component-dependencies_3":"0023","jetwc-component-dependencies_4":"0024","jetwc-component-dependencies_5":"0025","jetwc-prerelease-version":"0026","jetwc-prerelease-dependencies":"0027","jetwc-namespace":"0029","jetwc-vb-category_1":"0030","jetwc-vb-category_2":"0031","jetwc-jet-version_1":"0033","jetwc-jet-version_2":"0034","jetwc-absolute-jetversion":"0035","jetwc-semantic-version":"0040","jetwc-standard-files":"0041","jetwc-loader-file_1":"0044","jetwc-loader-file_2":"0045","jetwc-loader-file_3":"0046","jetwc-loader-file_4":"0047","jetwc-version-openrange_1":"0048","jetwc-version-openrange_2":"0049","jetwc-displayname_1":"0050","jetwc-displayname_2":"0051","jetwc-nls-root":"0052","jetwc-require-paths":"0053","jetwc-vb-icon_1":"0054","jetwc-vb-icon_2":"0055","jetwc-vb-icon_3":"0056","jetwc-vb-icon_4":"0057","jetwc-vb-icon_5":"0058","jetwc-vb-icon_6":"0059","jetwc-vb-icon_7":"0060","jetwc-vb-icon_8":"0061","jetwc-template-slots_1":"0062","jetwc-template-slots_2":"0063","jetwc-template-slots_3":"0064","jetwc-template-slots_4":"0065","jetwc-template-slots_5":"0066","jetwc-slots_1":"0067","jetwc-slots_2":"0068","jetwc-events_1":"0069","jetwc-events_2":"0070","jetwc-property-nesting":"0071","jetwc-nls-languages_1":"0072","jetwc-nls-languages_2":"0073","jetwc-nls-languages_3":"0074","jetwc-nls-languages_4":"0075","jetwc-event-displayname":"0076","jetwc-methods_1":"0077","jetwc-methods_2":"0078","jetwc-property-changed":"0079","jetwc-writeback-required_1":"0080","jetwc-writeback-required_2":"0081","jetwc-writeback-required_3":"0082","jetwc-writeback-required_4":"0083","jetwc-oj-register":"0084","jetwc-register-with-promises":"0085","jetwc-register-css":"0086","jetwc-deprecated-lifecycle":"0087","jetwc-aria-redefinition":"0088","jetwc-public-modules_1":"0089","jetwc-public-modules_2":"0090","jetwc-disabled-property":"0091","jetwc-reserved-property":"0092","jetwc-prerelease-pattern":"0093","jetwc-ojcss":"0094","jetwc-vb-icon_9":"0095","jetwc-component-location_3":"0096","jetwc-dynamic-slot-context":"0097","jetwc-dynamic-slots-naming":"0098","jetwc-unused-slots":"0099","jetwc-unused-events":"0100","jetwc-compjson-bp-obj":"0101","jetwc-compjson-bp-ar":"0102","jetwc-method-displayname":"0103","jetwc-slot-displayname":"0104","jetwc-component-displayname":"0105","jetwc-property-displayname":"0106","jetwc-data-property-prefix":"0107","jetwc-schema":"0108","jetwc-component-type":"0109","jetwc-subproperty-writeback":"0111","jetwc-nested-defaults":"0112","jetwc-required-subproperty":"0113","jetwc-vcomponent-jetversion_1":"0120","jetwc-vcomponent-jetversion_2":"0121","jetwc-vcomponent-version_1":"0130","jetwc-vcomponent-version_2":"0131","jetwc-vcomponent-version_3":"0132","jetwc-vcomponent-loader_1":"0140","jetwc-vcomponent-loader_2":"0141","jetwc-markdown-link_1":"0150","jetwc-markdown-link_2":"0151","jetwc-css-oj-complete":"0160","jetwc-supproperty-propagation":"0170","jetwc-css-scoping":"0180","jetwc-exchange-images_1":"0190","jetwc-exchange-images_2":"0191","jetwc-property-translatable":"0200","jetwc-status-since_1":"0210","jetwc-status-since_2":"0211","jetwc-status-since_3":"0212","jetwc-reference-npm-path":"0220","jetwc-css-pack-load-path":"0230","jetwc-well-formed-description":"0240"}
|
|
@@ -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
|
-
{"title":"Extended Audit Rules for JET Custom Component Authors","prefix":"JETWC","version":"1.
|
|
6
|
+
{"title":"Extended Audit Rules for JET Custom Component Authors","prefix":"JETWC","version":"1.28.1","rules":{"jetwc-bootstrap":{"group":"jetwc-do-not-disable","enabled":true,"severity":"info","debug":false,"diagnosticFile":"jetwc-diagnostics","auditBuildOutput":false,"testMode":false,"$required":true,"filetype":["tsx","css","html","js","json","md","ts"],"amd":false},"jetwc-component-foldername":{"group":"jetwc-structure","severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-component-location":{"group":"jetwc-structure","severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-pack-children":{"group":"jetwc-dependencies","severity":"blocker","filetype":["json"],"amd":false},"jetwc-packable-components":{"group":"jetwc-structure","severity":"blocker","filetype":["json"],"amd":false},"jetwc-component-dependencies":{"group":"jetwc-dependencies","severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-prerelease-version":{"group":"jetwc-pre-release","severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-prerelease-dependencies":{"group":"jetwc-pre-release","severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-namespace":{"group":"jetwc-api","enabled":false,"namespaces":[],"severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-vb-category":{"group":"jetwc-vb","enabled":false,"categories":[],"severity":"minor","filetype":["json","tsx"],"amd":false},"jetwc-jet-version":{"group":"jetwc-pre-release","enabled":false,"versionMatch":"upperLimit","severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-absolute-jetversion":{"group":"jetwc-dependencies","enabled":true,"severity":"minor","filetype":["json","tsx"],"amd":false},"jetwc-semantic-version":{"group":"jetwc-dependencies","severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-standard-files":{"group":"jetwc-structure","enabled":true,"files":["README.md","CHANGELOG.md"],"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-loader-file":{"group":["jetwc-structure","jet-js"],"enabled":true,"severity":"critical","filetype":["json","js","ts","tsx"],"amd":false},"jetwc-version-openrange":{"group":"jetwc-dependencies","severity":"major","filetype":["json","tsx"],"amd":false},"jetwc-displayname":{"group":"jetwc-vb","enabled":true,"limits":{"component":{"length":30,"words":4},"property":{"length":30,"words":4},"event":{"length":30,"words":4},"slot":{"length":30,"words":4},"template":{"length":40,"words":8}},"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-nls-root":{"group":"jetwc-nls","enabled":true,"severity":"info","filetype":["js","ts","tsx"],"amd":false},"jetwc-require-paths":{"group":"jetwc-dependencies","enabled":true,"severity":"blocker","standardPaths":["require","exports","ojs","oj-c","knockout","hammerjs","persist","jquery","vb","preact","@opentelemetry"],"filetype":["js","ts","tsx"],"amd":false},"jetwc-vb-icon":{"group":"jetwc-vb","enabled":true,"severity":"major","filetype":["json","tsx"],"amd":false},"jetwc-template-slots":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["html","tsx"],"amd":false},"jetwc-slots":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["html","tsx"],"amd":false},"jetwc-events":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["js","ts","tsx"],"amd":false},"jetwc-property-nesting":{"group":"jetwc-api","enabled":true,"depth":3,"severity":"minor","filetype":["json","tsx"],"amd":false},"jetwc-nls-languages":{"group":"jetwc-nls","enabled":false,"locales":[],"strict":false,"severity":"major","filetype":["js","ts"],"amd":false},"jetwc-event-displayname":{"group":"jetwc-vb","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-nested-defaults":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["json","tsx"],"amd":false},"jetwc-methods":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["js","ts"],"amd":false},"jetwc-property-changed":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["js","ts"],"amd":false},"jetwc-writeback-required":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["js","ts"],"amd":false},"jetwc-oj-register":{"group":"jetwc-deprecations","enabled":true,"severity":"minor","filetype":["js","ts"],"amd":false},"jetwc-register-with-promises":{"group":"jetwc-deprecations","enabled":true,"severity":"minor","filetype":["js","ts"],"amd":false},"jetwc-register-css":{"group":"jetwc-deprecations","enabled":true,"severity":"minor","filetype":["js","ts"],"amd":false},"jetwc-deprecated-lifecycle":{"group":"jetwc-deprecations","enabled":true,"severity":"major","filetype":["js","ts"],"amd":false},"jetwc-aria-redefinition":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["json","tsx"],"amd":false},"jetwc-public-modules":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["json"],"amd":false},"jetwc-disabled-property":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["json"],"amd":false},"jetwc-reserved-property":{"group":"jetwc-api","enabled":true,"severity":"major","reserved":["slot","key","ref","children"],"filetype":["json","tsx"],"amd":false},"jetwc-prerelease-pattern":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["json","tsx"],"amd":false},"jetwc-ojcss":{"group":"jetwc-theming","enabled":true,"severity":"minor","filetype":["js","ts","tsx"],"amd":false},"jetwc-dynamic-slot-context":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["json"],"amd":false},"jetwc-dynamic-slots-naming":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["json"],"amd":false},"jetwc-unused-slots":{"group":"jetwc-api","enabled":true,"severity":"info","filetype":["html"],"amd":false},"jetwc-unused-events":{"group":"jetwc-api","enabled":true,"severity":"info","filetype":["js","ts"],"amd":false},"jetwc-compjson-bp-obj":{"group":"jetwc-api","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-compjson-bp-ar":{"group":"jetwc-api","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-component-displayname":{"group":"jetwc-vb","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-method-displayname":{"group":"jetwc-vb","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-property-displayname":{"group":"jetwc-vb","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-slot-displayname":{"group":"jetwc-vb","enabled":true,"severity":"info","filetype":["json","tsx"],"amd":false},"jetwc-data-property-prefix":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["json","tsx"],"amd":false},"jetwc-schema":{"group":"jetwc-api","enabled":true,"severity":"blocker","ignoreAdditionalProperties":false,"filetype":["json","tsx"],"amd":false},"jetwc-component-type":{"group":"jetwc-api","enabled":true,"severity":"info","filetype":["json"],"amd":false},"jetwc-subproperty-writeback":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["html"],"amd":false},"jetwc-required-subproperty":{"group":"jetwc-api","enabled":true,"severity":"minor","filetype":["json"],"amd":false},"jetwc-vcomponent-jetversion":{"group":"jetwc-dependencies","enabled":true,"severity":"blocker","filetype":["tsx"],"amd":false},"jetwc-vcomponent-version":{"group":"jetwc-dependencies","enabled":true,"severity":"blocker","filetype":["tsx"],"amd":false},"jetwc-vcomponent-loader":{"group":"jetwc-structure","enabled":true,"severity":"blocker","filetype":["ts"],"amd":false},"jetwc-markdown-link":{"group":"jetwc-doc","enabled":true,"severity":"minor","filetype":["md"],"amd":false},"jetwc-css-oj-complete":{"group":"jetwc-css","enabled":true,"severity":"major","filetype":["css"],"amd":false},"jetwc-supproperty-propagation":{"group":"jetwc-api","enabled":true,"severity":"major","filetype":["html"],"amd":false},"jetwc-css-scoping":{"group":"jetwc-css","enabled":true,"severity":"blocker","filetype":["css"],"amd":false,"allowPackScoping":true},"jetwc-exchange-images":{"group":"jetwc-structure","enabled":true,"severity":"major","filetype":["json","tsx"],"amd":false},"jetwc-property-translatable":{"group":"jetwc-vb","enabled":false,"severity":"minor","filetype":["json","tsx"],"amd":false,"translatableProperties":[],"expressionMatch":false},"jetwc-status-since":{"group":"jetwc-api","enabled":true,"severity":"blocker","filetype":["json","tsx"],"amd":false},"jetwc-reference-npm-path":{"group":"jetwc-structure","enabled":true,"severity":"major","filetype":["json"],"amd":false},"jetwc-css-pack-load-path":{"group":"jetwc-dependencies","enabled":true,"severity":"blocker","filetype":["js","ts","tsx"],"amd":false},"jetwc-well-formed-description":{"group":"jetwc-api","enabled":false,"severity":"info","filetype":["json","tsx"],"amd":false}}}
|
|
@@ -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 path=require("path");const Utils=function(){this.rootPoint=this.toJAFPath(path.resolve(".")).length+1;this.isWindows=path.sep!=="/";this.noJSWarnDone=false};Utils.prototype.getKeyPathInfoForRulepack=function(context,auditBase){const paths={isBuiltOutput:false,componentRootFolder:null,exchangeCacheFolder:null,generalSourceRoot:"src",jsSource:null,tsSource:null,base:null};let jetConfig=context.ojetConfig;if(!jetConfig&&auditBase){const remoteConfig=path.join(auditBase,"oraclejetconfig.json");if(context.utils.fsUtils.pathExistsSync(remoteConfig)){jetConfig=context.utils.fsUtils.readJsonSync(remoteConfig)}}let jsDir="js";let tsDir="ts";paths.isBuiltOutput=context.rulePack.getRuleOptions().auditBuildOutput;paths.base=path.resolve(auditBase);if(jetConfig){jsDir=jetConfig.paths.source.javascript||"js";tsDir=jetConfig.paths.source.typescript||"ts";paths.exchangeCacheFolder=jetConfig.paths.source.exchangeComponents||"jet_components";paths.componentRootFolder=jetConfig.paths.source.components||"jet-composites";if(!paths.isBuiltOutput){paths.generalSourceRoot=jetConfig.paths.source.common||"src"}else{paths.generalSourceRoot=jetConfig.paths.staging.web||"web"}}paths.jsSource=this.toJAFPath(path.join(paths.generalSourceRoot,jsDir));if(!paths.isBuiltOutput){paths.tsSource=this.toJAFPath(path.join(paths.generalSourceRoot,tsDir))}return paths};Utils.prototype.matchComponentPath=function(context,checkPathBase,recursion){let checkPath=this.toJAFPath(checkPathBase);let componentMatch;if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allAuditableFilePaths")){if(context.rulePack.getExtension().allAuditableFilePaths.has(checkPath)){const x=context.rulePack.getExtension().allAuditableFilePaths;componentMatch=context.rulePack.getExtension().allAuditableFilePaths.get(checkPath)}else if(checkPath.includes(context.rulePack.getExtension().componentHome)){if(context.rulePack.getExtension().auditableComponentPaths.has(checkPath)){componentMatch=context.rulePack.getExtension().auditableComponentPaths.get(checkPath)}else{const parentPath=path.resolve(checkPathBase,".."+path.sep);componentMatch=this.matchComponentPath(context,parentPath,true)}if(!recursion){context.rulePack.getExtension().allAuditableFilePaths.set(checkPath,componentMatch)}}else{context.rulePack.getExtension().allAuditableFilePaths.set(checkPath)}}else{this.reportMissingBootstrapInfo(context,"allAuditableFilePaths")}return componentMatch};Utils.prototype.reportMissingBootstrapInfo=function(context,checkTopic){const msg=context.utils.msgLib;const extnContext=context.rulePack.getExtension();if(!extnContext||!extnContext.bootStrap){const bootstrapRule=context.rulePack.getPrefix().toLowerCase()+"-bootstrap";if(context.rulePack.isRuleDisabled(bootstrapRule)){msg.error(`You must enable the ${bootstrapRule} rule to run in order to carry out a full component set audit`)}else{msg.error(`Apparent bootstrap error, no information cached for ${checkTopic}`)}context.rulePack.setExtension({...extnContext,bootStrap:true})}};Utils.prototype.componentInfo=function(context,componentName){if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){return context.rulePack.getExtension().allComponents.get(componentName)}else{this.reportMissingBootstrapInfo(context,"allComponents")}return};Utils.prototype.getComponentFullName=function(metadata){return metadata.pack?`${metadata.pack}-${metadata.name}`:metadata.name};Utils.prototype.getComponentType=function(metadata){return metadata.type?metadata.type:"composite"};Utils.prototype.flattenComponentProperties=function(metaDef,valueAttribute,filterCondition,parentPath){let flattenedProps=[];if(metaDef.hasOwnProperty("properties")){const propArray=Object.keys(metaDef.properties);propArray.forEach(propertyName=>{const propertyMetadata=metaDef.properties[propertyName];let key;if(!parentPath){key=propertyName}else{key=parentPath+"."+propertyName}if(!filterCondition||filterCondition(propertyName,propertyMetadata)){flattenedProps.push({key:key,value:metaDef.properties[propertyName][valueAttribute]})}const subPropsArray=this.flattenComponentProperties(metaDef.properties[propertyName],valueAttribute,filterCondition,key);flattenedProps=flattenedProps.concat(subPropsArray)})}return flattenedProps};Utils.prototype.setupFileMethodMapping=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();const fileName=context.filepath;const withinComponent=this.matchComponentPath(context,path.dirname(fileName));if(withinComponent&&node.parent){if(node.parent.type===NT.ASSIGNMENT_EXPR&&node.parent.operator==="="){if(node.parent.left&&node.parent.left.property&&node.parent.left.property.type==NT.IDENTIFIER&&node.parent.left.property.name){const methodDef={name:node.parent.left.property.name,parameters:node.params?node.params.length:0};this.cacheFileMethod(context,fileName,methodDef)}}else if(node.parent.type===NT.METH_DEF&&node.parent.kind==="method"){if(node.parent.key&&node.parent.key.name){const methodDef={name:node.parent.key.name,parameters:node.params?node.params.length:0};this.cacheFileMethod(context,fileName,methodDef)}}else if(node.parent.type===NT.CLASS_PROP||node.parent.type===NT.PROPERTY_DEF){if(node.parent.key&&node.parent.key.name){const methodDef={name:node.parent.key.name,parameters:node.params?node.params.length:0};this.cacheFileMethod(context,fileName,methodDef)}}}};Utils.prototype.setupFileMethodMappingFromMethodDefintion=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();const fileName=context.filepath;const withinComponent=this.matchComponentPath(context,path.dirname(fileName));if(withinComponent){const methodDef={parameters:0};if(node.key&&node.key.type===NT.IDENTIFIER){methodDef.name=node.key.name;if(node.value&&node.value.type===NT.FUNC_EXPR&&node.value.params){methodDef.parameters=node.value.params.length}}if(methodDef.name){this.cacheFileMethod(context,fileName,methodDef)}}};Utils.prototype.cacheFileMethod=function(context,filePath,methodDef){if(!context.rulePack.getExtension().allDefinedFileMethods){context.rulePack.getExtension().allDefinedFileMethods=new Map}if(!context.rulePack.getExtension().allDefinedFileMethods.has(filePath)){context.rulePack.getExtension().allDefinedFileMethods.set(filePath,{methods:new Map})}if(!context.rulePack.getExtension().allDefinedFileMethods.get(filePath).methods.has(methodDef.name)){context.rulePack.getExtension().allDefinedFileMethods.get(filePath).methods.set(methodDef.name,methodDef)}};Utils.prototype.deriveViewModels=function(context,node){const fileName=context.filepath;if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){const withinComponent=this.matchComponentPath(context,path.dirname(fileName));const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);if(withinComponent&&componentInfo&&componentInfo.type==="composite"&&!componentInfo.viewModel.resolved){const targetLoaderExt=componentInfo.language==="tsx"?".ts":`.${componentInfo.language}`;if(path.basename(fileName,targetLoaderExt)==="loader"){switch(componentInfo.language){case"js":case"ts":const registerInfo=this.getLoaderRegisterInfo(context,node);if(registerInfo){const vmRelativeFilePath=this._mapVMToImpl(context,node,registerInfo.viewModel,componentInfo.language==="ts");if(vmRelativeFilePath){const fullVMPath=this._expandPathInContext(context,withinComponent,vmRelativeFilePath);if(fullVMPath){componentInfo.viewModel={path:this.toJAFPath(path.resolve(".",`${fullVMPath}.${componentInfo.language}`)),resolved:true,skip:false}}}}break;case"tsx":break}}}}else{this.reportMissingBootstrapInfo(context,"allComponents")}};Utils.prototype.getLoaderRegisterInfo=function(context,node){const msg=context.utils.msgLib;const NT=context.utils.AstUtils.getNodeTypes();let registerInfo;if(node.callee.type=NT.MEMBER_EXPR&&node.callee.object&&node.arguments&&node.arguments.length>0){let isRegister=false;let oldStyle=false;switch(node.callee.object.type){case NT.IDENTIFIER:if(node.callee.object.name==="Composite"){isRegister=this._astPropertyIdentifierName(context,node.callee,"register")}break;case NT.MEMBER_EXPR:if(node.callee.property&&node.callee.property.type===NT.IDENTIFIER&&node.callee.property.name==="register"){if(this._astPropertyIdentifierName(context,node.callee.object,"Composite")){isRegister=node.callee.object.object&&node.callee.object.object.type===NT.IDENTIFIER&&node.callee.object.object.name==="oj";if(isRegister){oldStyle=true}}}break}if(isRegister){registerInfo={oldStyle:oldStyle};const tagArg=node.arguments[0];const def=node.arguments[1];registerInfo.tag=tagArg.type===NT.LITERAL?tagArg.value:"?";if(def.type===NT.OBJ_EXPR){vmProp=def.properties.filter(prop=>prop.key.name==="viewModel");if(vmProp.length===1){switch(vmProp[0].value.type){case NT.IDENTIFIER:registerInfo.viewModel=vmProp[0].value.name;break;case NT.OBJ_EXPR:if(vmProp[0].value.properties&&vmProp[0].value.properties[0]&&vmProp[0].value.properties[0].key.name==="inline"){registerInfo.viewModel=vmProp[0].value.properties[0].value.name;registerInfo.usesPromises=true}break;case NT.MEMBER_EXPR:if(vmProp[0].value.property&&vmProp[0].value.property.type===NT.IDENTIFIER){registerInfo.viewModel=vmProp[0].value.object.name;registerInfo.transpiled=true}break;case"TSAsExpression":if(vmProp[0].value.expression&&vmProp[0].value.expression.type===NT.IDENTIFIER){registerInfo.viewModel=vmProp[0].value.expression.name}else if(vmProp[0].value.expression&&vmProp[0].value.expression.type===NT.AS_EXPR){registerInfo.viewModel=vmProp[0].value.expression.expression.name;msg.msg(`WARNING: Component loader file ${context.filepath} attempts to redefine the composite.register viewModel interface`)}break}}const cssCheck=def.properties.filter(prop=>prop.key.name==="css");if(cssCheck.length>0){registerInfo.registerCSS=true}}}}return registerInfo};Utils.prototype._astPropertyIdentifierName=function(context,node,checkName){const NT=context.utils.AstUtils.getNodeTypes();return node&&node.property&&node.property.type===NT.IDENTIFIER&&node.property.name===checkName};Utils.prototype._mapVMToImpl=function(context,node,vmName,useImports){let vmPathDef;if(vmName){let rootNode=node;if(useImports){vmPathDef=this._getImportPath(context,rootNode,vmName)}else{vmPathDef=this._getDefineStatementPath(context,rootNode,vmName);if(!vmPathDef){vmPathDef=this._mapToRequireAssignment(context,node,vmName)}}}return vmPathDef};Utils.prototype._mapToRequireAssignment=function(context,node,vmName){const NT=context.utils.AstUtils.getNodeTypes();let requirePath;const vmDeclNode=this._locateDeclaration(context,node,vmName);if(vmDeclNode.type===NT.CALL_EXPR&&vmDeclNode.callee.type===NT.IDENTIFIER&&vmDeclNode.callee.name==="require"){if(vmDeclNode.arguments&&vmDeclNode.arguments.length===1&&vmDeclNode.arguments[0].type===NT.LITERAL){requirePath=vmDeclNode.arguments[0].value}}return requirePath};Utils.prototype._getImportPath=function(context,node,importAs){const NT=context.utils.AstUtils.getNodeTypes();const bodyNodeArray=context.utils.AstUtils.getBody();let definePath;for(let i=0;i<bodyNodeArray.length;i++){const testNode=bodyNodeArray[i];switch(testNode.type){case"ImportDeclaration":if(testNode.specifiers&&Array.isArray(testNode.specifiers)&&testNode.specifiers.length===1&&(testNode.specifiers[0].type===NT.IMPORT_DEF_SPECIFIER||testNode.specifiers[0].type===NT.IMPORT_SPECIFIER)&&testNode.specifiers[0].local&&testNode.specifiers[0].local.name===importAs){definePath=testNode.source.value}break;case"TSImportEqualsDeclaration":if(testNode.id&&testNode.id.type===NT.IDENTIFIER&&testNode.id.name===importAs&&testNode.moduleReference&&testNode.moduleReference.type===NT.EXTERN_MOD_REF&&testNode.moduleReference.expression&&testNode.moduleReference.expression.type===NT.LITERAL){definePath=testNode.moduleReference.expression.value}break}if(definePath){;break}}return definePath};Utils.prototype._getDefineStatementPath=function(context,node,defineParam){const NT=context.utils.AstUtils.getNodeTypes();let checkNode=node.parent;let definePath;while(checkNode){if(checkNode.type===NT.CALL_EXPR&&checkNode.callee.name==="define"){definePath=context.utils.AstUtils.parseDefine(checkNode)[defineParam]}checkNode=checkNode.parent}return definePath};Utils.prototype._expandPathInContext=function(context,componentName,requirePath){let targetPath=requirePath;const parsePluginParts=requirePath.split("!");if(parsePluginParts.length>1){targetPath=parsePluginParts[1]}let pathParts=targetPath.split("/");const decodeRoot=pathParts[0];if(decodeRoot==="."){pathParts[0]=this.rootPathForComponent(context,componentName)}else{const remotePart=this.rootPathForComponent(context,decodeRoot);if(!remotePart){pathParts=[]}else{pathParts[0]=remotePart}}return pathParts.join("/")};Utils.prototype.rootPathForComponent=function(context,componentName){if(context.rulePack.getExtension().allComponents.has(componentName)){return context.rulePack.getExtension().allComponents.get(componentName).rootFolder}};Utils.prototype.getVMMethodsForLocalComposite=function(context,component){let vmMethods;const msg=context.utils.msgLib;const opts=context.rulePack.getRuleOptions();if(component.local&&component.type==="composite"){if(!component.viewModel.skip){if(!component.viewModel.resolved&&!component.viewModel.warned){if(!opts.testMode){msg.msg(`Warning: unable to derive the correct viewModel implementation for component ${component.fullName}, either your audit run does not include .js/.ts files, or you may need to set 'extension.audit.jetwc.viewModel' in the metadata to provide a hint`)}component.viewModel.warned=true}else{const rpState=context.rulePack.getExtension();if(rpState.allDefinedFileMethods&&rpState.allDefinedFileMethods.size>0){const vmMethodDef=rpState.allDefinedFileMethods.get(component.viewModel.path);if(vmMethodDef){vmMethods=vmMethodDef.methods}}else{if(!this.noJSWarnDone){msg.msg("Error: No JavaScript / TypeScript files have been processed. You need to ensure that your audit fileset includes .js, .ts, html and .json files to enable all audits in this rule-set. Use the ojaf --dryrun command to determine what files are covered by the audit");this.noJSWarnDone=true}}}}}return vmMethods};Utils.prototype.decomposeAssignment=function(auditContext,assignmentNode){const NT=auditContext.utils.AstUtils.getNodeTypes();const breakdown=[];this._walkAssignmentNodes(auditContext,assignmentNode.left,breakdown);if(!breakdown.includes("this")){const parentAssignment=breakdown[breakdown.length-1];const initialAssignmentNode=this._locateDeclaration(auditContext,assignmentNode,parentAssignment);if(initialAssignmentNode){if(initialAssignmentNode==="<parameter>"){breakdown.push("<parameter>")}else if(initialAssignmentNode.type===NT.THIS_EXPR){breakdown.push("this")}else if(initialAssignmentNode.type===NT.IDENTIFIER){breakdown.push(initialAssignmentNode.name);const indirectAssignmentNode=this._locateDeclaration(auditContext,assignmentNode,initialAssignmentNode.name);if(indirectAssignmentNode==="<parameter>"){breakdown.push("<parameter>")}else if(indirectAssignmentNode.type===NT.THIS_EXPR){breakdown.push("this")}}}}return breakdown};Utils.prototype._walkAssignmentNodes=function(context,node,accumulator){const NT=context.utils.AstUtils.getNodeTypes();switch(node.type){case NT.MEMBER_EXPR:accumulator.push(node.property.name);if(node.object){this._walkAssignmentNodes(context,node.object,accumulator)}break;case NT.IDENTIFIER:accumulator.push(node.name);break;case NT.THIS_EXPR:accumulator.push("this");break}};Utils.prototype._locateDeclaration=function(context,node,searchVariable){const NT=context.utils.AstUtils.getNodeTypes();let initialAssignment;let workingNode=node;while(!initialAssignment){if(workingNode.body&&workingNode.body.length>0){workingNode.body.forEach(bodyNode=>{if(bodyNode.type===NT.VAR_DECLARATION){bodyNode.declarations.forEach(declNode=>{if(declNode.id.type===NT.IDENTIFIER&&declNode.id.name===searchVariable){initialAssignment=declNode.init}})}})}else if(workingNode.params&&workingNode.params.length>0){workingNode.params.forEach(paramNode=>{if(paramNode.name===searchVariable){initialAssignment="<parameter>"}})}if(!workingNode.parent){break}else{workingNode=workingNode.parent}}return initialAssignment};Utils.prototype.extractComponentInfoFromJSONFile=function(auditContext,componentFolder,fileName,isLocal,fromPrecompile){const msg=auditContext.utils.msgLib;let componentInfo={};const mdFile=`${componentFolder}/${fileName}`;const compMetadata=auditContext.utils.fsUtils.readJsonSync(mdFile);if(compMetadata!==null){componentInfo.name=compMetadata.name;componentInfo.pack=compMetadata.pack;if(fromPrecompile&&compMetadata.pack){if(compMetadata.name.startsWith(`${compMetadata.pack}-`)){componentInfo.name=compMetadata.name.substring(compMetadata.pack.length+1)}}componentInfo.fullName=componentInfo.pack?`${componentInfo.pack}-${componentInfo.name}`:componentInfo.name;componentInfo.displayName=compMetadata.displayName;componentInfo.description=compMetadata.description;componentInfo.version=compMetadata.version;componentInfo.jetVersion=compMetadata.jetVersion;componentInfo.extension=compMetadata.extension;if(compMetadata.icon){componentInfo.icon=compMetadata.icon}componentInfo.type=compMetadata.type?compMetadata.type:"composite";componentInfo.subcomponentType=compMetadata.subcomponentType;componentInfo.local=isLocal;componentInfo.rootFolder=this.toJAFPath(componentFolder);componentInfo.requirePaths=new Set;switch(componentInfo.type){case"reference":if(compMetadata.extension&&compMetadata.extension.oracle&&compMetadata.extension.oracle.businessApprovals){componentInfo.ba=compMetadata.extension.oracle.businessApprovals}if(compMetadata.paths&&compMetadata.paths.name){componentInfo.requirePaths.add(compMetadata.paths.name)}else{const extractPathSegments=compMetadata.package.split("/");if(extractPathSegments.length>1){componentInfo.requirePaths.add(extractPathSegments[1])}else{componentInfo.requirePaths.add(extractPathSegments[0])}}break;case"composite":if(compMetadata.slots){componentInfo.slots=compMetadata.slots}if(compMetadata.properties){componentInfo.properties=compMetadata.properties}if(compMetadata.events){componentInfo.events=compMetadata.events}if(compMetadata.methods&&Object.keys(compMetadata.methods).length>0){componentInfo.methods=compMetadata.methods}componentInfo.viewModel={resolved:false};if(compMetadata&&compMetadata.extension&&compMetadata.extension.audit&&compMetadata.extension.audit.jetwc&&compMetadata.extension.audit.jetwc.hasOwnProperty("viewModel")){const overrideVM=compMetadata.extension.audit.jetwc.viewModel;if(overrideVM){componentInfo.viewModel={path:this.toJAFPath(path.resolve(".",componentInfo.rootFolder,overrideVM)),resolved:true,skip:false}}else{componentInfo.viewModel={skip:true}}}case"resource":componentInfo.requirePaths.add(".");if(compMetadata.pack){componentInfo.requirePaths.add(`${componentInfo.pack}/${componentInfo.name}`)}else{componentInfo.requirePaths.add(componentInfo.name)}if(compMetadata.dependencies){componentInfo.dependencies=[];Object.keys(compMetadata.dependencies).forEach(depname=>{componentInfo.dependencies.push({name:depname,range:compMetadata.dependencies[depname]})})}break}return componentInfo}else{msg.error(`Invalid JSON in component metadata ${mdFile}, component ignored`)}return};Utils.prototype.diagnosticReplacer=function(key,value){if(value instanceof Map){return Array.from(value).map(([vKey,vValue])=>{return{[vKey]:vValue?vValue:""}})}if(value instanceof Set){return Array.from(value)}return value};Utils.prototype.toJAFPath=function(sourcePath){if(sourcePath&&this.isWindows){return sourcePath.replace(/\\\\|\\/g,"/")}return sourcePath};Utils.prototype.toNativePath=function(sourcePath){if(sourcePath&&this.isWindows){return sourcePath.replace(/\//g,"\\")}return sourcePath};Utils.prototype.getDirectoryName=function(filePath){return path.dirname(filePath)};Utils.prototype.shouldIgnoreCheck=function(context,auditName,componentName,scope,target){let ignore=false;const checkComponentDef=context.rulePack.getExtension().allComponents.get(componentName);if(checkComponentDef){let targetDef;if(scope&&checkComponentDef[scope]){if(target.includes(".")&&scope==="properties"){targetDef=this.getPropertyAttributeFromPath(context,componentName,target)}else{targetDef=checkComponentDef[scope][target==="__default__"?"":target]}}else{targetDef=checkComponentDef}if(targetDef&&targetDef.extension&&targetDef.extension.hasOwnProperty("audit")&&targetDef.extension.audit.hasOwnProperty("ignore")){const ignoreArray=targetDef.extension.audit.ignore;ignore=ignoreArray.includes(auditName)}}return ignore};Utils.prototype.getPropertyAttributeFromPath=function(context,componentName,targetPath,attribute){const checkComponentDef=context.rulePack.getExtension().allComponents.get(componentName);let targetDef;if(checkComponentDef&&checkComponentDef.properties){if(targetPath.includes(".")){const propPath=targetPath.split(".");targetDef=checkComponentDef.properties[propPath[0]];for(let i=1;i<propPath.length;i++){targetDef=targetDef.properties[propPath[i]]}}else{targetDef=checkComponentDef.properties[targetPath]}}if(attribute){return targetDef[attribute]}else{return targetDef}};Utils.prototype.detectComponentSourceType=function(context,componentPathRoot,isVComponent){let componentImplType;if(isVComponent){componentImplType="tsx"}else{const{fsUtils}=context.utils;if(fsUtils.fileExistsSync(`${componentPathRoot}/loader.js`)){componentImplType="js"}else if(fsUtils.fileExistsSync(path.join(componentPathRoot,"loader.ts"))){componentImplType="ts"}else{const pathSegs=componentPathRoot.toLowerCase().split("/");if(pathSegs.includes("js")){componentImplType="js"}else{componentImplType="ts"}}}return componentImplType};Utils.prototype.safeSetExtension=function(context,extnValue){let existingContext=context.rulePack.getExtension();if(!existingContext){existingContext={}}const newContext={...existingContext,...extnValue};context.rulePack.setExtension(newContext)};Utils.prototype.disableRulePack=function(context){const rulesInPack=context.rulePack.getEnabledRuleList();rulesInPack.forEach(rule=>{context.rulePack.disableRule(rule)})};Utils.prototype.isMonoPackMember=function(context,metadata){let mpMember=false;const owningPack=metadata.pack;if(owningPack){const packInfo=this.componentInfo(context,owningPack);if(packInfo&&packInfo.type==="mono-pack"){mpMember=true}}return mpMember};module.exports=new Utils;
|
|
6
|
+
const path=require("path");const Utils=function(){this.rootPoint=this.toJAFPath(path.resolve(".")).length+1;this.isWindows=path.sep!=="/";this.noJSWarnDone=false};Utils.prototype.getKeyPathInfoForRulepack=function(context,auditBase){const paths={isBuiltOutput:false,componentRootFolder:null,exchangeCacheFolder:null,generalSourceRoot:"src",jsSource:null,tsSource:null,base:null};let jetConfig=context.ojetConfig;if(!jetConfig&&auditBase){const remoteConfig=path.join(auditBase,"oraclejetconfig.json");if(context.utils.fsUtils.pathExistsSync(remoteConfig)){jetConfig=context.utils.fsUtils.readJsonSync(remoteConfig)}}let jsDir="js";let tsDir="ts";paths.isBuiltOutput=context.rulePack.getRuleOptions().auditBuildOutput;paths.base=path.resolve(auditBase);if(jetConfig){jsDir=jetConfig.paths.source.javascript||"js";tsDir=jetConfig.paths.source.typescript||"ts";paths.exchangeCacheFolder=jetConfig.paths.source.exchangeComponents||"jet_components";paths.componentRootFolder=jetConfig.paths.source.components||"jet-composites";if(!paths.isBuiltOutput){paths.generalSourceRoot=jetConfig.paths.source.common||"src"}else{paths.generalSourceRoot=jetConfig.paths.staging.web||"web"}}paths.jsSource=this.toJAFPath(path.join(paths.generalSourceRoot,jsDir));if(!paths.isBuiltOutput){paths.tsSource=this.toJAFPath(path.join(paths.generalSourceRoot,tsDir))}return paths};Utils.prototype.matchComponentPath=function(context,checkPathBase,recursion){let checkPath=this.toJAFPath(checkPathBase);let componentMatch;if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allAuditableFilePaths")){if(context.rulePack.getExtension().allAuditableFilePaths.has(checkPath)){const x=context.rulePack.getExtension().allAuditableFilePaths;componentMatch=context.rulePack.getExtension().allAuditableFilePaths.get(checkPath)}else if(checkPath.includes(context.rulePack.getExtension().componentHome)){if(context.rulePack.getExtension().auditableComponentPaths.has(checkPath)){componentMatch=context.rulePack.getExtension().auditableComponentPaths.get(checkPath)}else{const parentPath=path.resolve(checkPathBase,".."+path.sep);componentMatch=this.matchComponentPath(context,parentPath,true)}if(!recursion){context.rulePack.getExtension().allAuditableFilePaths.set(checkPath,componentMatch)}}else{context.rulePack.getExtension().allAuditableFilePaths.set(checkPath)}}else{this.reportMissingBootstrapInfo(context,"allAuditableFilePaths")}return componentMatch};Utils.prototype.reportMissingBootstrapInfo=function(context,checkTopic){const msg=context.utils.msgLib;const extnContext=context.rulePack.getExtension();if(!extnContext||!extnContext.bootStrap){const bootstrapRule=context.rulePack.getPrefix().toLowerCase()+"-bootstrap";if(context.rulePack.isRuleDisabled(bootstrapRule)){msg.error(`You must enable the ${bootstrapRule} rule to run in order to carry out a full component set audit`)}else{msg.error(`Apparent bootstrap error, no information cached for ${checkTopic}`)}context.rulePack.setExtension({...extnContext,bootStrap:true})}};Utils.prototype.componentInfo=function(context,componentName){if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){return context.rulePack.getExtension().allComponents.get(componentName)}else{this.reportMissingBootstrapInfo(context,"allComponents")}return};Utils.prototype.getComponentFullName=function(metadata){return metadata.pack?`${metadata.pack}-${metadata.name}`:metadata.name};Utils.prototype.getComponentType=function(metadata){return metadata.type?metadata.type:"composite"};Utils.prototype.flattenComponentProperties=function(metaDef,valueAttribute,filterCondition,parentPath){let flattenedProps=[];if(metaDef.hasOwnProperty("properties")){const propArray=Object.keys(metaDef.properties);propArray.forEach(propertyName=>{const propertyMetadata=metaDef.properties[propertyName];let key;if(!parentPath){key=propertyName}else{key=parentPath+"."+propertyName}if(!filterCondition||filterCondition(propertyName,propertyMetadata)){flattenedProps.push({key:key,value:metaDef.properties[propertyName][valueAttribute]})}const subPropsArray=this.flattenComponentProperties(metaDef.properties[propertyName],valueAttribute,filterCondition,key);flattenedProps=flattenedProps.concat(subPropsArray)})}return flattenedProps};Utils.prototype.setupFileMethodMapping=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();const fileName=context.filepath;const withinComponent=this.matchComponentPath(context,path.dirname(fileName));if(withinComponent&&node.parent){if(node.parent.type===NT.ASSIGNMENT_EXPR&&node.parent.operator==="="){if(node.parent.left&&node.parent.left.property&&node.parent.left.property.type==NT.IDENTIFIER&&node.parent.left.property.name){const methodDef={name:node.parent.left.property.name,parameters:node.params?node.params.length:0};this.cacheFileMethod(context,fileName,methodDef)}}else if(node.parent.type===NT.METH_DEF&&node.parent.kind==="method"){if(node.parent.key&&node.parent.key.name){const methodDef={name:node.parent.key.name,parameters:node.params?node.params.length:0};this.cacheFileMethod(context,fileName,methodDef)}}else if(node.parent.type===NT.CLASS_PROP||node.parent.type===NT.PROPERTY_DEF){if(node.parent.key&&node.parent.key.name){const methodDef={name:node.parent.key.name,parameters:node.params?node.params.length:0};this.cacheFileMethod(context,fileName,methodDef)}}}};Utils.prototype.setupFileMethodMappingFromMethodDefintion=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();const fileName=context.filepath;const withinComponent=this.matchComponentPath(context,path.dirname(fileName));if(withinComponent){const methodDef={parameters:0};if(node.key&&node.key.type===NT.IDENTIFIER){methodDef.name=node.key.name;if(node.value&&node.value.type===NT.FUNC_EXPR&&node.value.params){methodDef.parameters=node.value.params.length}}if(methodDef.name){this.cacheFileMethod(context,fileName,methodDef)}}};Utils.prototype.cacheFileMethod=function(context,filePath,methodDef){if(!context.rulePack.getExtension().allDefinedFileMethods){context.rulePack.getExtension().allDefinedFileMethods=new Map}if(!context.rulePack.getExtension().allDefinedFileMethods.has(filePath)){context.rulePack.getExtension().allDefinedFileMethods.set(filePath,{methods:new Map})}if(!context.rulePack.getExtension().allDefinedFileMethods.get(filePath).methods.has(methodDef.name)){context.rulePack.getExtension().allDefinedFileMethods.get(filePath).methods.set(methodDef.name,methodDef)}};Utils.prototype.deriveViewModels=function(context,node){const fileName=context.filepath;if(context.rulePack.getExtension()&&context.rulePack.getExtension().hasOwnProperty("allComponents")){const withinComponent=this.matchComponentPath(context,path.dirname(fileName));const componentInfo=context.rulePack.getExtension().allComponents.get(withinComponent);if(withinComponent&&componentInfo&&componentInfo.type==="composite"&&!componentInfo.viewModel.resolved){const targetLoaderExt=componentInfo.language==="tsx"?".ts":`.${componentInfo.language}`;if(path.basename(fileName,targetLoaderExt)==="loader"){switch(componentInfo.language){case"js":case"ts":const registerInfo=this.getLoaderRegisterInfo(context,node);if(registerInfo){const vmRelativeFilePath=this._mapVMToImpl(context,node,registerInfo.viewModel,componentInfo.language==="ts");if(vmRelativeFilePath){const fullVMPath=this._expandPathInContext(context,withinComponent,vmRelativeFilePath);if(fullVMPath){componentInfo.viewModel={path:this.toJAFPath(path.resolve(".",`${fullVMPath}.${componentInfo.language}`)),resolved:true,skip:false}}}}break;case"tsx":break}}}}else{this.reportMissingBootstrapInfo(context,"allComponents")}};Utils.prototype.getLoaderRegisterInfo=function(context,node){const msg=context.utils.msgLib;const NT=context.utils.AstUtils.getNodeTypes();let registerInfo;if(node.callee.type=NT.MEMBER_EXPR&&node.callee.object&&node.arguments&&node.arguments.length>0){let isRegister=false;let oldStyle=false;switch(node.callee.object.type){case NT.IDENTIFIER:if(node.callee.object.name==="Composite"){isRegister=this._astPropertyIdentifierName(context,node.callee,"register")}break;case NT.MEMBER_EXPR:if(node.callee.property&&node.callee.property.type===NT.IDENTIFIER&&node.callee.property.name==="register"){if(this._astPropertyIdentifierName(context,node.callee.object,"Composite")){isRegister=node.callee.object.object&&node.callee.object.object.type===NT.IDENTIFIER&&node.callee.object.object.name==="oj";if(isRegister){oldStyle=true}}}break}if(isRegister){registerInfo={oldStyle:oldStyle};const tagArg=node.arguments[0];const def=node.arguments[1];registerInfo.tag=tagArg.type===NT.LITERAL?tagArg.value:"?";if(def.type===NT.OBJ_EXPR){vmProp=def.properties.filter(prop=>prop.key.name==="viewModel");if(vmProp.length===1){switch(vmProp[0].value.type){case NT.IDENTIFIER:registerInfo.viewModel=vmProp[0].value.name;break;case NT.OBJ_EXPR:if(vmProp[0].value.properties&&vmProp[0].value.properties[0]&&vmProp[0].value.properties[0].key.name==="inline"){registerInfo.viewModel=vmProp[0].value.properties[0].value.name;registerInfo.usesPromises=true}break;case NT.MEMBER_EXPR:if(vmProp[0].value.property&&vmProp[0].value.property.type===NT.IDENTIFIER){registerInfo.viewModel=vmProp[0].value.object.name;registerInfo.transpiled=true}break;case"TSAsExpression":if(vmProp[0].value.expression&&vmProp[0].value.expression.type===NT.IDENTIFIER){registerInfo.viewModel=vmProp[0].value.expression.name}else if(vmProp[0].value.expression&&vmProp[0].value.expression.type===NT.AS_EXPR){registerInfo.viewModel=vmProp[0].value.expression.expression.name;msg.msg(`WARNING: Component loader file ${context.filepath} attempts to redefine the composite.register viewModel interface`)}break}}const cssCheck=def.properties.filter(prop=>prop.key.name==="css");if(cssCheck.length>0){registerInfo.registerCSS=true}}}}return registerInfo};Utils.prototype._astPropertyIdentifierName=function(context,node,checkName){const NT=context.utils.AstUtils.getNodeTypes();return node&&node.property&&node.property.type===NT.IDENTIFIER&&node.property.name===checkName};Utils.prototype._mapVMToImpl=function(context,node,vmName,useImports){let vmPathDef;if(vmName){let rootNode=node;if(useImports){vmPathDef=this._getImportPath(context,rootNode,vmName)}else{vmPathDef=this._getDefineStatementPath(context,rootNode,vmName);if(!vmPathDef){vmPathDef=this._mapToRequireAssignment(context,node,vmName)}}}return vmPathDef};Utils.prototype._mapToRequireAssignment=function(context,node,vmName){const NT=context.utils.AstUtils.getNodeTypes();let requirePath;const vmDeclNode=this._locateDeclaration(context,node,vmName);if(vmDeclNode.type===NT.CALL_EXPR&&vmDeclNode.callee.type===NT.IDENTIFIER&&vmDeclNode.callee.name==="require"){if(vmDeclNode.arguments&&vmDeclNode.arguments.length===1&&vmDeclNode.arguments[0].type===NT.LITERAL){requirePath=vmDeclNode.arguments[0].value}}return requirePath};Utils.prototype._getImportPath=function(context,node,importAs){const NT=context.utils.AstUtils.getNodeTypes();const bodyNodeArray=context.utils.AstUtils.getBody();let definePath;for(let i=0;i<bodyNodeArray.length;i++){const testNode=bodyNodeArray[i];switch(testNode.type){case"ImportDeclaration":if(testNode.specifiers&&Array.isArray(testNode.specifiers)&&testNode.specifiers.length===1&&(testNode.specifiers[0].type===NT.IMPORT_DEF_SPECIFIER||testNode.specifiers[0].type===NT.IMPORT_SPECIFIER)&&testNode.specifiers[0].local&&testNode.specifiers[0].local.name===importAs){definePath=testNode.source.value}break;case"TSImportEqualsDeclaration":if(testNode.id&&testNode.id.type===NT.IDENTIFIER&&testNode.id.name===importAs&&testNode.moduleReference&&testNode.moduleReference.type===NT.EXTERN_MOD_REF&&testNode.moduleReference.expression&&testNode.moduleReference.expression.type===NT.LITERAL){definePath=testNode.moduleReference.expression.value}break}if(definePath){;break}}return definePath};Utils.prototype._getDefineStatementPath=function(context,node,defineParam){const NT=context.utils.AstUtils.getNodeTypes();let checkNode=node.parent;let definePath;while(checkNode){if(checkNode.type===NT.CALL_EXPR&&checkNode.callee.name==="define"){definePath=context.utils.AstUtils.parseDefine(checkNode)[defineParam]}checkNode=checkNode.parent}return definePath};Utils.prototype._expandPathInContext=function(context,componentName,requirePath){let targetPath=requirePath;const parsePluginParts=requirePath.split("!");if(parsePluginParts.length>1){targetPath=parsePluginParts[1]}let pathParts=targetPath.split("/");const decodeRoot=pathParts[0];if(decodeRoot==="."){pathParts[0]=this.rootPathForComponent(context,componentName)}else{const remotePart=this.rootPathForComponent(context,decodeRoot);if(!remotePart){pathParts=[]}else{pathParts[0]=remotePart}}return pathParts.join("/")};Utils.prototype.rootPathForComponent=function(context,componentName){if(context.rulePack.getExtension().allComponents.has(componentName)){return context.rulePack.getExtension().allComponents.get(componentName).rootFolder}};Utils.prototype.getVMMethodsForLocalComposite=function(context,component){let vmMethods;const msg=context.utils.msgLib;const opts=context.rulePack.getRuleOptions();if(component.local&&component.type==="composite"){if(!component.viewModel.skip){if(!component.viewModel.resolved&&!component.viewModel.warned){if(!opts.testMode){msg.msg(`Warning: unable to derive the correct viewModel implementation for component ${component.fullName}, either your audit run does not include .js/.ts files, or you may need to set 'extension.audit.jetwc.viewModel' in the metadata to provide a hint`)}component.viewModel.warned=true}else{const rpState=context.rulePack.getExtension();if(rpState.allDefinedFileMethods&&rpState.allDefinedFileMethods.size>0){const vmMethodDef=rpState.allDefinedFileMethods.get(component.viewModel.path);if(vmMethodDef){vmMethods=vmMethodDef.methods}}else{if(!this.noJSWarnDone){msg.msg("Error: No JavaScript / TypeScript files have been processed. You need to ensure that your audit fileset includes .js, .ts, html and .json files to enable all audits in this rule-set. Use the ojaf --dryrun command to determine what files are covered by the audit");this.noJSWarnDone=true}}}}}return vmMethods};Utils.prototype.decomposeAssignment=function(auditContext,assignmentNode){const NT=auditContext.utils.AstUtils.getNodeTypes();const breakdown=[];this._walkAssignmentNodes(auditContext,assignmentNode.left,breakdown);if(!breakdown.includes("this")){const parentAssignment=breakdown[breakdown.length-1];const initialAssignmentNode=this._locateDeclaration(auditContext,assignmentNode,parentAssignment);if(initialAssignmentNode){if(initialAssignmentNode==="<parameter>"){breakdown.push("<parameter>")}else if(initialAssignmentNode.type===NT.THIS_EXPR){breakdown.push("this")}else if(initialAssignmentNode.type===NT.IDENTIFIER){breakdown.push(initialAssignmentNode.name);const indirectAssignmentNode=this._locateDeclaration(auditContext,assignmentNode,initialAssignmentNode.name);if(indirectAssignmentNode==="<parameter>"){breakdown.push("<parameter>")}else if(indirectAssignmentNode.type===NT.THIS_EXPR){breakdown.push("this")}}}}return breakdown};Utils.prototype._walkAssignmentNodes=function(context,node,accumulator){const NT=context.utils.AstUtils.getNodeTypes();switch(node.type){case NT.MEMBER_EXPR:accumulator.push(node.property.name);if(node.object){this._walkAssignmentNodes(context,node.object,accumulator)}break;case NT.IDENTIFIER:accumulator.push(node.name);break;case NT.THIS_EXPR:accumulator.push("this");break}};Utils.prototype._locateDeclaration=function(context,node,searchVariable){const NT=context.utils.AstUtils.getNodeTypes();let initialAssignment;let workingNode=node;while(!initialAssignment){if(workingNode.body&&workingNode.body.length>0){workingNode.body.forEach(bodyNode=>{if(bodyNode.type===NT.VAR_DECLARATION){bodyNode.declarations.forEach(declNode=>{if(declNode.id.type===NT.IDENTIFIER&&declNode.id.name===searchVariable){initialAssignment=declNode.init}})}})}else if(workingNode.params&&workingNode.params.length>0){workingNode.params.forEach(paramNode=>{if(paramNode.name===searchVariable){initialAssignment="<parameter>"}})}if(!workingNode.parent){break}else{workingNode=workingNode.parent}}return initialAssignment};Utils.prototype.extractComponentInfoFromJSONFile=function(auditContext,componentFolder,fileName,isLocal,fromPrecompile){const msg=auditContext.utils.msgLib;let componentInfo={};const mdFile=`${componentFolder}/${fileName}`;const compMetadata=auditContext.utils.fsUtils.readJsonSync(mdFile);if(compMetadata!==null){return this.extractComponentInfoFromMetadata(auditContext,compMetadata,componentFolder,isLocal,fromPrecompile)}else{msg.error(`Invalid JSON in component metadata ${mdFile}, component ignored`)}return};Utils.prototype.extractComponentInfoFromMetadata=function(auditContext,compMetadata,componentFolder,isLocal,fromPrecompile){const msg=auditContext.utils.msgLib;let componentInfo={};componentInfo.name=compMetadata.name;componentInfo.pack=compMetadata.pack;if(fromPrecompile&&compMetadata.pack){if(compMetadata.name.startsWith(`${compMetadata.pack}-`)){componentInfo.name=compMetadata.name.substring(compMetadata.pack.length+1)}}componentInfo.fullName=componentInfo.pack?`${componentInfo.pack}-${componentInfo.name}`:componentInfo.name;componentInfo.displayName=compMetadata.displayName;componentInfo.description=compMetadata.description;componentInfo.version=compMetadata.version;componentInfo.jetVersion=compMetadata.jetVersion;componentInfo.license=compMetadata.license;componentInfo.extension=compMetadata.extension;if(compMetadata.icon){componentInfo.icon=compMetadata.icon}componentInfo.type=compMetadata.type?compMetadata.type:"composite";componentInfo.subcomponentType=compMetadata.subcomponentType;componentInfo.local=isLocal;componentInfo.rootFolder=this.toJAFPath(componentFolder);componentInfo.requirePaths=new Set;switch(componentInfo.type){case"reference":if(compMetadata.extension&&compMetadata.extension.oracle&&compMetadata.extension.oracle.businessApprovals){componentInfo.ba=compMetadata.extension.oracle.businessApprovals}if(compMetadata.paths&&compMetadata.paths.name){componentInfo.requirePaths.add(compMetadata.paths.name)}else{const extractPathSegments=compMetadata.package.split("/");if(extractPathSegments.length>1){componentInfo.requirePaths.add(extractPathSegments[1])}else{componentInfo.requirePaths.add(extractPathSegments[0])}}break;case"composite":if(compMetadata.styleClasses){componentInfo.styleClasses=compMetadata.styleClasses}if(compMetadata.styleVariables){componentInfo.styleVariables=compMetadata.styleVariables}if(compMetadata.slots){componentInfo.slots=compMetadata.slots}if(compMetadata.properties){componentInfo.properties=compMetadata.properties}if(compMetadata.events){componentInfo.events=compMetadata.events}if(compMetadata.methods&&Object.keys(compMetadata.methods).length>0){componentInfo.methods=compMetadata.methods}componentInfo.viewModel={resolved:false};if(compMetadata&&compMetadata.extension&&compMetadata.extension.audit&&compMetadata.extension.audit.jetwc&&compMetadata.extension.audit.jetwc.hasOwnProperty("viewModel")){const overrideVM=compMetadata.extension.audit.jetwc.viewModel;if(overrideVM){componentInfo.viewModel={path:this.toJAFPath(path.resolve(".",componentInfo.rootFolder,overrideVM)),resolved:true,skip:false}}else{componentInfo.viewModel={skip:true}}}case"resource":componentInfo.requirePaths.add(".");if(compMetadata.pack){componentInfo.requirePaths.add(`${componentInfo.pack}/${componentInfo.name}`)}else{componentInfo.requirePaths.add(componentInfo.name)}if(compMetadata.dependencies){componentInfo.dependencies=[];Object.keys(compMetadata.dependencies).forEach(depname=>{componentInfo.dependencies.push({name:depname,range:compMetadata.dependencies[depname]})})}break}return componentInfo};Utils.prototype.diagnosticReplacer=function(key,value){if(value instanceof Map){return Array.from(value).map(([vKey,vValue])=>{return{[vKey]:vValue?vValue:""}})}if(value instanceof Set){return Array.from(value)}return value};Utils.prototype.toJAFPath=function(sourcePath){if(sourcePath&&this.isWindows){return sourcePath.replace(/\\\\|\\/g,"/")}return sourcePath};Utils.prototype.toNativePath=function(sourcePath){if(sourcePath&&this.isWindows){return sourcePath.replace(/\//g,"\\")}return sourcePath};Utils.prototype.getDirectoryName=function(filePath){return path.dirname(filePath)};Utils.prototype.shouldIgnoreCheck=function(context,auditName,componentName,scope,target){let ignore=false;const checkComponentDef=context.rulePack.getExtension().allComponents.get(componentName);if(checkComponentDef){let targetDef;if(scope&&checkComponentDef[scope]){if(target.includes(".")&&scope==="properties"){targetDef=this.getPropertyAttributeFromPath(context,componentName,target)}else{targetDef=checkComponentDef[scope][target==="__default__"?"":target]}}else{targetDef=checkComponentDef}if(targetDef&&targetDef.extension&&targetDef.extension.hasOwnProperty("audit")&&targetDef.extension.audit.hasOwnProperty("ignore")){const ignoreArray=targetDef.extension.audit.ignore;ignore=ignoreArray.includes(auditName)}}return ignore};Utils.prototype.getPropertyAttributeFromPath=function(context,componentName,targetPath,attribute){const checkComponentDef=context.rulePack.getExtension().allComponents.get(componentName);let targetDef;if(checkComponentDef&&checkComponentDef.properties){if(targetPath.includes(".")){const propPath=targetPath.split(".");targetDef=checkComponentDef.properties[propPath[0]];for(let i=1;i<propPath.length;i++){targetDef=targetDef.properties[propPath[i]]}}else{targetDef=checkComponentDef.properties[targetPath]}}if(attribute){return targetDef[attribute]}else{return targetDef}};Utils.prototype.detectComponentSourceType=function(context,componentPathRoot,isVComponent){let componentImplType;if(isVComponent){componentImplType="tsx"}else{const{fsUtils}=context.utils;if(fsUtils.fileExistsSync(`${componentPathRoot}/loader.js`)){componentImplType="js"}else if(fsUtils.fileExistsSync(path.join(componentPathRoot,"loader.ts"))){componentImplType="ts"}else{const pathSegs=componentPathRoot.toLowerCase().split("/");if(pathSegs.includes("js")){componentImplType="js"}else{componentImplType="ts"}}}return componentImplType};Utils.prototype.safeSetExtension=function(context,extnValue){let existingContext=context.rulePack.getExtension();if(!existingContext){existingContext={}}const newContext={...existingContext,...extnValue};context.rulePack.setExtension(newContext)};Utils.prototype.disableRulePack=function(context){const rulesInPack=context.rulePack.getEnabledRuleList();rulesInPack.forEach(rule=>{context.rulePack.disableRule(rule)})};Utils.prototype.isMonoPackMember=function(context,metadata){let mpMember=false;const owningPack=metadata.pack;if(owningPack){const packInfo=this.componentInfo(context,owningPack);if(packInfo&&packInfo.type==="mono-pack"){mpMember=true}}return mpMember};Utils.prototype.cloneObject=function(o){return JSON.parse(JSON.stringify(o))};module.exports=new Utils;
|
|
@@ -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 path=require("path");const Utils=require("./jetwcutils-componentAuditUtils");const tsxUtils=require("./jetwcutils-tsxUtils");const ComponentFinder=function(){this.runOnce=false};ComponentFinder.prototype.findAllComponents=function(auditContext,projectPathInfo,componentRoots
|
|
6
|
+
const path=require("path");const Utils=require("./jetwcutils-componentAuditUtils");const tsxUtils=require("./jetwcutils-tsxUtils");const ComponentFinder=function(){this.runOnce=false};ComponentFinder.prototype.findAllComponents=function(auditContext,auditBase,projectPathInfo,componentRoots){const msg=auditContext.utils.msgLib;const metadataPatches=this._readPatchFile(auditContext,auditBase);let masterComponentList=[];if(!this.runOnce||auditContext.rulePack.getRuleOptions().testMode){if(projectPathInfo.exchangeCacheFolder){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.exchangeCacheFolder),false,false,auditContext,null,metadataPatches))}if(componentRoots&&componentRoots.length>0){componentRoots.forEach(root=>{let target=root;if(auditContext.utils.fsUtils.getFileTypeSync(target)==="f"){target=path.dirname(root);msg.msg(`Warning: Incorrectly defined "components" array entry in JAF configuration file. Entries should list folders only not explicit file names.\n Bad entry: "${root}"\nAudit will process the "${target}" folder instead.\n`)}masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(target,true,projectPathInfo.isBuiltOutput,auditContext,null,metadataPatches))})}else{if(projectPathInfo.componentRootFolder){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.jsSource,projectPathInfo.componentRootFolder),true,projectPathInfo.isBuiltOutput,auditContext,null,metadataPatches));if(projectPathInfo.tsSource&&projectPathInfo.tsSource!==projectPathInfo.jsSource){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.tsSource,projectPathInfo.componentRootFolder),true,false,auditContext,null,metadataPatches))}}}this.runOnce=true;this.masterComponentList=masterComponentList}return this.masterComponentList};ComponentFinder.prototype._discoverComponentsFromRoot=function(rootDir,isLocal,builtOutput,auditContext,parentPack,metadataPatches){const msg=auditContext.utils.msgLib;let componentArray=[];if(auditContext.utils.fsUtils.pathExistsSync(rootDir)){const compFileStructure=auditContext.utils.fsUtils.readDir(rootDir);compFileStructure.forEach(l1file=>{let componentInfo;if(!l1file.isFile&&l1file.files.length>0){l1file.files.forEach(l2file=>{if(!builtOutput){if(l2file.isFile&&l2file.name==="component.json"){componentInfo=Utils.extractComponentInfoFromJSONFile(auditContext,path.join(rootDir,l1file.name),"component.json",isLocal,false);componentArray.push(componentInfo);if(componentInfo.type&&componentInfo.type==="pack"){const packMembers=this._discoverComponentsFromRoot(Utils.toJAFPath(path.join(rootDir,l1file.name)),isLocal,false,auditContext,componentInfo.name,metadataPatches);componentArray=componentArray.concat(packMembers)}}else if(l2file.isFile&&path.extname(l2file.name)===".tsx"){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,path.join(rootDir,l1file.name),l2file.name,metadataPatches);if(componentInfo){componentArray.push(componentInfo)}}}else{if(!l2file.isFile&&l2file.files.length>0){l2file.files.forEach(l3file=>{if(l3file.isFile&&l3file.name==="component.json"){componentInfo=Utils.extractComponentInfoFromJSONFile(auditContext,path.join(rootDir,l1file.name,l2file.name),"component.json",isLocal,false);if(!componentInfo.pack){componentArray.push(componentInfo);if(componentInfo.type==="pack"){const packMembers=this._discoverComponentsFromRoot(Utils.toJAFPath(path.join(rootDir,l1file.name,l2file.name)),isLocal,false,auditContext,componentInfo.name,metadataPatches);componentArray=componentArray.concat(packMembers)}}}else if(l3file.isFile&&path.extname(l3file.name)===".tsx"){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,path.join(rootDir,l1file.name,l2file.name),l3file.name,metadataPatches);if(componentInfo){componentArray.push(componentInfo)}}})}}})}else{if(l1file.isFile&&l1file.name==="component.json"){componentInfo=Utils.extractComponentInfoFromJSONFile(auditContext,rootDir,"component.json",isLocal,false);if(componentInfo.type!=="pack"||componentInfo.name!==parentPack){componentArray.push(componentInfo)}}else if(l1file.isFile&&path.extname(l1file.name)===".tsx"){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,rootDir,l1file.name,metadataPatches);if(componentInfo){componentArray.push(componentInfo)}}}})}return componentArray};ComponentFinder.prototype._readPatchFile=function(auditContext,auditBase){const{fsUtils,msgLib}=auditContext.utils;const metadataPatchInstructionFile=auditContext.userDefs?.VComponentMetadataPatches;let actualPatchFilePath;if(metadataPatchInstructionFile){if(fsUtils.fileExistsSync(metadataPatchInstructionFile)){actualPatchFilePath=metadataPatchInstructionFile}else if(fsUtils.fileExistsSync(path.join(auditBase,metadataPatchInstructionFile))){actualPatchFilePath=path.join(auditBase,metadataPatchInstructionFile)}}if(actualPatchFilePath){return fsUtils.readJsonSync(actualPatchFilePath)}return};module.exports=new ComponentFinder;
|
|
@@ -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 Utils=require("./jetwcutils-componentAuditUtils");const path=require("path");const TsxUtils=function(){};TsxUtils.prototype.extractComponentInfoFromTSXFile=function(auditContext,componentFolder,fileName,
|
|
6
|
+
const Utils=require("./jetwcutils-componentAuditUtils");const path=require("path");const TsxUtils=function(){};TsxUtils.prototype.extractComponentInfoFromTSXFile=function(auditContext,componentFolder,fileName,metadataPatches){const{msgLib,fsUtils}=auditContext.utils;const packRegEx=/@ojmetadata[\s]*pack[\s]*[\"|'](?<pack>[a-zA-Z\-0-9]*)[\"|']/mg;const versionRegEx=/@ojmetadata[\s]*version[\s]*[\"|'](?<version>[\.0-9\-a-zA-Z]*)[\"|']/mg;const jetVersionRegEx=/@ojmetadata[\s]*jetVersion[\s]*[\"|'](?<version>[\.0-9\-a-zA-Z^~><=]*)[\"|']/mg;const tsxFile=path.join(componentFolder,fileName);const fileAsStr=auditContext.utils.fsUtils.readFileSync(tsxFile);const componentIdentification=this.getVComponentElementNameAndImpl(fileAsStr,msgLib);const fullName=componentIdentification.elementName;const className=componentIdentification.class;const componentName=this.getVComponentComponentName(fileAsStr);let precompiledInfo=auditContext.utils.metaLib.getTagMetadata(fullName);if(!precompiledInfo&&auditContext.rulePack.getRuleOptions().hasOwnProperty("precompileCache")&&auditContext.rulePack.getRuleOptions().testMode){msgLib.info(`Test mode, bypassing Typescript compilation...`);const jsonLoc=path.join(auditContext.rulePack.getRuleOptions().precompileCache,`${fullName}.json`);if(fsUtils.fileExistsSync(jsonLoc)){precompiledInfo=fsUtils.readJsonSync(jsonLoc)}else{msgLib.error(`Missing test mode metadata for ${jsonLoc}`)}}if(precompiledInfo){if(metadataPatches){let componentPatches;if(precompiledInfo.pack){componentPatches=metadataPatches?.[precompiledInfo.pack]?.[precompiledInfo.name]}else{componentPatches=metadataPatches?.[precompiledInfo.name]}if(componentPatches&&Array.isArray(componentPatches)){msgLib.info(`Processing metadata type patches for ${fullName} [${componentPatches.length} patch(es) specified]`);componentPatches.forEach(patch=>{switch(patch.target){case"property":this._handlePropertyTypePatch(patch,precompiledInfo);break;case"method":this._handleMethodTypePatch(patch,precompiledInfo);break;case"event":this._handleEventDetailTypePatch(patch,precompiledInfo);break;case"slot":this._handleSlotDataTypePatch(patch,precompiledInfo);break}})}}const componentInfo=Utils.extractComponentInfoFromMetadata(auditContext,precompiledInfo,componentFolder,true,true);componentInfo.compiledMetadata=precompiledInfo;componentInfo.vcomponent=true;componentInfo.viewModel={resolved:true,path:Utils.toJAFPath(tsxFile)};componentInfo.viewModel.className=className;if(!componentName){componentInfo.inferredName=true}if(componentInfo.pack){const matchPack=packRegEx.exec(fileAsStr);if(!matchPack||!matchPack.groups.pack){componentInfo.inferredPack=true}}const matchVer=versionRegEx.exec(fileAsStr);if(!matchVer||!matchVer.groups.version){componentInfo.inferredVersion=true}const matchJetVer=jetVersionRegEx.exec(fileAsStr);if(!matchJetVer||!matchJetVer.groups.version){componentInfo.inferredJetVersion=true}return componentInfo}else{if(fullName){msgLib.error(`Unable to audit VComponent ${fullName}, pre-compiled metadata is not available`)}return}};TsxUtils.prototype.getVComponentElementNameAndImpl=function(sourceCode,msgLib){var resolvedElementName,implementationClass;const elementRegExForFunction=/export const\s*(?<className>\w+)[\w\s\<\>:]*=\s*registerCustomElement[\s<>\w]*\(\s*[\"\'](?<fullName>[\w-]*)\s*[\"\']\s*,/mg;const matchElementFunction=elementRegExForFunction.exec(sourceCode);if(matchElementFunction&&matchElementFunction.groups&&matchElementFunction.groups.fullName&&matchElementFunction.groups.className){resolvedElementName=matchElementFunction.groups.fullName;implementationClass=matchElementFunction.groups.className}else{const elementRegExForClass=/\s*@customElement\s*\(\s*[\"\']\s*(?<fullName>[\w-]*)\s*[\"\']\s*\)/mg;const matchElementClass=elementRegExForClass.exec(sourceCode);if(matchElementClass&&matchElementClass.groups&&matchElementClass.groups.fullName){resolvedElementName=matchElementClass.groups.fullName}const elementRegExForClassImpl=/[\s]*export[\s]*class[\s]*(?<className>[a-zA-Z\-0-9_]*)[\s]*extends[\s]*(?<superClass>[a-zA-Z\-0-9_]*)/mg;while((classDef=elementRegExForClassImpl.exec(sourceCode))!==null){if(classDef.groups.superClass==="Component"){implementationClass=classDef.groups.className}}}if(resolvedElementName&&!implementationClass){msgLib.info(`WARNING: Unable to determine VComponent class-name for ${resolvedElementName}`)}return{elementName:resolvedElementName,class:implementationClass}};TsxUtils.prototype.getVComponentComponentName=function(sourceCode){const nameRegEx=/@ojmetadata[\s]*name [\"|'](?<componentName>[a-zA-Z\-0-9]*)[\"|']/mg;const matchElement=nameRegEx.exec(sourceCode);if(matchElement&&matchElement.groups&&matchElement.groups.componentName){return matchElement.groups.componentName}else{return}};TsxUtils.prototype.matchToVComponentImpl=function(auditContext,testFileName){let componentInfo;let fileNameCanonical=Utils.toJAFPath(testFileName);if(fileNameCanonical.endsWith(".tsx")){const componentMatch=Utils.matchComponentPath(auditContext,fileNameCanonical);if(componentMatch){const testPossibleComponentInfo=Utils.componentInfo(auditContext,componentMatch);if(testPossibleComponentInfo.viewModel&&fileNameCanonical===testPossibleComponentInfo.viewModel.path){componentInfo=testPossibleComponentInfo}}}return componentInfo};TsxUtils.prototype._handlePropertyTypePatch=function(patch,metadata){this._patchPropertyViaPath(patch,patch.locator.split("."),metadata)};TsxUtils.prototype._patchPropertyViaPath=function(patch,path,node){const contactProp=path.shift();if(node.properties?.hasOwnProperty(contactProp)){if(path.length>0){this._patchPropertyViaPath(patch,path,node.properties[contactProp])}else{const propDef=node.properties[contactProp];const existingType=propDef.type;if(this._verifyType(existingType,patch)){propDef.type=patch.patchType}}}};TsxUtils.prototype._verifyType=function(existingType,patch){let expectedTypeMatches=existingType===patch?.expectedType||!patch?.expectedType;let abortNoMatch=false;if(patch.enforceMatch){if(!expectedTypeMatches){abortNoMatch=true}}return!abortNoMatch};TsxUtils.prototype._handleMethodTypePatch=function(patch,metadata){const locatorSegs=patch.locator.split(":");const methodName=locatorSegs[0];const methodTarget=locatorSegs[1];if(metadata.methods?.hasOwnProperty(methodName)){const methodDef=metadata.methods[methodName];if(methodTarget==="return"){this._patchMethodReturnType(patch,methodDef)}else{this._patchMethodParamType(patch,methodDef,methodTarget)}}};TsxUtils.prototype._patchMethodParamType=function(patch,methodDef,parameterName){let paramDef;for(let i=0;i<methodDef.params.length;i++){if(methodDef.params[i].name===parameterName){paramDef=methodDef.params[i]}}const existingType=paramDef.type;if(this._verifyType(existingType,patch)){paramDef.type=patch.patchType}};TsxUtils.prototype._patchMethodReturnType=function(patch,methodDef){const existingType=methodDef.return;if(this._verifyType(existingType,patch)){methodDef.return=patch.patchType}};TsxUtils.prototype._handleEventDetailTypePatch=function(patch,metadata){const locatorSegs=patch.locator.split(":");const eventName=locatorSegs[0];const detailName=locatorSegs[1];if(metadata.events?.hasOwnProperty(eventName)){const eventDef=metadata.events[eventName];if(eventDef.detail?.hasOwnProperty(detailName)){const existingType=eventDef.detail[detailName].type;if(this._verifyType(existingType,patch)){eventDef.detail[detailName].type=patch.patchType}}}};TsxUtils.prototype._handleSlotDataTypePatch=function(patch,metadata){const locatorSegs=patch.locator.split(":");const slotName=locatorSegs[0];const dataName=locatorSegs[1];if(metadata.slots?.hasOwnProperty(slotName)){const slotDef=metadata.slots[slotName];if(slotDef.data?.hasOwnProperty(dataName)){const existingType=slotDef.data[dataName].type;if(this._verifyType(existingType,patch)){slotDef.data[dataName].type=patch.patchType}}}};module.exports=new TsxUtils;
|
|
@@ -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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const componentFinder=require("../jetwc-lib/jetwcutils-componentFinder");const
|
|
6
|
+
const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const componentFinder=require("../jetwc-lib/jetwcutils-componentFinder");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwco-bootstrap"};ruleDef.prototype.getShortDescription=function(){return"Bootstrap processing for the JETWCO rulset"};ruleDef.prototype.getDescription=function(){return"This rule is for internal use by the ruleset and should not be disabled"};ruleDef.prototype.register=function(context){this.componentRoots=context.config.components;this.auditBase=context.config.base;this.typeScriptCompile=context.config.typescript&&context.config.typescript.compile;return{startupRP:this._getAllVisibleComponents,closedownRP:this._reportDiagnostics}};ruleDef.prototype._getAllVisibleComponents=function(context){const{msgLib}=context.utils;msgLib.info(`builtinJetWcOracleRules (${context.rulePack.getPackInfo().prefix}): ${context.rulePack.getPackInfo().version}`);const projectPathInfo=Utils.getKeyPathInfoForRulepack(context,this.auditBase);const componentRootFolder=context.rulePack.getRuleOptions().componentRoot||projectPathInfo.componentRootFolder;const exchangeURL=context.rulePack.getRuleOptions().exchangeURL;const masterComponentList=componentFinder.findAllComponents(context,this.auditBase,projectPathInfo,this.componentRoots);if(masterComponentList&&masterComponentList.length>0){const allComponentsMap=masterComponentList.reduce((wmap,component)=>{if(!projectPathInfo.isBuiltOutput||projectPathInfo.isBuiltOutput&&!wmap.has(component.fullName)){wmap.set(component.fullName,component)}return wmap},new Map);const referenceComponents=new Map;const componentPaths=new Map;allComponentsMap.forEach(component=>{component.language=Utils.detectComponentSourceType(context,component.rootFolder);switch(component.type){case"reference":referenceComponents.set(component.fullName,component.ba);break;case"composite":case"resource":if(component.local){if(component.dependencies){Object.values(component.dependencies).forEach(dependencyName=>{if(allComponentsMap.has(dependencyName)){const proxyPaths=allComponentsMap.get(dependencyName).requirePaths;proxyPaths.forEach(path=>{component.requirePaths.add(path)})}})}componentPaths.set(component.rootFolder,component.fullName)}break}});context.rulePack.setExtension({rulepackVersion:context.rulePack.getPackInfo().version,bootStrap:true,exchangeURL:exchangeURL,platform:Utils.isWindows?"Windows":"Unix-like",precompiled:this.typeScriptCompile,componentHome:`/${componentRootFolder}/`,auditBuildOutput:projectPathInfo.isBuiltOutput,discoveredPaths:projectPathInfo,componentRoots:this.componentRoots,allReferenceComponents:referenceComponents,allComponents:allComponentsMap,auditableComponentPaths:componentPaths,allAuditableFilePaths:new Map})}else{msgLib.error(`No components have been discovered from the JAF configuration for the ${context.rulePack.getPackInfo().prefix} ruleset to process. You will need to configure the "components" array to point at your component root folder`);Utils.disableRulePack(context)}};ruleDef.prototype._reportDiagnostics=function(context){const msgLib=context.utils.msgLib;const opts=context.rulePack.getRuleOptions();const diagnostics=context.rulePack.getExtension();if(!opts.testMode){let foundVMMapping=0;let candidateLocal=0;if(diagnostics&&diagnostics.allComponents&&diagnostics.allComponents.length>0){diagnostics.allComponents.forEach((component,compName)=>{if(component.local&&component.type==="composite"){candidateLocal++;if(component.viewModel&&component.viewModel.resolved){foundVMMapping++}}});if(foundVMMapping!==candidateLocal){msgLib.error(`Error: Audit was only able to map ${foundVMMapping} out of ${candidateLocal} components to their viewModels. Some audits will be unable to operate.`)}}}if(opts.debug&&opts.diagnosticFile&&diagnostics){msgLib.msg(`Writing JETWCO diagnostics to ${opts.diagnosticFile}.json`);const dFile=Utils.toJAFPath(path.join(path.resolve("."),opts.diagnosticFile+".json"));context.utils.fsUtils.writeJsonSync(diagnostics,dFile,{spaces:2,replacer:Utils.diagnosticReplacer})}};module.exports=ruleDef;
|
|
@@ -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 CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="composite"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;const removeControlMetadata=CaccHelpers.deriveConstraintMetadata(baselines,removeConstraint);if(metadata.hasOwnProperty("methods")&&compareMetadata.hasOwnProperty("methods")){for(const[methodName,methodDef]of Object.entries(metadata.methods)){if(compareMetadata.methods.hasOwnProperty(methodName)){if(methodDef.hasOwnProperty("params")){methodDef.params.forEach(paramDef=>{const historicalParamDef=compareMetadata.methods[methodName].params
|
|
6
|
+
const CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="composite"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;const removeControlMetadata=CaccHelpers.deriveConstraintMetadata(baselines,removeConstraint);if(metadata.hasOwnProperty("methods")&&compareMetadata.hasOwnProperty("methods")){for(const[methodName,methodDef]of Object.entries(metadata.methods)){if(compareMetadata.methods.hasOwnProperty(methodName)){if(methodDef.hasOwnProperty("params")){methodDef.params.forEach(paramDef=>{const historicalParamDef=compareMetadata.methods[methodName].params?.find(hpd=>hpd.name===paramDef.name);if(historicalParamDef){const diffs=CaccHelpers.typeDiff(paramDef.type,historicalParamDef.type,overrideTypeMappings);if(CaccHelpers.checkConstraintMinorMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Types ${diffs.add.map(addition=>addition.type).join(", ")} added to method parameter ${methodName}.${paramDef.name} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.mutate,mutateConstraint,componentVersionDiff)){errorConditions.push(`Method parameter type mutated for ${methodName} in${errorMsgContext}'${mutateConstraint}'`)}const removeErrors=CaccHelpers.checkConstraintMajorWithDeprecation(diffs.remove,removeConstraint,componentVersionDiff,cacheManager,componentName,removeControlMetadata,diff=>{return["methods",methodName,"params",`[name:${paramDef.name}]`]},"parameterType",diff=>diff.historicalType);if(removeErrors.length>0){errorConditions.push(`Type(s) ${removeErrors.map(d=>d.historicalType).join(", ")} removed for parameter ${methodName}.${paramDef.name} in${errorMsgContext}'${removeConstraint}'`)}}})}}}}if(errorConditions.length>0){return errorConditions.join("\n")}}return};module.exports=controlCallback;
|
|
@@ -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 CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="composite"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;if(metadata.hasOwnProperty("methods")&&compareMetadata.hasOwnProperty("methods")){for(const[methodName,methodDef]of Object.entries(metadata.methods)){if(compareMetadata.methods.hasOwnProperty(methodName)){const diffs=CaccHelpers.typeDiff(methodDef.return,compareMetadata.methods[methodName].return,overrideTypeMappings);if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Method return type amended to include ${diffs.add.map(addition=>addition.type).join(", ")} added to ${methodName} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.mutate,mutateConstraint,componentVersionDiff)){const errorAction=diffs.mutate[0].type?"added":"removed";errorConditions.push(`Method return type ${errorAction} for ${methodName} in${errorMsgContext}'${mutateConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.remove,removeConstraint,componentVersionDiff)){errorConditions.push(`
|
|
6
|
+
const CaccHelpers=require("./jetwco-cacc-helpers");function controlCallback(controlRuleName,controlRuleDef,semver,cacheManager,metadata,compareMetadata,componentVersionDiff,baselines,componentType,componentName,errorMsgContext,overrideTypeMappings){if(componentType==="composite"){let errorConditions=[];const{add:addConstraint,remove:removeConstraint,mutate:mutateConstraint}=controlRuleDef;if(metadata.hasOwnProperty("methods")&&compareMetadata.hasOwnProperty("methods")){for(const[methodName,methodDef]of Object.entries(metadata.methods)){if(compareMetadata.methods.hasOwnProperty(methodName)){const diffs=CaccHelpers.typeDiff(methodDef.return,compareMetadata.methods[methodName].return,overrideTypeMappings);if(diffs.mutate.length>0){let refactorMutate=false;diffs.mutate.forEach(({type,historicalType})=>{if(type.length>0&&historicalType.length===0){diffs.add.push({type});refactorMutate=true}if(historicalType.length>0&&type.length===0){diffs.remove.push(historicalType);refactorMutate=true}});if(refactorMutate){diffs.mutate=[]}}if(CaccHelpers.checkConstraintPatchMajor(diffs.add,addConstraint,componentVersionDiff)){errorConditions.push(`Method return type amended to include ${diffs.add.map(addition=>addition.type).join(", ")} added to ${methodName} in${errorMsgContext}'${addConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.mutate,mutateConstraint,componentVersionDiff)){const errorAction=diffs.mutate[0].type?"added":"removed";errorConditions.push(`Method return type ${errorAction} for ${methodName} in${errorMsgContext}'${mutateConstraint}'`)}if(CaccHelpers.checkConstraintMajor(diffs.remove,removeConstraint,componentVersionDiff)){errorConditions.push(`Method return type removed for ${methodName} in${errorMsgContext}'${removeConstraint}'`)}}}if(errorConditions.length>0){return errorConditions.join("\n")}}}return};module.exports=controlCallback;
|
|
@@ -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 Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const SENTENCE_PATTERN=/^([A-Z])/gm;const FORBIDDEN=[/spectra[\s\.,]/gmi,/vb[\s\.,]/gmi,/fa[\s\.,]/gmi];const INTERNAL_URLS=[/http(s?):\/\/(\w)*.(\w){2,}.oracle.com/gmi,/http(s?):\/\/(\w)*.oraclecorp.com/gmi];SCOPE_MAP={property:"properties",propertyEditorValues:"properties",slot:"slots",method:"methods",event:"events"};const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwco-description-standards"};ruleDef.prototype.getShortDescription=function(){return"Verifies the description attributes of a component meet the documented standards"};ruleDef.prototype.getDescription=function(){return"Internal Oracle standards for description dictate the use of sentence case with normal punctuation, but no trailing period on the final sentence. This audit does a basic scan for this."};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);const componentType=Utils.getComponentType(meta);if(componentType==="composite"){this._checkDescriptions(context,fullName,meta)}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkDescriptions(context,componentInfo.fullName,componentInfo)}};ruleDef.prototype._checkDescriptions=function(context,fullName,metadata){if(metadata){this._checkInScope(context,fullName,metadata.description);if(metadata.properties){const flattenedProps=Utils.flattenComponentProperties(metadata,"description");flattenedProps.forEach(prop=>{this._checkInScope(context,fullName,prop.value,"property",prop.key)});const flattenedPEV=Utils.flattenComponentProperties(metadata,"propertyEditorValues");flattenedPEV.forEach(prop=>{if(prop.value){for([pevKey,pevDef]of Object.entries(prop.value)){this._checkInScope(context,fullName,pevDef.description,"propertyEditorValues",prop.key,pevKey)}}})}if(metadata.events){for(const[key,value]of Object.entries(metadata.events)){this._checkInScope(context,fullName,value.description,"event",key)}}if(metadata.methods){for(const[key,value]of Object.entries(metadata.methods)){if(!["setProperty","getProperty","setProperties"].includes(key)){this._checkInScope(context,fullName,value.description,"method",key)}}}if(metadata.slots){for(const[key,value]of Object.entries(metadata.slots)){this._checkInScope(context,fullName,value.description,"slot",key)}}}};ruleDef.prototype._checkInScope=function(context,fullName,checkDescription,scopeType,scope,scopeDetail){const ignore=Utils.shouldIgnoreCheck(context,context.ruleName,fullName,scopeType?SCOPE_MAP[scopeType]:null,scope);let description=new String(checkDescription);if(!ignore&&description&&description.length>0){
|
|
6
|
+
const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const SENTENCE_PATTERN=/^([A-Z])/gm;const FORBIDDEN=[/spectra[\s\.,]/gmi,/vb[\s\.,]/gmi,/fa[\s\.,]/gmi];const INTERNAL_URLS=[/http(s?):\/\/(\w)*.(\w){2,}.oracle.com/gmi,/http(s?):\/\/(\w)*.oraclecorp.com/gmi];SCOPE_MAP={property:"properties",propertyEditorValues:"properties",slot:"slots",method:"methods",event:"events"};const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwco-description-standards"};ruleDef.prototype.getShortDescription=function(){return"Verifies the description attributes of a component meet the documented standards"};ruleDef.prototype.getDescription=function(){return"Internal Oracle standards for description dictate the use of sentence case with normal punctuation, but no trailing period on the final sentence. This audit does a basic scan for this."};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);const componentType=Utils.getComponentType(meta);if(componentType==="composite"){this._checkDescriptions(context,fullName,meta)}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkDescriptions(context,componentInfo.fullName,componentInfo)}};ruleDef.prototype._checkDescriptions=function(context,fullName,metadata){if(metadata){this._checkInScope(context,fullName,metadata.description);if(metadata.properties){const flattenedProps=Utils.flattenComponentProperties(metadata,"description");flattenedProps.forEach(prop=>{this._checkInScope(context,fullName,prop.value,"property",prop.key)});const flattenedPEV=Utils.flattenComponentProperties(metadata,"propertyEditorValues");flattenedPEV.forEach(prop=>{if(prop.value){for([pevKey,pevDef]of Object.entries(prop.value)){this._checkInScope(context,fullName,pevDef.description,"propertyEditorValues",prop.key,pevKey)}}})}if(metadata.events){for(const[key,value]of Object.entries(metadata.events)){this._checkInScope(context,fullName,value.description,"event",key)}}if(metadata.methods){for(const[key,value]of Object.entries(metadata.methods)){if(!["setProperty","getProperty","setProperties"].includes(key)){this._checkInScope(context,fullName,value.description,"method",key)}}}if(metadata.slots){for(const[key,value]of Object.entries(metadata.slots)){this._checkInScope(context,fullName,value.description,"slot",key)}}}};ruleDef.prototype._checkInScope=function(context,fullName,checkDescription,scopeType,scope,scopeDetail){const ignore=Utils.shouldIgnoreCheck(context,context.ruleName,fullName,scopeType?SCOPE_MAP[scopeType]:null,scope);let description=new String(checkDescription);if(!ignore&&description&&description.length>0){description=description.replace("e.g.","");const endSent=/\.[^A-Z^a-z]/;const sentences=description.split(endSent);sentences.forEach(sentence=>{const cleaned=sentence.trim();if(cleaned&&cleaned.length>0){const ucMatches=cleaned.match(SENTENCE_PATTERN);if(!ucMatches){const issue=new context.Issue(`Component ${fullName} ${scopeType?scopeType+" > "+scope+" ":""}${scopeDetail?"("+scopeDetail+") ":""}description does not meet the Oracle standards. Indication: sentences must begin with a capital letter`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}}});FORBIDDEN.forEach(pattern=>{if(description.match(pattern)){const issue=new context.Issue(`Component ${fullName} ${scopeType?scopeType+" > "+scope+" ":""}${scopeDetail?"("+scopeDetail+") ":""}description does not meet the Oracle standards. Indication: forbidden term '${pattern.toString().substring(1,pattern.toString().length-11)}'`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context,"blocker")}});INTERNAL_URLS.forEach(pattern=>{const detectedUrls=description.match(pattern);if(detectedUrls){detectedUrls.forEach(url=>{const issue=new context.Issue(`Component ${fullName} ${scopeType?scopeType+" > "+scope+" ":""}${scopeDetail?"("+scopeDetail+") ":""}description does not meet the Oracle standards. Indication: internal URL '${url}'`);issue.setMsgKey(context.ruleName+"_3");context.reporter.addIssue(issue,context,"blocker")})}})}};module.exports=ruleDef;
|