@oracle/oraclejet-audit 14.1.4 → 15.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.
Files changed (278) hide show
  1. package/corePackMigrator/cli.js +6 -0
  2. package/corePackMigrator/corePackMigrator.js +10 -0
  3. package/corePackMigrator/metadata/avatarMetadata.json +40 -0
  4. package/corePackMigrator/metadata/buttonMetadata.json +55 -0
  5. package/corePackMigrator/metadata/collapsibleMetadata.json +15 -0
  6. package/corePackMigrator/metadata/filePickerMetadata.json +8 -0
  7. package/corePackMigrator/metadata/inputNumberMetadata.json +56 -0
  8. package/corePackMigrator/metadata/inputPasswordMetadata.json +50 -0
  9. package/corePackMigrator/metadata/inputTextMetadata.json +62 -0
  10. package/corePackMigrator/metadata/legendItemMetadata.json +8 -0
  11. package/corePackMigrator/metadata/legendMetadata.json +18 -0
  12. package/corePackMigrator/metadata/legendSectionMetadata.json +8 -0
  13. package/corePackMigrator/metadata/listItemLayoutMetadata.json +15 -0
  14. package/corePackMigrator/metadata/listviewMetadata.json +8 -0
  15. package/corePackMigrator/metadata/messagesMetadata.json +35 -0
  16. package/corePackMigrator/metadata/progressBarMetadata.json +15 -0
  17. package/corePackMigrator/metadata/progressCircleMetadata.json +8 -0
  18. package/corePackMigrator/metadata/ratingGaugeMetadata.json +78 -0
  19. package/corePackMigrator/metadata/selectManyMetadata.json +39 -0
  20. package/corePackMigrator/metadata/selectSingleMetadata.json +39 -0
  21. package/corePackMigrator/metadata/statusMeterGaugeMetadata.json +99 -0
  22. package/corePackMigrator/metadata/textAreaMetadata.json +44 -0
  23. package/corePackMigrator/resource/astUtils.js +6 -0
  24. package/corePackMigrator/resource/componentMigrator.js +6 -0
  25. package/corePackMigrator/resource/fileScanner.js +6 -0
  26. package/corePackMigrator/resource/htmlUtils.js +6 -0
  27. package/corePackMigrator/resource/manifest.json +102 -0
  28. package/corePackMigrator/resource/migrationConfig.json +21 -0
  29. package/corePackMigrator/templates/componentMetaData.json +119 -0
  30. package/corePackMigrator/templates/migrationConfig.json +17 -0
  31. package/corePackMigrator/utilities/logging.js +6 -0
  32. package/jaf-amd.js +1 -1
  33. package/lib/AST_Ts.js +1 -1
  34. package/lib/Cli.js +1 -1
  35. package/lib/Components.js +1 -1
  36. package/lib/Config.js +1 -1
  37. package/lib/ConfigLib.js +1 -1
  38. package/lib/DomUtils.js +1 -1
  39. package/lib/FileIndex.js +1 -1
  40. package/lib/FileSet.js +1 -1
  41. package/lib/FsUtils.js +1 -1
  42. package/lib/HtmlUtils.js +1 -1
  43. package/lib/JsonLoader.js +1 -1
  44. package/lib/MetaLib.js +1 -1
  45. package/lib/NetUtils.js +1 -1
  46. package/lib/Parser.js +1 -1
  47. package/lib/RegTypes.js +1 -1
  48. package/lib/Registry.js +1 -1
  49. package/lib/Reporter.js +1 -1
  50. package/lib/RulePack.js +1 -1
  51. package/lib/RuleSet.js +1 -1
  52. package/lib/Rules.js +1 -1
  53. package/lib/Scope.js +1 -1
  54. package/lib/Ts.js +1 -1
  55. package/lib/TsxUtils.js +1 -1
  56. package/lib/TsxUtils2.js +6 -0
  57. package/lib/Utils.js +1 -1
  58. package/lib/ZipUtils.js +1 -1
  59. package/lib/checkage.js +1 -1
  60. package/lib/cmdline.js +1 -1
  61. package/lib/defaults.js +1 -1
  62. package/lib/exportRules.js +1 -1
  63. package/lib/filetypes.js +1 -1
  64. package/lib/groups.js +1 -1
  65. package/lib/help.js +1 -1
  66. package/lib/jetver.js +1 -1
  67. package/lib/jsx.js +1 -1
  68. package/lib/maint.js +6 -0
  69. package/lib/manpage.js +1 -1
  70. package/lib/manual.js +1 -1
  71. package/lib/migrator.js +6 -0
  72. package/lib/msgidLoader.js +1 -1
  73. package/lib/ns.js +1 -1
  74. package/lib/outfile.js +1 -1
  75. package/lib/schema.js +1 -1
  76. package/lib/scopewalker.js +1 -1
  77. package/libext/expparser.js +1 -1
  78. package/meta/14.0.0/jetauditmeta.js +1 -1
  79. package/meta/14.1.0/jetauditmeta.js +1 -1
  80. package/meta/15.0.0/jetauditmeta.js +9 -0
  81. package/meta/metaverlist.json +1 -1
  82. package/package.json +16 -8
  83. package/profiles/redwood-strict.json +2 -1
  84. package/rulepacks/csp/csp-html-script-unsafe-inline.js +1 -1
  85. package/rulepacks/csp/csp-html-unsafe-expr.js +1 -1
  86. package/rulepacks/csp/csp-js-script-unsafe-eval.js +1 -1
  87. package/rulepacks/csp/csp-js-style-unsafe-inline.js +1 -1
  88. package/rulepacks/csp/csp-json-unsafe-expr.js +6 -0
  89. package/rulepacks/csp/msgid.json +1 -1
  90. package/rulepacks/csp/rules.json +1 -1
  91. package/rulepacks/jetwc/jetwc-absolute-jetversion.js +1 -1
  92. package/rulepacks/jetwc/jetwc-aria-redefinition.js +1 -1
  93. package/rulepacks/jetwc/jetwc-bootstrap.js +1 -1
  94. package/rulepacks/jetwc/jetwc-compjson-bp-ar.js +1 -1
  95. package/rulepacks/jetwc/jetwc-compjson-bp-obj.js +1 -1
  96. package/rulepacks/jetwc/jetwc-component-dependencies.js +1 -1
  97. package/rulepacks/jetwc/jetwc-component-displayname.js +1 -1
  98. package/rulepacks/jetwc/jetwc-component-foldername.js +1 -1
  99. package/rulepacks/jetwc/jetwc-component-location.js +1 -1
  100. package/rulepacks/jetwc/jetwc-component-type.js +1 -1
  101. package/rulepacks/jetwc/jetwc-css-oj-complete.js +1 -1
  102. package/rulepacks/jetwc/jetwc-css-pack-load-path.js +6 -0
  103. package/rulepacks/jetwc/jetwc-css-scoping.js +1 -1
  104. package/rulepacks/jetwc/jetwc-data-property-prefix.js +1 -1
  105. package/rulepacks/jetwc/jetwc-deprecated-lifecycle.js +1 -1
  106. package/rulepacks/jetwc/jetwc-disabled-property.js +1 -1
  107. package/rulepacks/jetwc/jetwc-displayname.js +1 -1
  108. package/rulepacks/jetwc/jetwc-dynamic-slot-context.js +1 -1
  109. package/rulepacks/jetwc/jetwc-event-displayname.js +1 -1
  110. package/rulepacks/jetwc/jetwc-events.js +1 -1
  111. package/rulepacks/jetwc/jetwc-exchange-images.js +1 -1
  112. package/rulepacks/jetwc/jetwc-jet-version.js +1 -1
  113. package/rulepacks/jetwc/jetwc-loader-file.js +1 -1
  114. package/rulepacks/jetwc/jetwc-markdown-link.js +1 -1
  115. package/rulepacks/jetwc/jetwc-method-displayname.js +1 -1
  116. package/rulepacks/jetwc/jetwc-methods.js +1 -1
  117. package/rulepacks/jetwc/jetwc-namespace.js +1 -1
  118. package/rulepacks/jetwc/jetwc-nested-defaults.js +1 -1
  119. package/rulepacks/jetwc/jetwc-nls-languages.js +1 -1
  120. package/rulepacks/jetwc/jetwc-nls-root.js +1 -1
  121. package/rulepacks/jetwc/jetwc-oj-register.js +1 -1
  122. package/rulepacks/jetwc/jetwc-ojcss.js +1 -1
  123. package/rulepacks/jetwc/jetwc-pack-children.js +1 -1
  124. package/rulepacks/jetwc/jetwc-packable-components.js +1 -1
  125. package/rulepacks/jetwc/jetwc-prerelease-dependencies.js +1 -1
  126. package/rulepacks/jetwc/jetwc-prerelease-pattern.js +1 -1
  127. package/rulepacks/jetwc/jetwc-prerelease-version.js +1 -1
  128. package/rulepacks/jetwc/jetwc-property-changed.js +1 -1
  129. package/rulepacks/jetwc/jetwc-property-displayname.js +1 -1
  130. package/rulepacks/jetwc/jetwc-property-nesting.js +1 -1
  131. package/rulepacks/jetwc/jetwc-property-translatable.js +1 -1
  132. package/rulepacks/jetwc/jetwc-public-modules.js +1 -1
  133. package/rulepacks/jetwc/jetwc-reference-npm-path.js +6 -0
  134. package/rulepacks/jetwc/jetwc-register-css.js +1 -1
  135. package/rulepacks/jetwc/jetwc-register-with-promises.js +1 -1
  136. package/rulepacks/jetwc/jetwc-require-paths.js +1 -1
  137. package/rulepacks/jetwc/jetwc-required-subproperty.js +1 -1
  138. package/rulepacks/jetwc/jetwc-reserved-property.js +1 -1
  139. package/rulepacks/jetwc/jetwc-schema.js +1 -1
  140. package/rulepacks/jetwc/jetwc-semantic-version.js +1 -1
  141. package/rulepacks/jetwc/jetwc-slot-displayname.js +1 -1
  142. package/rulepacks/jetwc/jetwc-slots.js +1 -1
  143. package/rulepacks/jetwc/jetwc-standard-files.js +1 -1
  144. package/rulepacks/jetwc/jetwc-status-since.js +6 -0
  145. package/rulepacks/jetwc/jetwc-unused-events.js +1 -1
  146. package/rulepacks/jetwc/jetwc-unused-slots.js +1 -1
  147. package/rulepacks/jetwc/jetwc-vb-category.js +1 -1
  148. package/rulepacks/jetwc/jetwc-vb-icon.js +1 -1
  149. package/rulepacks/jetwc/jetwc-vcomponent-jetversion.js +1 -1
  150. package/rulepacks/jetwc/jetwc-vcomponent-loader.js +1 -1
  151. package/rulepacks/jetwc/jetwc-vcomponent-version.js +1 -1
  152. package/rulepacks/jetwc/jetwc-version-openrange.js +1 -1
  153. package/rulepacks/jetwc/jetwc-writeback-required.js +1 -1
  154. package/rulepacks/jetwc/msgid.json +1 -1
  155. package/rulepacks/jetwc/rules.json +1 -1
  156. package/rulepacks/jetwc-lib/jetwcutils-auditComponentCacheManager.js +1 -1
  157. package/rulepacks/jetwc-lib/jetwcutils-commonListenerImpls.js +1 -1
  158. package/rulepacks/jetwc-lib/jetwcutils-componentAuditUtils.js +1 -1
  159. package/rulepacks/jetwc-lib/jetwcutils-componentFinder.js +1 -1
  160. package/rulepacks/jetwc-lib/jetwcutils-preCompiler.js +1 -1
  161. package/rulepacks/jetwc-lib/jetwcutils-tsxUtils.js +1 -1
  162. package/rulepacks/jetwco/jetwco-bootstrap.js +1 -1
  163. package/rulepacks/jetwco/jetwco-cacc-componentType.js +1 -1
  164. package/rulepacks/jetwco/jetwco-cacc-dependencies.js +1 -1
  165. package/rulepacks/jetwco/jetwco-cacc-dynamicSlots.js +1 -1
  166. package/rulepacks/jetwco/jetwco-cacc-eventBubbles.js +1 -1
  167. package/rulepacks/jetwco/jetwco-cacc-eventCancelable.js +1 -1
  168. package/rulepacks/jetwco/jetwco-cacc-eventPayload.js +1 -1
  169. package/rulepacks/jetwco/jetwco-cacc-events.js +1 -1
  170. package/rulepacks/jetwco/jetwco-cacc-helpers.js +1 -1
  171. package/rulepacks/jetwco/jetwco-cacc-jetVer.js +1 -1
  172. package/rulepacks/jetwco/jetwco-cacc-methodParamTypes.js +1 -1
  173. package/rulepacks/jetwco/jetwco-cacc-methodParams.js +1 -1
  174. package/rulepacks/jetwco/jetwco-cacc-methodReturnType.js +1 -1
  175. package/rulepacks/jetwco/jetwco-cacc-methods.js +1 -1
  176. package/rulepacks/jetwco/jetwco-cacc-packBundle.js +1 -1
  177. package/rulepacks/jetwco/jetwco-cacc-packBundleContent.js +1 -1
  178. package/rulepacks/jetwco/jetwco-cacc-packContent.js +1 -1
  179. package/rulepacks/jetwco/jetwco-cacc-properties.js +1 -1
  180. package/rulepacks/jetwco/jetwco-cacc-propertyDefault.js +1 -1
  181. package/rulepacks/jetwco/jetwco-cacc-propertyEnumeration.js +1 -1
  182. package/rulepacks/jetwco/jetwco-cacc-propertyReadOnly.js +1 -1
  183. package/rulepacks/jetwco/jetwco-cacc-propertyRequired.js +1 -1
  184. package/rulepacks/jetwco/jetwco-cacc-propertyType.js +1 -1
  185. package/rulepacks/jetwco/jetwco-cacc-propertyWriteback.js +1 -1
  186. package/rulepacks/jetwco/jetwco-cacc-publicModules.js +1 -1
  187. package/rulepacks/jetwco/jetwco-cacc-slotDataVariable.js +1 -1
  188. package/rulepacks/jetwco/jetwco-cacc-slotDataVariableType.js +1 -1
  189. package/rulepacks/jetwco/jetwco-cacc-slots.js +1 -1
  190. package/rulepacks/jetwco/jetwco-cacc-styleClasses.js +1 -1
  191. package/rulepacks/jetwco/jetwco-cacc-styleVariables.js +1 -1
  192. package/rulepacks/jetwco/jetwco-cacc-typeMappingOverrides.js +6 -0
  193. package/rulepacks/jetwco/jetwco-compjson-ns-reg.js +1 -1
  194. package/rulepacks/jetwco/jetwco-component-api-baseline-changes.js +1 -1
  195. package/rulepacks/jetwco/jetwco-component-api-changes.js +1 -1
  196. package/rulepacks/jetwco/jetwco-component-api-controlled-changes.js +1 -1
  197. package/rulepacks/jetwco/jetwco-component-cdn.js +1 -1
  198. package/rulepacks/jetwco/jetwco-description-standards.js +1 -1
  199. package/rulepacks/jetwco/jetwco-displayname-standards.js +1 -1
  200. package/rulepacks/jetwco/jetwco-exchange-version-check.js +1 -1
  201. package/rulepacks/jetwco/jetwco-license-info.js +1 -1
  202. package/rulepacks/jetwco/jetwco-prerelease-cdn.js +1 -1
  203. package/rulepacks/jetwco/jetwco-thirdparty-ba.js +1 -1
  204. package/rulepacks/jetwco/msgid.json +1 -1
  205. package/rulepacks/jetwco/rules.json +1 -1
  206. package/rules/jaf/jaf-ts-noparser.js +6 -0
  207. package/rules/jaf/msgid.json +1 -1
  208. package/rules/jaf/rules.json +1 -1
  209. package/rules/jet/helpers/has-slot-name.js +1 -1
  210. package/rules/jet/helpers/style-selector.js +1 -1
  211. package/rules/jet/helpers/tsx/has-slot-name.js +6 -0
  212. package/rules/jet/msgid.json +1 -1
  213. package/rules/jet/oj-acc-aria-labelledby.js +1 -1
  214. package/rules/jet/oj-cca-compjson-bp-ar.js +1 -1
  215. package/rules/jet/oj-cca-compjson-bp-obj.js +1 -1
  216. package/rules/jet/oj-css-bp-dir-flow.js +1 -1
  217. package/rules/jet/oj-html-attr-$unique.js +1 -1
  218. package/rules/jet/oj-html-attr-expr-delims.js +6 -0
  219. package/rules/jet/oj-html-combo-converter.js +1 -1
  220. package/rules/jet/oj-html-file-pick-accept.js +1 -1
  221. package/rules/jet/oj-html-form-bindif.js +1 -1
  222. package/rules/jet/oj-html-input-isodate.js +1 -1
  223. package/rules/jet/oj-html-invalid-doctype.js +1 -1
  224. package/rules/jet/oj-html-msgs-cat-text.js +1 -1
  225. package/rules/jet/oj-html-ojattr-deprecated.js +1 -1
  226. package/rules/jet/oj-html-ojattr-enum-deprecated.js +1 -1
  227. package/rules/jet/oj-html-ojtag-deprecated.js +1 -1
  228. package/rules/jet/oj-html-ojtag-ns.js +1 -1
  229. package/rules/jet/oj-html-rating-gauge-track-resize.js +6 -0
  230. package/rules/jet/oj-html-self-close.js +1 -1
  231. package/rules/jet/oj-html-slot-deprecated.js +1 -1
  232. package/rules/jet/oj-html-slot-item-minmax.js +1 -1
  233. package/rules/jet/oj-html-slot-name.js +1 -1
  234. package/rules/jet/oj-html-slot-pref-content.js +1 -1
  235. package/rules/jet/oj-html-style.js +1 -1
  236. package/rules/jet/oj-html-stylesel.js +1 -1
  237. package/rules/jet/oj-html-tabbar-edge.js +6 -0
  238. package/rules/jet/oj-html-unsup-theme.js +1 -1
  239. package/rules/jet/oj-html-wctag-maintenance.js +1 -1
  240. package/rules/jet/oj-html-wctag-nested.js +1 -1
  241. package/rules/jet/oj-html-wctag-supersedes.js +6 -0
  242. package/rules/jet/oj-js-numconv-pattern.js +6 -0
  243. package/rules/jet/oj-ts-numconv-pattern.js +6 -0
  244. package/rules/jet/oj-tsx-5-tag-obs.js +1 -1
  245. package/rules/jet/oj-tsx-acc-avatar-aria-role.js +6 -0
  246. package/rules/jet/oj-tsx-acc-button-onclick.js +1 -1
  247. package/rules/jet/oj-tsx-aria-ojselector-labelledby.js +1 -1
  248. package/rules/jet/oj-tsx-aria-prop.js +1 -1
  249. package/rules/jet/oj-tsx-attr-req.js +1 -1
  250. package/rules/jet/oj-tsx-cca-tagname.js +1 -1
  251. package/rules/jet/oj-tsx-combo-converter.js +1 -1
  252. package/rules/jet/oj-tsx-databind-all.js +1 -1
  253. package/rules/jet/oj-tsx-dlg-title.js +1 -1
  254. package/rules/jet/oj-tsx-form-bindif.js +6 -0
  255. package/rules/jet/oj-tsx-form-noflex.js +6 -0
  256. package/rules/jet/oj-tsx-input-isodate.js +1 -1
  257. package/rules/jet/oj-tsx-ojattr-deprecated.js +6 -0
  258. package/rules/jet/oj-tsx-ojattr-enum-deprecated.js +6 -0
  259. package/rules/jet/oj-tsx-ojattr-value.js +1 -1
  260. package/rules/jet/oj-tsx-ojattr.js +1 -1
  261. package/rules/jet/oj-tsx-ojtag-deprecated.js +1 -1
  262. package/rules/jet/oj-tsx-ojtag-ns.js +6 -0
  263. package/rules/jet/oj-tsx-pageopts-type.js +1 -1
  264. package/rules/jet/oj-tsx-picker-attrs.js +1 -1
  265. package/rules/jet/oj-tsx-prop-inline-definition.js +1 -1
  266. package/rules/jet/oj-tsx-rating-gauge-size.js +1 -1
  267. package/rules/jet/oj-tsx-rating-gauge-track-resize.js +6 -0
  268. package/rules/jet/oj-tsx-slot-deprecated.js +6 -0
  269. package/rules/jet/oj-tsx-slot-pref-content.js +6 -0
  270. package/rules/jet/oj-tsx-tabbar-edge.js +6 -0
  271. package/rules/jet/oj-tsx-unsup-theme.js +1 -1
  272. package/rules/jet/oj-tsx-wctag-maintenance.js +1 -1
  273. package/rules/jet/oj-tsx-wctag-nested.js +1 -1
  274. package/rules/jet/rules.json +1 -1
  275. package/schema/component-schema.json +1 -1
  276. package/src/JafCore.js +1 -1
  277. package/types/index.d.ts +6 -4
  278. package/rules/jet/oj-html-cspexpr.js +0 -6
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2023, 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-status-since"};ruleDef.prototype.getShortDescription=function(){return"Verify that the since value defined in any status metadata relates to a production version"};ruleDef.prototype.getDescription=function(){return"This rule checks that the since metadata associated with deprecations and maintanence mode specifies a production version of the component as opposed to a pre-production version which is not valid"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){let issue;const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);this._checkDeprecationSinceValues(context,fullName,meta)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkDeprecationSinceValues(context,componentInfo.fullName,componentInfo)}};ruleDef.prototype._checkDeprecationSinceValues=function(auditContext,fullName,metadata){const semver=auditContext.utils.semVerUtils;const allStatusSinceEntries=this._extractSinceValues(semver,metadata,[]);allStatusSinceEntries.forEach(sinceRecord=>{let issueScope="";if(sinceRecord.scope.length>0){issueScope=` (${sinceRecord.scope.join(" > ")})`}if(!sinceRecord.value){issue=new auditContext.Issue(`Component ${fullName}${issueScope} specifies a status record without a "since" value which should be added to help the consumer understand when the change was made and will be used by other audits.`);issue.setMsgKey(auditContext.ruleName+"_1");auditContext.reporter.addIssue(issue,auditContext)}else if(!sinceRecord.validSemver){issue=new auditContext.Issue(`Component ${fullName}${issueScope} specifies a status record with an invalid version number for "since" (${sinceRecord.value}). A valid semantic version number (not range) must be used.`);issue.setMsgKey(auditContext.ruleName+"_2");auditContext.reporter.addIssue(issue,auditContext)}else if(sinceRecord.preReleaseSemver){issue=new auditContext.Issue(`Component ${fullName}${issueScope} specifies a status record with a pre-release version number for "since" (${sinceRecord.value}). A production version number must be used.`);issue.setMsgKey(auditContext.ruleName+"_3");auditContext.reporter.addIssue(issue,auditContext)}})};ruleDef.prototype._extractSinceValues=function(semver,metadata,statusScope){const statusEntries=[];for(const[key,value]of Object.entries(metadata)){if(key==="status"&&Array.isArray(value)){value.forEach(statusRec=>{const sinceRec={scope:statusScope,value:null,validSemver:false,preReleaseSemver:false};if(statusRec.hasOwnProperty("since")&&typeof statusRec.since==="string"){sinceRec.value=statusRec.since;if(semver.isValid(statusRec.since)){if(semver.minVersion(statusRec.since).version===statusRec.since){sinceRec.validSemver=true;if(semver.prerelease(statusRec.since)){sinceRec.preReleaseSemver=true}}}}statusEntries.push(sinceRec)})}else if(key!=="extension"&&typeof value==="object"&&value!==null){const newScope=statusScope.concat(key);const downStreamEntries=this._extractSinceValues(semver,value,newScope);downStreamEntries.forEach(sen=>statusEntries.push(sen))}}return statusEntries};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-unused-events"};ruleDef.prototype.getShortDescription=function(){return"Verify that all declared events are actually used"};ruleDef.prototype.getDescription=function(){return"This rule checks that any events declared in the metadata are then actually raised in the associated viewModel"};ruleDef.prototype.register=function(context){return{CallExpression:this._flagEventUse,closedownRP:this._doAudit}};ruleDef.prototype._flagEventUse=function(context,node){const NT=context.utils.AstUtils.getNodeTypes();if(node.callee.type===NT.MEMBER_EXPR&&node.callee.property.type===NT.IDENTIFIER&&node.callee.property.name==="dispatchEvent"){if(node.arguments[0].type===NT.CALL_EXPR||node.arguments[0].type===NT.NEW_EXPR){if(node.arguments[0].callee.name==="CustomEvent"){const eventNameNode=node.arguments[0].arguments[0];if(eventNameNode.type===NT.LITERAL){const eventName=eventNameNode.value;const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));this._markEventUsed(context,componentName,eventName)}}}}};ruleDef.prototype._doAudit=function(context){if(context.rulePack.getExtension()){const eventUsage=context.rulePack.getExtension().eventUsage;if(eventUsage){eventUsage.forEach(function(value,key){if(!value){const idParts=key.split(":");const componentName=idParts[0];const eventName=idParts[1];if(!Utils.shouldIgnoreCheck(context,"jetwc-unused-events",componentName,"events",eventName)){const issue=new context.Issue(`Event '${eventName}' for component ${componentName} does not appear to be raised`);context.reporter.addIssue(issue,context)}}})}}};ruleDef.prototype._markEventUsed=function(context,componentName,eventName){const msg=context.utils.msgLib;if(componentName){let eventUsage=context.rulePack.getExtension().eventUsage;const eventKey=`${componentName}:${eventName}`;if(!eventUsage){eventUsage=new Map;context.rulePack.getExtension().eventUsage=eventUsage}if(!eventUsage.has(eventKey)){const eventComponentDef=context.rulePack.getExtension().allComponents.get(componentName);if(eventComponentDef){if(eventComponentDef.hasOwnProperty("events")){Object.keys(eventComponentDef.events).forEach(event=>{eventUsage.set(`${componentName}:${event}`,false)})}}else{msg.error(`JETWC Error (jetwc-unused-events): component ${componentName} missing from allComponents map`)}}if(eventUsage.has(eventKey)){eventUsage.set(eventKey,true)}}else{msg.msg(`JETWC Warning (jetwc-unused-events): component event ${eventName} cannot be mapped to a component due to missing viewModel mapping`)}};module.exports=ruleDef;
6
+ const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-unused-events"};ruleDef.prototype.getShortDescription=function(){return"Verify that all declared events are actually used"};ruleDef.prototype.getDescription=function(){return"This rule checks that any events declared in the metadata are then actually raised in the associated viewModel"};ruleDef.prototype.register=function(context){return{CallExpression:this._flagEventUse,closedownRP:this._doAudit}};ruleDef.prototype._flagEventUse=function(context,node){Utils.deriveViewModels(context,node);const NT=context.utils.AstUtils.getNodeTypes();if(node.callee.type===NT.MEMBER_EXPR&&node.callee.property.type===NT.IDENTIFIER&&node.callee.property.name==="dispatchEvent"){if(node.arguments[0].type===NT.CALL_EXPR||node.arguments[0].type===NT.NEW_EXPR){if(node.arguments[0].callee.name==="CustomEvent"){const eventNameNode=node.arguments[0].arguments[0];if(eventNameNode.type===NT.LITERAL){const eventName=eventNameNode.value;const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));this._markEventUsed(context,componentName,eventName)}}}}};ruleDef.prototype._doAudit=function(context){if(context.rulePack.getExtension()){const eventUsage=context.rulePack.getExtension().eventUsage;if(eventUsage){eventUsage.forEach(function(value,key){if(!value){const idParts=key.split(":");const componentName=idParts[0];const eventName=idParts[1];if(!Utils.shouldIgnoreCheck(context,"jetwc-unused-events",componentName,"events",eventName)){const compInfo=Utils.componentInfo(context,componentName);let reportSource=compInfo.fullName;if(compInfo.viewModel.resolved&&!compInfo.viewModel.skip){reportSource=compInfo.viewModel.path}const issue=new context.Issue(`Event '${eventName}' for component ${componentName} does not appear to be raised`);issue.setReportedFilePath(reportSource);context.reporter.addIssue(issue,context)}}})}}};ruleDef.prototype._markEventUsed=function(context,componentName,eventName){const msg=context.utils.msgLib;if(componentName){let eventUsage=context.rulePack.getExtension().eventUsage;const eventKey=`${componentName}:${eventName}`;if(!eventUsage){eventUsage=new Map;context.rulePack.getExtension().eventUsage=eventUsage}if(!eventUsage.has(eventKey)){const eventComponentDef=context.rulePack.getExtension().allComponents.get(componentName);if(eventComponentDef){if(eventComponentDef.hasOwnProperty("events")){Object.keys(eventComponentDef.events).forEach(event=>{eventUsage.set(`${componentName}:${event}`,false)})}}else{msg.error(`JETWC Error (jetwc-unused-events): component ${componentName} missing from allComponents map`)}}if(eventUsage.has(eventKey)){eventUsage.set(eventKey,true)}}else{msg.msg(`JETWC Warning (jetwc-unused-events): component event ${eventName} cannot be mapped to a component due to missing viewModel mapping`)}};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-unused-slots"};ruleDef.prototype.getShortDescription=function(){return"Verify that all declared slots are actually used"};ruleDef.prototype.getDescription=function(){return"This rule checks that any slots declared in the metadata are then actually used via an oj-bind-* in the associated html"};ruleDef.prototype.register=function(context){return{"<oj-bind-template-slot>":this._flagSlotUse,"<oj-bind-slot>":this._flagSlotUse,closedownRP:this._doAudit}};ruleDef.prototype._flagSlotUse=function(context){const slotName=context.tagNode.attribs.name?context.tagNode.attribs.name:"__default__";if(slotName&&!context.utils.DomUtils.isExpression(slotName)){const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));if(componentName){this._markSlotUsed(context,componentName,slotName)}}};ruleDef.prototype._doAudit=function(context){if(context.rulePack.getExtension()){const slotUsage=context.rulePack.getExtension().slotUsage;if(slotUsage){slotUsage.forEach(function(value,key){if(!value){const idParts=key.split(":");const componentName=idParts[0];const slotName=idParts[1];if(!Utils.shouldIgnoreCheck(context,"jetwc-unused-slots",componentName,"slots",slotName)){const issue=new context.Issue(`Slot '${slotName?slotName:"default"}' for component ${componentName} does not appear to be bound to the UI`);context.reporter.addIssue(issue,context)}}})}}};ruleDef.prototype._markSlotUsed=function(context,componentName,slotName){let slotUsage=context.rulePack.getExtension().slotUsage;const slotKey=`${componentName}:${slotName}`;if(!slotUsage){slotUsage=new Map;context.rulePack.getExtension().slotUsage=slotUsage}if(!slotUsage.has(slotKey)){const slotComponentDef=context.rulePack.getExtension().allComponents.get(componentName);if(slotComponentDef.hasOwnProperty("slots")){Object.keys(slotComponentDef.slots).forEach(slot=>{slotUsage.set(`${componentName}:${slot?slot:"__default__"}`,false)})}}if(slotUsage.has(slotKey)){slotUsage.set(slotKey,true)}};module.exports=ruleDef;
6
+ const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-unused-slots"};ruleDef.prototype.getShortDescription=function(){return"Verify that all declared slots are actually used"};ruleDef.prototype.getDescription=function(){return"This rule checks that any slots declared in the metadata are then actually used via an oj-bind-* in the associated html"};ruleDef.prototype.register=function(context){return{"<oj-bind-template-slot>":this._flagSlotUse,"<oj-bind-slot>":this._flagSlotUse,closedownRP:this._doAudit}};ruleDef.prototype._flagSlotUse=function(context){const slotName=context.tagNode.attribs.name?context.tagNode.attribs.name:"__default__";if(slotName&&!context.utils.DomUtils.isExpression(slotName)){const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));if(componentName){this._markSlotUsed(context,componentName,slotName)}}};ruleDef.prototype._doAudit=function(context){if(context.rulePack.getExtension()){const slotUsage=context.rulePack.getExtension().slotUsage;if(slotUsage){slotUsage.forEach(function(value,key){if(!value){const idParts=key.split(":");const componentName=idParts[0];const slotName=idParts[1];if(!Utils.shouldIgnoreCheck(context,"jetwc-unused-slots",componentName,"slots",slotName)){const compInfo=Utils.componentInfo(context,componentName);const reportSource=compInfo.rootFolder+"/component.json";const issue=new context.Issue(`Slot '${slotName?slotName:"default"}' for component ${componentName} does not appear to be bound to the UI`);issue.setReportedFilePath(reportSource);context.reporter.addIssue(issue,context)}}})}}};ruleDef.prototype._markSlotUsed=function(context,componentName,slotName){let slotUsage=context.rulePack.getExtension().slotUsage;const slotKey=`${componentName}:${slotName}`;if(!slotUsage){slotUsage=new Map;context.rulePack.getExtension().slotUsage=slotUsage}if(!slotUsage.has(slotKey)){const slotComponentDef=context.rulePack.getExtension().allComponents.get(componentName);if(slotComponentDef.hasOwnProperty("slots")){Object.keys(slotComponentDef.slots).forEach(slot=>{slotUsage.set(`${componentName}:${slot?slot:"__default__"}`,false)})}}if(slotUsage.has(slotKey)){slotUsage.set(slotKey,true)}};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 Utils=require('../jetwc-lib/jetwcutils-componentAuditUtils');const TsxUtils=require('../jetwc-lib/jetwcutils-tsxUtils');const ruleDef=function(){};ruleDef.prototype.getName=function(){return'jetwc-vb-category'};ruleDef.prototype.getShortDescription=function(){return'Verify the category specified '};ruleDef.prototype.getDescription=function(){return'This rule is configured with your preferred Visual Builder component palette category'};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);let category;if(meta.extension&&meta.extension.catalog){category=meta.extension.catalog.category}this._checkCategory(context,fullName,componentType,category)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){let category;if(componentInfo.extension&&componentInfo.extension.catalog){category=componentInfo.extension.catalog.category}this._checkCategory(context,componentInfo.fullName,componentInfo.type,category,true)}};ruleDef.prototype._checkCategory=function(context,fullName,componentType,category,isVComponent){let issue;const ruleOptions=context.rulePack.getRuleOptions();if(ruleOptions.categories&&ruleOptions.categories.length>0){switch(componentType){case'composite':case'vbcs-pattern':if(category){if(ruleOptions.categories.filter(cat=>cat===category).length===0){issue=new context.Issue(`Component ${fullName} (${isVComponent?'vcomponent':componentType}) has an unexpected palette category set of '${category}'`);issue.setMsgKey(context.ruleName+'_2');context.reporter.addIssue(issue,context)}}else{issue=new context.Issue(`Component ${fullName} (${isVComponent?'vcomponent':componentType}) does not have a palette category set`);issue.setMsgKey(context.ruleName+'_1');context.reporter.addIssue(issue,context)}break;default:break;}}};module.exports=ruleDef;
6
+ const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vb-category"};ruleDef.prototype.getShortDescription=function(){return"Verify the category specified "};ruleDef.prototype.getDescription=function(){return"This rule is configured with your preferred Visual Builder component palette category"};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);let category;if(meta.extension&&meta.extension.catalog){category=meta.extension.catalog.category}this._checkCategory(context,fullName,componentType,category)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){let category;if(componentInfo.extension&&componentInfo.extension.catalog){category=componentInfo.extension.catalog.category}this._checkCategory(context,componentInfo.fullName,componentInfo.type,category,true)}};ruleDef.prototype._checkCategory=function(context,fullName,componentType,category,isVComponent){let issue;const ruleOptions=context.rulePack.getRuleOptions();if(ruleOptions.categories&&ruleOptions.categories.length>0){switch(componentType){case"composite":case"vbcs-pattern":if(category){if(ruleOptions.categories.filter(cat=>cat===category).length===0){issue=new context.Issue(`Component ${fullName} (${isVComponent?"vcomponent":componentType}) has an unexpected palette category set of '${category}'`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}}else{issue=new context.Issue(`Component ${fullName} (${isVComponent?"vcomponent":componentType}) does not have a palette category set`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}break;default:break}}};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 TsxUtils=require('../jetwc-lib/jetwcutils-tsxUtils');const ruleDef=function(){};ruleDef.prototype.getName=function(){return'jetwc-vb-icon'};ruleDef.prototype.getShortDescription=function(){return'Verify components have icons for Visual Builder'};ruleDef.prototype.getDescription=function(){return'This rule checks that the correct icon variants are supplied for the visual builder component palette'};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);this._checkIcon(context,fullName,componentType,meta.icon)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkIcon(context,componentInfo.fullName,componentInfo.type,componentInfo.icon)}};ruleDef.prototype._checkIcon=function(context,fullName,componentType,iconDef){let issue;const inRedwood=context.utils.jafLib.getConfig().getTheme().toLowerCase()==='redwood';switch(componentType){case'composite':case'vbcs-pattern':case'vbcs-action':if(!iconDef){issue=new context.Issue(`Component ${fullName} does not have a Visual Builder icon assigned`);issue.setMsgKey(context.ruleName+'_1');context.reporter.addIssue(issue,context,'info')}else{if(!iconDef.iconPath){issue=new context.Issue(`Component ${fullName} does not have a base Visual Builder icon assigned via iconPath`);issue.setMsgKey(context.ruleName+'_2');context.reporter.addIssue(issue,context,'info')}else{this._checkIconLocationAndFormat(context,'iconPath',iconDef.iconPath,fullName)}if(inRedwood){if(iconDef.hoverIconPath){this._checkIconLocationAndFormat(context,'hoverIconPath',iconDef.hoverIconPath,fullName)}if(iconDef.iconPath&&iconDef.hoverIconPath&&iconDef.iconPath!==iconDef.hoverIconPath){issue=new context.Issue(`Component ${fullName} should use the same icon for the base and hover state in the Visual Builder Redwood component palette`);issue.setMsgKey(context.ruleName+'_9');context.reporter.addIssue(issue,context,'info')}}else{if(!iconDef.hoverIconPath){issue=new context.Issue(`Component ${fullName} does not have a Visual Builder icon assigned for hover (hoverIconPath)`);issue.setMsgKey(context.ruleName+'_3');context.reporter.addIssue(issue,context,'info')}else{this._checkIconLocationAndFormat(context,'hoverIconPath',iconDef.hoverIconPath,fullName)}if(iconDef.iconPath&&iconDef.hoverIconPath&&iconDef.iconPath===iconDef.hoverIconPath){issue=new context.Issue(`Component ${fullName} uses identical icons for the base and hover state in the Visual Builder component palette`);issue.setMsgKey(context.ruleName+'_4');context.reporter.addIssue(issue,context,'info')}}}break;case'vbcs-template':if(!iconDef||!iconDef.iconPath){issue=new context.Issue(`Template ${fullName} does not have a Visual Builder icon assigned`);issue.setMsgKey(context.ruleName+'_8');context.reporter.addIssue(issue,context,'info')}break;}};ruleDef.prototype._checkIconLocationAndFormat=function(context,use,iconFile,componentName){const pathSegs=iconFile.split('/');if(pathSegs[0]!=='extension'){issue=new context.Issue(`Design time ${use} icon ${iconFile} for component ${componentName} should be located under the /extension folder`);issue.setMsgKey(context.ruleName+'_5');context.reporter.addIssue(issue,context,'info')}if(path.extname(iconFile).toLowerCase()!=='.svg'){issue=new context.Issue(`Design time ${use} icon ${iconFile} for component ${componentName} should ideally be in SVG format`);issue.setMsgKey(context.ruleName+'_6');context.reporter.addIssue(issue,context,'info')}if(context.rulePack.getExtension().allComponents.has(componentName)){const componentRoot=context.rulePack.getExtension().allComponents.get(componentName).rootFolder;if(!context.utils.fsUtils.fileExists(path.join(componentRoot,iconFile))){issue=new context.Issue(`Design time ${use} icon ${iconFile} for component ${componentName} does not exist or is outside of the component distribution`);issue.setMsgKey(context.ruleName+'_7');context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;
6
+ const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vb-icon"};ruleDef.prototype.getShortDescription=function(){return"Verify components have icons for Visual Builder"};ruleDef.prototype.getDescription=function(){return"This rule checks that the correct icon variants are supplied for the visual builder component palette"};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);this._checkIcon(context,fullName,componentType,meta.icon)}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._checkIcon(context,componentInfo.fullName,componentInfo.type,componentInfo.icon)}};ruleDef.prototype._checkIcon=function(context,fullName,componentType,iconDef){let issue;const inRedwood=context.utils.jafLib.getConfig().getTheme().toLowerCase()==="redwood";switch(componentType){case"composite":case"vbcs-pattern":case"vbcs-action":if(!iconDef){issue=new context.Issue(`Component ${fullName} does not have a Visual Builder icon assigned`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context,"info")}else{if(!iconDef.iconPath){issue=new context.Issue(`Component ${fullName} does not have a base Visual Builder icon assigned via iconPath`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context,"info")}else{this._checkIconLocationAndFormat(context,"iconPath",iconDef.iconPath,fullName)}if(inRedwood){if(iconDef.hoverIconPath){this._checkIconLocationAndFormat(context,"hoverIconPath",iconDef.hoverIconPath,fullName)}if(iconDef.iconPath&&iconDef.hoverIconPath&&iconDef.iconPath!==iconDef.hoverIconPath){issue=new context.Issue(`Component ${fullName} should use the same icon for the base and hover state in the Visual Builder Redwood component palette`);issue.setMsgKey(context.ruleName+"_9");context.reporter.addIssue(issue,context,"info")}}else{if(!iconDef.hoverIconPath){issue=new context.Issue(`Component ${fullName} does not have a Visual Builder icon assigned for hover (hoverIconPath)`);issue.setMsgKey(context.ruleName+"_3");context.reporter.addIssue(issue,context,"info")}else{this._checkIconLocationAndFormat(context,"hoverIconPath",iconDef.hoverIconPath,fullName)}if(iconDef.iconPath&&iconDef.hoverIconPath&&iconDef.iconPath===iconDef.hoverIconPath){issue=new context.Issue(`Component ${fullName} uses identical icons for the base and hover state in the Visual Builder component palette`);issue.setMsgKey(context.ruleName+"_4");context.reporter.addIssue(issue,context,"info")}}}break;case"vbcs-template":if(!iconDef||!iconDef.iconPath){issue=new context.Issue(`Template ${fullName} does not have a Visual Builder icon assigned`);issue.setMsgKey(context.ruleName+"_8");context.reporter.addIssue(issue,context,"info")}break}};ruleDef.prototype._checkIconLocationAndFormat=function(context,use,iconFile,componentName){const pathSegs=iconFile.split("/");if(pathSegs[0]!=="extension"){issue=new context.Issue(`Design time ${use} icon ${iconFile} for component ${componentName} should be located under the /extension folder`);issue.setMsgKey(context.ruleName+"_5");context.reporter.addIssue(issue,context,"info")}if(path.extname(iconFile).toLowerCase()!==".svg"){issue=new context.Issue(`Design time ${use} icon ${iconFile} for component ${componentName} should ideally be in SVG format`);issue.setMsgKey(context.ruleName+"_6");context.reporter.addIssue(issue,context,"info")}if(context.rulePack.getExtension().allComponents.has(componentName)){const componentRoot=context.rulePack.getExtension().allComponents.get(componentName).rootFolder;if(!context.utils.fsUtils.fileExists(path.join(componentRoot,iconFile))){issue=new context.Issue(`Design time ${use} icon ${iconFile} for component ${componentName} does not exist or is outside of the component distribution`);issue.setMsgKey(context.ruleName+"_7");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 Utils=require('../jetwc-lib/jetwcutils-componentAuditUtils');const TsxUtils=require('../jetwc-lib/jetwcutils-tsxUtils');const path=require('path');const ruleDef=function(){};ruleDef.prototype.getName=function(){return'jetwc-vcomponent-jetversion'};ruleDef.prototype.getShortDescription=function(){return'Verify that a VComponent .tsx file includes the supported JET version'};ruleDef.prototype.getDescription=function(){return'This rule checks that a vcomponent either directly, or indirectly provides the jetVersion metadata needed to indicate the support range'};ruleDef.prototype.register=function(context){return{startaudit:this._checkForApplicability,Program:this._doVComponentAudit}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){let checkVersion=componentInfo.jetVersion;if(!context.utils.semVerUtils.isValidRange(checkVersion)){if(componentInfo.inferredJetVersion){issue=new context.Issue(`Component ${componentInfo.fullName} inherits a JET version dependency from its pack that is using an invalid format (${checkVersion})`)}else{issue=new context.Issue(`Component ${componentInfo.fullName} defines a JET version dependency using an invalid format (${checkVersion})`)}issue.setMsgKey(context.ruleName+'_2');context.reporter.addIssue(issue,context)}else{if(componentInfo.inferredJetVersion){issue=new context.Issue(`Component ${componentInfo.fullName} is using an inferred / defaulted JET version range`);issue.setMsgKey(context.ruleName+'_1');context.reporter.addIssue(issue,context,'info')}}}};module.exports=ruleDef;
6
+ const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const path=require("path");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vcomponent-jetversion"};ruleDef.prototype.getShortDescription=function(){return"Verify that a VComponent .tsx file includes the supported JET version"};ruleDef.prototype.getDescription=function(){return"This rule checks that a vcomponent either directly, or indirectly provides the jetVersion metadata needed to indicate the support range"};ruleDef.prototype.register=function(context){return{startaudit:this._checkForApplicability,Program:this._doVComponentAudit}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){let checkVersion=componentInfo.jetVersion;if(!context.utils.semVerUtils.isValidRange(checkVersion)){if(componentInfo.inferredJetVersion){issue=new context.Issue(`Component ${componentInfo.fullName} inherits a JET version dependency from its pack that is using an invalid format (${checkVersion})`)}else{issue=new context.Issue(`Component ${componentInfo.fullName} defines a JET version dependency using an invalid format (${checkVersion})`)}issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}else{if(componentInfo.inferredJetVersion){issue=new context.Issue(`Component ${componentInfo.fullName} is using an inferred / defaulted JET version range`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context,"info")}}}};module.exports=ruleDef;
@@ -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 path=require('path');const{nodeModuleNameResolver}=require('typescript');const{nextTick}=require('process');let NT;const ruleDef=function(){};ruleDef.prototype.getName=function(){return'jetwc-vcomponent-loader'};ruleDef.prototype.getShortDescription=function(){return'Verify that a VComponent has the required loader'};ruleDef.prototype.getDescription=function(){return'This rule checks that a VComponent is correctly matched with a loader.ts and that the class being exported matches the VComponent implementation'};ruleDef.prototype.register=function(context){NT=context.tsNodeTypes;return{startaudit:this._checkForApplicability,[NT.EXPORT_NAMED_DECL]:this._matchLoaderToComponents,closedownRP:this._checkForMissingLoaders}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._matchLoaderToComponents=function(context){if(context.filepath.endsWith('/loader.ts')){const loaderRoot=Utils.toNativePath(context.filepath.substring(0,context.filepath.lastIndexOf('/')));let issue;if(context.node.exportKind==='value'&&context.node.source&&context.node.source.type===NT.LITERAL){const relativeSource=Utils.toNativePath(context.node.source.value);const absoluteSource=Utils.toJAFPath(path.join(loaderRoot,`${relativeSource}.tsx`));const componentInfo=TsxUtils.matchToVComponentImpl(context,absoluteSource);if(componentInfo){componentInfo.viewModel.loaderMatch=true;const exportedClass=componentInfo.viewModel.className;if(exportedClass&&context.node.specifiers){context.node.specifiers.forEach(specifier=>{if(specifier.exported.type===NT.IDENTIFIER&&specifier.exported.name===exportedClass){componentInfo.viewModel.loaderCorrectExport=true}})}if(exportedClass&&!componentInfo.viewModel.loaderCorrectExport){const issue=new context.Issue(`The loader for component ${componentInfo.fullName} does not re-export the expected class name of ${exportedClass}`);issue.setMsgKey(context.ruleName+'_2');context.reporter.addIssue(issue,context,'blocker')}}}}};ruleDef.prototype._checkForMissingLoaders=function(context){if(context.rulePack.getExtension()&&context.rulePack.getExtension().allComponents){const allVComponents=[...context.rulePack.getExtension().allComponents].map(pair=>pair[1]).filter(componentInfo=>componentInfo.vcomponent&&!componentInfo.viewModel.loaderMatch);allVComponents.forEach(componentInfo=>{const issue=new context.Issue(`Component ${componentInfo.fullName} does not have a matching loader.ts. All VComponents must be re-exported by a loader.`);issue.setMsgKey(context.ruleName+'_1');context.reporter.addIssue(issue,context)})}};module.exports=ruleDef;
6
+ const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const path=require("path");const{nodeModuleNameResolver}=require("typescript");const{nextTick}=require("process");let NT;const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vcomponent-loader"};ruleDef.prototype.getShortDescription=function(){return"Verify that a VComponent has the required loader"};ruleDef.prototype.getDescription=function(){return"This rule checks that a VComponent is correctly matched with a loader.ts and that the class being exported matches the VComponent implementation"};ruleDef.prototype.register=function(context){NT=context.tsNodeTypes;return{startaudit:this._checkForApplicability,[NT.EXPORT_NAMED_DECL]:this._matchLoaderToComponents,closedownRP:this._checkForMissingLoaders}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._matchLoaderToComponents=function(context){if(context.filepath.endsWith("/loader.ts")){const loaderRoot=Utils.toNativePath(context.filepath.substring(0,context.filepath.lastIndexOf("/")));let issue;if(context.node.exportKind==="value"&&context.node.source&&context.node.source.type===NT.LITERAL){const relativeSource=Utils.toNativePath(context.node.source.value);const absoluteSource=Utils.toJAFPath(path.join(loaderRoot,`${relativeSource}.tsx`));const componentInfo=TsxUtils.matchToVComponentImpl(context,absoluteSource);if(componentInfo){componentInfo.viewModel.loaderMatch=true;const exportedClass=componentInfo.viewModel.className;if(exportedClass&&context.node.specifiers){context.node.specifiers.forEach(specifier=>{if(specifier.exported.type===NT.IDENTIFIER&&specifier.exported.name===exportedClass){componentInfo.viewModel.loaderCorrectExport=true}})}if(exportedClass&&!componentInfo.viewModel.loaderCorrectExport){const issue=new context.Issue(`The loader for component ${componentInfo.fullName} does not re-export the expected class name of ${exportedClass}`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context,"blocker")}}}}};ruleDef.prototype._checkForMissingLoaders=function(context){if(context.rulePack.getExtension()&&context.rulePack.getExtension().allComponents){const allVComponents=[...context.rulePack.getExtension().allComponents].map(pair=>pair[1]).filter(componentInfo=>componentInfo.vcomponent&&!componentInfo.viewModel.loaderMatch);allVComponents.forEach(componentInfo=>{let reportSource=componentInfo.fullName;if(componentInfo.viewModel.resolved&&!componentInfo.viewModel.skip){reportSource=componentInfo.viewModel.path}const issue=new context.Issue(`Component ${componentInfo.fullName} does not have a matching loader.ts. All VComponents must be re-exported by a loader.`);issue.setMsgKey(context.ruleName+"_1");issue.setReportedFilePath(reportSource);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 Utils=require('../jetwc-lib/jetwcutils-componentAuditUtils');const TsxUtils=require('../jetwc-lib/jetwcutils-tsxUtils');const path=require('path');const ruleDef=function(){};ruleDef.prototype.getName=function(){return'jetwc-vcomponent-version'};ruleDef.prototype.getShortDescription=function(){return'Verify that a VComponent .tsx file defines a version number for the component'};ruleDef.prototype.getDescription=function(){return'This rule checks that a vcomponent either directly, or indirectly provides the version metadata needed for managing dependencies'};ruleDef.prototype.register=function(context){return{startaudit:this._checkForApplicability,Program:this._doVComponentAudit}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);let issue;if(componentInfo){if(componentInfo.version){if(!context.utils.semVerUtils.isValid(componentInfo.version)){if(componentInfo.pack&&componentInfo.inferredVersion){issue=new context.Issue(`Component ${componentInfo.fullName} inherits an invalid version number format (${componentInfo.version}) from its pack definition`)}else{issue=new context.Issue(`Component ${componentInfo.fullName} defines a version number using an invalid format (${componentInfo.version})`)}issue.setMsgKey(context.ruleName+'_2');context.reporter.addIssue(issue,context)}else if(componentInfo.pack&&componentInfo.inferredVersion){issue=new context.Issue(`Component ${componentInfo.fullName} is inheriting a version number from its pack`);issue.setMsgKey(context.ruleName+'_3');context.reporter.addIssue(issue,context,'info')}}else{issue=new context.Issue(`Component ${componentInfo?componentInfo.fullName:context.filepath.split('/').reverse()[0]} does not define a version number`);issue.setMsgKey(context.ruleName+'_1');context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;
6
+ const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const path=require("path");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-vcomponent-version"};ruleDef.prototype.getShortDescription=function(){return"Verify that a VComponent .tsx file defines a version number for the component"};ruleDef.prototype.getDescription=function(){return"This rule checks that a vcomponent either directly, or indirectly provides the version metadata needed for managing dependencies"};ruleDef.prototype.register=function(context){return{startaudit:this._checkForApplicability,Program:this._doVComponentAudit}};ruleDef.prototype._checkForApplicability=function(context){if(context.rulePack.getExtension()&&!context.rulePack.getExtension().precompiled){context.rulePack.disableRule()}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);let issue;if(componentInfo){if(componentInfo.version){if(!context.utils.semVerUtils.isValid(componentInfo.version)){if(componentInfo.pack&&componentInfo.inferredVersion){issue=new context.Issue(`Component ${componentInfo.fullName} inherits an invalid version number format (${componentInfo.version}) from its pack definition`)}else{issue=new context.Issue(`Component ${componentInfo.fullName} defines a version number using an invalid format (${componentInfo.version})`)}issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}else if(componentInfo.pack&&componentInfo.inferredVersion){issue=new context.Issue(`Component ${componentInfo.fullName} is inheriting a version number from its pack`);issue.setMsgKey(context.ruleName+"_3");context.reporter.addIssue(issue,context,"info")}}else{issue=new context.Issue(`Component ${componentInfo?componentInfo.fullName:context.filepath.split("/").reverse()[0]} does not define a version number`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context)}}};module.exports=ruleDef;
@@ -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 ruleDef=function(){};ruleDef.prototype.getName=function(){return'jetwc-version-openrange'};ruleDef.prototype.getShortDescription=function(){return'Verify that any version ranges for dependencies have an upper bound'};ruleDef.prototype.getDescription=function(){return'This rule checks that the component is not promising to support all future JET versions or unknown future versions of dependent components'};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){let issue;const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);this._verifyJetVersion(context,fullName,meta.jetVersion);if(meta.dependencies){const deps=Object.keys(meta.dependencies);deps.forEach(dependency=>{const checkVersion=meta.dependencies[dependency];this._verifyDependencyVersion(context,fullName,dependency,checkVersion)})}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._verifyJetVersion(context,componentInfo.fullName,componentInfo.jetVersion);if(componentInfo.dependencies){componentInfo.dependencies.forEach(dependency=>{this._verifyDependencyVersion(context,componentInfo.fullName,dependency.name,dependency.range)})}}};ruleDef.prototype._hasNoUpper=function(auditContext,rangeString){let noUpper=false;if(rangeString){if(!auditContext.utils.semVerUtils.isValid(rangeString)&&auditContext.utils.semVerUtils.isValidRange(rangeString)){noUpper=auditContext.utils.semVerUtils.satisfiesRange('99999.0.0',rangeString)}}return noUpper};ruleDef.prototype._verifyJetVersion=function(auditContext,fullName,jetVersion){if(this._hasNoUpper(auditContext,jetVersion)){issue=new auditContext.Issue(`Component ${fullName} specifies a JET Range that has no upper limit '${jetVersion}'`);issue.setMsgKey(auditContext.ruleName+'_1');auditContext.reporter.addIssue(issue,auditContext)}};ruleDef.prototype._verifyDependencyVersion=function(auditContext,fullName,dependency,checkVersion){if(this._hasNoUpper(auditContext,checkVersion)){issue=new auditContext.Issue(`Component ${fullName} specifies a dependency range for ${dependency} that has no upper limit '${checkVersion}'`);issue.setMsgKey(auditContext.ruleName+'_2');auditContext.reporter.addIssue(issue,auditContext)}};module.exports=ruleDef;
6
+ const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-version-openrange"};ruleDef.prototype.getShortDescription=function(){return"Verify that any version ranges for dependencies have an upper bound"};ruleDef.prototype.getDescription=function(){return"This rule checks that the component is not promising to support all future JET versions or unknown future versions of dependent components"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){let issue;const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);this._verifyJetVersion(context,fullName,meta.jetVersion);if(meta.dependencies){const deps=Object.keys(meta.dependencies);deps.forEach(dependency=>{const checkVersion=meta.dependencies[dependency];this._verifyDependencyVersion(context,fullName,dependency,checkVersion)})}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo){this._verifyJetVersion(context,componentInfo.fullName,componentInfo.jetVersion);if(componentInfo.dependencies){componentInfo.dependencies.forEach(dependency=>{this._verifyDependencyVersion(context,componentInfo.fullName,dependency.name,dependency.range)})}}};ruleDef.prototype._hasNoUpper=function(auditContext,rangeString){let noUpper=false;if(rangeString){if(!auditContext.utils.semVerUtils.isValid(rangeString)&&auditContext.utils.semVerUtils.isValidRange(rangeString)){noUpper=auditContext.utils.semVerUtils.satisfiesRange("99999.0.0",rangeString)}}return noUpper};ruleDef.prototype._verifyJetVersion=function(auditContext,fullName,jetVersion){if(this._hasNoUpper(auditContext,jetVersion)){issue=new auditContext.Issue(`Component ${fullName} specifies a JET Range that has no upper limit '${jetVersion}'`);issue.setMsgKey(auditContext.ruleName+"_1");auditContext.reporter.addIssue(issue,auditContext)}};ruleDef.prototype._verifyDependencyVersion=function(auditContext,fullName,dependency,checkVersion){if(this._hasNoUpper(auditContext,checkVersion)){issue=new auditContext.Issue(`Component ${fullName} specifies a dependency range for ${dependency} that has no upper limit '${checkVersion}'`);issue.setMsgKey(auditContext.ruleName+"_2");auditContext.reporter.addIssue(issue,auditContext)}};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-writeback-required'};ruleDef.prototype.getShortDescription=function(){return'Verifies that properties are marked with writeback if needed'};ruleDef.prototype.getDescription=function(){return'This rule attempts to match up calls to the setProperty() api, or direct assignments to this.properties, with the properties being addressed and then verifies that they are set to writeback:true. (The properties object should not be used as a private cache for component state)'};ruleDef.prototype.register=function(context){return{CallExpression:this._doAuditOnSetProperty,AssignmentExpression:this._doAuditOnPropertyAssignment,attrexpr:this._doAuditOnPropertyHTMLRef}};ruleDef.prototype._doAuditOnSetProperty=function(context,node){let issue;const NT=context.utils.AstUtils.getNodeTypes();const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent&&node.callee.property&&node.callee.property.type===NT.IDENTIFIER&&node.callee.property.name==='setProperty'){let isStyle=false;if(node.callee.object&&node.callee.object.property&&node.callee.object.property.type===NT.IDENTIFIER&&node.callee.object.property.name==='style'){isStyle=true}let compRef=false;if(node.callee.object&&node.callee.object.object&&node.callee.object.property&&node.callee.object.property.type===NT.IDENTIFIER){if(node.callee.object.object.type===NT.THIS_EXPR||node.callee.object.object.type===NT.IDENTIFIER&&node.callee.object.object.name==='self'){compRef=true}}if(!isStyle&&compRef&&node.arguments&&node.arguments.length===2){if(node.arguments[0].type=NT.LITERAL&&node.arguments[0].value){let potentialProperty=node.arguments[0].value;if(potentialProperty.includes('.')){potentialProperty=potentialProperty.split('.')[0]}const componentInfo=Utils.componentInfo(context,withinComponent);if(componentInfo.properties&&componentInfo.properties.hasOwnProperty(potentialProperty)){if(!componentInfo.properties[potentialProperty].hasOwnProperty('writeback')||!componentInfo.properties[potentialProperty].writeback){issue=new context.Issue(`Component '${withinComponent}' makes a call to setProperty() for the property ${potentialProperty} but this is not marked as writeback in the metadata`);issue.setMsgKey(context.ruleName+'_1');context.reporter.addIssue(issue,context,'blocker')}}else{this._reportUndclProp(context,withinComponent,potentialProperty)}}}}};ruleDef.prototype._doAuditOnPropertyAssignment=function(context,node){let issue;const NT=context.utils.AstUtils.getNodeTypes();const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent&&node.left.type===NT.MEMBER_EXPR&&node.left.object.type===NT.MEMBER_EXPR&&node.left.object.property.name==='properties'){const setProperty=this._isContextProperties(context,node);if(setProperty){const componentInfo=Utils.componentInfo(context,withinComponent);if(componentInfo.properties&&componentInfo.properties.hasOwnProperty(setProperty)){if(!componentInfo.properties[setProperty].hasOwnProperty('writeback')||!componentInfo.properties[setProperty].writeback){issue=new context.Issue(`Component '${withinComponent}' assigns a value to the property ${setProperty} but this is not marked as writeback in the metadata`);issue.setMsgKey(context.ruleName+'_2');context.reporter.addIssue(issue,context)}}else{this._reportUndclProp(context,withinComponent,setProperty)}}}};ruleDef.prototype._doAuditOnPropertyHTMLRef=function(context,attribName,attribValue,rawAttribValue){let issue;const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent){const parser=/^(?:\{\{\$props\.|\{\{\$properties\.)(.*)(?:\}\})$/;if(attribValue.match(parser)){const expressionParts=attribValue.split(parser);const checkProperty=expressionParts[1];const componentInfo=Utils.componentInfo(context,withinComponent);if(componentInfo.properties&&componentInfo.properties.hasOwnProperty(checkProperty)){if(!componentInfo.properties[checkProperty].hasOwnProperty('writeback')||!componentInfo.properties[checkProperty].writeback){issue=new context.Issue(`Component '${withinComponent}' assigns the property '${checkProperty}' using a read-write binding to the <${context.tag}> attribute '${attribName}', however, the property is not marked as writeback in the metadata`);issue.setMsgKey(context.ruleName+'_3');context.reporter.addIssue(issue,context)}}else{this._reportUndclProp(context,withinComponent,checkProperty)}}}};ruleDef.prototype._reportUndclProp=function(context,component,property){issue=new context.Issue(`Component '${component}' makes a call to setProperty() or cached context.properties for an undeclared property ${property}`);issue.setMsgKey(context.ruleName+'_4');context.reporter.addIssue(issue,context,'blocker')};ruleDef.prototype._isContextProperties=function(context,node){let assignedProperty;let assignmentChain=Utils.decomposeAssignment(context,node);const assignmentRoot=assignmentChain.pop();const assignmentSecondary=assignmentChain.pop();if(assignmentRoot==='this'||assignmentRoot==='<parameter>'&&assignmentSecondary==='context'){assignedProperty=assignmentChain[0]}return assignedProperty};module.exports=ruleDef;
6
+ const path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-writeback-required"};ruleDef.prototype.getShortDescription=function(){return"Verifies that properties are marked with writeback if needed"};ruleDef.prototype.getDescription=function(){return"This rule attempts to match up calls to the setProperty() api, or direct assignments to this.properties, with the properties being addressed and then verifies that they are set to writeback:true. (The properties object should not be used as a private cache for component state)"};ruleDef.prototype.register=function(context){return{CallExpression:this._doAuditOnSetProperty,AssignmentExpression:this._doAuditOnPropertyAssignment,attrexpr:this._doAuditOnPropertyHTMLRef}};ruleDef.prototype._doAuditOnSetProperty=function(context,node){let issue;const NT=context.utils.AstUtils.getNodeTypes();const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent&&node.callee.property&&node.callee.property.type===NT.IDENTIFIER&&node.callee.property.name==="setProperty"){let isStyle=false;if(node.callee.object&&node.callee.object.property&&node.callee.object.property.type===NT.IDENTIFIER&&node.callee.object.property.name==="style"){isStyle=true}let compRef=false;if(node.callee.object&&node.callee.object.object&&node.callee.object.property&&node.callee.object.property.type===NT.IDENTIFIER){if(node.callee.object.object.type===NT.THIS_EXPR||node.callee.object.object.type===NT.IDENTIFIER&&node.callee.object.object.name==="self"){compRef=true}}if(!isStyle&&compRef&&node.arguments&&node.arguments.length===2){if(node.arguments[0].type=NT.LITERAL&&node.arguments[0].value){let potentialProperty=node.arguments[0].value;if(potentialProperty.includes(".")){potentialProperty=potentialProperty.split(".")[0]}const componentInfo=Utils.componentInfo(context,withinComponent);if(componentInfo.properties&&componentInfo.properties.hasOwnProperty(potentialProperty)){if(!componentInfo.properties[potentialProperty].hasOwnProperty("writeback")||!componentInfo.properties[potentialProperty].writeback){issue=new context.Issue(`Component '${withinComponent}' makes a call to setProperty() for the property ${potentialProperty} but this is not marked as writeback in the metadata`);issue.setMsgKey(context.ruleName+"_1");context.reporter.addIssue(issue,context,"blocker")}}else{this._reportUndclProp(context,withinComponent,potentialProperty)}}}}};ruleDef.prototype._doAuditOnPropertyAssignment=function(context,node){let issue;const NT=context.utils.AstUtils.getNodeTypes();const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent&&node.left.type===NT.MEMBER_EXPR&&node.left.object.type===NT.MEMBER_EXPR&&node.left.object.property.name==="properties"){const setProperty=this._isContextProperties(context,node);if(setProperty){const componentInfo=Utils.componentInfo(context,withinComponent);if(componentInfo.properties&&componentInfo.properties.hasOwnProperty(setProperty)){if(!componentInfo.properties[setProperty].hasOwnProperty("writeback")||!componentInfo.properties[setProperty].writeback){issue=new context.Issue(`Component '${withinComponent}' assigns a value to the property ${setProperty} but this is not marked as writeback in the metadata`);issue.setMsgKey(context.ruleName+"_2");context.reporter.addIssue(issue,context)}}else{this._reportUndclProp(context,withinComponent,setProperty)}}}};ruleDef.prototype._doAuditOnPropertyHTMLRef=function(context,attribName,attribValue,rawAttribValue){let issue;const withinComponent=Utils.matchComponentPath(context,path.dirname(context.filepath));if(withinComponent){const parser=/^(?:\{\{\$props\.|\{\{\$properties\.)(.*)(?:\}\})$/;if(attribValue.match(parser)){const expressionParts=attribValue.split(parser);const checkProperty=expressionParts[1];const componentInfo=Utils.componentInfo(context,withinComponent);if(componentInfo.properties&&componentInfo.properties.hasOwnProperty(checkProperty)){if(!componentInfo.properties[checkProperty].hasOwnProperty("writeback")||!componentInfo.properties[checkProperty].writeback){issue=new context.Issue(`Component '${withinComponent}' assigns the property '${checkProperty}' using a read-write binding to the <${context.tag}> attribute '${attribName}', however, the property is not marked as writeback in the metadata`);issue.setMsgKey(context.ruleName+"_3");context.reporter.addIssue(issue,context)}}else{this._reportUndclProp(context,withinComponent,checkProperty)}}}};ruleDef.prototype._reportUndclProp=function(context,component,property){issue=new context.Issue(`Component '${component}' makes a call to setProperty() or cached context.properties for an undeclared property ${property}`);issue.setMsgKey(context.ruleName+"_4");context.reporter.addIssue(issue,context,"blocker")};ruleDef.prototype._isContextProperties=function(context,node){let assignedProperty;let assignmentChain=Utils.decomposeAssignment(context,node);const assignmentRoot=assignmentChain.pop();const assignmentSecondary=assignmentChain.pop();if(assignmentRoot==="this"||assignmentRoot==="<parameter>"&&assignmentSecondary==="context"){assignedProperty=assignmentChain[0]}return assignedProperty};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"}
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"}
@@ -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.22.0","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"],"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","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":[]}}}
6
+ {"title":"Extended Audit Rules for JET Custom Component Authors","prefix":"JETWC","version":"1.26.0","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","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}}}
@@ -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 NetUtils=require('../../lib/NetUtils');const AuditComponentCacheManager=function(context,ruleName,exchangeURL){const msg=context.utils.msgLib;this.cacheFolder=`jaftmp@-${context.rulePack.getPrefix()}`;this.fsUtils=context.utils.fsUtils;this.exchangeURL=exchangeURL;this.ruleName=ruleName;this._ensureLocalCache();this.baselineOpts=context.rulePack.getRuleOption('baseline',ruleName);if(this.baselineOpts&&Object.entries(this.baselineOpts).length>0){this.baselineIndexFileName=path.join(this.cacheFolder,`${this._getObjectHashSignature(this.baselineOpts)}.json`)}else{this.baselineIndexFileName=null}};AuditComponentCacheManager.prototype.isBaselineIndexAvailable=function(){return this.baselineIndexFileName!==null};AuditComponentCacheManager.prototype.getBaselineOpts=function(){return this.baselineOpts};AuditComponentCacheManager.prototype.readComponentCacheIndexFile=function(){if(this.baselineIndexFileName){if(this.fsUtils.fileExistsSync(this.baselineIndexFileName)){return this.fsUtils.readJsonSync(this.baselineIndexFileName)}else{return{}}}else{return}};AuditComponentCacheManager.prototype.writeComponentCacheIndexFile=function(index){if(this.baselineIndexFileName){this.fsUtils.writeJsonSync(index,this.baselineIndexFileName)}};AuditComponentCacheManager.prototype.removeLocalCache=function(){if(this.fsUtils.pathExistsSync(this.cacheFolder)){this.fsUtils.deleteFolderSync(this.cacheFolder,true)}};AuditComponentCacheManager.prototype.generateComponentCachePath=function(component,componentVersion){const mungedVersion=componentVersion.replace(/\./g,'-');return path.join(this.cacheFolder,`${component}@${mungedVersion}-component.json`)};AuditComponentCacheManager.prototype.existsInComponentCache=function(component,componentVersion){const cacheFile=this.generateComponentCachePath(component,componentVersion);return this.fsUtils.fileExistsSync(cacheFile)};AuditComponentCacheManager.prototype.writeToComponentCache=function(component,componentVersion,metadata){if(metadata){const cacheFile=this.generateComponentCachePath(component,componentVersion);this.fsUtils.writeJsonSync(metadata,cacheFile)}};AuditComponentCacheManager.prototype.readFromComponentCache=function(component,componentVersion){const cacheFile=this.generateComponentCachePath(component,componentVersion);return this.fsUtils.readJsonSync(cacheFile)};AuditComponentCacheManager.prototype.getComponentMetadata=function(component,componentVersion){if(this.existsInComponentCache(component,componentVersion)){return this.readFromComponentCache(component,componentVersion)}else{try{const netUtils=new NetUtils;const getResp=netUtils.loadUrl(`${this.exchangeURL}components/${component}/versions/${componentVersion}`);if(getResp.statusCode=200&&getResp.body){const cachedDef=JSON.parse(getResp.body).component;this.writeToComponentCache(component,componentVersion,cachedDef);return cachedDef}else{this.msg.error(`The exchange component ${component}@${componentVersion} needed by the rule ${this.ruleName} cannot be retrieved, ensure it is public`)}}catch(e){this.msg.error(`Unable to read component ${component}@${componentVersion} for rule ${this.ruleName}:\n${JSON.stringify(e)}`)};}return};AuditComponentCacheManager.prototype._ensureLocalCache=function(){if(!this.fsUtils.pathExistsSync(this.cacheFolder)){this.fsUtils.createFolderSync(this.cacheFolder)}};AuditComponentCacheManager.prototype._getObjectHashSignature=function(sourceObject){const sourceAsStringArray=Array.from(JSON.stringify(sourceObject));return sourceAsStringArray.reduce((hash,c)=>Math.imul(31,hash)+c.charCodeAt(0)|0,0)};module.exports=AuditComponentCacheManager;
6
+ const path=require("path");const NetUtils=require("../../lib/NetUtils");const AuditComponentCacheManager=function(context,ruleName,exchangeURL){const msg=context.utils.msgLib;this.cacheFolder=`jaftmp@-${context.rulePack.getPrefix()}`;this.fsUtils=context.utils.fsUtils;this.exchangeURL=exchangeURL;this.ruleName=ruleName;this._ensureLocalCache();this.baselineOpts=context.rulePack.getRuleOption("baseline",ruleName);if(this.baselineOpts&&Object.entries(this.baselineOpts).length>0){this.baselineIndexFileName=path.join(this.cacheFolder,`${this._getObjectHashSignature(this.baselineOpts)}.json`)}else{this.baselineIndexFileName=null}};AuditComponentCacheManager.prototype.isBaselineIndexAvailable=function(){return this.baselineIndexFileName!==null};AuditComponentCacheManager.prototype.getBaselineOpts=function(){return this.baselineOpts};AuditComponentCacheManager.prototype.readComponentCacheIndexFile=function(){if(this.baselineIndexFileName){if(this.fsUtils.fileExistsSync(this.baselineIndexFileName)){return this.fsUtils.readJsonSync(this.baselineIndexFileName)}else{return{}}}else{return}};AuditComponentCacheManager.prototype.writeComponentCacheIndexFile=function(index){if(this.baselineIndexFileName){this.fsUtils.writeJsonSync(index,this.baselineIndexFileName)}};AuditComponentCacheManager.prototype.removeLocalCache=function(){if(this.fsUtils.pathExistsSync(this.cacheFolder)){this.fsUtils.deleteFolderSync(this.cacheFolder,true)}};AuditComponentCacheManager.prototype.generateComponentCachePath=function(component,componentVersion){const mungedVersion=componentVersion.replace(/\./g,"-");return path.join(this.cacheFolder,`${component}@${mungedVersion}-component.json`)};AuditComponentCacheManager.prototype.existsInComponentCache=function(component,componentVersion){const cacheFile=this.generateComponentCachePath(component,componentVersion);return this.fsUtils.fileExistsSync(cacheFile)};AuditComponentCacheManager.prototype.writeToComponentCache=function(component,componentVersion,metadata){if(metadata){const cacheFile=this.generateComponentCachePath(component,componentVersion);this.fsUtils.writeJsonSync(metadata,cacheFile)}};AuditComponentCacheManager.prototype.readFromComponentCache=function(component,componentVersion){const cacheFile=this.generateComponentCachePath(component,componentVersion);return this.fsUtils.readJsonSync(cacheFile)};AuditComponentCacheManager.prototype.getComponentMetadata=function(component,componentVersion){if(this.existsInComponentCache(component,componentVersion)){return this.readFromComponentCache(component,componentVersion)}else{try{const netUtils=new NetUtils;const getResp=netUtils.loadUrl(`${this.exchangeURL}components/${component}/versions/${componentVersion}`);if(getResp.statusCode=200&&getResp.body){const cachedDef=JSON.parse(getResp.body).component;this.writeToComponentCache(component,componentVersion,cachedDef);return cachedDef}else{this.msg.error(`The exchange component ${component}@${componentVersion} needed by the rule ${this.ruleName} cannot be retrieved, ensure it is public`)}}catch(e){this.msg.error(`Unable to read component ${component}@${componentVersion} for rule ${this.ruleName}:\n${JSON.stringify(e)}`)};}return};AuditComponentCacheManager.prototype._ensureLocalCache=function(){if(!this.fsUtils.pathExistsSync(this.cacheFolder)){this.fsUtils.createFolderSync(this.cacheFolder)}};AuditComponentCacheManager.prototype._getObjectHashSignature=function(sourceObject){const sourceAsStringArray=Array.from(JSON.stringify(sourceObject));return sourceAsStringArray.reduce((hash,c)=>Math.imul(31,hash)+c.charCodeAt(0)|0,0)};module.exports=AuditComponentCacheManager;
@@ -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 NetUtils=require('../../lib/NetUtils');const EXCHANGE_URL_OPTION='exchangeURL';function checkForExchangeConfiguration(auditContext){const{msgLib}=auditContext.utils;let exchangeURL;if(auditContext.rulePack.getRuleOptions()){exchangeURL=auditContext.rulePack.getRuleOptions()[EXCHANGE_URL_OPTION]}if((!exchangeURL||exchangeURL.length===0)&&auditContext.rulePack.getExtension()){exchangeURL=auditContext.rulePack.getExtension()[EXCHANGE_URL_OPTION]}if(exchangeURL&&exchangeURL.length>0){exchangeURL=exchangeURL.endsWith('/')?exchangeURL:`${exchangeURL}/`;const netUtils=new NetUtils;const statusResp=netUtils.loadUrl(`${exchangeURL}status`);if(statusResp.statusCode===200){return exchangeURL}else{msgLib.error(`The supplied ${EXCHANGE_URL_OPTION} value '${this.exchangeURL}' for the rule ${auditContext.ruleName} does not appear to be valid, the rule will be disabled`);auditContext.rulePack.disableRule();return}}else{msgLib.error(`The ${EXCHANGE_URL_OPTION} configuration option has not been defined for rule ${auditContext.ruleName}, the rule will be disabled`);auditContext.rulePack.disableRule();return}}module.exports={checkForExchangeConfiguration};
6
+ const NetUtils=require("../../lib/NetUtils");const EXCHANGE_URL_OPTION="exchangeURL";function checkForExchangeConfiguration(auditContext){const{msgLib}=auditContext.utils;let exchangeURL;if(auditContext.rulePack.getRuleOptions()){exchangeURL=auditContext.rulePack.getRuleOptions()[EXCHANGE_URL_OPTION]}if((!exchangeURL||exchangeURL.length===0)&&auditContext.rulePack.getExtension()){exchangeURL=auditContext.rulePack.getExtension()[EXCHANGE_URL_OPTION]}if(exchangeURL&&exchangeURL.length>0){exchangeURL=exchangeURL.endsWith("/")?exchangeURL:`${exchangeURL}/`;const netUtils=new NetUtils;const statusResp=netUtils.loadUrl(`${exchangeURL}status`);if(statusResp.statusCode===200){return exchangeURL}else{msgLib.error(`The supplied ${EXCHANGE_URL_OPTION} value '${this.exchangeURL}' for the rule ${auditContext.ruleName} does not appear to be valid, the rule will be disabled`);auditContext.rulePack.disableRule();return}}else{msgLib.error(`The ${EXCHANGE_URL_OPTION} configuration option has not been defined for rule ${auditContext.ruleName}, the rule will be disabled`);auditContext.rulePack.disableRule();return}}module.exports={checkForExchangeConfiguration};
@@ -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,parentPath){let flattenedProps=[];if(metaDef.hasOwnProperty('properties')){const propArray=Object.keys(metaDef.properties);propArray.forEach(propertyName=>{let key;if(!parentPath){key=propertyName}else{key=parentPath+'.'+propertyName}flattenedProps.push({key:key,value:metaDef.properties[propertyName][valueAttribute]});const subPropsArray=this.flattenComponentProperties(metaDef.properties[propertyName],valueAttribute,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(this.isWindows){return sourcePath.replace(/\\\\|\\/g,'/')}return sourcePath};Utils.prototype.toNativePath=function(sourcePath){if(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)})};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){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;
@@ -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,precompileCache){const msg=auditContext.utils.msgLib;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,null))}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,precompileCache))})}else{if(projectPathInfo.componentRootFolder){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.jsSource,projectPathInfo.componentRootFolder),true,projectPathInfo.isBuiltOutput,auditContext,null,precompileCache));if(projectPathInfo.tsSource&&projectPathInfo.tsSource!==projectPathInfo.jsSource){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.tsSource,projectPathInfo.componentRootFolder),true,false,auditContext,null,precompileCache))}}}this.runOnce=true;this.masterComponentList=masterComponentList}return this.masterComponentList};ComponentFinder.prototype._discoverComponentsFromRoot=function(rootDir,isLocal,builtOutput,auditContext,parentPack,precompileCache){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,precompileCache);componentArray=componentArray.concat(packMembers)}}else if(l2file.isFile&&path.extname(l2file.name)==='.tsx'&&precompileCache){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,path.join(rootDir,l1file.name),l2file.name,isLocal,precompileCache);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,precompileCache);componentArray=componentArray.concat(packMembers)}}}else if(l3file.isFile&&path.extname(l3file.name)==='.tsx'&&precompileCache){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,path.join(rootDir,l1file.name,l2file.name),l3file.name,isLocal,precompileCache);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'&&precompileCache){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,rootDir,l1file.name,isLocal,precompileCache);if(componentInfo){componentArray.push(componentInfo)}}}})}return componentArray};module.exports=new ComponentFinder;
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,precompileCache){const msg=auditContext.utils.msgLib;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,null))}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,precompileCache))})}else{if(projectPathInfo.componentRootFolder){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.jsSource,projectPathInfo.componentRootFolder),true,projectPathInfo.isBuiltOutput,auditContext,null,precompileCache));if(projectPathInfo.tsSource&&projectPathInfo.tsSource!==projectPathInfo.jsSource){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.tsSource,projectPathInfo.componentRootFolder),true,false,auditContext,null,precompileCache))}}}this.runOnce=true;this.masterComponentList=masterComponentList}return this.masterComponentList};ComponentFinder.prototype._discoverComponentsFromRoot=function(rootDir,isLocal,builtOutput,auditContext,parentPack,precompileCache){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,precompileCache);componentArray=componentArray.concat(packMembers)}}else if(l2file.isFile&&path.extname(l2file.name)===".tsx"&&precompileCache){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,path.join(rootDir,l1file.name),l2file.name,isLocal,precompileCache);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,precompileCache);componentArray=componentArray.concat(packMembers)}}}else if(l3file.isFile&&path.extname(l3file.name)===".tsx"&&precompileCache){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,path.join(rootDir,l1file.name,l2file.name),l3file.name,isLocal,precompileCache);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"&&precompileCache){componentInfo=tsxUtils.extractComponentInfoFromTSXFile(auditContext,rootDir,l1file.name,isLocal,precompileCache);if(componentInfo){componentArray.push(componentInfo)}}}})}return componentArray};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 path=require('path');const os=require('os');const Utils=require('./jetwcutils-componentAuditUtils');const COMPILER_OPTIONS={experimentalDecorators:true,failOnTypeErrors:true,jsx:'react',jsxFactory:'h',module:'commonjs',moduleResolution:'node',noEmitOnError:false,stripInternal:true,target:'es6'};const JAF_TEMP='jaf';const WORKING_ROOT_FOLDER='jetwc-temp';const OUTPUT_FOLDER='precompiled';const JSON_FOLDER='precompiled-json';const PreCompiler=function(){this.workingRootFolder=Utils.toJAFPath(path.join(os.tmpdir(),JAF_TEMP,WORKING_ROOT_FOLDER));this.runOnce=false};PreCompiler.prototype.getPrecompileCacheIfNeeded=function(auditContext,auditBase,tsSource,componentRootFolder){const{msgLib}=auditContext.utils;let precompileCache;if(!this.runOnce||auditContext.rulePack.getRuleOptions().testMode){if(auditContext.rulePack.getRuleOptions().hasOwnProperty('precompileCache')&&auditContext.rulePack.getRuleOptions().testMode){msgLib.info(`Test mode, bypassing Typescript compilation...`);precompileCache=Utils.toJAFPath(path.join(auditBase,auditContext.rulePack.getRuleOptions().precompileCache))}else{let tsConfigPath;if(auditContext.rulePack.getRuleOptions().hasOwnProperty('tsConfig')){tsConfigPath=auditContext.rulePack.getRuleOptions().tsConfig}else{tsConfigPath=path.join(auditBase,'tsconfig.json')}precompileCache=this._transformVComponents(auditContext,tsConfigPath,auditBase,tsSource,componentRootFolder)}this.runOnce=true;this.precompileCache=precompileCache}return this.precompileCache};PreCompiler.prototype._transformVComponents=function(auditContext,tsConfigPath,auditBase,sourceBase,componentBase){const{fsUtils,msgLib}=auditContext.utils;const normalizedTsConfigPath=Utils.toJAFPath(tsConfigPath);const normalizedAuditBase=Utils.toJAFPath(auditBase);const normalizedSourceBase=Utils.toJAFPath(sourceBase);if(fsUtils.fileExistsSync(normalizedTsConfigPath)){const outputFolder=fsUtils.getUniqueFileNameSync('_XXXXXX');const compiledOutputFolder=`${this.workingRootFolder}/js${outputFolder}`;const compiledJSONFolder=`${this.workingRootFolder}/json${outputFolder}`;const allTsConfig=fsUtils.readJsonSync(tsConfigPath,true,error=>msgLib.error(`Typescript configuration file ${tsConfigPath} cannot be read, unable to process VComponents.\nError: ${error}`));if(allTsConfig){msgLib.msg(`builtinJetWcRules: Typescript detected, compiling project...`);allTsConfig.compilerOptions.paths[`${componentBase}/*`]=[`${auditBase}/${sourceBase}/${componentBase}/*`];const sourceBaseRoot=sourceBase.includes('/')?sourceBase.split('/')[0]:sourceBase;Object.entries(allTsConfig.compilerOptions.paths).forEach(([pathKey,pathValues])=>{const remapped=pathValues.map(mappedPath=>{return this._remapPath(mappedPath,sourceBaseRoot,auditBase)});allTsConfig.compilerOptions.paths[pathKey]=remapped});allTsConfig.compilerOptions.typeRoots=allTsConfig.compilerOptions.typeRoots.map(typeroot=>this._remapPath(typeroot,sourceBaseRoot,auditBase));if(allTsConfig.compilerOptions.hasOwnProperty('types')){allTsConfig.compilerOptions.types=allTsConfig.compilerOptions.types.map(type=>this._remapPath(type,sourceBaseRoot,auditBase))}allTsConfig.compilerOptions.rootDir=auditBase;allTsConfig.compilerOptions.outDir=compiledOutputFolder;if(!fsUtils.pathExistsSync(this.workingRootFolder)){fsUtils.createFolderSync(this.workingRootFolder)}else{fsUtils.deleteFolderSync(this.workingRootFolder,false)}msgLib.debug(`builtinJetWcRules: Typescript compiled into ${this.workingRootFolder}`);const customTsc=`${auditBase}/node_modules/@oracle/oraclejet/dist/custom-tsc`;const nodeJetPackage=path.join(auditBase,'node_modules','@oracle','oraclejet','package.json');if(fsUtils.pathExistsSync(customTsc)&&fsUtils.pathExistsSync(nodeJetPackage)){const packageJson=fsUtils.readJsonSync(nodeJetPackage);let jetVerString;if(packageJson){jetVerString=packageJson.version}const CustomTypescriptCompiler=require(customTsc);const readFrom=`${auditBase}/${sourceBase}`;const files=this._discoverCompilableFiles(auditContext,readFrom,readFrom);const buildOptions={debug:false,dtDir:compiledJSONFolder,version:'',jetVersion:'',templatePath:path.join(customTsc,'templates'),tsBuiltDir:compiledOutputFolder,mainEntryFile:'loader.d.ts',typesDir:compiledOutputFolder};const compileOptionsPre12={files,compilerOptions:allTsConfig.compilerOptions,buildOptions:buildOptions};const compileOptions1201={tsconfigJson:{compilerOptions:allTsConfig.compilerOptions,files},buildOptions:buildOptions};let compileOptions;if(jetVerString){if(auditContext.utils.semVerUtils.gt(jetVerString,'12.0.0')){compileOptions=compileOptions1201}else{compileOptions=compileOptionsPre12}}if(compileOptions){try{const{errors}=CustomTypescriptCompiler.compile(compileOptions);if(errors.length){msgLib.error('Errors during Typescript pre-compilation of VComponents');errors.forEach(error=>{if(error.hasOwnProperty('message')){msgLib.error(error.message);msgLib.error(error.stack)}else{msgLib.error(JSON.stringify(error))}})}else{msgLib.info(`builtinJetWcRules: Typescript compilation successful...`);return compiledJSONFolder}}catch(uncaughtFromCompile){msgLib.error('Uncaught error during Typescript pre-compilation of VComponents');msgLib.error(uncaughtFromCompile.stack)}}else{msgLib.error('Unable to run VComponent pre-compilation, cannot detect JET custom compiler version')}}else{msgLib.error('Unable to run VComponent pre-compilation as the required packages are not available. Run "ojet restore" or "npm install" to correct this.')}}}else{msgLib.info(`Typescript configuration file ${tsConfigPath} not found, pre-compilation will be skipped`)}return};PreCompiler.prototype._discoverCompilableFiles=function(auditContext,root,pathPrefix){const{fsUtils,msgLib}=auditContext.utils;const allSources=fsUtils.readDirSync(root);return this._extractCompilables(fsUtils,allSources,'').map(sourceFile=>`${pathPrefix}/${sourceFile}`)};PreCompiler.prototype._extractCompilables=function(fsUtils,sources,folder){return sources.reduce((compilables,candidate)=>{if(candidate.isFile&&(candidate.name.endsWith('.ts')||candidate.name.endsWith('.tsx'))){compilables.push(`${folder}/${candidate.name}`)}else if(candidate.files){compilables=compilables.concat(this._extractCompilables(fsUtils,candidate.files,`${folder}/${candidate.name}`,true))}return compilables},new Array)};PreCompiler.prototype._remapPath=function(definedPath,sourceFolder,auditBase){let newPath=definedPath;const segs=definedPath.split('/');if(segs[0]==='.'){segs.shift()}switch(segs[0]){case'node_modules':case sourceFolder:newPath=`${auditBase}/${segs.join('/')}`;break;}return newPath};module.exports=new PreCompiler;
6
+ const path=require("path");const os=require("os");const Utils=require("./jetwcutils-componentAuditUtils");const COMPILER_OPTIONS={experimentalDecorators:true,failOnTypeErrors:true,jsx:"react",jsxFactory:"h",module:"commonjs",moduleResolution:"node",noEmitOnError:false,stripInternal:true,target:"es6"};const JAF_TEMP="jaf";const WORKING_ROOT_FOLDER="jetwc-temp";const OUTPUT_FOLDER="precompiled";const JSON_FOLDER="precompiled-json";const PreCompiler=function(){this.workingRootFolder=Utils.toJAFPath(path.join(os.tmpdir(),JAF_TEMP,WORKING_ROOT_FOLDER));this.runOnce=false};PreCompiler.prototype.getPrecompileCacheIfNeeded=function(auditContext,auditBase,tsSource,componentRootFolder){const{msgLib}=auditContext.utils;let precompileCache;if(!this.runOnce||auditContext.rulePack.getRuleOptions().testMode){if(auditContext.rulePack.getRuleOptions().hasOwnProperty("precompileCache")&&auditContext.rulePack.getRuleOptions().testMode){msgLib.info(`Test mode, bypassing Typescript compilation...`);precompileCache=Utils.toJAFPath(path.join(auditBase,auditContext.rulePack.getRuleOptions().precompileCache))}else{let tsConfigPath;if(auditContext.rulePack.getRuleOptions().hasOwnProperty("tsConfig")){tsConfigPath=auditContext.rulePack.getRuleOptions().tsConfig}else{tsConfigPath=path.join(auditBase,"tsconfig.json")}precompileCache=this._transformVComponents(auditContext,tsConfigPath,auditBase,tsSource,componentRootFolder)}this.runOnce=true;this.precompileCache=precompileCache}return this.precompileCache};PreCompiler.prototype._transformVComponents=function(auditContext,tsConfigPath,auditBase,sourceBase,componentBase){const{fsUtils,msgLib}=auditContext.utils;const normalizedTsConfigPath=Utils.toJAFPath(tsConfigPath);const normalizedAuditBase=Utils.toJAFPath(auditBase);const normalizedSourceBase=Utils.toJAFPath(sourceBase);if(fsUtils.fileExistsSync(normalizedTsConfigPath)){const outputFolder=fsUtils.getUniqueFileNameSync("_XXXXXX");const compiledOutputFolder=`${this.workingRootFolder}/js${outputFolder}`;const compiledJSONFolder=`${this.workingRootFolder}/json${outputFolder}`;const allTsConfig=fsUtils.readJsonSync(tsConfigPath,true,error=>msgLib.error(`Typescript configuration file ${tsConfigPath} cannot be read, unable to process VComponents.\nError: ${error}`));if(allTsConfig){msgLib.msg(`VComponent Processing: Compiling project...`);allTsConfig.compilerOptions.paths[`${componentBase}/*`]=[`${auditBase}/${sourceBase}/${componentBase}/*`];const sourceBaseRoot=sourceBase.includes("/")?sourceBase.split("/")[0]:sourceBase;Object.entries(allTsConfig.compilerOptions.paths).forEach(([pathKey,pathValues])=>{const remapped=pathValues.map(mappedPath=>{return this._remapPath(mappedPath,sourceBaseRoot,auditBase)});allTsConfig.compilerOptions.paths[pathKey]=remapped});allTsConfig.compilerOptions.typeRoots=allTsConfig.compilerOptions.typeRoots.map(typeroot=>this._remapPath(typeroot,sourceBaseRoot,auditBase));if(allTsConfig.compilerOptions.hasOwnProperty("types")){allTsConfig.compilerOptions.types=allTsConfig.compilerOptions.types.map(type=>this._remapPath(type,sourceBaseRoot,auditBase))}allTsConfig.compilerOptions.rootDir=auditBase;allTsConfig.compilerOptions.outDir=compiledOutputFolder;if(!fsUtils.pathExistsSync(this.workingRootFolder)){fsUtils.createFolderSync(this.workingRootFolder)}else{fsUtils.deleteFolderSync(this.workingRootFolder,false)}msgLib.debug(`VComponent Processing: Typescript compiled into ${this.workingRootFolder}`);let nodeJetRoot=path.join(auditBase,"node_modules","@oracle","oraclejet");if(!fsUtils.pathExistsSync(nodeJetRoot)){nodeJetRoot=path.normalize(path.join(auditBase,"..","..","node_modules","@oracle","oraclejet"))}let nodeJetPackage=path.join(nodeJetRoot,"package.json");let customTsc=Utils.toJAFPath(path.join(nodeJetRoot,"dist","custom-tsc"));if(fsUtils.pathExistsSync(customTsc)&&fsUtils.pathExistsSync(nodeJetPackage)){const packageJson=fsUtils.readJsonSync(nodeJetPackage);let jetVerString;if(packageJson){jetVerString=packageJson.version}const CustomTypescriptCompiler=require(customTsc);const readFrom=`${auditBase}/${sourceBase}`;const files=this._discoverCompilableFiles(auditContext,readFrom,readFrom);const buildOptions={debug:false,dtDir:compiledJSONFolder,version:"",jetVersion:"",templatePath:path.join(customTsc,"templates"),tsBuiltDir:compiledOutputFolder,mainEntryFile:"loader.d.ts",typesDir:compiledOutputFolder};const compileOptionsPre12={files,compilerOptions:allTsConfig.compilerOptions,buildOptions:buildOptions};const compileOptions1201={tsconfigJson:{compilerOptions:allTsConfig.compilerOptions,files},buildOptions:buildOptions};let compileOptions;if(jetVerString){if(auditContext.utils.semVerUtils.gt(jetVerString,"12.0.0")){compileOptions=compileOptions1201}else{compileOptions=compileOptionsPre12}}if(compileOptions){try{const{errors}=CustomTypescriptCompiler.compile(compileOptions);if(errors.length){msgLib.error("Errors during Typescript pre-compilation of VComponents");errors.forEach(error=>{if(error.hasOwnProperty("message")){msgLib.error(error.message);msgLib.error(error.stack)}else{msgLib.error(JSON.stringify(error))}});msgLib.msg(`VComponent Processing: Typescript compilation completed with errors...`)}else{msgLib.msg(`VComponent Processing: Typescript compilation successful...`)}this._patchGeneratedMetadata(auditContext,auditBase,compiledJSONFolder);return compiledJSONFolder}catch(uncaughtFromCompile){msgLib.error("Uncaught error during Typescript pre-compilation of VComponents");msgLib.error(uncaughtFromCompile.stack)}}else{msgLib.error("Unable to run VComponent pre-compilation, cannot detect JET custom compiler version")}}else{msgLib.error("Unable to run VComponent pre-compilation as the required packages are not available. Run \"ojet restore\" or \"npm install\" to correct this.")}}}else{msgLib.info(`Typescript configuration file ${tsConfigPath} not found, pre-compilation will be skipped`)}return};PreCompiler.prototype._discoverCompilableFiles=function(auditContext,root,pathPrefix){const{fsUtils,msgLib}=auditContext.utils;const allSources=fsUtils.readDirSync(root);return this._extractCompilables(fsUtils,allSources,"").map(sourceFile=>`${pathPrefix}/${sourceFile}`)};PreCompiler.prototype._extractCompilables=function(fsUtils,sources,folder){return sources.reduce((compilables,candidate)=>{if(candidate.isFile&&(candidate.name.endsWith(".ts")||candidate.name.endsWith(".tsx"))){compilables.push(`${folder}/${candidate.name}`)}else if(candidate.files){compilables=compilables.concat(this._extractCompilables(fsUtils,candidate.files,`${folder}/${candidate.name}`,true))}return compilables},new Array)};PreCompiler.prototype._remapPath=function(definedPath,sourceFolder,auditBase){let newPath=definedPath;const segs=definedPath.split("/");if(segs[0]==="."){segs.shift()}switch(segs[0]){case"node_modules":case"jet_components":case"exchange_components":case sourceFolder:newPath=`${auditBase}${segs.join("/")}`;break}return newPath};PreCompiler.prototype._patchGeneratedMetadata=function(auditContext,auditBase,compiledJSONFolder){const{fsUtils,msgLib}=auditContext.utils;const metadataPatchInstructionFile=auditContext.userDefs?.VComponentMetadataPatches;if(metadataPatchInstructionFile){let actualPatchFilePath;if(fsUtils.fileExistsSync(metadataPatchInstructionFile)){actualPatchFilePath=metadataPatchInstructionFile}else if(fsUtils.fileExistsSync(path.join(auditBase,metadataPatchInstructionFile))){actualPatchFilePath=path.join(auditBase,metadataPatchInstructionFile)}if(actualPatchFilePath){const patchInstructions=fsUtils.readJsonSync(actualPatchFilePath);if(patchInstructions){msgLib.msg(`VComponent Processing: applying patch file for generated metadata...`);for(const[pack,componentPatches]of Object.entries(patchInstructions)){for(const[component,patches]of Object.entries(componentPatches)){const targetComponentJsonFileName=path.join(compiledJSONFolder,`${pack}-${component}.json`);if(fsUtils.fileExistsSync(targetComponentJsonFileName)){const generatedMetadata=fsUtils.readJsonSync(targetComponentJsonFileName);if(generatedMetadata&&patches.length>0){msgLib.info(`Processing metadata type patches for ${pack}-${component} [${patches.length} patch(es) specified]`);patches.forEach(patch=>{switch(patch.target){case"property":this._handlePropertyTypePatch(patch,generatedMetadata);break;case"method":this._handleMethodTypePatch(patch,generatedMetadata);break;case"event":this._handleEventDetailTypePatch(patch,generatedMetadata);break;case"slot":this._handleSlotDataTypePatch(patch,generatedMetadata);break}});fsUtils.writeJsonSync(generatedMetadata,targetComponentJsonFileName,{spaces:2})}else{msgLib.error(`VComponent Processing: metadata for ${pack}-${component} is missing...`)}}}}}else{msgLib.error(`VComponent Processing: Metadata patching file ${metadataPatchInstructionFile} not found, patching will not take place.`)}}}};PreCompiler.prototype._handlePropertyTypePatch=function(patch,metadata){this._patchPropertyViaPath(patch,patch.locator.split("."),metadata)};PreCompiler.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}}}};PreCompiler.prototype._verifyType=function(existingType,patch){let expectedTypeMatches=existingType===patch?.expectedType||!patch?.expectedType;let abortNoMatch=false;if(patch.enforceMatch){if(!expectedTypeMatches){abortNoMatch=true}}return!abortNoMatch};PreCompiler.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)}}};PreCompiler.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}};PreCompiler.prototype._patchMethodReturnType=function(patch,methodDef){const existingType=methodDef.return;if(this._verifyType(existingType,patch)){methodDef.return=patch.patchType}};PreCompiler.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}}}};PreCompiler.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 PreCompiler;
@@ -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,isLocal,precompileCache){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;let componentInfo={};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 fullNameMetadata=false;if(precompileCache){let mdSource=null;if(fullName){msgLib.debug(`Processing tsx and metadata for ${fullName}`);mdSource=`${precompileCache}/${fullName}.json`;if(!fsUtils.fileExistsSync(mdSource)){mdSource=`${precompileCache}/${componentName}.json`;if(!componentName||!fsUtils.fileExistsSync(mdSource)){mdSource=null}}else{fullNameMetadata=true}}if(mdSource!==null){componentInfo=Utils.extractComponentInfoFromJSONFile(auditContext,precompileCache,`${fullNameMetadata?fullName:componentName}.json`,isLocal,true);componentInfo.rootFolder=Utils.toJAFPath(componentFolder);componentInfo.compiledMetadata=mdSource;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{return}}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};module.exports=new TsxUtils;
6
+ const Utils=require("./jetwcutils-componentAuditUtils");const path=require("path");const TsxUtils=function(){};TsxUtils.prototype.extractComponentInfoFromTSXFile=function(auditContext,componentFolder,fileName,isLocal,precompileCache){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;let componentInfo={};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 fullNameMetadata=false;if(precompileCache){let mdSource=null;if(fullName){msgLib.debug(`Processing tsx and metadata for ${fullName}`);mdSource=`${precompileCache}/${fullName}.json`;if(!fsUtils.fileExistsSync(mdSource)){mdSource=`${precompileCache}/${componentName}.json`;if(!componentName||!fsUtils.fileExistsSync(mdSource)){mdSource=null}}else{fullNameMetadata=true}}if(mdSource!==null){componentInfo=Utils.extractComponentInfoFromJSONFile(auditContext,precompileCache,`${fullNameMetadata?fullName:componentName}.json`,isLocal,true);componentInfo.rootFolder=Utils.toJAFPath(componentFolder);componentInfo.compiledMetadata=mdSource;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{return}}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};module.exports=new TsxUtils;