@oracle/oraclejet-audit 10.0.0 → 11.1.3

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 (702) hide show
  1. package/jaf-amd.js +12 -4
  2. package/jaf.js +6 -1
  3. package/jafapi.js +6 -1
  4. package/lib/AST.js +6 -1
  5. package/lib/AST_Ts.js +6 -1
  6. package/lib/AstJson.js +6 -1
  7. package/lib/AstNodeTypes.js +6 -1
  8. package/lib/Comments.js +6 -1
  9. package/lib/ComponentSvcs.js +5 -0
  10. package/lib/Components.js +6 -1
  11. package/lib/Config.js +6 -1
  12. package/lib/ConfigLib.js +6 -1
  13. package/lib/CssLib.js +5 -0
  14. package/lib/CssUtils.js +5 -0
  15. package/lib/DomUtils.js +6 -1
  16. package/lib/FileIndex.js +5 -0
  17. package/lib/FileSet.js +5 -0
  18. package/lib/FsUtils.js +6 -1
  19. package/lib/Histo.js +6 -0
  20. package/lib/HtmlTree.js +6 -1
  21. package/lib/HtmlUtils.js +5 -0
  22. package/lib/Issue.js +5 -0
  23. package/lib/JafEvents.js +5 -0
  24. package/lib/JafLib.js +6 -1
  25. package/lib/Json.js +6 -0
  26. package/lib/JsonLoader.js +6 -1
  27. package/lib/MetaLib.js +6 -1
  28. package/lib/NetUtils.js +5 -0
  29. package/lib/NodeTypes.js +5 -0
  30. package/lib/Parser.js +6 -1
  31. package/lib/RegTypes.js +5 -0
  32. package/lib/Registry.js +5 -0
  33. package/lib/Reporter.js +5 -0
  34. package/lib/RuleContext.js +5 -0
  35. package/lib/RulePack.js +5 -0
  36. package/lib/RuleSet.js +6 -1
  37. package/lib/Rules.js +6 -1
  38. package/lib/Scope.js +6 -1
  39. package/lib/SemVer.js +5 -0
  40. package/lib/Server.js +5 -0
  41. package/lib/SevLib.js +5 -0
  42. package/lib/Severity.js +6 -1
  43. package/lib/Stats.js +6 -0
  44. package/lib/Ts.js +6 -1
  45. package/lib/Utils.js +6 -1
  46. package/lib/Watch.js +5 -0
  47. package/lib/Writer.js +5 -0
  48. package/lib/ZipUtils.js +5 -0
  49. package/lib/api.js +6 -0
  50. package/lib/cliStats.js +6 -0
  51. package/lib/clone.js +5 -0
  52. package/lib/cmdline.js +6 -1
  53. package/lib/colors.js +5 -0
  54. package/lib/exportRules.js +6 -0
  55. package/lib/extends.js +6 -0
  56. package/lib/filetypes.js +6 -0
  57. package/lib/groups.js +6 -0
  58. package/lib/help.js +6 -1
  59. package/lib/imanual.js +6 -0
  60. package/lib/jetver.js +6 -1
  61. package/lib/macros.js +6 -0
  62. package/lib/metaLoader.js +5 -0
  63. package/lib/metahist.js +5 -0
  64. package/lib/msgidLoader.js +6 -1
  65. package/lib/ns.js +6 -1
  66. package/lib/nslist.js +6 -1
  67. package/lib/outFormat.js +6 -0
  68. package/lib/outfile.js +5 -0
  69. package/lib/ruleLoader.js +5 -0
  70. package/lib/scaffold.js +6 -1
  71. package/lib/scaffoldRule.js +6 -1
  72. package/lib/schema.js +5 -0
  73. package/lib/scopewalker.js +6 -0
  74. package/lib/spinner.js +5 -0
  75. package/lib/spinnernoop.js +5 -0
  76. package/lib/tabs.js +5 -0
  77. package/lib/xmanual.js +6 -0
  78. package/libext/expparser.js +6 -1
  79. package/meta/10.1.0/jetauditmeta.js +9 -0
  80. package/meta/11.0.0/jetauditmeta.js +9 -0
  81. package/meta/11.1.0/jetauditmeta.js +9 -0
  82. package/meta/metaverlist.json +1 -1
  83. package/package.json +2 -3
  84. package/rulepacks/csp/csp-html-script-unsafe-inline.js +5 -0
  85. package/rulepacks/csp/csp-html-style-unsafe-inline.js +5 -0
  86. package/rulepacks/csp/csp-html-unsafe-expr.js +5 -0
  87. package/rulepacks/csp/csp-js-script-unsafe-eval.js +6 -1
  88. package/rulepacks/csp/csp-js-style-unsafe-inline.js +5 -0
  89. package/rulepacks/csp/csp-ts-script-unsafe-eval.js +6 -0
  90. package/rulepacks/csp/csp-ts-style-unsafe-inline.js +6 -0
  91. package/rulepacks/csp/msgid.json +6 -1
  92. package/rulepacks/csp/rules.json +6 -1
  93. package/rulepacks/jetwc/jetwc-absolute-jetversion.js +6 -1
  94. package/rulepacks/jetwc/jetwc-aria-redefinition.js +6 -1
  95. package/rulepacks/jetwc/jetwc-bootstrap.js +6 -1
  96. package/rulepacks/jetwc/jetwc-compjson-bp-ar.js +6 -1
  97. package/rulepacks/jetwc/jetwc-compjson-bp-obj.js +6 -1
  98. package/rulepacks/jetwc/jetwc-component-dependencies.js +6 -1
  99. package/rulepacks/jetwc/jetwc-component-displayname.js +6 -1
  100. package/rulepacks/jetwc/jetwc-component-foldername.js +6 -1
  101. package/rulepacks/jetwc/jetwc-component-location.js +6 -1
  102. package/rulepacks/jetwc/jetwc-component-type.js +6 -1
  103. package/rulepacks/jetwc/jetwc-data-property-prefix.js +6 -1
  104. package/rulepacks/jetwc/jetwc-deprecated-lifecycle.js +6 -1
  105. package/rulepacks/jetwc/jetwc-disabled-property.js +6 -1
  106. package/rulepacks/jetwc/jetwc-displayname.js +6 -1
  107. package/rulepacks/jetwc/jetwc-dynamic-slot-context.js +6 -1
  108. package/rulepacks/jetwc/jetwc-dynamic-slots-naming.js +6 -1
  109. package/rulepacks/jetwc/jetwc-event-displayname.js +6 -1
  110. package/rulepacks/jetwc/jetwc-events.js +6 -1
  111. package/rulepacks/jetwc/jetwc-jet-version.js +6 -1
  112. package/rulepacks/jetwc/jetwc-loader-file.js +6 -1
  113. package/rulepacks/jetwc/jetwc-method-displayname.js +6 -1
  114. package/rulepacks/jetwc/jetwc-methods.js +6 -1
  115. package/rulepacks/jetwc/jetwc-namespace.js +6 -1
  116. package/rulepacks/jetwc/jetwc-nested-defaults.js +6 -1
  117. package/rulepacks/jetwc/jetwc-nls-languages.js +6 -1
  118. package/rulepacks/jetwc/jetwc-nls-root.js +6 -1
  119. package/rulepacks/jetwc/jetwc-oj-register.js +6 -1
  120. package/rulepacks/jetwc/jetwc-ojcss.js +6 -1
  121. package/rulepacks/jetwc/jetwc-pack-children.js +6 -1
  122. package/rulepacks/jetwc/jetwc-packable-components.js +6 -1
  123. package/rulepacks/jetwc/jetwc-prerelease-dependencies.js +6 -1
  124. package/rulepacks/jetwc/jetwc-prerelease-pattern.js +6 -1
  125. package/rulepacks/jetwc/jetwc-prerelease-version.js +6 -1
  126. package/rulepacks/jetwc/jetwc-property-changed.js +6 -1
  127. package/rulepacks/jetwc/jetwc-property-displayname.js +6 -1
  128. package/rulepacks/jetwc/jetwc-property-nesting.js +6 -1
  129. package/rulepacks/jetwc/jetwc-public-modules.js +6 -1
  130. package/rulepacks/jetwc/jetwc-register-css.js +6 -1
  131. package/rulepacks/jetwc/jetwc-register-with-promises.js +6 -1
  132. package/rulepacks/jetwc/jetwc-require-paths.js +6 -1
  133. package/rulepacks/jetwc/jetwc-required-subproperty.js +6 -0
  134. package/rulepacks/jetwc/jetwc-reserved-property.js +6 -1
  135. package/rulepacks/jetwc/jetwc-schema.js +6 -1
  136. package/rulepacks/jetwc/jetwc-semantic-version.js +6 -1
  137. package/rulepacks/jetwc/jetwc-slot-displayname.js +6 -1
  138. package/rulepacks/jetwc/jetwc-slots.js +6 -1
  139. package/rulepacks/jetwc/jetwc-standard-files.js +6 -1
  140. package/rulepacks/jetwc/jetwc-subproperty-writeback.js +6 -0
  141. package/rulepacks/jetwc/jetwc-template-slots.js +6 -1
  142. package/rulepacks/jetwc/jetwc-unused-events.js +6 -1
  143. package/rulepacks/jetwc/jetwc-unused-slots.js +6 -1
  144. package/rulepacks/jetwc/jetwc-vb-category.js +6 -1
  145. package/rulepacks/jetwc/jetwc-vb-icon.js +6 -1
  146. package/rulepacks/jetwc/jetwc-version-openrange.js +6 -1
  147. package/rulepacks/jetwc/jetwc-writeback-required.js +6 -1
  148. package/rulepacks/jetwc/msgid.json +6 -0
  149. package/rulepacks/jetwc/rules.json +6 -1
  150. package/rulepacks/jetwc-lib/component-audit-utils.js +6 -1
  151. package/rulepacks/jetwco/jetwco-bootstrap.js +6 -1
  152. package/rulepacks/jetwco/jetwco-compjson-ns-reg.js +6 -1
  153. package/rulepacks/jetwco/jetwco-component-api-baseline-changes.js +6 -0
  154. package/rulepacks/jetwco/jetwco-component-api-changes.js +6 -1
  155. package/rulepacks/jetwco/jetwco-component-cdn.js +6 -1
  156. package/rulepacks/jetwco/jetwco-exchange-version-check.js +6 -1
  157. package/rulepacks/jetwco/jetwco-license-info.js +6 -1
  158. package/rulepacks/jetwco/jetwco-prerelease-cdn.js +6 -1
  159. package/rulepacks/jetwco/jetwco-thirdparty-ba.js +6 -1
  160. package/rulepacks/jetwco/msgid.json +6 -0
  161. package/rulepacks/jetwco/rules.json +6 -1
  162. package/rulepacks/spoc/msgid.json +5 -0
  163. package/rulepacks/spoc/rules.json +5 -0
  164. package/rulepacks/spoc/spoc-dom-manip-inv-tag.js +5 -0
  165. package/rulepacks/spoc/spoc-dom-manip-tag-pos.js +5 -0
  166. package/rulepacks/spoc/spoc-dom-manip.js +5 -0
  167. package/rules/jaf/jaf-css-diagnose.js +5 -0
  168. package/rules/jaf/jaf-html-diagnose.js +5 -0
  169. package/rules/jaf/jaf-init-schema.js +5 -0
  170. package/rules/jaf/jaf-js-diagnose.js +5 -0
  171. package/rules/jaf/jaf-ts-diagnose.js +6 -0
  172. package/rules/jaf/msgid.json +6 -1
  173. package/rules/jaf/rules.json +6 -1
  174. package/rules/jet/helpers/acc-aria-label.js +6 -1
  175. package/rules/jet/helpers/bp-checkPropType.js +5 -0
  176. package/rules/jet/helpers/cssHelper.js +6 -1
  177. package/rules/jet/helpers/extractStylesFromClass.js +6 -1
  178. package/rules/jet/helpers/has-slot-name.js +6 -1
  179. package/rules/jet/helpers/has-slot.js +5 -0
  180. package/rules/jet/helpers/json-prop-pos.js +5 -0
  181. package/rules/jet/helpers/json-propname-pos.js +5 -0
  182. package/rules/jet/helpers/style-selector.js +6 -1
  183. package/rules/jet/helpers/valid-attr.js +5 -0
  184. package/rules/jet/helpers/vartrack.js +5 -0
  185. package/rules/jet/jet-css-ojselector.js +5 -0
  186. package/rules/jet/msgid.json +6 -1
  187. package/rules/jet/oj-acc-aria-labelledby.js +5 -0
  188. package/rules/jet/oj-acc-aria-prop.js +5 -0
  189. package/rules/jet/oj-acc-avatar-aria-role.js +5 -0
  190. package/rules/jet/oj-acc-combobox-aria-label.js +6 -1
  191. package/rules/jet/oj-acc-film-strip-aria-label.js +5 -0
  192. package/rules/jet/oj-acc-input-aria-label.js +6 -1
  193. package/rules/jet/oj-acc-select-aria-label.js +6 -1
  194. package/rules/jet/oj-cca-compjson-bp-ar.js +5 -0
  195. package/rules/jet/oj-cca-compjson-bp-dsplyname.js +5 -0
  196. package/rules/jet/oj-cca-compjson-bp-jetver.js +5 -0
  197. package/rules/jet/oj-cca-compjson-bp-obj.js +5 -0
  198. package/rules/jet/oj-cca-compjson-ns-reg.js +5 -0
  199. package/rules/jet/oj-css-bp-border-color.js +5 -0
  200. package/rules/jet/oj-css-bp-dir-flow.js +6 -1
  201. package/rules/jet/oj-css-bp-float.js +5 -0
  202. package/rules/jet/oj-css-bp-textalign.js +5 -0
  203. package/rules/jet/oj-css-style-abs-units.js +5 -0
  204. package/rules/jet/oj-css-style-bp-color.js +6 -1
  205. package/rules/jet/oj-css-style-bp-display.js +6 -1
  206. package/rules/jet/oj-css-style-bp-font-family.js +6 -1
  207. package/rules/jet/oj-css-style-bp-font.js +5 -0
  208. package/rules/jet/oj-css-style-deprecated.js +6 -1
  209. package/rules/jet/oj-css-style-override.js +6 -1
  210. package/rules/jet/oj-css-var-override.js +5 -0
  211. package/rules/jet/oj-form-maxcols.js +6 -0
  212. package/rules/jet/oj-html-5-attr-obs.js +5 -0
  213. package/rules/jet/oj-html-5-tag-obs.js +5 -0
  214. package/rules/jet/oj-html-attr-$unique.js +5 -0
  215. package/rules/jet/oj-html-attr-2def.js +5 -0
  216. package/rules/jet/oj-html-attr-json.js +6 -1
  217. package/rules/jet/oj-html-attr-prefix-expr.js +6 -1
  218. package/rules/jet/oj-html-attr-prefix-ro.js +5 -0
  219. package/rules/jet/oj-html-attr-req.js +5 -0
  220. package/rules/jet/oj-html-bindforeach-data.js +5 -0
  221. package/rules/jet/oj-html-bindif-test.js +5 -0
  222. package/rules/jet/oj-html-binding-attr.js +5 -0
  223. package/rules/jet/oj-html-cca-count.js +5 -0
  224. package/rules/jet/oj-html-cca-tagname.js +6 -1
  225. package/rules/jet/oj-html-cdn.js +5 -0
  226. package/rules/jet/oj-html-combo-converter.js +5 -0
  227. package/rules/jet/oj-html-cspexpr.js +6 -1
  228. package/rules/jet/oj-html-databind-all.js +5 -0
  229. package/rules/jet/oj-html-dlg-title.js +5 -0
  230. package/rules/jet/oj-html-file-pick-accept.js +6 -0
  231. package/rules/jet/oj-html-form-bindif.js +6 -1
  232. package/rules/jet/oj-html-form-layout-maxcols.js +6 -0
  233. package/rules/jet/oj-html-form-noflex.js +5 -0
  234. package/rules/jet/oj-html-input-isodate.js +6 -0
  235. package/rules/jet/oj-html-invalid-doctype.js +6 -1
  236. package/rules/jet/oj-html-jq-databind.js +6 -1
  237. package/rules/jet/oj-html-ko-comment.js +5 -0
  238. package/rules/jet/oj-html-ko-databind.js +5 -0
  239. package/rules/jet/oj-html-label-for-prefix.js +5 -0
  240. package/rules/jet/oj-html-missing-doctype.js +6 -1
  241. package/rules/jet/oj-html-oj-lib.js +5 -0
  242. package/rules/jet/oj-html-ojattr-520.js +6 -1
  243. package/rules/jet/oj-html-ojattr-deprecated.js +6 -1
  244. package/rules/jet/oj-html-ojattr-enum-deprecated.js +6 -1
  245. package/rules/jet/oj-html-ojattr-evt-syntax.js +5 -0
  246. package/rules/jet/oj-html-ojattr-value.js +6 -1
  247. package/rules/jet/oj-html-ojattr.js +6 -1
  248. package/rules/jet/oj-html-ojevent.js +6 -1
  249. package/rules/jet/oj-html-ojslot.js +5 -0
  250. package/rules/jet/oj-html-ojstyle.js +5 -0
  251. package/rules/jet/oj-html-ojtag-datacmd.js +6 -1
  252. package/rules/jet/oj-html-ojtag-datactx.js +5 -0
  253. package/rules/jet/oj-html-ojtag-deprecated.js +6 -1
  254. package/rules/jet/oj-html-ojtag-globattr-noprefix.js +5 -0
  255. package/rules/jet/oj-html-ojtag-id.js +5 -0
  256. package/rules/jet/oj-html-ojtag-nonglobattr-prefix.js +5 -0
  257. package/rules/jet/oj-html-ojtag-ns.js +5 -0
  258. package/rules/jet/oj-html-picker-attrs.js +6 -0
  259. package/rules/jet/oj-html-redwood-cssnovars.js +6 -0
  260. package/rules/jet/oj-html-redwood-cssvars.js +6 -0
  261. package/rules/jet/oj-html-self-close.js +5 -0
  262. package/rules/jet/oj-html-slot-item-minmax.js +6 -0
  263. package/rules/jet/oj-html-slot-name.js +6 -1
  264. package/rules/jet/oj-html-slot-pref-content.js +6 -0
  265. package/rules/jet/oj-html-style-abs-units.js +5 -0
  266. package/rules/jet/oj-html-style-bp-color.js +5 -0
  267. package/rules/jet/oj-html-style-bp-display.js +6 -1
  268. package/rules/jet/oj-html-style-bp-font-family.js +5 -0
  269. package/rules/jet/oj-html-style-bp-font.js +5 -0
  270. package/rules/jet/oj-html-style-deprecated.js +5 -0
  271. package/rules/jet/oj-html-style.js +6 -1
  272. package/rules/jet/oj-html-stylesel.js +6 -1
  273. package/rules/jet/oj-html-tag-attr-noprefix.js +5 -0
  274. package/rules/jet/oj-html-template-index.js +6 -0
  275. package/rules/jet/oj-html-unsup-theme.js +6 -1
  276. package/rules/jet/oj-html-wctag-$props.js +6 -1
  277. package/rules/jet/oj-html-wctag-arialabelledby.js +5 -0
  278. package/rules/jet/oj-html-wctag-for.js +5 -0
  279. package/rules/jet/oj-html-wctag-id.js +5 -0
  280. package/rules/jet/oj-html-wctag-packprivate.js +6 -0
  281. package/rules/jet/oj-js-comp-attr-deprecated.js +5 -0
  282. package/rules/jet/oj-js-comp-meth-deprecated.js +5 -0
  283. package/rules/jet/oj-js-no-ext-final.js +5 -0
  284. package/rules/jet/oj-js-noconsole.js +5 -0
  285. package/rules/jet/oj-js-ojcomp-deprecated.js +6 -1
  286. package/rules/jet/oj-js-ojcomp-exist.js +5 -0
  287. package/rules/jet/oj-js-ojcomp-new.js +5 -0
  288. package/rules/jet/oj-js-poly-promise.js +6 -1
  289. package/rules/jet/oj-js-var-undef.js +5 -0
  290. package/rules/jet/oj-json-syntax.js +6 -1
  291. package/rules/jet/oj-ts-comp-attr-deprecated.js +5 -0
  292. package/rules/jet/oj-ts-comp-meth-deprecated.js +5 -0
  293. package/rules/jet/oj-ts-no-ext-final.js +6 -0
  294. package/rules/jet/oj-ts-noconsole.js +6 -1
  295. package/rules/jet/oj-ts-ojcomp-deprecated.js +6 -1
  296. package/rules/jet/oj-ts-ojcomp-exist.js +6 -1
  297. package/rules/jet/oj-ts-ojcomp-new.js +6 -1
  298. package/rules/jet/oj-ts-poly-promise.js +6 -1
  299. package/rules/jet/rules.json +6 -1
  300. package/schema/component-schema.json +122 -2
  301. package/src/JafCore.js +6 -1
  302. package/types/index.d.ts +144 -35
  303. package/lib/manual.js +0 -1
  304. package/lib/stats.js +0 -1
  305. package/rules/exch/helpers/json-prop-pos.js +0 -1
  306. package/rules/exch/msgid.json +0 -1
  307. package/rules/exch/oj-cca-comp-zip-content-composite.js +0 -1
  308. package/rules/exch/oj-cca-comp-zip-content-pack.js +0 -1
  309. package/rules/exch/oj-cca-comp-zip-expand.js +0 -1
  310. package/rules/exch/oj-cca-compjson-evnames.js +0 -1
  311. package/rules/exch/oj-cca-compjson-file.js +0 -1
  312. package/rules/exch/oj-cca-compjson-prefix.js +0 -1
  313. package/rules/exch/oj-cca-compjson-prop-compdeps.js +0 -1
  314. package/rules/exch/oj-cca-compjson-prop-deps.js +0 -1
  315. package/rules/exch/oj-cca-compjson-prop-jetver.js +0 -1
  316. package/rules/exch/oj-cca-compjson-prop-obs.js +0 -1
  317. package/rules/exch/oj-cca-compjson-prop-type.js +0 -1
  318. package/rules/exch/oj-cca-compjson-prop-types.js +0 -1
  319. package/rules/exch/oj-cca-compjson-prop-undef.js +0 -1
  320. package/rules/exch/oj-cca-compjson-prop-version.js +0 -1
  321. package/rules/exch/oj-cca-compjson-schema.js +0 -1
  322. package/rules/exch/oj-cca-zip-compjson.js +0 -1
  323. package/rules/exch/rules.json +0 -1
  324. package/rules/jet/oj-css-bp-bgcolor.js +0 -1
  325. package/tests/components/attr-req-test/component.json +0 -1
  326. package/tests/components/demo-analog-clock/component.json +0 -1
  327. package/tests/components/demo-analog-clock/demo-analog-clock-viewModel.js +0 -1
  328. package/tests/components/demo-analog-clock/extension/demo/js/viewModels/demo.js +0 -1
  329. package/tests/components/demo-analog-clock/loader.js +0 -1
  330. package/tests/components/demo-card/component.json +0 -1
  331. package/tests/components/demo-chart-orientation-control/component.json +0 -1
  332. package/tests/components/demo-chart-stack-control/component.json +0 -1
  333. package/tests/components/made-up/component.json +0 -1
  334. package/tests/components/oj-made-up/component.json +0 -1
  335. package/tests/components/sp-activity-item/component.json +0 -1
  336. package/tests/config/config_base.json +0 -1
  337. package/tests/golden/10.0.0/golden_base.json +0 -1
  338. package/tests/golden/8.1.0/golden_base.json +0 -1
  339. package/tests/golden/9.0.0/golden_base.json +0 -1
  340. package/tests/rulepacks/hooks/hook-rpext.js +0 -1
  341. package/tests/rulepacks/hooks/hook-start-close-rulepack.js +0 -1
  342. package/tests/rulepacks/hooks/rule-rpext.js +0 -1
  343. package/tests/rulepacks/hooks/rules.json +0 -1
  344. package/tests/rulepacks/tags/proc_directive.js +0 -1
  345. package/tests/rulepacks/tags/rules.json +0 -1
  346. package/tests/rulepacks/tags/tag-count-setup.js +0 -1
  347. package/tests/rulepacks/tags/tag-count.js +0 -1
  348. package/tests/rules/bugs/JET-4770_PASS_1.html +0 -9
  349. package/tests/rules/comments/com_FAIL_1.js +0 -57
  350. package/tests/rules/comments/com_FAIL_2.js +0 -96
  351. package/tests/rules/comments/com_PASS_1.js +0 -42
  352. package/tests/rules/comments/com_PASS_2.js +0 -63
  353. package/tests/rules/comments/com_PASS_3.js +0 -40
  354. package/tests/rules/comments/com_PASS_4.js +0 -36
  355. package/tests/rules/comments/com_PASS_5.js +0 -19
  356. package/tests/rules/csp/html-script-unsafe-inline/FAIL_1.html +0 -11
  357. package/tests/rules/csp/html-script-unsafe-inline/FAIL_2.html +0 -8
  358. package/tests/rules/csp/html-script-unsafe-inline/PASS_1.html +0 -8
  359. package/tests/rules/csp/html-script-unsafe-inline/PASS_2.html +0 -8
  360. package/tests/rules/csp/html-script-unsafe-inline/PASS_3.html +0 -8
  361. package/tests/rules/csp/html-style-unsafe-inline/FAIL_1.html +0 -11
  362. package/tests/rules/csp/html-style-unsafe-inline/PASS_1.html +0 -11
  363. package/tests/rules/csp/html-unsafe-expr/FAIL_1.html +0 -14
  364. package/tests/rules/csp/html-unsafe-expr/PASS_1.html +0 -23
  365. package/tests/rules/csp/js-script-unsafe-eval/FAIL_1.js +0 -17
  366. package/tests/rules/csp/js-script-unsafe-eval/FAIL_2.js +0 -40
  367. package/tests/rules/csp/js-script-unsafe-eval/FAIL_3.js +0 -22
  368. package/tests/rules/csp/js-script-unsafe-eval/PASS_1.js +0 -20
  369. package/tests/rules/csp/js-script-unsafe-eval/PASS_2.js +0 -44
  370. package/tests/rules/csp/js-script-unsafe-eval/PASS_3.js +0 -16
  371. package/tests/rules/csp/js-style-unsafe-inline/FAIL_1.js +0 -25
  372. package/tests/rules/csp/js-style-unsafe-inline/PASS.js +0 -22
  373. package/tests/rules/demo/noself_FAIL_1.js +0 -101
  374. package/tests/rules/import/import_FAIL_1.js +0 -11
  375. package/tests/rules/import/import_PASS_1.js +0 -10
  376. package/tests/rules/jet-composites/demo-buttonset-enum/component.json +0 -57
  377. package/tests/rules/jet-composites/demo-buttonset-enum/loader.js +0 -19
  378. package/tests/rules/jet-composites/demo-buttonset-enum/view.html +0 -48
  379. package/tests/rules/jet-composites/demo-card/component.json +0 -28
  380. package/tests/rules/jet-composites/demo-card/loader.js +0 -16
  381. package/tests/rules/jet-composites/demo-card/view.html +0 -30
  382. package/tests/rules/jet-composites/demo-card/viewModel.js +0 -46
  383. package/tests/rules/jet-composites/demo-card/view_PASS_1.html +0 -21
  384. package/tests/rules/jet-composites/demo-contact-form/component.json +0 -23
  385. package/tests/rules/jet-composites/demo-contact-form/loader.js +0 -16
  386. package/tests/rules/jet-composites/demo-contact-form/view.html +0 -9
  387. package/tests/rules/jet-composites/demo-grocery-list/component.json +0 -18
  388. package/tests/rules/jet-composites/demo-grocery-list/loader.js +0 -19
  389. package/tests/rules/jet-composites/demo-grocery-list/view.html +0 -22
  390. package/tests/rules/jet-composites/demo-grocery-list/viewModel.js +0 -48
  391. package/tests/rules/jet-composites/dummy-component-1/component.json +0 -82
  392. package/tests/rules/jet-composites/dummy-component-2/component.json +0 -72
  393. package/tests/rules/jet-composites/foo-my-cca/component.json +0 -14
  394. package/tests/rules/jet-composites/foo-unsup-theme/component.json +0 -29
  395. package/tests/rules/jet-composites/header/component.json +0 -12
  396. package/tests/rules/jet-composites/oj-cgbu-omc/attribute-selection/component.json +0 -154
  397. package/tests/rules/jet-composites/oj-cgbu-omc/component.json +0 -11
  398. package/tests/rules/jet-composites/oj-cgbu-omc/reference/component.json +0 -185
  399. package/tests/rules/jet-composites/oj-cgbu-omc/wctag_props_FAIL_1.html +0 -34
  400. package/tests/rules/jet-composites/oj-enum-depr/component.json +0 -69
  401. package/tests/rules/jet-composites/oj-html-wctag-id/id_FAIL_1.html +0 -10
  402. package/tests/rules/jet-composites/oj-html-wctag-id/id_PASS_1.html +0 -6
  403. package/tests/rules/misc/oj.js +0 -12
  404. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_FAIL_1.html +0 -23
  405. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_FAIL_2.html +0 -22
  406. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_PASS_1.html +0 -23
  407. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_PASS_2.html +0 -22
  408. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_PASS_3.html +0 -22
  409. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_PASS_4.html +0 -22
  410. package/tests/rules/oj-acc-aria-labelledby/aria_labelledby_PASS_5.html +0 -22
  411. package/tests/rules/oj-acc-aria-prop/aria_prop_FAIL_1.html +0 -22
  412. package/tests/rules/oj-acc-avatar-aria-role/aria_avatar_role_FAIL_1.html +0 -20
  413. package/tests/rules/oj-acc-avatar-aria-role/aria_avatar_role_PASS_1.html +0 -23
  414. package/tests/rules/oj-acc-avatar-aria-role/aria_avatar_role_PASS_2.html +0 -24
  415. package/tests/rules/oj-acc-avatar-aria-role/aria_avatar_role_PASS_3.html +0 -21
  416. package/tests/rules/oj-acc-avatar-aria-role/aria_avatar_role_PASS_4.html +0 -22
  417. package/tests/rules/oj-acc-avatar-aria-role/aria_avatar_role_PASS_5.html +0 -22
  418. package/tests/rules/oj-acc-combobox-aria-label/aria_combo_many_FAIL_1.html +0 -20
  419. package/tests/rules/oj-acc-combobox-aria-label/aria_combo_many_FAIL_2.html +0 -21
  420. package/tests/rules/oj-acc-combobox-aria-label/aria_combo_many_PASS_1.html +0 -20
  421. package/tests/rules/oj-acc-combobox-aria-label/aria_combo_one_FAIL_1.html +0 -21
  422. package/tests/rules/oj-acc-combobox-aria-label/aria_combo_one_FAIL_2.html +0 -22
  423. package/tests/rules/oj-acc-combobox-aria-label/aria_combo_one_PASS_1.html +0 -22
  424. package/tests/rules/oj-acc-film-strip-aria-label/aria_filmstrip_FAIL_1.html +0 -18
  425. package/tests/rules/oj-acc-film-strip-aria-label/aria_filmstrip_FAIL_2.html +0 -18
  426. package/tests/rules/oj-acc-film-strip-aria-label/aria_filmstrip_PASS_1.html +0 -18
  427. package/tests/rules/oj-acc-film-strip-aria-label/aria_filmstrip_PASS_2.html +0 -19
  428. package/tests/rules/oj-acc-film-strip-aria-label/aria_filmstrip_PASS_3.html +0 -22
  429. package/tests/rules/oj-acc-input-aria-label/oj_input_date_FAIL_1.html +0 -21
  430. package/tests/rules/oj-acc-input-aria-label/oj_input_date_FAIL_2.html +0 -22
  431. package/tests/rules/oj-acc-input-aria-label/oj_input_date_PASS_1.html +0 -16
  432. package/tests/rules/oj-acc-input-aria-label/oj_input_date_PASS_2.html +0 -17
  433. package/tests/rules/oj-acc-input-aria-label/oj_input_date_PASS_3.html +0 -26
  434. package/tests/rules/oj-acc-input-aria-label/oj_input_date_time_FAIL_1.html +0 -19
  435. package/tests/rules/oj-acc-input-aria-label/oj_input_date_time_FAIL_2.html +0 -20
  436. package/tests/rules/oj-acc-input-aria-label/oj_input_date_time_PASS_1.html +0 -19
  437. package/tests/rules/oj-acc-input-aria-label/oj_input_number_FAIL_1.html +0 -17
  438. package/tests/rules/oj-acc-input-aria-label/oj_input_number_FAIL_2.html +0 -18
  439. package/tests/rules/oj-acc-input-aria-label/oj_input_number_PASS_1.html +0 -17
  440. package/tests/rules/oj-acc-input-aria-label/oj_input_password_FAIL_1.html +0 -17
  441. package/tests/rules/oj-acc-input-aria-label/oj_input_password_FAIL_2.html +0 -17
  442. package/tests/rules/oj-acc-input-aria-label/oj_input_password_PASS_1.html +0 -17
  443. package/tests/rules/oj-acc-input-aria-label/oj_input_text_3_PASS_1.html +0 -20
  444. package/tests/rules/oj-acc-input-aria-label/oj_input_text_FAIL_1.html +0 -20
  445. package/tests/rules/oj-acc-input-aria-label/oj_input_text_FAIL_2.html +0 -21
  446. package/tests/rules/oj-acc-input-aria-label/oj_input_text_PASS_2.html +0 -62
  447. package/tests/rules/oj-acc-input-aria-label/oj_input_text_nolabel_PASS_2.html +0 -17
  448. package/tests/rules/oj-acc-input-aria-label/oj_input_time_FAIL_1.html +0 -19
  449. package/tests/rules/oj-acc-input-aria-label/oj_input_time_FAIL_2.html +0 -20
  450. package/tests/rules/oj-acc-input-aria-label/oj_input_time_PASS_1.html +0 -19
  451. package/tests/rules/oj-acc-select-aria-label/aria_selectmany_FAIL_1.html +0 -19
  452. package/tests/rules/oj-acc-select-aria-label/aria_selectmany_FAIL_2.html +0 -20
  453. package/tests/rules/oj-acc-select-aria-label/aria_selectmany_PASS_1.html +0 -19
  454. package/tests/rules/oj-acc-select-aria-label/aria_selectone_FAIL_1.html +0 -20
  455. package/tests/rules/oj-acc-select-aria-label/aria_selectone_FAIL_2.html +0 -21
  456. package/tests/rules/oj-cca-comp-zip/zip_FAIL_1.zip +0 -1
  457. package/tests/rules/oj-cca-comp-zip/zip_FAIL_2.zip +0 -0
  458. package/tests/rules/oj-cca-comp-zip/zip_FAIL_3.zip +0 -0
  459. package/tests/rules/oj-cca-comp-zip/zip_FAIL_4.zip +0 -0
  460. package/tests/rules/oj-cca-comp-zip/zip_FAIL_5.zip +0 -0
  461. package/tests/rules/oj-cca-comp-zip/zip_FAIL_6.zip +0 -0
  462. package/tests/rules/oj-cca-comp-zip/zip_FAIL_7.zip +0 -0
  463. package/tests/rules/oj-cca-comp-zip/zip_FAIL_8.zip +0 -0
  464. package/tests/rules/oj-cca-comp-zip/zip_PASS_1.zip +0 -0
  465. package/tests/rules/oj-cca-ns-reg/oj-cca-ns-FAIL_1/component.json +0 -19
  466. package/tests/rules/oj-cca-ns-reg/oj-cca-ns-PASS_1/component.json +0 -19
  467. package/tests/rules/oj-cgbu-omc_tests/html_ojevent_FAIL_1.html +0 -15
  468. package/tests/rules/oj-cgbu-omc_tests/html_ojevent_PASS_1.html +0 -17
  469. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_1/component.json +0 -16
  470. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_10/component.json +0 -103
  471. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_11/component.json +0 -24
  472. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_12/component.json +0 -17
  473. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_13/component.json +0 -17
  474. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_14/component.json +0 -40
  475. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_15/component.json +0 -24
  476. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_16/component.json +0 -44
  477. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_17/component.json +0 -8
  478. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_18/component.json +0 -8
  479. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_19/component.json +0 -8
  480. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_2/component.json +0 -15
  481. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_20/component.json +0 -18
  482. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_21/component.json +0 -16
  483. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_22/component.json +0 -19
  484. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_3/component.json +0 -15
  485. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_4/component.json +0 -16
  486. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_5/component.json +0 -16
  487. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_6/component.json +0 -18
  488. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_7/component.json +0 -15
  489. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_8/component.json +0 -15
  490. package/tests/rules/oj-compjson-syntax/ojcomp-FAIL_9/component.json +0 -52
  491. package/tests/rules/oj-compjson-syntax/ojcomp-PASS_1/component.json +0 -17
  492. package/tests/rules/oj-compjson-syntax/ojcomp-PASS_2/component.json +0 -88
  493. package/tests/rules/oj-compjson-syntax/ojcomp-PASS_3/component.json +0 -19
  494. package/tests/rules/oj-css-bp-dir-flow/dirflow_FAIL_1.html +0 -22
  495. package/tests/rules/oj-css-bp-dir-flow/dirflow_FAIL_2.html +0 -22
  496. package/tests/rules/oj-css-diagnose/css_FAIL_1.html +0 -14
  497. package/tests/rules/oj-css-diagnose/css_PASS_1.html +0 -14
  498. package/tests/rules/oj-css-var-override/varovr_FAIL_1.html +0 -8
  499. package/tests/rules/oj-html-5-attr-depr/attrdepr_FAIL_1.html +0 -16
  500. package/tests/rules/oj-html-5-attr-depr/attrdepr_PASS_1.html +0 -16
  501. package/tests/rules/oj-html-5-tag-depr/tagdepr_FAIL_1.html +0 -9
  502. package/tests/rules/oj-html-attr/attr_FAIL_1.html +0 -27
  503. package/tests/rules/oj-html-attr-$unique/attr_$unique1_FAIL_1.html +0 -19
  504. package/tests/rules/oj-html-attr-$unique/attr_$unique_FAIL_2.html +0 -25
  505. package/tests/rules/oj-html-attr-2def/attr2def_FAIL_1.html +0 -10
  506. package/tests/rules/oj-html-attr-2def/attr2def_PASS_1.html +0 -10
  507. package/tests/rules/oj-html-attr-json/attr-json_FAIL_1.html +0 -20
  508. package/tests/rules/oj-html-attr-json/attr-json_FAIL_2.html +0 -20
  509. package/tests/rules/oj-html-attr-json/attr-json_FAIL_3.html +0 -20
  510. package/tests/rules/oj-html-attr-json/attr-json_PASS_1.html +0 -20
  511. package/tests/rules/oj-html-attr-json/attr-json_PASS_2.html +0 -20
  512. package/tests/rules/oj-html-attr-json/attr-json_PASS_3.html +0 -8
  513. package/tests/rules/oj-html-attr-prefix-expr/attrprefixexpr_FAIL_1.html +0 -10
  514. package/tests/rules/oj-html-attr-prefix-expr/attrprefixexpr_PASS_1.html +0 -10
  515. package/tests/rules/oj-html-attr-prefix-ro/attrprefixro_FAIL_1.html +0 -10
  516. package/tests/rules/oj-html-attr-prefix-ro/attrprefixro_PASS_1.html +0 -10
  517. package/tests/rules/oj-html-attr-req/attrreq_FAIL_1.html +0 -17
  518. package/tests/rules/oj-html-attr-req/attrreq_FAIL_2.html +0 -13
  519. package/tests/rules/oj-html-attr-req/attrreq_FAIL_3.html +0 -8
  520. package/tests/rules/oj-html-attr-req/attrreq_FAIL_4.html +0 -13
  521. package/tests/rules/oj-html-attr-req/attrreq_FAIL_5.html +0 -17
  522. package/tests/rules/oj-html-attr-req/attrreq_PASS_1.html +0 -24
  523. package/tests/rules/oj-html-attr-req/attrreq_PASS_2.html +0 -24
  524. package/tests/rules/oj-html-attr-req/attrreq_PASS_3.html +0 -10
  525. package/tests/rules/oj-html-attr-req/attrreq_PASS_4.html +0 -11
  526. package/tests/rules/oj-html-bindforeach-data/bindforeach_data_FAIL_1.html +0 -19
  527. package/tests/rules/oj-html-bindforeach-data/bindforeach_data_PASS_1.html +0 -10
  528. package/tests/rules/oj-html-bindif-test/bindif_test_FAIL_1.html +0 -22
  529. package/tests/rules/oj-html-bindif-test/bindif_test_PASS_1.html +0 -11
  530. package/tests/rules/oj-html-binding-attr/binding-foreach_FAIL_2.html +0 -28
  531. package/tests/rules/oj-html-binding-attr/binding-if_FAIL_1.html +0 -23
  532. package/tests/rules/oj-html-binding-attr/binding-if_PASS_1.html +0 -23
  533. package/tests/rules/oj-html-cca-count/cca-count_FAIL_1.html +0 -119
  534. package/tests/rules/oj-html-cca-tagname/ccatag_FAIL_1.html +0 -7
  535. package/tests/rules/oj-html-cca-tagname/ccatag_PASS_1.html +0 -7
  536. package/tests/rules/oj-html-cca-tagname/tag_ns_FAIL_1.html +0 -8
  537. package/tests/rules/oj-html-cca-tagname/tag_ns_FAIL_2.html +0 -8
  538. package/tests/rules/oj-html-cca-tagname/tag_ns_FAIL_3.html +0 -8
  539. package/tests/rules/oj-html-cca-tagname/tag_ns_PASS_1.html +0 -10
  540. package/tests/rules/oj-html-cdn/html_cdn_FAIL_1.html +0 -18
  541. package/tests/rules/oj-html-cspexpr/cspexpr_FAIL_1.html +0 -14
  542. package/tests/rules/oj-html-cspexpr/cspexpr_FAIL_2.html +0 -10
  543. package/tests/rules/oj-html-cspexpr/cspexpr_PASS_1.html +0 -23
  544. package/tests/rules/oj-html-cspexpr/cspexpr_PASS_2.html +0 -10
  545. package/tests/rules/oj-html-cspexpr/cspexpr_PASS_3.html +0 -13
  546. package/tests/rules/oj-html-dlg-title/dlgtitle_FAIL_1.html +0 -12
  547. package/tests/rules/oj-html-dlg-title/dlgtitle_PASS_1.html +0 -12
  548. package/tests/rules/oj-html-form-noflex/noflex_FAIL_1.html +0 -10
  549. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_FAIL_1.html +0 -20
  550. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_FAIL_2.html +0 -13
  551. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_FAIL_3.html +0 -16
  552. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_FAIL_4.html +0 -13
  553. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_PASS_1.html +0 -6
  554. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_PASS_2.html +0 -7
  555. package/tests/rules/oj-html-invalid-doctype/doctype_invalid_PASS_3.html +0 -7
  556. package/tests/rules/oj-html-jq-databind/jq-databind_FAIL_1.html +0 -37
  557. package/tests/rules/oj-html-jq-databind/jq-databind_FAIL_2.html +0 -34
  558. package/tests/rules/oj-html-jq-databind/jq-databind_FAIL_3.html +0 -27
  559. package/tests/rules/oj-html-jq-databind/jq-databind_PASS_1.html +0 -30
  560. package/tests/rules/oj-html-ko-comment/ko-comment_FAIL_1.html +0 -47
  561. package/tests/rules/oj-html-ko-comment/ko-comment_FAIL_2.html +0 -36
  562. package/tests/rules/oj-html-ko-databind/ko-databind_FAIL_1.html +0 -24
  563. package/tests/rules/oj-html-ko-databind/ko-databind_FAIL_2.html +0 -36
  564. package/tests/rules/oj-html-ko-databind/ko-databind_FAIL_3.html +0 -29
  565. package/tests/rules/oj-html-label-for-prefix/for_FAIL_1.html +0 -8
  566. package/tests/rules/oj-html-label-for-prefix/for_PASS_1.html +0 -8
  567. package/tests/rules/oj-html-missing-doctype/doctype_missing_FAIL_1.html +0 -12
  568. package/tests/rules/oj-html-missing-doctype/doctype_missing_FAIL_2.html +0 -11
  569. package/tests/rules/oj-html-missing-doctype/doctype_missing_PASS_1.html +0 -14
  570. package/tests/rules/oj-html-missing-doctype/doctype_missing_PASS_2.html +0 -5
  571. package/tests/rules/oj-html-missing-doctype/doctype_missing_PASS_3.html +0 -12
  572. package/tests/rules/oj-html-missing-doctype/doctype_missing_PASS_5.html +0 -6
  573. package/tests/rules/oj-html-nonvoid-close/close_FAIL_1.html +0 -28
  574. package/tests/rules/oj-html-nonvoid-close/close_FAIL_2.html +0 -14
  575. package/tests/rules/oj-html-nonvoid-close/close_FAIL_3.html +0 -13
  576. package/tests/rules/oj-html-nonvoid-close/close_FAIL_5.html +0 -28
  577. package/tests/rules/oj-html-nonvoid-close/close_FAIL_6.html +0 -28
  578. package/tests/rules/oj-html-nonvoid-close/close_PASS_1.html +0 -7
  579. package/tests/rules/oj-html-oj-lib/oj_lib_FAIL_1.html +0 -15
  580. package/tests/rules/oj-html-ojattr/ojattr_PASS_1.html +0 -8
  581. package/tests/rules/oj-html-ojattr/ojattr_PASS_2.html +0 -10
  582. package/tests/rules/oj-html-ojattr/ojattr_PASS_3.html +0 -7
  583. package/tests/rules/oj-html-ojattr/ojattr_PASS_4.html +0 -7
  584. package/tests/rules/oj-html-ojattr-deprecated/ojattr-dep_FAIL1.html +0 -156
  585. package/tests/rules/oj-html-ojattr-enum-deprecated/enum_FAIL_1.html +0 -19
  586. package/tests/rules/oj-html-ojattr-enum-deprecated/enum_FAIL_2.html +0 -20
  587. package/tests/rules/oj-html-ojattr-enum-deprecated/enum_PASS_1.html +0 -25
  588. package/tests/rules/oj-html-ojattr-evt-syntax/evt-attr-syntax_FAIL_1.html +0 -6
  589. package/tests/rules/oj-html-ojattr-evt-syntax/evt-attr-syntax_PASS_1.html +0 -6
  590. package/tests/rules/oj-html-ojattr-value/attr-value_FAIL_1.html +0 -26
  591. package/tests/rules/oj-html-ojattr-value/attr-value_FAIL_2.html +0 -26
  592. package/tests/rules/oj-html-ojattr-value/attr-value_FAIL_3.html +0 -8
  593. package/tests/rules/oj-html-ojattr-value/attr-value_FAIL_4.html +0 -8
  594. package/tests/rules/oj-html-ojattr-value/attr-value_FAIL_5.html +0 -8
  595. package/tests/rules/oj-html-ojattr-value/attr-value_PASS_1.html +0 -26
  596. package/tests/rules/oj-html-ojattr-value/attr-value_PASS_2.html +0 -8
  597. package/tests/rules/oj-html-ojattr-value/attr-value_PASS_3.html +0 -7
  598. package/tests/rules/oj-html-ojattr-value/attr-value_PASS_6.html +0 -7
  599. package/tests/rules/oj-html-ojattr-value/attr-value_PASS_7.html +0 -10
  600. package/tests/rules/oj-html-ojattr-value/attr_value_PASS_4.html +0 -7
  601. package/tests/rules/oj-html-ojattr-value/attr_value_PASS_5.html +0 -9
  602. package/tests/rules/oj-html-ojslot/ojslot_FAIL_1.html +0 -11
  603. package/tests/rules/oj-html-ojslot/ojslot_PASS_1.html +0 -12
  604. package/tests/rules/oj-html-ojstyle/style_FAIL_1.html +0 -103
  605. package/tests/rules/oj-html-ojstyle/style_PASS_2.html +0 -7
  606. package/tests/rules/oj-html-ojtag-datacmd/datacmd_FAIL_1.html +0 -10
  607. package/tests/rules/oj-html-ojtag-datacmd/datacmd_FAIL_2.html +0 -18
  608. package/tests/rules/oj-html-ojtag-datacmd/datacmd_FAIL_3.html +0 -10
  609. package/tests/rules/oj-html-ojtag-datacmd/datacmd_PASS_1.html +0 -28
  610. package/tests/rules/oj-html-ojtag-datacmd/datacmd_PASS_2.html +0 -15
  611. package/tests/rules/oj-html-ojtag-datactx/datactx_FAIL_1.html +0 -14
  612. package/tests/rules/oj-html-ojtag-datactx/datactx_PASS_1.html +0 -14
  613. package/tests/rules/oj-html-ojtag-globattr-noprefix/globattr-noprefix_FAIL_1.html +0 -36
  614. package/tests/rules/oj-html-ojtag-nonglobattr-prefix/nonglobattr-prefix_FAIL_1.html +0 -26
  615. package/tests/rules/oj-html-slot-name/slot_name.FAIL_1.html +0 -24
  616. package/tests/rules/oj-html-slot-name/slot_name.FAIL_2.html +0 -46
  617. package/tests/rules/oj-html-slot-name/slot_name.FAIL_3.html +0 -10
  618. package/tests/rules/oj-html-slot-name/slot_name.PASS_1.html +0 -24
  619. package/tests/rules/oj-html-slot-name/slot_name.PASS_2.html +0 -39
  620. package/tests/rules/oj-html-slot-name/slot_name.PASS_3.html +0 -10
  621. package/tests/rules/oj-html-slot-name/slot_name_PASS_4.html +0 -16
  622. package/tests/rules/oj-html-slot-name/slot_name_PASS_5.html +0 -11
  623. package/tests/rules/oj-html-slot-name/slot_name_PASS_6.html +0 -14
  624. package/tests/rules/oj-html-slot-name/slot_name_PASS_7.html +0 -10
  625. package/tests/rules/oj-html-style/style_FAIL_1.html +0 -7
  626. package/tests/rules/oj-html-style/style_PASS_1.html +0 -12
  627. package/tests/rules/oj-html-style/style_PASS_2.html +0 -7
  628. package/tests/rules/oj-html-style-bp-color/color-FAIL_1.html +0 -17
  629. package/tests/rules/oj-html-style-bp-color/color-FAIL_2.html +0 -15
  630. package/tests/rules/oj-html-style-bp-color/color-FAIL_3.html +0 -7
  631. package/tests/rules/oj-html-style-bp-color/color-PASS_1.html +0 -7
  632. package/tests/rules/oj-html-style-bp-font-family/fam_FAIL_1.html +0 -23
  633. package/tests/rules/oj-html-tag-attr-noprefix/attr-noprefix_FAIL_1.html +0 -15
  634. package/tests/rules/oj-html-tag-attr-noprefix/attr-noprefix_FAIL_2.html +0 -9
  635. package/tests/rules/oj-html-tag-attr-noprefix/attr-noprefix_PASS_1.html +0 -9
  636. package/tests/rules/oj-html-unsup-theme/unsup_FAIL_1.html +0 -8
  637. package/tests/rules/oj-html-wctag-for/for_FAIL_1.html +0 -8
  638. package/tests/rules/oj-html-wctag-for/for_PASS_1.html +0 -8
  639. package/tests/rules/oj-js-comp-attr-deprecated/attr-del_FAIL_1.js +0 -20
  640. package/tests/rules/oj-js-comp-attr-deprecated/attr-dep_FAIL_1.js +0 -20
  641. package/tests/rules/oj-js-comp-meth-deprecated/meth-del_FAIL_1.js +0 -20
  642. package/tests/rules/oj-js-comp-meth-deprecated/meth-dep_FAIL_1.js +0 -20
  643. package/tests/rules/oj-js-define-promise/def-prom_FAIL_1.js +0 -16
  644. package/tests/rules/oj-js-define-promise/def-prom_FAIL_2.js +0 -16
  645. package/tests/rules/oj-js-diagnose/es6_PASS_1.js +0 -24
  646. package/tests/rules/oj-js-diagnose/js_FAIL_1.js +0 -12
  647. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_1.js +0 -30
  648. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_2.js +0 -23
  649. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_3.js +0 -22
  650. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_4.js +0 -20
  651. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_5.js +0 -24
  652. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_6.js +0 -30
  653. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_7.js +0 -15
  654. package/tests/rules/oj-js-no-ext-final/noextfinal_FAIL_8.js +0 -16
  655. package/tests/rules/oj-js-no-ext-final/noextfinal_PASS_1.js +0 -17
  656. package/tests/rules/oj-js-no-ext-final/noextfinal_PASS_2.js +0 -17
  657. package/tests/rules/oj-js-noconsole/nocons_FAIL_1.js +0 -11
  658. package/tests/rules/oj-js-ojcomp-deprecated/jscomp_FAIL_1.js +0 -27
  659. package/tests/rules/oj-json-syntax/json_FAIL_1.json +0 -8
  660. package/tests/rules/oj-json-syntax/json_FAIL_2.json +0 -12
  661. package/tests/rules/oj-json-syntax/json_PASS_1.json +0 -25
  662. package/tests/rules/oj-json-syntax/json_PASS_2.json +0 -12
  663. package/tests/rules/oj-json-syntax/json_PASS_3.json +0 -14
  664. package/tests/rules/ojcompjson/attrreq_FAIL_1/component.json +0 -69
  665. package/tests/rules/pack-compjson/audit-pack/component-1/component-1-view.html +0 -6
  666. package/tests/rules/pack-compjson/audit-pack/component-1/component-1-viewModel.js +0 -56
  667. package/tests/rules/pack-compjson/audit-pack/component-1/component.json +0 -13
  668. package/tests/rules/pack-compjson/audit-pack/component-1/loader.js +0 -20
  669. package/tests/rules/pack-compjson/audit-pack/component-1/resources/nls/component-1-strings.js +0 -18
  670. package/tests/rules/pack-compjson/audit-pack/component-2/component-2-view.html +0 -5
  671. package/tests/rules/pack-compjson/audit-pack/component-2/component-2-viewModel.js +0 -56
  672. package/tests/rules/pack-compjson/audit-pack/component-2/component.json +0 -13
  673. package/tests/rules/pack-compjson/audit-pack/component-2/loader.js +0 -20
  674. package/tests/rules/pack-compjson/audit-pack/component-2/resources/nls/component-1-strings.js +0 -18
  675. package/tests/rules/pack-compjson/audit-pack/component.json +0 -12
  676. package/tests/rules/pack-compjson/audit-singleton-1/audit-singleton-1-view.html +0 -5
  677. package/tests/rules/pack-compjson/audit-singleton-1/audit-singleton-1-viewModel.js +0 -56
  678. package/tests/rules/pack-compjson/audit-singleton-1/component.json +0 -20
  679. package/tests/rules/pack-compjson/audit-singleton-1/loader.js +0 -20
  680. package/tests/rules/pack-compjson/audit-singleton-1/resources/nls/audit-singleton-1-strings.js +0 -18
  681. package/tests/rules/pack-compjson/audit-singleton-2/audit-singleton-2-view.html +0 -8
  682. package/tests/rules/pack-compjson/audit-singleton-2/audit-singleton-2-viewModel.js +0 -56
  683. package/tests/rules/pack-compjson/audit-singleton-2/component.json +0 -15
  684. package/tests/rules/pack-compjson/audit-singleton-2/loader.js +0 -20
  685. package/tests/rules/pack-compjson/audit-singleton-2/resources/nls/audit-singleton-2-strings.js +0 -18
  686. package/tests/rules/parse-html/proc_instr.html +0 -9
  687. package/tests/rules/spoc-dom-manip/dom-manip_FAIL_1.js +0 -113
  688. package/tests/rules/spoc-dom-manip/dom-manip_FAIL_2.js +0 -151
  689. package/tests/rules/spoc-dom-manip/dom-manip_PASS_1.js +0 -149
  690. package/tests/rules/spoc-dom-manip/dom-manip_PASS_2.js +0 -147
  691. package/tests/rules/spoc-dom-manip/dom-manip_PASS_3.js +0 -147
  692. package/tests/rules/spoc-dom-manip/dom-manip_PASS_4.js +0 -20
  693. package/tests/rules/spoc-dom-manip/dom-manip_PASS_5.js +0 -246
  694. package/tests/rules/tab-tests/tab-test_FAIL_1.html +0 -37
  695. package/tests/rules/tab-tests/tab-test_FAIL_2.html +0 -8
  696. package/tests/rules/webcomptests/jet-composites/oj-html-wctag-$props/prop_PASS_1.html +0 -8
  697. package/tests/rules/webcomptests/jet-composites/oj-html-wctag-$props/prop_PASS_2.html +0 -8
  698. package/tests/rules/webcomptests/jet-composites/oj-html-wctag-for/for_FAIL_1.html +0 -8
  699. package/tests/rules/webcomptests/jet-composites/oj-html-wctag-for/for_PASS_1.html +0 -8
  700. package/tests/src/JetTest.js +0 -1
  701. package/tests/src/server.js +0 -1
  702. package/tests/test.js +0 -1
package/lib/RuleSet.js CHANGED
@@ -1 +1,6 @@
1
- const REG=require("./RegTypes");const RULE_FILE="rules.json";const BUILTIN_RULES_PATH="../rules/";const BUILTIN_RULEPACK_PATH="../rulepacks/";const BUILTIN_ZIP_RULEPACK_PATH="../../jafrulepacks/";const JAF_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jaf";const JET_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jet";const EXCH_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"exch";const SPOC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"spoc";const CSP_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"csp";const JETWC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwc";const JETWCO_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwco";const JET_MIN_VERSION="5.2.0";const TEMP_FILE_TEMPLATE="@@rpziptmp-XXXXXX";const PROP_$BUILTIN="$builtin";const FILETYPE_HTML="html";const FILETYPE_CSS="css";const FILETYPE_JS="js";const FILETYPE_TS="ts";const FILE_TYPE_JSON="json";const FILE_TYPE_ZIP="zip";const FILE_TYPES=[FILETYPE_HTML,FILETYPE_CSS,FILETYPE_JS,FILETYPE_TS,FILE_TYPE_JSON,FILE_TYPE_ZIP];const RESERVED_RULE_PREFIX=["oj-","jaf-","csp-","spoc-","jetwc-","exch-","demo-"];const RESERVED_PACK_PREFIX=["JAF","JET","SPOC","CSP","JETWC","DEMO"];const NO_MSGID_PACKS=["JETWC","JETWCO"];const RULE_STATUS=["prod","production","ready","beta","alpha","deprecated"];const FUNCTION="function";const RULE_RE=new RegExp(/[~`!#$%\^&*+\[\]\\';,/{}|\\"\?]/,"g");const RulePack=require("./RulePack");const Registry=require("./Registry");const SemVer=require("./SemVer");const CssUtils=require("./CssUtils");const AstNodeTypes=require("./AstNodeTypes");const clone=require("./clone");var RuleSet=function(config,nodeDeps,appCtx){this._config=config;this._ruleSets=config.getRulePacks();this._ruleMods=config.getRuleMods();this._ruleCount=0;this._appCtx=appCtx;this._nodeDeps=nodeDeps;this._isAMD=!!nodeDeps.AmdRulePackLoader;this._isCLI=appCtx.runMode==="cli";this._isCliOrApi=!this._isAMD;this._metaLib=appCtx.metaLib;this._utils=appCtx.utils;this._severity=appCtx.severity;this._tmpDir=appCtx.tmpDir;this._semVer=new SemVer;this._useBuiltinRules=config._config.builtinJetRules;this._rulePacks=null;this._shadowRulePacks=null;this._rulesetSummary=[];this._registerCtx={sysOpts:{verboseMode:this._appCtx.verboseMode,debugMode:this._appCtx.debugMode}};this._registerCtx.utils={};this._registerCtx.utils.metaLib=this._metaLib;this._registerCtx.runMode=appCtx.runMode;this._registerCtx.VsCodeExtHint=appCtx.VsCodeExtHint;this._registerCtx.utils.semVerUtils=this._semVer;this._registerCtx.utils.utils=this._utils;this._registerCtx.utils.CssUtils=CssUtils;this._registerCtx.config=JSON.parse(JSON.stringify(this._config._config));this._registerCtx.error=appCtx.error;this._registerCtx.info=appCtx.info;this._registerCtx.msg=appCtx.msg;this._registerCtx.utils.msgLib={msg:appCtx.msg,error:appCtx.error,info:appCtx.info,debug:appCtx.debug,assert:appCtx.assert};this._registerCtx.utils.sevLib=this._severity.getSevLib();this._msg=appCtx.msg;this._info=appCtx.info;this._debug=appCtx.debug;this._error=appCtx.error;this._assert=appCtx.assert;this._debugMode=appCtx.debugMode;this._verboseMode=appCtx.verboseMode;if(!this._ruleSets){this._ruleSets=[]}let rsi=0;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JAF_BUILTIN_RULES_PATH):null,"builtin":true});if(config._config.builtinJetRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JET_BUILTIN_RULES_PATH):null,"builtin":true})}if(config._config.builtinExchRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,EXCH_BUILTIN_RULES_PATH),"builtin":true})}if(config._config.builtinCspRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,CSP_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWC_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcOracleRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWCO_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinSpocRules){this._ruleSets.splice(rsi,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,SPOC_BUILTIN_RULES_PATH),"builtin":true})}};RuleSet.prototype.loadRulePacks=function(config,isDryRun,isRuleDump){var ruleSet,rulePath,rulesJson,rulePack,rsi,rule,prefix,groups,gname,arules,j,k,s="",rulesetSummaryIndex=-1,spocFound,demoFound,errors=false,rc,ruleName,jetVersion;this._config=config;this._confSeverity=config._sev;this._confNamedRules=config.ruleNames;jetVersion=this._metaLib.getRevisionInfo().jetVersion;if(!this._semVer.setReference(jetVersion,JET_MIN_VERSION)){this._error(`JET metadata version ${jetVersion} not supported (less than ${JET_MIN_VERSION})`);return false}if(this._debugMode){this._debug(this._ruleSets?"Processing "+this._ruleSets.length+" Rule Sets":"No Rule Sets defined")}if(!this._ruleSets){return false}this._rulePacks=[];this._shadowRulePacks=[];for(rsi=0;rsi<this._ruleSets.length;rsi++){ruleSet=this._ruleSets[rsi];groups=null;try{if(typeof ruleSet.enabled==="boolean"&&!ruleSet.enabled){s+=(rsi?"\n":"")+" "+(rsi+1)+") "+"Disabled ruleSet at '"+ruleSet.path;continue}if(!ruleSet.status){ruleSet.status=["all"]}if(!this._isAMD){if(this._debugMode){this._debug("Ruleset '"+ruleSet.name+"' path->'"+ruleSet.path+"'")}if(ruleSet.path.endsWith(".zip")){ruleSet.container=ruleSet.path;let tmpFile=this._nodeDeps.fsUtils.getUniqueFileName(TEMP_FILE_TEMPLATE);let tmpDir=this._nodeDeps.path.join(this._tmpDir,tmpFile);rc=this._nodeDeps.fsUtils.createFolder(tmpDir);if(typeof rc!=="boolean"){this._error(`Unable to create folder ${rc.message}`);break}var zipUtils=new this._nodeDeps.zipUtils;;rc=zipUtils.extractAll(tmpDir,ruleSet.container,true);if(typeof rc!=="boolean"){this._error(`Unable to extract from zip ('${rc.message}') : "${ruleSet.container}"`);break}ruleSet.path=tmpDir}rulePath=this._nodeDeps.path.join(ruleSet.path,RULE_FILE);rulesJson=this._loadJson(rulePath)}else{rulesJson=this._nodeDeps.AmdRulePackLoader(this._nodeDeps,rsi,ruleSet,this._error)}if(!rulesJson){continue}if(!rulesJson.title){rulesJson.title="unknown"}if(!rulesJson.version){rulesJson.version="0.0.0"}prefix=rulesJson.prefix;ruleSet.prefix=prefix;s+=(rsi?"\n":"")+" "+(rsi+1)+") "+rulesJson.title+"\n "+rulesJson.version+" : "+prefix+(ruleSet.builtin?"":" -> "+(ruleSet.container?ruleSet.container:ruleSet.path));if(this._appCtx.isUnitTest&&!spocFound&&prefix==="SPOC"){ruleSet.builtin=true;if(prefix==="SPOC"){spocFound=true}if(prefix==="DEMO"){demoFound=true}}if(!demoFound&&prefix==="DEMO"){ruleSet.builtin=true;if(prefix==="DEMO"){demoFound=true}}if(!ruleSet.builtin){if(RESERVED_PACK_PREFIX.includes(prefix)){this._error("Rule pack at '"+rulePath+"' cannot use use reserved prefix '"+prefix+"'!");break}}for(j=0;j<this._rulesetSummary.length;j++){if(this._rulesetSummary[j].prefix===prefix){this._error("Rule pack prefix '"+prefix+"' at '"+rulePath+"' ignored - previously defined at '"+rulePack.path+"'");break}}if(j<this._rulesetSummary.length){continue}this._rulesetSummary.push({title:rulesJson.title,path:ruleSet.path,version:rulesJson.version,prefix:rulesJson.prefix,status:ruleSet.status,packData:ruleSet.packData});++rulesetSummaryIndex;for(ruleName in rulesJson.rules){rule=rulesJson.rules[ruleName];rule._rsi=rulesetSummaryIndex;if(this._ruleSets[rulesetSummaryIndex].builtin){rule[PROP_$BUILTIN]=true}if(rule.group){groups=groups||{};let rg=rule.group;if(typeof rg==="string"){arules=groups[rg];if(!arules){groups[rg]=arules=[]}arules.push(ruleName)}else if(Array.isArray(rg)){for(k=0;k<rg.length;k++){gname=rg[k];arules=groups[gname];if(!arules){groups[gname]=arules=[]}arules.push(ruleName)}}}}this._rulePacks.push({path:ruleSet.path,rulesJson:rulesJson});ruleSet.groupMap=groups;this._mergeRuleOptions(rulesJson,ruleSet.builtin)}catch(e){this._error(`Failure processing ruleset at '${rulePath}' (${e.message})`);errors=true}}if(s.length){this._info("[info]: ------ Rulepacks found: --------");this._info(s)}if(this._debugMode){this._debug("------ group mappings : --------");let self=this;this._ruleSets.forEach(function(s){self._debug(s.prefix+": "+JSON.stringify(s.groupMap,null,3))})}if(errors){return false}this._registry=new Registry(this._appCtx);this._postProcess_RuleMods();this._postProcess_RuleNames();if(!this._processRuleSets()){return false}if(config.options.debug&&!isRuleDump||config.options.verbose&&!isRuleDump||isDryRun){var f=isDryRun||config.options.verbose?this._info:this._debug;var rules,opts;if(this._ruleCount){f("\n-------- Active Rule Summmary --------");for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];f("\n ["+(rsi+1)+"] Rule Set '"+rulePack.rulesJson.title+"'");rules=rulePack.rulesJson.rules;let n=0;for(ruleName in rules){opts=rules[ruleName];if(opts.enabled){f("\n "+ruleName+" : "+JSON.stringify(this._utils.extend(opts)));n++}}if(!n){f("\n "+"No rules enabled in pack.")}}}}return!errors};RuleSet.prototype._postProcess_RuleMods=function(){var rs,rm,are,ard,count=0,n;rm=this._config.ruleMods;if(rm&&(rm.enable||rm.disable)){rs=this._ruleSets;are=rm.enable;if(are){n=_replaceGroups(are,rs);if(n){are=_removeDups(are);count+=n}}ard=rm.disable;if(ard){n=_replaceGroups(ard,rs);if(n){ard=_removeDups(ard);count+=n}}this._enableDisableGroupRules(are,ard)}return count};RuleSet.prototype._enableDisableGroupRules=function(are,ard){var ar,rname,packs,rules,rule,enable,m1,i,j,k;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Enabling rules found in ruleMods.enable ---");if(!are){this._info("* None found")}}packs=this._rulePacks;i=2;ar=are;enable=true;m1="enabled";while(i){if(ar){for(j=0;j<ar.length;j++){rname=ar[j];for(k=0;k<packs.length;k++){rules=packs[k];if(rules){rules=rules.rulesJson;if(rules){rule=rules.rules[rname];if(rule){rule.enabled=enable;if(this._verboseMode||this._debugMode){this._info(` Rule ${rname} ${m1}`)}break}}}}}}if(enable){ar=ard;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Disabling rules found in ruleMods.disable ---");m1="disabled";if(!ard){this._info("* None found")}}if(!ard){return}}enable=false;i--}};RuleSet.prototype._postProcess_RuleNames=function(){var ret=0;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Processing config ruleNames entries ---")}if(this._config.ruleNames){ret=_replaceGroups(this._config.ruleNames,this._ruleSets);this._config.ruleNames=_removeDups(this._config.ruleNames)}if(this._verboseMode||this._debugMode){this._info(`\n[Info]: ${ret} ruleNames group entr${ret===1?"y":"ies"} replaced ---`)}return ret};function _replaceGroups(ar,rs){var val,o,group,grules,rc=0,rsi,i;var replaced=[];for(i=0;i<ar.length;i++){val=ar[i];replaced.length=0;for(rsi=0;rsi<rs.length;rsi++){o=rs[rsi];if(o.groupMap){for(group in o.groupMap){if(group===val){grules=o.groupMap[group];replaced.push(...grules);break}}}}if(replaced.length){ar.splice(i,1,...replaced);i+=replaced.length-1;rc++}}return rc};function _removeDups(ar){return[...new Set(ar)]};RuleSet.prototype.dumpRegistry=function(){console.log("\n-------- Active Rule Type Listener Types --------");console.log(this._registry.dump())};RuleSet.prototype.getRulePacks=function(){return this._rulePacks};RuleSet.prototype.getRulePacksSummary=function(){return this._rulesetSummary};RuleSet.prototype.getShadowRulePacks=function(){return this._shadowRulePacks};RuleSet.prototype.getActiveRuleCount=function(){return this._ruleCount};RuleSet.prototype.getRegistry=function(){return this._registry};RuleSet.prototype.getRulesetSummary=function(){return this._rulesetSummary};RuleSet.prototype.getRsiFromMsgId=function(msgId){var i,prefix,ret=-1;i=msgId.indexOf("-");prefix=i>=0?msgId.substring(0,i):msgId;if(this._rulesetSummary){for(i=0;i<this._rulesetSummary.length;i++){if(this._rulesetSummary[i].prefix===prefix){ret=i;break}}}return ret};RuleSet.prototype.loadMsgIds=function(){var msgObj,rp,rs,o,rsi,fpath,err;if(this._rulePacks&&this._rulePacks.length){for(rsi=0;rsi<this._rulePacks.length;rsi++){rp=this._rulePacks[rsi];rs=this._ruleSets[rsi];if(rs.builtin&&NO_MSGID_PACKS.includes(rs.prefix)){continue}if(this._ruleSets[rsi].enabled){if(!msgObj){msgObj={}}o=null;try{if(this._isCliOrApi){fpath=this._nodeDeps.path.join(rp.path,"msgid.json");if(rs.builtin||this._nodeDeps.fsUtils.fileExists(fpath)){o=this._nodeDeps.msgidLoader(fpath)}}else{o=this._nodeDeps.msgidLoader(this._nodeDeps,rsi,this._ruleSets[rsi],this._error)}}catch(e){this._error(`'Failed to load ${rs.builtin?"builtin":"external"} rulepack msgid file : ${e.message}`);err=true;o=null}msgObj[rp.rulesJson.prefix]=o}}}return err?-1:msgObj};RuleSet.prototype.getLoadedRule=function(rsi,ruleName){return this._shadowRulePacks[rsi][ruleName]};RuleSet.prototype.getSemVer=function(){return this._semVer};RuleSet.prototype._processRuleSets=function(){var ruleName,ruleNamesWild,rulePack,rules,opts,ruleJS,rule,rulePath,packStat,callbacks,callback,atLine,rn,rsi,s,i,j;for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];rules=rulePack.rulesJson.rules;rulePack.rulePack=new RulePack(this._rulesetSummary,this._rulePacks,this._shadowRulePacks,rsi,this._appCtx);this._registerCtx.rulePack=rulePack.rulePack;packStat=this._rulesetSummary[rsi].status;for(ruleName in rules){opts=rules[ruleName];if(this._debugMode){this._debug("Loading rule '"+ruleName+"'")}try{if(this._isAMD&&!_isAMDRule(opts)){this._showIgnoredRule(`rule '${ruleName}' is not supported in AMD mode - ignored`);opts.enabled=false;continue}opts.enabled=typeof opts.enabled==="boolean"?opts.enabled:true;if(!opts.enabled){this._showIgnoredRule("rule '"+ruleName+"' is disabled - ignored");continue}if(opts._rsi===undefined){this._showIgnoredRule("rule '"+ruleName+"' does not belong to an active ruleset - ignored");opts.enabled=false;continue}if(opts.severity){if(typeof opts.severity!=="string"||!this._severity.isValidRuleSeverity(opts.severity)){this._showIgnoredRule("rule '"+ruleName+"' has invalid 'severity' of "+opts.severity+" - assuming default of '"+this._severity.DEFAULT+"'",true);opts.severity=this._severity.DEFAULT;opts.enabled=false}}else{opts.severity=this._severity.DEFAULT}if(opts.group){if(rsi&&!this._isGroupActive(opts.group)){this._showIgnoredRule("rule '"+ruleName+"' ignored by group");opts.enabled=false;continue}}if(!opts.status){opts.status="production"}if(!RULE_STATUS.includes(opts.status)){this._showIgnoredRule("rule '"+ruleName+"' invalid 'status' (i.e. not 'production', 'prod', 'ready', 'deprecated', 'beta', 'alpha'",true);opts.enabled=false;continue}if(!_isStatEnabledByPack(packStat,opts.status)){this._showIgnoredRule("rule '"+ruleName+"' status does not match rulepack status - ignored");opts.enabled=false;continue}if(opts.filetype){if(Array.isArray(opts.filetype)){for(j=0;j<opts.filetype.length;j++){opts.filetype[j]=opts.filetype[j].toLowerCase();if(FILE_TYPES.indexOf(opts.filetype[j])<0){this._showIgnoredRule("rule '"+ruleName+"' ignored by 'filetype' value '"+opts.filetype[j]+"'");opts.enabled=false;continue}}}else{if(FILE_TYPES.indexOf(opts.filetype)<0){this._showIgnoredRule("rule '"+ruleName+"' ignored by 'filetype' value '"+opts.filetype+"'");opts.enabled=false;continue}}}if(!ruleName.startsWith("jaf-")&&this._confNamedRules&&this._confNamedRules.length){if(!ruleNamesWild){ruleNamesWild=[];for(j=0;j<this._confNamedRules.length;j++){rn=this._confNamedRules[j];ruleNamesWild.push(_isRE(rn)?new RegExp(rn):null)}}for(j=0;j<this._confNamedRules.length;j++){if(this._confNamedRules.includes(ruleName)){break}rn=ruleNamesWild[j];if(rn){if(rn.test(ruleName)){break}}}if(j>=this._confNamedRules.length){this._showIgnoredRule(`rule '${ruleName}' ignored - excluded by config 'ruleNames'`);opts.enabled=false;continue}}if(opts.jetver){if(!this._semVer.match(opts.jetver)){this._showIgnoredRule(`rule '${ruleName}' ignored : 'jetVer' option is '${opts.jetver}' but metadata is '${this._semVer.getReference()}'`);opts.enabled=false;continue}}if(this._isCliOrApi){rulePath=this._rulesetSummary[opts._rsi].path;rulePath=this._nodeDeps.path.join(rulePath,ruleName+".js");ruleJS=this._nodeDeps.ruleLoader(rulePath)}else{ruleJS=this._nodeDeps.ruleLoader(ruleName,opts._rsi,this._error)}if(!ruleJS){continue}rule=ruleJS;if(ruleJS.prototype||!ruleJS.getName){try{rule=new ruleJS}catch(e){this._showIgnoredRule("rule '"+ruleName+"' "+e.message,true);rule=null;continue}}if(!opts.$internal){if(typeof rule.register!==FUNCTION){this._showIgnoredRule("rule '"+ruleName+"' ignored - has no register() method",true);opts.enabled=false;continue}}if(typeof rule.getName!==FUNCTION){this._showIgnoredRule("rule '"+ruleName+"' ignored - has no getName() method",true);opts.enabled=false;continue}if(typeof rule.getDescription!==FUNCTION){this._showIgnoredRule("rule '"+ruleName+"' ignored - has no getDescription() method",true);opts.enabled=false;continue}if(typeof rule.getShortDescription!==FUNCTION){this._showIgnoredRule("rule '"+ruleName+"' ignored - has no getShortDescription() method",true);opts.enabled=false;continue}if(ruleName!==rule.getName()){this._showIgnoredRule("[rule '"+ruleName+"' ignored - name '"+rule.getName()+"' does not match external name '"+ruleName+"'",true);opts.enabled=false;continue}if(!opts.$internal){this._registerCtx.ruleOpts=clone.cloneOptions(opts);if(opts.filetype){if(typeof opts.filetype==="string"&&opts.filetype==="js"||opts.filetype.includes("js")){this._registerCtx.jsNodeTypes=AstNodeTypes}}if(this._isCliOrApi){this._registerCtx.utils.fsUtils=this._nodeDeps.fsUtils;if(ruleName==="oj-html-cspexpr"){this._registerCtx.decache=this._nodeDeps.decache}}this._registerCtx.ruleName=ruleName;this._registerCtx.rulePack._setCBCtx(this._registerCtx);callbacks=rule.register(this._registerCtx);if(!callbacks){this._showIgnoredRule("rule '"+ruleName+"' has disabled itself during registration");opts.enabled=false;continue}for(callback in callbacks){if(callbacks[callback]){callbacks[callback]=callbacks[callback].bind(rule)}else{s="rule '"+ruleName+"' listener '"+callback+"' in register() is not defined - rule is disabled";this._error(s);this._showIgnoredRule(s);opts.enabled=false;continue}}if(_isHookRule(callbacks)){opts.$hook=true}else{if(!this._checkRuleSeverity(opts)){this._showIgnoredRule("rule '"+ruleName+"' ignored by severity");opts.enabled=false;continue}}}this._addToShadowRulePacks(ruleName,rule,opts);if(!opts.$internal){this._registry.setRuleCallback(ruleName,callbacks,opts._rsi)}this._ruleCount++}catch(e){atLine=e.stack.replace(rulePath,"").trim();i=NaN;if(atLine.startsWith(":")){i=parseInt(atLine.substr(1))}if(!isNaN(i)){atLine=" line "+i+": "}else{i=atLine.indexOf(":");if(i<0){atLine=""}else{atLine=this._utils.eatLine(atLine,i);i=atLine.indexOf(":");if(i>=0){atLine=atLine.substring(i+1);i=atLine.indexOf(")");if(i>=0){atLine="("+atLine.substring(0,i).replace(":",",")+") - "}}else{atLine=""}};}this._showIgnoredRule("cannot load rule "+ruleName+" ["+atLine+"'"+e.message+"']",true)}}}this._showIgnoredRule(null);return true};RuleSet.prototype._showIgnoredRule=function(msg,isError){if(msg){if(!this._ignoredRulesShown){this._info("\n--------- Start-up Rule analysis ---------");this._ignoredRulesShown=true}isError?this._error(msg):this._info(msg)}else if(this._ignoredRulesShown){this._info("------------ End Rule analysis -------------")}};RuleSet.prototype._mergeRuleOptions=function(rulesJson,isBuiltinRules){var prefix,rules,overrides,ruleName,opts,error,x;this._debug("Augmenting config defined rules in rulePack from ruleMods...");prefix=rulesJson.prefix;rules=rulesJson.rules;overrides=this._getRuleModsByPrefix(prefix);for(ruleName in rules){error=false;if(!isBuiltinRules){x=RESERVED_RULE_PREFIX.indexOf(ruleName.toLowerCase());if(x>=0){this._showIgnoredRule("rule '"+ruleName+"' in rulepack (prefix: '"+prefix+"') must not use JET reserved prefix '"+RESERVED_RULE_PREFIX[x]+"'",true);error=true}}if(overrides){if(error){continue}if(overrides[ruleName]&&rules[ruleName]){if(this._isAMD){opts=rules[ruleName];if(!_isAMDRule(opts)){if(this._debugMode){this._debug(`Rule options override ignored for non-AMD ${ruleName} in AMD mode`)}continue}if(!this._nodeDeps.ruleLoader(ruleName,opts._rsi,this._error)){continue}}if(this._debugMode){this._debug(`Merging rule props of ${ruleName}`)}this._mergeOverrideProps(ruleName,overrides[ruleName],rules[ruleName],isBuiltinRules)}}}};RuleSet.prototype._mergeOverrideProps=function(ruleName,configOpts,ruleOpts){var prop;for(prop in configOpts){if(prop.charAt(0)==="$"){delete configOpts[prop];this._showIgnoredRule("rule '"+ruleName+"' ignored - property '"+prop+"' in config 'rulesMod' property cannot use '$' prefix",true)}ruleOpts[prop]=configOpts[prop]}};RuleSet.prototype._addToShadowRulePacks=function(ruleName,loadedRule,ruleOpts){var rsi=ruleOpts._rsi;var srp=this._shadowRulePacks;while(rsi>=srp.length){srp.push({})}srp[rsi][ruleName]=loadedRule};RuleSet.prototype._getRuleModsByPrefix=function(prefix){var modPrefix,ret;if(this._ruleMods){prefix=prefix.toLowerCase();for(modPrefix in this._ruleMods){if(prefix===modPrefix.toLowerCase()){ret=this._ruleMods[modPrefix];break}}}return ret};RuleSet.prototype._isGroupActive=function(group){var groups,defs,def,i;groups=this._config.groups;defs=this._config.defGroups;if(this._checkGroups(groups,group)){return true}if(!defs){return false}for(i=0;i<groups.length;i++){def=groups[i];if(this._checkDefGroup(defs,def,group)){return true}}return false};RuleSet.prototype._checkGroups=function(cfgGroups,ruleGroup){var theGroup,i;if(Array.isArray(ruleGroup)){for(i=0;i<ruleGroup.length;i++){theGroup=ruleGroup[i];if(this._checkGroup(cfgGroups,theGroup)){return true}}}else if(this._checkGroup(cfgGroups,ruleGroup)){return true}return false};RuleSet.prototype._checkGroup=function(cfgGroups,group){return!cfgGroups||cfgGroups.includes(group)||cfgGroups.includes(this._severity.ALL)};RuleSet.prototype._isJetInRuleSet=function(jetPrefix){var i,ret=false;if(this._ruleSets&&this._ruleSets.length){for(i=0;i<this._ruleSets.length;i++){if(this._ruleSets[i].prefix===jetPrefix){ret=true;break}}}return ret};RuleSet.prototype._checkRuleSeverity=function(opts){var severities,severity,_sev,i,ret=false;severities=this._config.severity;severity=opts.severity;if(typeof severities==="string"){_sev=this._severity.getConfigSevExpr();if(_sev){ret=true}else{ret=severity===severities||severities===this._severity.ALL}}else{for(var i=0;i<severities.length;i++){if(severity===severities[i]||severities[i]===this._severity.ALL){ret=true;break}}}return ret};RuleSet.prototype._loadJson=function(filepath){var data,stats,msg;try{stats=this._nodeDeps.fs.lstatSync(filepath);if(!stats.isFile()){this._error("RuleSet '"+filepath+"' not found!");return null}else{data=this._nodeDeps.fs.readFileSync(filepath,"utf8");data=JSON.parse(this._nodeDeps.decomment(data))}}catch(e){if(e.code){if(e.message.startsWith("ENOENT:")){this._error("RuleSet error - '"+filepath+"' not found!")}}else if(e.toString().startsWith("SyntaxError")){msg=_convertMsgToRowCol(e.message,data,this._utils)}else{msg=e.message}if(msg){this._error("JSON load error '"+filepath+"' - "+msg)}data=null}return data};function _isStatEnabledByPack(pstat,rstat){var ret=false;if(pstat.includes("all")||pstat.includes(rstat)){ret=true}else{if(rstat==="ready"||rstat.startsWith("prod")){ret=pstat.includes("ready")||pstat.includes("production")||pstat.includes("prod")}}return ret};function _isHookRule(callbacks){return callbacks[REG.PHASE_STARTUP]||callbacks[REG.PHASE_CLOSEDOWN]||callbacks[REG.PHASE_FILE]?true:false};function _isAMDRule(opts){return opts.hasOwnProperty("amd")?!!opts.amd:true};function _convertMsgToRowCol(msg,data,utils){var x,n,rc;x=msg.indexOf("position");if(x<0){return msg}n=parseInt(msg.substr(x+8).trim());rc=utils.getRowColFromIndex(data,n);return msg.substr(0,x)+"line "+rc.row+", col "+rc.col};function _isRE(s){return RULE_RE.test(s)};module.exports=RuleSet;
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 REG=require("./RegTypes");const FILETYPE=require("./filetypes");const RULE_FILE="rules.json";const BUILTIN_RULES_PATH="../rules/";const BUILTIN_RULEPACK_PATH="../rulepacks/";const BUILTIN_ZIP_RULEPACK_PATH="../../jafrulepacks/";const JAF_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jaf";const JET_BUILTIN_RULES_PATH=BUILTIN_RULES_PATH+"jet";const SPOC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"spoc";const CSP_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"csp";const JETWC_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwc";const JETWCO_BUILTIN_RULES_PATH=BUILTIN_RULEPACK_PATH+"jetwco";const JET_MIN_VERSION="5.2.0";const TEMP_FILE_TEMPLATE="@@rpziptmp-XXXXXX";const PROP_$BUILTIN="$builtin";const RESERVED_RULE_PREFIX=["oj-","jaf-","csp-","spoc-","jetwc-","exch-","demo-"];const RESERVED_PACK_PREFIX=["JAF","JET","SPOC","CSP","JETWC","DEMO"];const NO_MSGID_PACKS=[];const RULE_STATUS=["prod","production","ready","beta","alpha","deprecated"];const FUNCTION="function";const COLON=":";const RULE_RE=new RegExp(/[~`!#$%\^&*+\[\]\\';,/{}|\\"\?]/,"g");const RulePack=require("./RulePack");const Registry=require("./Registry");const SemVer=require("./SemVer");const CssUtils=require("./CssUtils");const AstNodeTypes=require("./AstNodeTypes");const clone=require("./clone");var RuleSet=function(config,nodeDeps,appCtx,AMDRulePacks){this._config=config;this._ruleSets=config.getRulePacks();this._ruleMods=config.getRuleMods();this._ruleCount=0;this._AmdPacks=AMDRulePacks;this._appCtx=appCtx;this._nodeDeps=nodeDeps;this._isAMD=!!nodeDeps.AmdRulePackLoader;this._isCLI=appCtx.runMode==="cli";this._isCliOrApi=!this._isAMD;this._metaLib=appCtx.metaLib;this._utils=appCtx.utils;this._severity=appCtx.severity;this._tmpDir=appCtx.tmpDir;this._semVer=new SemVer;this._targFiletypes=[];this._useBuiltinRules=config._config.builtinJetRules;this._rulePacks=null;this._shadowRulePacks=null;this._rulesetSummary=[];this._registerCtx={sysOpts:{verboseMode:this._appCtx.verboseMode,debugMode:this._appCtx.debugMode}};this._registerCtx.utils={};this._registerCtx.utils.metaLib=this._metaLib;this._registerCtx.runMode=appCtx.runMode;this._registerCtx.VsCodeExtHint=appCtx.VsCodeExtHint;this._registerCtx.utils.semVerUtils=this._semVer;this._registerCtx.utils.utils=this._utils;this._registerCtx.utils.CssUtils=CssUtils;this._registerCtx.config=JSON.parse(JSON.stringify(this._config._config));this._registerCtx.error=appCtx.error;this._registerCtx.info=appCtx.info;this._registerCtx.msg=appCtx.msg;this._registerCtx.utils.msgLib={msg:appCtx.msg,error:appCtx.error,info:appCtx.info,debug:appCtx.debug,assert:appCtx.assert};this._registerCtx.utils.sevLib=this._severity.getSevLib();this._msg=appCtx.msg;this._info=appCtx.info;this._debug=appCtx.debug;this._error=appCtx.error;this._assert=appCtx.assert;this._debugMode=appCtx.debugMode;this._verboseMode=appCtx.verboseMode;if(!this._ruleSets){this._ruleSets=[]}let rsi=0;this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JAF_BUILTIN_RULES_PATH):null,"builtin":true});if(config._config.builtinJetRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":this._isCliOrApi?nodeDeps.path.join(__dirname,JET_BUILTIN_RULES_PATH):null,"builtin":true})}if(config._config.builtinCspRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,CSP_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWC_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinJetWcOracleRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,JETWCO_BUILTIN_RULES_PATH),"builtin":true})}if(!this._isAMD&&config._config.builtinSpocRules){this._ruleSets.splice(rsi++,0,{"enabled":true,"path":nodeDeps.path.join(__dirname,SPOC_BUILTIN_RULES_PATH),"builtin":true})}if(this._isAMD&&this._AmdPacks){let i,apack;for(i=0;i<this._AmdPacks.length;i++){apack=this._AmdPacks[i];this._ruleSets.splice(rsi++,0,{enabled:true,path:null,builtin:false,amdpack:apack})}}};RuleSet.prototype.loadRulePacks=function(config,isDryRun,isRuleDump){var ruleSet,rulePath,rulesJson,rulePack,rsi,rule,prefix,groups,gname,arules,j,k,s="",rulesetSummaryIndex=-1,spocFound,demoFound,errors=false,rc,ruleName,jetVersion;this._config=config;this._confSeverity=config._sev;this._confNamedRules=config.ruleNames;jetVersion=this._metaLib.getRevisionInfo().jetVersion;if(!this._semVer.setReference(jetVersion,JET_MIN_VERSION)){this._error(`JET metadata version ${jetVersion} not supported (less than ${JET_MIN_VERSION})`);return false}if(this._debugMode){this._debug(this._ruleSets?"Processing "+this._ruleSets.length+" Rule Sets":"No Rule Sets defined")}if(!this._ruleSets){return false}this._rulePacks=[];this._shadowRulePacks=[];for(rsi=0;rsi<this._ruleSets.length;rsi++){ruleSet=this._ruleSets[rsi];groups=null;try{if(typeof ruleSet.enabled==="boolean"&&!ruleSet.enabled){s+=(rsi?"\n":"")+" "+(rsi+1)+") "+"Disabled ruleSet at '"+ruleSet.path;continue}if(!ruleSet.status){ruleSet.status=["all"]}if(!this._isAMD){if(this._debugMode){let rname=ruleSet.path.endsWith("jaf")?"JAF":ruleSet.path.endsWith("jet")?"JET":ruleSet.name;this._debug("Ruleset '"+rname+"' path->'"+ruleSet.path+"'")}if(ruleSet.path.endsWith(".zip")){ruleSet.container=ruleSet.path;let tmpFile=this._nodeDeps.fsUtils.getUniqueFileName(TEMP_FILE_TEMPLATE);let tmpDir=this._nodeDeps.path.join(this._tmpDir,tmpFile);rc=this._nodeDeps.fsUtils.createFolder(tmpDir);if(typeof rc!=="boolean"){this._error(`Unable to create folder ${rc.message}`);break}var zipUtils=new this._nodeDeps.zipUtils;;rc=zipUtils.extractAll(tmpDir,ruleSet.container,true);if(typeof rc!=="boolean"){this._error(`Unable to extract from zip ('${rc.message}') : "${ruleSet.container}"`);break}ruleSet.path=tmpDir}rulePath=this._nodeDeps.path.join(ruleSet.path,RULE_FILE);rulesJson=this._loadJson(rulePath)}else{if(ruleSet.builtin){rulesJson=this._nodeDeps.AmdRulePackLoader(this._nodeDeps,rsi,ruleSet,this._error)}else if(ruleSet.amdpack){rulesJson=ruleSet.amdpack.rulesJson}}if(!rulesJson){continue}if(!rulesJson.title){rulesJson.title="unknown"}if(!rulesJson.version){rulesJson.version="0.0.0"}prefix=rulesJson.prefix;ruleSet.prefix=prefix;s+=(rsi?"\n":"")+" "+(rsi+1)+") "+rulesJson.title+"\n "+rulesJson.version+" : "+prefix+(ruleSet.builtin||ruleSet.amdpack?"":" -> "+(ruleSet.container?ruleSet.container:ruleSet.path));if(this._appCtx.isUnitTest&&!spocFound&&prefix==="SPOC"){ruleSet.builtin=true;if(prefix==="SPOC"){spocFound=true}if(prefix==="DEMO"){demoFound=true}}if(!demoFound&&prefix==="DEMO"){ruleSet.builtin=true;if(prefix==="DEMO"){demoFound=true}}if(!ruleSet.builtin){if(RESERVED_PACK_PREFIX.includes(prefix)){this._error("Rule pack at '"+rulePath+"' cannot use use reserved prefix '"+prefix+"'!");break}}for(j=0;j<this._rulesetSummary.length;j++){if(this._rulesetSummary[j].prefix===prefix){this._error("Rule pack prefix '"+prefix+"' at '"+rulePath+"' ignored - previously defined at '"+rulePack.path+"'");break}}if(j<this._rulesetSummary.length){continue}this._rulesetSummary.push({title:rulesJson.title,path:ruleSet.path,version:rulesJson.version,prefix:rulesJson.prefix,status:ruleSet.status,packData:ruleSet.packData});++rulesetSummaryIndex;for(ruleName in rulesJson.rules){rule=rulesJson.rules[ruleName];rule._rsi=rulesetSummaryIndex;if(this._ruleSets[rulesetSummaryIndex].builtin){rule[PROP_$BUILTIN]=true}if(rule.group){groups=groups||{};let rg=rule.group;if(typeof rg==="string"){arules=groups[rg];if(!arules){groups[rg]=arules=[]}arules.push(ruleName)}else if(Array.isArray(rg)){for(k=0;k<rg.length;k++){gname=rg[k];arules=groups[gname];if(!arules){groups[gname]=arules=[]}arules.push(ruleName)}}}}this._rulePacks.push({path:ruleSet.path,rulesJson:rulesJson});ruleSet.groupMap=groups;this._mergeRuleOptions(rulesJson,ruleSet.builtin)}catch(e){this._error(`Failure processing ruleset at '${rulePath}' (${e.message})`);errors=true}}if(s.length){this._info("[info]: ------ Rulepacks found: --------");this._info(s)}if(this._debugMode){this._debug("------ group mappings : --------");let self=this;this._ruleSets.forEach(s=>{self._debug(s.prefix+": "+(s.groupMap?JSON.stringify(s.groupMap,null,3):"none"))})}if(errors){return false}this._registry=new Registry(this._appCtx);this._postProcess_RuleMods();this._postProcess_RuleNames();if(!this._processRuleSets()){return false}if(config.options.debug&&!isRuleDump||config.options.verbose&&!isRuleDump||isDryRun){var f=isDryRun||config.options.verbose?this._info:this._debug;var rules,opts;if(this._ruleCount){f("\n-------- Active Rule Summmary --------");for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];f("\n ["+(rsi+1)+"] Rule Set '"+rulePack.rulesJson.title+"'");rules=rulePack.rulesJson.rules;let n=0;for(ruleName in rules){opts=rules[ruleName];if(opts.enabled){f("\n "+ruleName+" : "+JSON.stringify(this._utils.extend(opts)));n++}}if(!n){f("\n "+"No rules enabled in pack.")}}}}return!errors};RuleSet.prototype._postProcess_RuleMods=function(){var rs,rm,are,ard,count=0,n;rm=this._config.ruleMods;if(rm&&(rm.enable||rm.disable)){rs=this._ruleSets;are=rm.enable;if(are){n=_replaceGroups(are,rs);if(n){are=_removeDups(are);count+=n}}ard=rm.disable;if(ard){n=_replaceGroups(ard,rs);if(n){ard=_removeDups(ard);count+=n}}this._enableDisableGroupRules(are,ard)}return count};RuleSet.prototype._enableDisableGroupRules=function(are,ard){var ar,rname,packs,rules,rule,enable,m1,i,j,k;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Enabling rules found in ruleMods.enable ---");if(!are){this._info("* None found")}}packs=this._rulePacks;i=2;ar=are;enable=true;m1="enabled";while(i){if(ar){for(j=0;j<ar.length;j++){rname=ar[j];for(k=0;k<packs.length;k++){rules=packs[k];if(rules){rules=rules.rulesJson;if(rules){rule=rules.rules[rname];if(rule){if(!enable&&rule.$required){this._error(`rule '${rname}' is mandatory and cannot be disabled using config 'ruleMods.disable' property.`);continue}rule.enabled=enable;if(this._verboseMode||this._debugMode){this._info(` Rule ${rname} ${m1}`)}break}}}}}}if(enable){ar=ard;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Disabling rules found in ruleMods.disable ---");m1="disabled";if(!ard){this._info("* None found")}}if(!ard){return}}enable=false;i--}};RuleSet.prototype._postProcess_RuleNames=function(){var ret=0;if(this._verboseMode||this._debugMode){this._info("\n[Info]: --- Processing config ruleNames entries ---")}if(this._config.ruleNames){ret=_replaceGroups(this._config.ruleNames,this._ruleSets);this._config.ruleNames=_removeDups(this._config.ruleNames)}if(this._verboseMode||this._debugMode){this._info(`\n[Info]: ${ret} ruleNames group entr${ret===1?"y":"ies"} replaced ---`)}return ret};function _replaceGroups(ar,rs){var val,o,group,grules,rc=0,rsi,i;var replaced=[];for(i=0;i<ar.length;i++){val=ar[i];replaced.length=0;for(rsi=0;rsi<rs.length;rsi++){o=rs[rsi];if(o.groupMap){for(group in o.groupMap){if(group===val){grules=o.groupMap[group];replaced.push(...grules);break}}}}if(replaced.length){ar.splice(i,1,...replaced);i+=replaced.length-1;rc++}}return rc};function _removeDups(ar){return[...new Set(ar)]};RuleSet.prototype.dumpRegistry=function(){console.log("\n-------- Active Rule Type Listener Types --------");console.log(this._registry.dump())};RuleSet.prototype.getRulePacks=function(){return this._rulePacks};RuleSet.prototype.getRulePacksSummary=function(){return this._rulesetSummary};RuleSet.prototype.getShadowRulePacks=function(){return this._shadowRulePacks};RuleSet.prototype.getActiveRuleCount=function(){return this._ruleCount};RuleSet.prototype.getActiveFiletypes=function(){return this._targFiletypes?this._targFiletypes:[]};RuleSet.prototype.getRegistry=function(){return this._registry};RuleSet.prototype.getRulesetSummary=function(){return this._rulesetSummary};RuleSet.prototype.getRsiFromMsgId=function(msgId){var i,prefix,ret=-1;i=msgId.indexOf("-");prefix=i>=0?msgId.substring(0,i):msgId;if(this._rulesetSummary){for(i=0;i<this._rulesetSummary.length;i++){if(this._rulesetSummary[i].prefix===prefix){ret=i;break}}}return ret};RuleSet.prototype.loadMsgIds=function(){var msgObj,rp,rs,o,rsi,fpath,err;if(this._rulePacks&&this._rulePacks.length){for(rsi=0;rsi<this._rulePacks.length;rsi++){rp=this._rulePacks[rsi];rs=this._ruleSets[rsi];if(rs.builtin&&NO_MSGID_PACKS.includes(rs.prefix)){continue}if(rs.enabled){if(!msgObj){msgObj={}}o=null;try{if(this._isCliOrApi){fpath=this._nodeDeps.path.join(rp.path,"msgid.json");if(rs.builtin||this._nodeDeps.fsUtils.fileExists(fpath)){o=this._nodeDeps.msgidLoader(fpath,this._nodeDeps,this._appCtx)}}else{if(rs.builtin){o=this._nodeDeps.msgidLoader(this._nodeDeps,rsi,this._ruleSets[rsi],this._error)}else if(rs.amdpack&&rs.amdpack.msgid){o=rs.amdpack.msgid}}}catch(e){this._error(`'Failed to load ${rs.builtin?"built-in":"external"} rulepack msgid file : ${e.message}`);err=true;o=null}msgObj[rp.rulesJson.prefix]=o}}}return err?-1:msgObj};RuleSet.prototype.getLoadedRule=function(rsi,ruleName){return this._shadowRulePacks[rsi][ruleName]};RuleSet.prototype.getSemVer=function(){return this._semVer};RuleSet.prototype._processRuleSets=function(){var ruleName,ruleNamesWild,rulePack,rules,opts,ruleJS,rule,rulePath,packStat,rset,callbacks,callback,atLine,rn,rsi,s,i,j;for(rsi=0;rsi<this._rulePacks.length;rsi++){rulePack=this._rulePacks[rsi];rules=rulePack.rulesJson.rules;rulePack.rulePack=new RulePack(this._rulesetSummary,this._rulePacks,this._shadowRulePacks,rsi,this._appCtx);this._registerCtx.rulePack=rulePack.rulePack;packStat=this._rulesetSummary[rsi].status;for(ruleName in rules){opts=rules[ruleName];if(this._debugMode){this._debug(`Loading rule '${ruleName}'`)}if(opts.hasOwnProperty("inservice")){if(!opts.inservice){this._showIgnoredRule(`rule '${ruleName}' is not in service - ignored`);opts.enabled=false;continue}}try{if(this._isAMD){if(!_isAMDRule(opts)){this._showIgnoredRule(`rule '${ruleName}' is not supported in AMD mode - ignored`);opts.enabled=false;continue}}opts.enabled=typeof opts.enabled==="boolean"?opts.enabled:true;if(!opts.enabled){this._showIgnoredRule(`rule '${ruleName}' is disabled - ignored`);continue}if(opts._rsi===undefined){this._showIgnoredRule(`rule '${ruleName}' does not belong to an active ruleset - ignored`);opts.enabled=false;continue}if(opts.severity){if(typeof opts.severity!=="string"||!this._severity.isValidRuleSeverity(opts.severity)){this._showIgnoredRule(`rule '${ruleName}' has invalid 'severity' of ${opts.severity} - assuming default of '${this._severity.DEFAULT}'`,true);opts.severity=this._severity.DEFAULT;opts.enabled=false}}else{opts.severity=this._severity.DEFAULT}if(opts.group){if(rsi&&!this._isGroupActive(opts.group)){this._showIgnoredRule(`rule '${ruleName}' ignored by group`);opts.enabled=false;continue}}if(!opts.status){opts.status="production"}if(!RULE_STATUS.includes(opts.status)){this._showIgnoredRule(`rule '${ruleName}' invalid 'status' (i.e. not 'production', 'prod', 'ready', 'deprecated', 'beta', 'alpha'`,true);opts.enabled=false;continue}if(!_isStatEnabledByPack(packStat,opts.status)){this._showIgnoredRule(`rule '${ruleName}' status does not match rulepack status - ignored`);opts.enabled=false;continue}if(opts.filetype){if(Array.isArray(opts.filetype)){for(j=0;j<opts.filetype.length;j++){opts.filetype[j]=opts.filetype[j].toLowerCase();if(!FILETYPE.isFileTypeSupported(opts.filetype[j])){this._showIgnoredRule(`rule '${ruleName}' ignored by 'filetype' value '${opts.filetype[j]}'`);opts.enabled=false;continue}}}else{if(!FILETYPE.isFileTypeSupported(opts.filetype)){this._showIgnoredRule(`rule '${ruleName}' ignored by 'filetype' value '${opts.filetype}'`);opts.enabled=false;continue}}}if(!ruleName.startsWith("jaf-")&&this._confNamedRules&&this._confNamedRules.length){if(!ruleNamesWild){ruleNamesWild=[];for(j=0;j<this._confNamedRules.length;j++){rn=this._confNamedRules[j];ruleNamesWild.push(_isRE(rn)?new RegExp(rn):null)}}for(j=0;j<this._confNamedRules.length;j++){if(this._confNamedRules.includes(ruleName)){break}rn=ruleNamesWild[j];if(rn){if(rn.test(ruleName)){break}}}if(j>=this._confNamedRules.length){if(opts.$required){this._showIgnoredRule(`rule '${ruleName}' not excluded by config 'ruleNames'- rule is mandatory`)}else{this._showIgnoredRule(`rule '${ruleName}' ignored - excluded by config 'ruleNames'`);opts.enabled=false}continue}}if(opts.jetver){if(!this._semVer.match(opts.jetver)){this._showIgnoredRule(`rule '${ruleName}' ignored : 'jetVer' option is '${opts.jetver}' but metadata is '${this._semVer.getReference()}'`);opts.enabled=false;continue}}if(this._isCliOrApi){rulePath=this._rulesetSummary[opts._rsi].path;rulePath=this._nodeDeps.path.join(rulePath,ruleName+".js");ruleJS=this._nodeDeps.ruleLoader(rulePath)}else{rset=this._ruleSets[opts._rsi];if(rset.builtin){ruleJS=this._nodeDeps.ruleLoader(ruleName,opts._rsi,this._error)}else if(rset.amdpack){ruleJS=rset.amdpack.rules[ruleName]}}if(!ruleJS){continue}rule=ruleJS;if(rset&&rset.amdpack){try{rule=new ruleJS.default}catch(e){this._showIgnoredRule(`AMD rule '${ruleName}' ${e.message}`,true);rule=null;continue}}else{if(ruleJS.prototype||!ruleJS.getName){try{rule=new ruleJS}catch(e){this._showIgnoredRule(`rule '${ruleName}' ${e.message}`,true);rule=null;continue}}}if(!opts.$internal){if(typeof rule.register!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no register() method`,true);opts.enabled=false;continue}}if(typeof rule.getName!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getName() method`,true);opts.enabled=false;continue}if(typeof rule.getDescription!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getDescription() method`,true);opts.enabled=false;continue}if(typeof rule.getShortDescription!==FUNCTION){this._showIgnoredRule(`rule '${ruleName}' ignored - has no getShortDescription() method`,true);opts.enabled=false;continue}if(ruleName!==rule.getName()){this._showIgnoredRule(`rule '${ruleName}' ignored - name '${rule.getName()}' does not match external name '${ruleName}`,true);opts.enabled=false;continue}if(!opts.$internal){this._registerCtx.ruleOpts=clone.cloneOptions(opts);if(opts.filetype){if(typeof opts.filetype==="string"&&opts.filetype==="js"||opts.filetype.includes("js")){this._registerCtx.jsNodeTypes=AstNodeTypes}else if(typeof opts.filetype==="string"&&opts.filetype==="ts"||opts.filetype.includes("ts")){this._registerCtx.tsNodeTypes=AstNodeTypes}}if(this._isCliOrApi){this._registerCtx.utils.fsUtils=this._nodeDeps.fsUtils;if(ruleName==="oj-html-cspexpr"){this._registerCtx.decache=this._nodeDeps.decache}}this._registerCtx.ruleName=ruleName;this._registerCtx.rulePack._setCBCtx(this._registerCtx);callbacks=rule.register(this._registerCtx);if(!callbacks){this._showIgnoredRule(`rule '${ruleName}' has disabled itself during registration`);opts.enabled=false;continue}for(callback in callbacks){if(callbacks[callback]){callbacks[callback]=callbacks[callback].bind(rule)}else{s=`rule '${ruleName}' listener '${callback}' in register() is not defined - rule is disabled`;this._error(s);this._showIgnoredRule(s);opts.enabled=false;continue}}if(_isHookRule(callbacks)){opts.$hook=true}else{if(!this._checkRuleSeverity(opts)){this._showIgnoredRule(`rule '${ruleName}' ignored by severity`);opts.enabled=false;continue}}}this._addToShadowRulePacks(ruleName,rule,opts);if(!opts.$internal){this._registry.setRuleCallback(ruleName,callbacks,opts._rsi)}this._ruleCount++;this._updateTargetFiletypes(opts)}catch(e){atLine=e.stack.replace(rulePath,"").trim();i=NaN;if(atLine.startsWith(":")){i=parseInt(atLine.substr(1))}if(!isNaN(i)){atLine=" line "+i+": "}else{i=atLine.indexOf(":");if(i<0){atLine=""}else{atLine=this._utils.eatLine(atLine,i);i=atLine.indexOf(":");if(i>=0){atLine=atLine.substring(i+1);i=atLine.indexOf(")");if(i>=0){atLine="("+atLine.substring(0,i).replace(":",",")+") - "}}else{atLine=""}};}this._showIgnoredRule(`Cannot load rule ${ruleName} [${atLine} '${e.message}']`,true)}}}this._showIgnoredRule(null);return true};RuleSet.prototype._showIgnoredRule=function(msg,isError){if(msg){if(!this._ignoredRulesShown){this._info("\n--------- Start-up Rule analysis ---------");this._ignoredRulesShown=true}isError?this._error(msg):this._info(msg)}else if(this._ignoredRulesShown){this._info("------------ End Rule analysis -------------")}};RuleSet.prototype._mergeRuleOptions=function(rulesJson,isBuiltinRules){var prefix,rules,overrides,ruleName,opts,error,x;this._debug("Augmenting config defined rules in rulePack from ruleMods...");prefix=rulesJson.prefix;rules=rulesJson.rules;overrides=this._getRuleModsByPrefix(prefix);for(ruleName in rules){error=false;if(!isBuiltinRules){x=RESERVED_RULE_PREFIX.indexOf(ruleName.toLowerCase());if(x>=0){this._showIgnoredRule(`rule '${ruleName}' in rulepack (prefix: '${prefix}') must not use JET reserved prefix '${RESERVED_RULE_PREFIX[x]}'`,true);error=true}}if(overrides){if(error){continue}if(overrides[ruleName]&&rules[ruleName]){if(this._isAMD){opts=rules[ruleName];if(!_isAMDRule(opts)){if(this._debugMode){this._debug(`Rule options override ignored for non-AMD ${ruleName} in AMD mode`)}continue}if(!this._nodeDeps.ruleLoader(ruleName,opts._rsi,this._error)){continue}}if(this._debugMode){this._debug(`Merging rule props of ${ruleName}`)}this._mergeOverrideProps(ruleName,overrides[ruleName],rules[ruleName],isBuiltinRules)}}}};RuleSet.prototype._mergeOverrideProps=function(ruleName,configOpts,ruleOpts){var prop;for(prop in configOpts){if(prop.charAt(0)==="$"){delete configOpts[prop];this._showIgnoredRule(`rule '${ruleName}' : '${prop}' in config 'rulesMod' cannot use reserved '$' prefix`,true);continue}if(prop==="enabled"&&!configOpts[prop]&&ruleOpts["$required"]){this._showIgnoredRule(`rule '${ruleName}' is mandatory and cannot be disabled using config 'ruleMods' property.`,true);continue}ruleOpts[prop]=configOpts[prop]}};RuleSet.prototype._addToShadowRulePacks=function(ruleName,loadedRule,ruleOpts){var rsi=ruleOpts._rsi;var srp=this._shadowRulePacks;while(rsi>=srp.length){srp.push({})}srp[rsi][ruleName]=loadedRule};RuleSet.prototype._updateTargetFiletypes=function(opts){var ft=opts.filetype;if(ft){if(typeof ft==="string"){ft=[ft]}ft.forEach(t=>{if(!opts.$internal){if(!this._targFiletypes.includes(t)){this._targFiletypes.push(t)}}},this)}};RuleSet.prototype._getRuleModsByPrefix=function(prefix){var modPrefix,ret;if(this._ruleMods){prefix=prefix.toLowerCase();for(modPrefix in this._ruleMods){if(prefix===modPrefix.toLowerCase()){ret=this._ruleMods[modPrefix];break}}}return ret};RuleSet.prototype._isGroupActive=function(group){var groups,defs,def,i;groups=this._config.groups;defs=this._config.defGroups;if(this._checkGroups(groups,group)){return true}if(!defs){return false}for(i=0;i<groups.length;i++){def=groups[i];if(this._checkDefGroup(defs,def,group)){return true}}return false};RuleSet.prototype._checkGroups=function(cfgGroups,ruleGroup){var theGroup,i;if(Array.isArray(ruleGroup)){for(i=0;i<ruleGroup.length;i++){theGroup=ruleGroup[i];if(this._checkGroup(cfgGroups,theGroup)){return true}}}else if(this._checkGroup(cfgGroups,ruleGroup)){return true}return false};RuleSet.prototype._checkGroup=function(cfgGroups,group){return!cfgGroups||cfgGroups.includes(group)||cfgGroups.includes(this._severity.ALL)};RuleSet.prototype._isJetInRuleSet=function(jetPrefix){var i,ret=false;if(this._ruleSets&&this._ruleSets.length){for(i=0;i<this._ruleSets.length;i++){if(this._ruleSets[i].prefix===jetPrefix){ret=true;break}}}return ret};RuleSet.prototype._checkRuleSeverity=function(opts){var severities,severity,_sev,i,ret=false;severities=this._config.severity;severity=opts.severity;if(typeof severities==="string"){_sev=this._severity.getConfigSevExpr();if(_sev){ret=true}else{ret=severity===severities||severities===this._severity.ALL}}else{for(var i=0;i<severities.length;i++){if(severity===severities[i]||severities[i]===this._severity.ALL){ret=true;break}}}return ret};RuleSet.prototype._loadJson=function(filepath){var data,stats,msg;try{stats=this._nodeDeps.fs.lstatSync(filepath);if(!stats.isFile()){this._error(`RuleSet '${filepath}' not found!`);return null}else{data=this._nodeDeps.fs.readFileSync(filepath,"utf8");data=JSON.parse(this._nodeDeps.decomment(data))}}catch(e){if(e.code){if(e.message.startsWith("ENOENT:")){this._error(`RuleSet error - '${filepath}' not found!`)}}else if(e.toString().startsWith("SyntaxError")){msg=_convertMsgToRowCol(e.message,data,this._utils)}else{msg=e.message}if(msg){this._error(`JSON load error '${filepath}' - ${msg}`)}data=null}return data};function _isStatEnabledByPack(pstat,rstat){var ret=false;if(pstat.includes("all")||pstat.includes(rstat)){ret=true}else{if(rstat==="ready"||rstat.startsWith("prod")){ret=pstat.includes("ready")||pstat.includes("production")||pstat.includes("prod")}}return ret};function _isHookRule(callbacks){return callbacks[REG.PHASE_STARTUP]||callbacks[REG.PHASE_CLOSEDOWN]||callbacks[REG.PHASE_FILE]?true:false};function _isAMDRule(opts){return opts.hasOwnProperty("amd")?!!opts.amd:true};function _convertMsgToRowCol(msg,data,utils){var x,n,rc;x=msg.indexOf("position");if(x<0){return msg}n=parseInt(msg.substr(x+8).trim());rc=utils.getRowColFromIndex(data,n);return msg.substr(0,x)+"line "+rc.row+", col "+rc.col};function _isRE(s){return RULE_RE.test(s)};module.exports=RuleSet;
package/lib/Rules.js CHANGED
@@ -1 +1,6 @@
1
- const RuleContext=require("./RuleContext");const REG=require("../lib/RegTypes");const PROP_FILETYPE="filetype";const FILETYPE_CSS="css";const NL="\n";var _builtinJetRules=null;var Rules=function(ruleSets,nodeDeps,config,fnMsgId,appCtx){this._appCtx=appCtx;this._msg=appCtx.msg;this._info=appCtx.info;this._debug=appCtx.debug;this._error=appCtx.error;this._assert=appCtx.assert;this._metaLib=appCtx.metaLib;this._reporter=appCtx.reporter;this._Issue=appCtx.Issue;this._semVer=ruleSets.getSemVer();this._utils=appCtx.utils;this._sevLib=appCtx.severity.getSevLib();this._registry=ruleSets.getRegistry();this._ruleCount=ruleSets.getActiveRuleCount();this._rulesetSummary=ruleSets.getRulesetSummary();this._rulePacks=ruleSets.getRulePacks();this._common=this._createCommon();this._shadowRulePacks=ruleSets.getShadowRulePacks();this._ruleSets=ruleSets;this._rulesFired=0;this._hooksFired=0;this._useBuiltinJetRules=true;this._config=config;this._nodeDeps=nodeDeps;this._isNode=!!nodeDeps.fs;this._curFile=null;this._getMsgId=fnMsgId;this._sysOpts={verboseMode:appCtx.verboseMode,debugMode:appCtx.debugMode};this._message={msg:this._msg,info:this._info,debug:this._debug,error:this._error,assert:this._assert}};Rules.prototype.fireRules=function(ruleCtx,arg1,filepath,filetype,arg2,isEmbeddedCss){var ruleName,callbacks,typeObj;if(this._curFile!==filepath){this._curFile=filepath;this._fileType=filetype}typeObj=this._registry.getRegisteredCallbacks(ruleCtx.type);if(typeObj){for(ruleName in typeObj){if(this._isRuleDisabledByComment&&this._isRuleDisabledByComment(ruleName)){continue}callbacks=typeObj[ruleName];this._fireRulePreTest(ruleCtx,ruleName,arg1,filepath,arg2,isEmbeddedCss,callbacks)}}};Rules.prototype.setJafLib=function(jl){this._jafLib=jl};Rules.prototype._fireRulePreTest=function(ruleCtx,ruleName,arg1,filepath,arg2,isEmbeddedCss,callbacks){var opts,callback,fileType,i;if(!callbacks){return}for(i=0;i<callbacks.length;i++){callback=callbacks[i];opts=this._getRuleOptionsByName(ruleName,callback.rsi);if(!opts.enabled){return}fileType=opts[PROP_FILETYPE];if(fileType){if(isEmbeddedCss&&!this._isFileTypeOk(fileType,FILETYPE_CSS)){return}if(!this._isFileTypeOk(fileType,this._fileType)){return}}ruleCtx._rsi=callback.rsi;ruleCtx.getMsgId=this._getMsgId;this._fireRule(ruleCtx,ruleName,arg1,arg2,filepath,fileType,callback.cb)}};Rules.prototype._fireRule=function(ruleCtx,ruleName,name,value,filepath,filetype,callback){var rule,msg,ctxType;ctxType=ruleCtx.type;this._debug("Firing rule "+ruleName+" type="+ctxType+" name="+name+" value="+value);rule=this._getRuleByName(ruleName,ruleCtx._rsi);if(!rule){return}ruleCtx.Issue=this._Issue;ruleCtx.reporter=this._reporter;ruleCtx.filepath=filepath;ruleCtx.filetype=filetype;ruleCtx.utils=ruleCtx.utils?ruleCtx.utils:{};ruleCtx.msgLib=this._message;ruleCtx.message=this._message;ruleCtx.ruleName=ruleName;ruleCtx.rulePack=this._rulePacks[ruleCtx._rsi].rulePack;ruleCtx.sysOpts=this._sysOpts;ruleCtx.common=this._common[ruleCtx._rsi];ruleCtx.userDefs=this._config.userDefs;ruleCtx.utils.utils=this._utils;ruleCtx.utils.fsUtils=this._nodeDeps.fsUtils;ruleCtx.utils.metaLib=this._metaLib;ruleCtx.utils.msgLib=this._message;ruleCtx.utils.sevLib=this._sevLib;if(filetype==="html"||filetype==="json"||ruleCtx.type.includes("json")){ruleCtx.utils.semVerUtils=this._semVer}ruleCtx.utils.jafLib=this._jafLib.getJafLib();this._curCtx=ruleCtx;try{if(callback){ruleCtx.rulePack._setCBCtx(ruleCtx);if((ctxType==="attr"||ctxType==="attrexpr"||ctxType==="class"||ctxType==="style")&&typeof value!=="string"){if(ctxType==="style"){callback(ruleCtx,name,_extractStyles(value.val),value.rawval)}else{callback(ruleCtx,name,value.val,value.rawval)}}else if(ctxType.startsWith("compjson")||ctxType==="comment"){callback(ruleCtx,value)}else{callback(ruleCtx,name,value)}this._rulesFired++}else{rule.run(ruleCtx,name,value)}}catch(e){msg=!e||!e.message?"Unknown error (rule JS syntax issue?)":e.message;this._error("** running rule "+ruleName+" ["+msg+"]"+"\n - "+ruleCtx.filepath);this._error(e.stack)}};Rules.prototype.makeRuleContext=function(){return new RuleContext};Rules.prototype.isTypeRegistered=function(regType){return this._registry.isRegisteredCallback(regType)};Rules.prototype.setJSCommentCallback=function(fnCB){this._isRuleDisabledByComment=fnCB};Rules.prototype.filterHtmlCallbacks=function(htmlCB){return htmlCB};Rules.prototype.getRulesProse=function(isInternal){var prose,rulePacks,rulePack,rules,ruleName,rsi,opts,haveRules;var indent=4,spacer=" ".repeat(indent),spacer2=" ".repeat(indent+3),spacer3=" ".repeat(indent+5);prose="\n------------ Rules Currently Active (rule severity: "+this._config.severity+") ---------------\n";rulePacks=this._rulePacks;for(rsi=0;rsi<rulePacks.length;rsi++){rulePack=rulePacks[rsi];rules=rulePack.rulesJson;prose+="["+(rsi+1)+"] "+rules.title+NL;prose+=spacer+"version : "+rules.version+NL;prose+=spacer+"prefix : "+rules.prefix+NL;prose+=spacer+"path : "+rulePack.path+NL;haveRules=false;rules=rules.rules;for(ruleName in rules){if(!rules[ruleName].enabled){continue}prose+=!haveRules?spacer+"Rules:"+NL:"";opts=this._utils.extend(rules[ruleName],isInternal);prose+=spacer2+"* "+ruleName+" :"+NL;prose+=spacer3+"options : "+JSON.stringify(opts)+NL;prose+=spacer3+"short : "+this._shadowRulePacks[rsi][ruleName].getShortDescription()+NL;prose+=spacer3+"long : "+this._shadowRulePacks[rsi][ruleName].getDescription()+NL;haveRules=true}if(!haveRules){prose+="* No enabled rules available for this severity."}prose+=NL}return prose+NL};Rules.prototype.getRulesJson=function(obj){var rulePacks,rulePack,ruleset,rulesJson,rules,ruleName,ruleOpts,opts,rsi;obj=obj||{};obj.rulesets=[];rulePacks=this._rulePacks;for(rsi=0;rsi<rulePacks.length;rsi++){rulePack=rulePacks[rsi];ruleset={};obj.rulesets.push(ruleset);ruleset.title=rulePack.rulesJson.title;ruleset.path=rulePack.path;ruleset.prefix=rulePack.rulesJson.prefix;ruleset.version=rulePack.rulesJson.version;ruleset.rules=rules={};rulesJson=rulePack.rulesJson;for(ruleName in rulesJson.rules){ruleOpts=rulesJson.rules[ruleName];if(!ruleOpts.enabled){continue}rules[ruleName]=opts=this._utils.extend(ruleOpts);opts.shortDescription=this._shadowRulePacks[rsi][ruleName].getShortDescription();opts.description=this._shadowRulePacks[rsi][ruleName].getDescription()}}obj.meta={"severity":this._config.severity};return obj};Rules.prototype.getRulesSonar=function(){var rulePacks,rulePack,ruleName,rules,rule,rsi,options,opt,val,i;var indent=" ";var indent2=" ";var indent3=" ";var xml="\n<rules>\n";rulePacks=this._rulePacks;for(rsi=0;rsi<rulePacks.length;rsi++){rulePack=rulePacks[rsi];rules=rulePack.rulesJson.rules;for(ruleName in rules){if(!rules[ruleName].enabled){continue}rule=this._shadowRulePacks[rsi][ruleName];xml+=indent+"<rule>\n";xml+=indent2+"<key>"+ruleName+"</key>\n";xml+=indent2+"<name>"+_escapeChevrons(rule.getShortDescription())+"</name>\n";xml+=indent2+"<description>\n";xml+=indent3+"<![CDATA["+_escapeCData(rule.getDescription())+"]]>\n";xml+=indent2+"</description>\n";options=rules[ruleName];for(opt in options){val=options[opt];if(opt==="severity"){xml+=indent2+"<severity>"+val.toUpperCase()+"</severity>\n"}else if(opt==="status"){val=val.toUpperCase();val=val==="PRODUCTION"?"READY":val;xml+=indent2+"<status>"+val+"</status>\n"}else if(opt==="group"){if(typeof val==="string"){xml+=indent2+"<tag>"+val+"</tag>\n"}else{for(i=0;i<val.length;i++){xml+=indent2+"<tag>"+val[i]+"</tag>\n"}}}}xml+=indent+"</rule>\n"}}xml+="</rules>";return xml};Rules.prototype.getRuleOptions=function(ruleName,rsi){return this._getRuleOptionsByName(ruleName,rsi)};Rules.prototype.getActiveRuleCount=function(){return this._ruleCount};Rules.prototype.getRuleSetSummaryByIndex=function(rsi){return this._rulesetSummary[rsi]};Rules.prototype.getRulePack=function(rsi){return this._rulePacks[rsi].rulePack};Rules.prototype.getRSIByPrefix=function(prefix){var i,rsi=-1;;for(i=0;i<this._rulesetSummary.length;i++){if(this._rulesetSummary[i].prefix===prefix){rsi=i;break}}return rsi};Rules.prototype.isRuleEnabled=function(ruleName,rsi){if(rsi===undefined){rsi=this.getRSIByRuleName(ruleName);if(rsi<0){return false}}var opts=this._getRuleOptionsByName(ruleName,rsi);return!!(opts&&opts.enabled)};Rules.prototype.getRSIByRuleName=function(ruleName){var rsi,rp,len;len=this._shadowRulePacks.length;for(rsi=0;rsi<len;rsi++){rp=this._shadowRulePacks[rsi];if(rp[ruleName]){break}}return rsi<len?rsi:-1};Rules.prototype.getRuleDescription=function(prefix,ruleName,isShort){var rule,rsi,ret="";rsi=this.getRSIByPrefix(prefix);if(rsi>=0){rule=this._shadowRulePacks[rsi][ruleName];if(rule){ret=isShort?rule.getShortDescription():rule.getDescription()}}return ret};Rules.prototype.getRuleDescriptionEx=function(msgId,ruleName,isShort){var descrip,rule,prefix,msgNum,rsi,msgTab,msgIds,mid,rules,sev,x;if(ruleName){var rp=this._shadowRulePacks;for(rsi=0;rsi<rp.length;rsi++){rule=rp[rsi][ruleName];if(rule){descrip=isShort?rule.getShortDescription():rule.getDescription();if(descrip){break}}}}if(msgId){rsi=this._ruleSets.getRsiFromMsgId(msgId);if(rsi>=0){x=msgId.indexOf("-");prefix=msgId.substring(0,x);msgNum=msgId.substring(x+1);msgTab=this._ruleSets.loadMsgIds();msgIds=msgTab[prefix];for(mid in msgIds){if(msgIds[mid]===msgNum){rules=this._shadowRulePacks[rsi];for(ruleName in rules){x=mid.replace(ruleName,"");if(x.length>0){if(x.startsWith("_")){if(isNaN(x.substring(1))){continue}}}descrip=this.getRuleDescription(prefix,ruleName,isShort)}break}}}}if(ruleName){sev=this._getRuleOptionsByName(ruleName,rsi);sev=sev?sev.severity:""}return{descrip:descrip,rule:ruleName,sev:sev}};Rules.prototype.getRulesFired=function(){return this._rulesFired};Rules.prototype.getHooksFired=function(){return this._hooksFired};Rules.prototype._showIgnoredRule=function(msg,isError){if(msg){if(!this._ignoredRulesShown){this._info("\n--------- Start-up Rule analysis ---------");this._ignoredRulesShown=true}isError?this._error(msg):this._info(msg)}else if(this._ignoredRulesShown){this._info("------------ End Rule analysis -------------")}};Rules.prototype.fireHookRules=function(ruleCtx,rsi){var ruleName,typeObj,callbacks,callback,opts,rc,i;var _rsi;ruleCtx.Issue=this._Issue;ruleCtx.reporter=this._reporter;ruleCtx.metaLib=this._metaLib;ruleCtx.msgLib=this._message;ruleCtx.message=this._message;_rsi=rsi;typeObj=this._registry.getRegisteredCallbacks(ruleCtx.type);if(!typeObj){return}for(ruleName in typeObj){callbacks=typeObj[ruleName];if(!callbacks){continue}for(i=0;i<callbacks.length;i++){callback=callbacks[i];if(rsi===undefined){_rsi=callback.rsi}else{if(rsi!==callback.rsi){continue}_rsi=rsi}opts=this._getRuleOptionsByName(ruleName,_rsi);if(ruleCtx.type==="file"||ruleCtx.type==="startscript"){if(opts&&opts.filetype){if(!this._isFileTypeOk(opts.filetype,ruleCtx.filetype)){continue}}}ruleCtx.ruleName=ruleName;ruleCtx.rulePack=this._rulePacks[_rsi].rulePack;ruleCtx._rsi=_rsi;ruleCtx.common=this._common[_rsi];ruleCtx.userDefs=this._config.userDefs;ruleCtx.utils.metaLib=this._metaLib;ruleCtx.utils.utils=this._utils;ruleCtx.utils.fsUtils=this._nodeDeps.fsUtils;ruleCtx.utils.msgLib=this._message;ruleCtx.utils.semverUtils=this._semVer;ruleCtx.sysOpts=this._sysOpts;ruleCtx.getMsgId=this._getMsgId;this._debug("Firing hook rule "+ruleName+" type="+ruleCtx.type);ruleCtx.rulePack._setCBCtx(ruleCtx);rc=callback.cb(ruleCtx);this._hooksFired++;if((ruleCtx.phase===REG.STARTUP||ruleCtx.phase===REG.PHASE_FILE)&&typeof rc==="boolean"&&!rc){this._info("Hook rule ('"+ruleCtx.type+"') veto! by '"+ruleName+"'");return rc}}}return true};Rules.prototype._getRuleByName=function(ruleName,rsi){var rs=this._shadowRulePacks[rsi];return rs[ruleName]};Rules.prototype._getRuleOptionsByName=function(ruleName,rsi){var rulePack=this._rulePacks[rsi];return rulePack.rulesJson.rules[ruleName]};Rules.prototype._isGroupActive=function(group){var groups,defs,def,i;groups=this._config.groups;defs=this._config.defGroups;if(this._checkGroups(groups,group)){return true}if(!defs){return false}for(i=0;i<groups.length;i++){def=groups[i];if(this._checkDefGroup(defs,def,group)){return true}}return false};Rules.prototype._loadBuiltinJetRulesDescriptions=function(){var ruleName,rules;try{if(!_builtinJetRules){_builtinJetRules=require("../rules/jet/rules.json")}}catch(e){this._error("Unable to load builtin rule definition file "+e)}if(_builtinJetRules&&_builtinJetRules.rules){rules=_builtinJetRules.rules;for(ruleName in rules){rules[ruleName].$builtin=true}}return _builtinJetRules};Rules.prototype._isFileTypeOk=function(ruleFileType,fileType){var ret=false;if(Array.isArray(ruleFileType)){ret=ruleFileType.indexOf(fileType)>=0}else{ret=ruleFileType===fileType}return ret};Rules.prototype._createCommon=function(){var i,a=[];for(i=0;i<this._rulesetSummary.length;i++){a.push({})}return a};function _escapeChevrons(s){var ret;ret=s.replace(/\</g,"&lt;");ret=ret.replace(/\>/g,"&gt;");return ret};function _escapeCData(s){var i,bChange;while(true){bChange=false;i=s.indexOf("<oj-");if(i>=0){s=s.substr(0,i)+"&lt;"+s.substr(i+1);bChange=true;i=s.indexOf(">",i+1);if(i>=0){s=s.substr(0,i)+"&gt;"+s.substr(i+1)}i=s.indexOf("</oj-",i);if(i>=0){s=s.substr(0,i)+"&lt;"+s.substr(i+1);bChange=true;i=s.indexOf(">",i+1);if(i>=0){s=s.substr(0,i)+"&gt;"+s.substr(i+1)}}}i=s.indexOf("<!DOCTYPE");if(i>=0){s=s.substr(0,i)+"&lt;"+s.substr(i+1);i=s.indexOf(">",i+1);if(i>=0){s=s.substr(0,i)+"&gt;"+s.substr(i+1);bChange=true}}if(!bChange){break}}return s};function _extractStyles(s){var a,isExpr,i,sc=";";s=s.trim();isExpr=_isExpr(s);s=s.replace(/[\'\"\[\]\{\}]/g,"").trim();if(!s.includes(";")){if(isExpr){if(s.includes(",")){sc=","}}}a=s.split(sc);for(i=0;i<a.length;i++){a[i]=a[i].trim();if(!a[i].length){a.splice(i,1);i--}}return a};function _isExpr(s){s=s.trim();return s.startsWith("[[")||s.startsWith("{{")};module.exports=Rules;
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 RuleContext=require("./RuleContext");const REG=require("../lib/RegTypes");const PROP_FILETYPE="filetype";const FILETYPE_CSS="css";var _builtinJetRules=null;var Rules=function(ruleSets,nodeDeps,config,fnMsgId,appCtx){this._appCtx=appCtx;this._msg=appCtx.msg;this._info=appCtx.info;this._debug=appCtx.debug;this._error=appCtx.error;this._assert=appCtx.assert;this._metaLib=appCtx.metaLib;this._reporter=appCtx.reporter;this._Issue=appCtx.Issue;this._semVer=ruleSets.getSemVer();this._utils=appCtx.utils;this._sevLib=appCtx.severity.getSevLib();this._registry=ruleSets.getRegistry();this._ruleCount=ruleSets.getActiveRuleCount();this._rulesetSummary=ruleSets.getRulesetSummary();this._rulePacks=ruleSets.getRulePacks();this._common=this._createCommon();this._shadowRulePacks=ruleSets.getShadowRulePacks();this._ruleSets=ruleSets;this._Stats=appCtx.Stats;this._isUnitTest=appCtx.isUnitTest;if(this._isUnitTest||config.rulesFired){this._Stats.packRulesFired=[];for(let i=0;i<ruleSets._ruleSets.length;i++)this._Stats.packRulesFired.push({pack:ruleSets._ruleSets[i].prefix,rules:{}})}this._useBuiltinJetRules=true;this._config=config;this._nodeDeps=nodeDeps;this._isNode=!!nodeDeps.fs;this._curFile=null;this._getMsgId=fnMsgId;this._sysOpts={verboseMode:appCtx.verboseMode,debugMode:appCtx.debugMode};this._message={msg:this._msg,info:this._info,debug:this._debug,error:this._error,assert:this._assert}};Rules.prototype.fireRules=function(ruleCtx,arg1,filepath,filetype,arg2,isEmbeddedCss){var ruleName,callbacks,typeObj;if(this._curFile!==filepath){this._curFile=filepath;this._fileType=filetype}typeObj=this._registry.getRegisteredCallbacks(ruleCtx.type);if(typeObj){for(ruleName in typeObj){if(this._isRuleDisabledByComment&&this._isRuleDisabledByComment(ruleName)){continue}callbacks=typeObj[ruleName];this._fireRulePreTest(ruleCtx,ruleName,arg1,filepath,arg2,isEmbeddedCss,callbacks)}}};Rules.prototype.setJafLib=function(jl){this._jafLib=jl};Rules.prototype._fireRulePreTest=function(ruleCtx,ruleName,arg1,filepath,arg2,isEmbeddedCss,callbacks){var opts,callback,fileType,i;if(!callbacks){return}for(i=0;i<callbacks.length;i++){callback=callbacks[i];opts=this._getRuleOptionsByName(ruleName,callback.rsi);if(!opts.enabled){return}fileType=opts[PROP_FILETYPE];if(fileType){if(isEmbeddedCss&&!this._isFileTypeOk(fileType,FILETYPE_CSS)){return}if(!this._isFileTypeOk(fileType,this._fileType)){return}}ruleCtx._rsi=callback.rsi;ruleCtx.getMsgId=this._getMsgId;this._fireRule(ruleCtx,ruleName,arg1,arg2,filepath,fileType,callback.cb)}};Rules.prototype._fireRule=function(ruleCtx,ruleName,name,value,filepath,filetype,callback){var rule,msg,ctxType,oFired;ctxType=ruleCtx.type;this._debug("Firing rule "+ruleName+" type="+ctxType+" name="+name+" value="+value);rule=this._getRuleByName(ruleName,ruleCtx._rsi);if(!rule){return}ruleCtx.Issue=this._Issue;ruleCtx.reporter=this._reporter;ruleCtx.filepath=filepath;ruleCtx.filetype=filetype;ruleCtx.utils=ruleCtx.utils?ruleCtx.utils:{};ruleCtx.msgLib=this._message;ruleCtx.message=this._message;ruleCtx.ruleName=ruleName;ruleCtx.rulePack=this._rulePacks[ruleCtx._rsi].rulePack;ruleCtx.sysOpts=this._sysOpts;ruleCtx.common=this._common[ruleCtx._rsi];ruleCtx.userDefs=this._config.userDefs;ruleCtx.utils.utils=this._utils;ruleCtx.utils.fsUtils=this._nodeDeps.fsUtils;ruleCtx.utils.metaLib=this._metaLib;ruleCtx.utils.msgLib=this._message;ruleCtx.utils.sevLib=this._sevLib;if(filetype==="html"||filetype==="json"||ruleCtx.type.includes("json")){ruleCtx.utils.semVerUtils=this._semVer}ruleCtx.utils.jafLib=this._jafLib.getJafLib();this._curCtx=ruleCtx;try{if(callback){ruleCtx.rulePack._setCBCtx(ruleCtx);if((ctxType==="attr"||ctxType==="attrexpr"||ctxType==="class"||ctxType==="style")&&typeof value!=="string"){if(ctxType==="style"){callback(ruleCtx,name,_extractStyles(value.val),value.rawval)}else{callback(ruleCtx,name,value.val,value.rawval)}}else if(ctxType.startsWith("compjson")||ctxType==="comment"){callback(ruleCtx,value)}else{callback(ruleCtx,name,value)}this._Stats.rulesFired++;if(this._isUnitTest||this._config.rulesFired){if(oFired=this._Stats.packRulesFired[ruleCtx._rsi]){oFired=oFired.rules;if(oFired[ruleName]){oFired[ruleName]++}else{oFired[ruleName]=1}}}}else{rule.run(ruleCtx,name,value)}}catch(e){msg=!e||!e.message?"Unknown error (rule "+this._getFileSuffix(ruleCtx.filepath)+" syntax issue?)":e.message;this._error("** running rule "+ruleName+" ["+msg+"]"+"\n - "+ruleCtx.filepath);this._error(e.stack)}};Rules.prototype.makeRuleContext=function(){return new RuleContext};Rules.prototype.isTypeRegistered=function(regType){return this._registry.isRegisteredCallback(regType)};Rules.prototype.setJSCommentCallback=function(fnCB){this._isRuleDisabledByComment=fnCB};Rules.prototype.filterHtmlCallbacks=function(htmlCB){return htmlCB};Rules.prototype.getRulesProse=function(isInternal){var rulePacks,rulePack,rules,rule,ruleName,rsi,opts,haveRules;this._nodeDeps.exportRules.setupRulesToProse(this._config.severity,this._utils);rulePacks=this._rulePacks;for(rsi=0;rsi<rulePacks.length;rsi++){rulePack=rulePacks[rsi];rules=rulePack.rulesJson;this._nodeDeps.exportRules.packToProse(rules,rulePack.path,rsi);haveRules=false;rules=rules.rules;for(ruleName in rules){if(!rules[ruleName].enabled){continue}opts=this._utils.extend(rules[ruleName],isInternal);rule=this._shadowRulePacks[rsi][ruleName];this._nodeDeps.exportRules.ruleToProse(ruleName,rule,opts);haveRules=true}if(!haveRules){this._nodeDeps.exportRules.packToProse()}}return this._nodeDeps.exportRules.getProse()};Rules.prototype.getRulesJson=function(obj){var rulePacks,rulePack,rulesJson,ruleName,rule,ruleOpts,opts,rsi;rulePacks=this._rulePacks;this._nodeDeps.exportRules.setupRulesToJson(obj,this._config.severity,this._utils);for(rsi=0;rsi<rulePacks.length;rsi++){rulePack=rulePacks[rsi];this._nodeDeps.exportRules.packToJson(rulePack);rulesJson=rulePack.rulesJson;for(ruleName in rulesJson.rules){ruleOpts=rulesJson.rules[ruleName];if(!ruleOpts.enabled){continue}opts=this._utils.extend(ruleOpts);rule=this._shadowRulePacks[rsi][ruleName];this._nodeDeps.exportRules.ruleToJson(ruleName,rule,opts)}}return this._nodeDeps.exportRules.getJson()};Rules.prototype.getRulesSonar=function(){var rulePacks,rulePack,ruleName,rules,rule,opts,rsi;this._nodeDeps.exportRules.setupRulesToXml(this._utils);rulePacks=this._rulePacks;for(rsi=0;rsi<rulePacks.length;rsi++){rulePack=rulePacks[rsi];rules=rulePack.rulesJson.rules;for(ruleName in rules){if(!rules[ruleName].enabled){continue}rule=this._shadowRulePacks[rsi][ruleName];opts=rules[ruleName];this._nodeDeps.exportRules.ruleToXml(ruleName,rule,opts)}}return this._nodeDeps.exportRules.getXml()};Rules.prototype.getRuleOptions=function(ruleName,rsi){return this._getRuleOptionsByName(ruleName,rsi)};Rules.prototype.getActiveRuleCount=function(){return this._ruleCount};Rules.prototype.getRuleSetSummaryByIndex=function(rsi){return this._rulesetSummary[rsi]};Rules.prototype.getRulePack=function(rsi){return this._rulePacks[rsi].rulePack};Rules.prototype.getRSIByPrefix=function(prefix){var i,rsi=-1;;for(i=0;i<this._rulesetSummary.length;i++){if(this._rulesetSummary[i].prefix===prefix){rsi=i;break}}return rsi};Rules.prototype.isRuleEnabled=function(ruleName,rsi){if(rsi===undefined){rsi=this.getRSIByRuleName(ruleName);if(rsi<0){return false}}var opts=this._getRuleOptionsByName(ruleName,rsi);return!!(opts&&opts.enabled)};Rules.prototype.getRSIByRuleName=function(ruleName){var rsi,rp,len;len=this._shadowRulePacks.length;for(rsi=0;rsi<len;rsi++){rp=this._shadowRulePacks[rsi];if(rp[ruleName]){break}}return rsi<len?rsi:-1};Rules.prototype.getRuleDescription=function(prefix,ruleName,isShort){var rule,rsi,ret="";rsi=this.getRSIByPrefix(prefix);if(rsi>=0){rule=this._shadowRulePacks[rsi][ruleName];if(rule){ret=isShort?rule.getShortDescription():rule.getDescription()}}return ret};Rules.prototype.getRuleDescriptionEx=function(msgId,ruleName,isShort){var descrip,rule,prefix,msgNum,rsi,msgTab,msgIds,mid,sev,x;var idList=[];if(ruleName){var rp=this._shadowRulePacks;for(rsi=0;rsi<rp.length;rsi++){rule=rp[rsi][ruleName];if(rule){descrip=isShort?rule.getShortDescription():rule.getDescription();if(descrip){msgTab=this._ruleSets.loadMsgIds();if(prefix=this._rulesetSummary[rsi]){prefix=prefix.prefix;if(msgIds=msgTab[prefix]){for(mid in msgIds){if(mid.startsWith(ruleName)){idList.push(msgIds[mid])}}}}break}}}}if(msgId){rsi=this._ruleSets.getRsiFromMsgId(msgId);if(rsi>=0){x=msgId.indexOf("-");prefix=msgId.substring(0,x);msgNum=msgId.substring(x+1);msgTab=this._ruleSets.loadMsgIds();msgIds=msgTab[prefix];if(msgNum.length<4){msgNum="0".repeat(4-msgNum.length)+msgNum}for(mid in msgIds){if(msgIds[mid]===msgNum){x=mid.lastIndexOf("_");ruleName=x>0?mid.substring(0,x):mid;if(descrip=this.getRuleDescription(prefix,ruleName,isShort)){for(mid in msgIds){if(mid.startsWith(ruleName)){idList.push(msgIds[mid])}}break}}}}}if(ruleName){sev=this._getRuleOptionsByName(ruleName,rsi);sev=sev?sev.severity:""}return{descrip:descrip,rule:ruleName,prefix:prefix,sev:sev,idList:idList}};Rules.prototype._showIgnoredRule=function(msg,isError){if(msg){if(!this._ignoredRulesShown){this._info("\n--------- Start-up Rule analysis ---------");this._ignoredRulesShown=true}isError?this._error(msg):this._info(msg)}else if(this._ignoredRulesShown){this._info("------------ End Rule analysis -------------")}};Rules.prototype.fireHookRules=function(ruleCtx,rsi){var ruleName,typeObj,callbacks,callback,opts,rc,i;var _rsi;ruleCtx.Issue=this._Issue;ruleCtx.reporter=this._reporter;ruleCtx.metaLib=this._metaLib;ruleCtx.msgLib=this._message;ruleCtx.message=this._message;_rsi=rsi;typeObj=this._registry.getRegisteredCallbacks(ruleCtx.type);if(!typeObj){return}for(ruleName in typeObj){callbacks=typeObj[ruleName];if(!callbacks){continue}for(i=0;i<callbacks.length;i++){callback=callbacks[i];if(rsi===undefined){_rsi=callback.rsi}else{if(rsi!==callback.rsi){continue}_rsi=rsi}opts=this._getRuleOptionsByName(ruleName,_rsi);if(ruleCtx.type==="file"||ruleCtx.type==="startscript"){if(opts&&opts.filetype){if(!this._isFileTypeOk(opts.filetype,ruleCtx.filetype)){continue}}}ruleCtx.ruleName=ruleName;ruleCtx.rulePack=this._rulePacks[_rsi].rulePack;ruleCtx._rsi=_rsi;ruleCtx.common=this._common[_rsi];ruleCtx.userDefs=this._config.userDefs;ruleCtx.utils.metaLib=this._metaLib;ruleCtx.utils.utils=this._utils;ruleCtx.utils.fsUtils=this._nodeDeps.fsUtils;ruleCtx.utils.msgLib=this._message;ruleCtx.utils.semverUtils=this._semVer;ruleCtx.sysOpts=this._sysOpts;ruleCtx.getMsgId=this._getMsgId;this._debug("Firing hook rule "+ruleName+" type="+ruleCtx.type);ruleCtx.rulePack._setCBCtx(ruleCtx);rc=callback.cb(ruleCtx);this._Stats.hooksFired++;if((ruleCtx.phase===REG.STARTUP||ruleCtx.phase===REG.PHASE_FILE)&&typeof rc==="boolean"&&!rc){this._info("Hook rule ('"+ruleCtx.type+"') veto! by '"+ruleName+"'");return rc}}}return true};Rules.prototype._getRuleByName=function(ruleName,rsi){var rs=this._shadowRulePacks[rsi];return rs[ruleName]};Rules.prototype._getRuleOptionsByName=function(ruleName,rsi){var rulePack=this._rulePacks[rsi];return rulePack.rulesJson.rules[ruleName]};Rules.prototype._isGroupActive=function(group){var groups,defs,def,i;groups=this._config.groups;defs=this._config.defGroups;if(this._checkGroups(groups,group)){return true}if(!defs){return false}for(i=0;i<groups.length;i++){def=groups[i];if(this._checkDefGroup(defs,def,group)){return true}}return false};Rules.prototype._loadBuiltinJetRulesDescriptions=function(){var ruleName,rules;try{if(!_builtinJetRules){_builtinJetRules=require("../rules/jet/rules.json")}}catch(e){this._error("Unable to load builtin rule definition file "+e)}if(_builtinJetRules&&_builtinJetRules.rules){rules=_builtinJetRules.rules;for(ruleName in rules){rules[ruleName].$builtin=true}}return _builtinJetRules};Rules.prototype._isFileTypeOk=function(ruleFileType,fileType){var ret=false;if(Array.isArray(ruleFileType)){ret=ruleFileType.indexOf(fileType)>=0}else{ret=ruleFileType===fileType}return ret};Rules.prototype._createCommon=function(){var i,a=[];for(i=0;i<this._rulesetSummary.length;i++){a.push({})}return a};Rules.prototype._getFileSuffix=function(fp){var s="";if(fp){s=this._nodeDeps.path.extname(fp)}return s.length?s:"?"};function _extractStyles(s){var a,isExpr,i,sc=";";s=s.trim();isExpr=_isExpr(s);s=s.replace(/[\'\"\[\]\{\}]/g,"").trim();if(!s.includes(";")){if(isExpr){if(s.includes(",")){sc=","}}}a=s.split(sc);for(i=0;i<a.length;i++){a[i]=a[i].trim();if(!a[i].length){a.splice(i,1);i--}}return a};function _isExpr(s){s=s.trim();return s.startsWith("[[")||s.startsWith("{{")};module.exports=Rules;
package/lib/Scope.js CHANGED
@@ -1 +1,6 @@
1
- var walker=require('estraverse');const TS_ANY='TSAnyKeyword';const TS_TYPEREF='TSTypeReference';const TS_ARRAY='TSArrayType';const PROGRAM='Program';const GLOBAL_SCOPE='_@global';const ANON='$anon';class Scope{constructor(){this.reset()}reset(){this._fStack=[];this._bStack=[];this._funcStack=[];this._idxStack=0;this._parents=[];this._blockStack=[];this._idxBlkStack=0;this._blkParents=[];this._nextAnonId=0;this._varKind}build(ast){this.reset();walker.traverse(ast,{enter:this._enter.bind(this),leave:this._leave.bind(this)});return{funcs:this._fStack,blocks:this._bStack}}_buildFuncIndexesToBlocks(){var i,j;for(i=0;i<this._fStack.length;i++){for(j=0;j<this._bStack.length;j++){if(this._bStack[j].func==i){this._fStack[i].blocks.push(j)}}}}getAccessor(){return new _scope(this._fStack,this._bStack)}_enter(node){var type;type=node.type;if(this._isNewScope(node)){this._addNewFunc(node)}else if(type==='VariableDeclarator'){this._varDecl(node)}else if(type==='VariableDeclaration'){this._varKind=node.kind}else if(type==='BlockStatement'){if(node.range!==this._fStack[this._getCurFunc()].node.body.range){this._addNewBlock(node)}}}_leave(node){if(this._isNewScope(node)){if(this._parents.length){this._parents.pop()}this._funcStack.pop()}else if(node.type==='BlockStatement'){if(this._blkParents.length){this._blkParents.pop()}this._blockStack.pop()}}_addNewFunc(node){var type,func,curParent,x;type=node.type;func=type===PROGRAM?GLOBAL_SCOPE:node.id?node.id.name:this._getNextAnon();if(this._parents.length){curParent=this._fStack[this._parents[this._parents.length-1]]}x=this._fStack.push({func:func,node:node,vars:{},args:{},blocks:[],children:[],parent:this._parents.length?this._parents[this._parents.length-1]:-1});x--;this._parents.push(x);if(curParent){curParent.children.push(x)}this._funcStack.push(x);this._addFuncArgs(node)}_addNewBlock(node){var func,curParent,x;var func=this._fStack[this._getCurFunc()];if(node.range===func.node.body.range){return}if(this._blkParents.length){curParent=this._bStack[this._blkParents[this._blkParents.length-1]]}x=this._bStack.push({func:this._getCurFunc(),node:node,lets:{},children:[],parent:this._blkParents.length?this._blkParents[this._blkParents.length-1]:-1});x--;this._blkParents.push(x);if(curParent){curParent.children.push(x)}this._blockStack.push(x);func.blocks.push(x)}_getCurFunc(){return this._funcStack[this._funcStack.length-1]}_getCurBlock(){return this._blockStack[this._blockStack.length-1]}_addFuncArgs(node){var vt,curScope;if(node.params){curScope=this._fStack[this._getCurFunc()];node.params.forEach(function(n){if(n.type==='Identifier'){vt=this._getVarType(n);curScope.args[n.name]={type:vt}}else{curScope.args.push({type:'???'})}},this)}}_isNewScope(node){var type=node.type;return type==='FunctionDeclaration'||type==='FunctionExpression'||type==='Program'}_varDecl(node){var curScope,vt;vt=this._getVarType(node);if(this._varKind==='let'){if(this._blockStack.length===0){this._varKind='var'}}if(this._varKind==='var'){curScope=this._fStack[this._getCurFunc()];curScope.vars[node.id.name]={type:vt}}else if(this._varKind==='let'){let b=this._getCurBlock();if(b>=0){let block=this._bStack[b];let br=block.node.range;let start=node.range;if(start[0]>=br[0]&&start[1]<=br[1]){block.lets[node.id.name]={type:vt}}}}}_getVarType(node){var vt,ta,et;ta=node.id&&node.id.typeAnnotation?node.id.typeAnnotation:node.typeAnnotation;if(!ta){vt=TS_ANY}else{vt=ta.typeAnnotation.type;if(vt===TS_TYPEREF){vt=ta.typeAnnotation.typeName.name}else if(vt===TS_ARRAY){et=ta.typeAnnotation.elementType.type;if(et===TS_TYPEREF){vt=ta.typeAnnotation.elementType.typeName.name+'[]'}else{vt=et+'[]'}}}const DEBUG_TYPES=['TSAnyKeyword','TSTypeReference','TSArrayType','TSStringKeyword','TSNumberKeyword','TSBooleanKeyword'];if(vt.startsWith('TS')&&!DEBUG_TYPES.includes(vt))console.log(`***** [ASSERT] var xx is ${vt}`);return vt}_dumpEnter(node){let funcName=node.id?node.id.name:'anon';console.log(`ENTER=${funcName} ${node.type}`)}_dumpLeave(node){let funcName=node.id?node.id.name:'anon';console.log(`LEAVE=${funcName} ${node.type}`)}dumpStacks(){this._dumpFuncStack();this._dumpBlockStack()}dumpFuncStack(){var st,v,o,s,i,title;console.log('\n-------- Function Scope Map --------');st=this._fStack;for(i=0;i<st.length;i++){o=st[i];s=(o.children.length?'children='+_dumpArrayIndices(o.children):'')+' blocks='+_dumpArrayIndices(o.blocks);console.log(`\n[${i}] "${o.func}" parent=${o.parent} ${s}`);title=false;if(_hasProps(o.args)){for(v in o.args){console.log((!title?' Args: ':' ')+v+': '+o.args[v].type);title=true}}else{console.log(' Args: none')}title=false;if(_hasProps(o.vars)){for(v in o.vars){console.log((!title?' Vars: ':' ')+v+': '+o.vars[v].type);title=true}}else{console.log(' Vars: none')}}}dumpBlockStack(){var st,v,o,ch,i,title;console.log('\n-------- Block Scope Map --------');st=this._bStack;if(!st.length){console.log('\nNo blocks.');return''}for(i=0;i<st.length;i++){o=st[i];ch=o.children.length?'children='+_dumpArrayIndices(o.children):'';console.log(`\n[${i}] Func="${this._fStack[o.func].func}" parent=${o.parent} ${ch}`);title=false;if(_hasProps(o.lets)){for(v in o.lets){console.log((!title?' Lets: ':' ')+v+': '+o.lets[v].type);title=true}}else{console.log(' Lets: none')}}}_getNextAnon(){return ANON+ ++this._nextAnonId}};function _hasProps(obj){var ret=false;for(var prop in obj){if(obj.hasOwnProperty(prop)){ret=true;break}}return ret};function _dumpArrayIndices(a){var ret='[';a.forEach(function(v,i){ret+=(i?', ':'')+v});return ret+']'}class _scope{constructor(fs,bs){this._fstk=fs;this._bstk=bs}getVarType(node){var name,func,block,v;name=node.name;if(!node.name){return null}block=this.getContainingBlock(node);if(block){v=block.lets[name];if(v){return v.type}while(block.parent>=0){block=this._bstk[block.parent];if(block){v=block.lets[name];if(v){return v.type}}}}func=this.getContainingFunc(node);do{if(func.vars&&func.vars[name]){v=func.vars[name].type}else if(func.args&&func.args[name]){v=func.args[name].type}if(v){break}if(func.parent>=0){func=this._fstk[func.parent]}else{func=null}}while(func);return v}getContainingFunc(node){var start,fnRange,fnIndex,func,fr,i;start=node.range[0];for(i=0;i<this._fstk.length;i++){func=this._fstk[i];fr=func.node.range;if(start>=fr[0]&&start<=fr[1]){if(fnRange){if(fr[0]>=fnRange[0]&&fr[1]<=fnRange[1]){fnRange=fr;fnIndex=i}}else{fnRange=fr;fnIndex=i}}}return typeof fnIndex==='number'?this._fstk[fnIndex]:null}getContainingBlock(node){var nrange,brange,range,bindex,blocks,block,i;if(!this._bstk.length)return;var blocks=this.getContainingFunc(node).blocks;nrange=node.range;for(i=0;i<blocks.length;i++){block=this._bstk[i];brange=block.node.range;if(nrange[0]>=brange[0]&&nrange[1]<=brange[1]){if(range){if(brange[0]>=range[0]&&brange[1]<=range[1]){range=nrange;bindex=i}}else{range=brange;bindex=i}}}return typeof bindex==='number'?this._bstk[bindex]:null}getGlobals(){return this._fstk[0]}getFuncStack(){return this._fstk}getBlockStack(){return this._bstk}};module.exports=Scope;
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ var walker=require('./scopewalker');const TS_ANY='TSAnyKeyword';const TS_TYPEREF='TSTypeReference';const TS_ARRAY='TSArrayType';const STRING='string';const NUMBER='number';const BOOLEAN='boolean';const NULL='null';const OBJECT='Object';const FUNCTION='function';const ANY='any';const UNKNOWN='unknown';const PROGRAM='Program';const GLOBAL_SCOPE='_@global';const ANON='$anon';const DOCUMENT_METHODS={createElement:'Element',createTextNode:'Element',getElementById:'Element',getElementsByClassName:'HTMLCollection',getElementsByName:'HTMLCollection',getElementsByTagName:'HTMLCollection',getElementsByTagNameNS:'HTMLCollecion',hasFocus:'boolean',querySelector:'Element',querySelectorAll:'NodeList'};const DOCUMENT_MEMBERS={activeElement:'Element',anchors:'HTMLCollection',body:'Element',childElementCount:'number',dir:'string',documentElement:'Element',documentURI:'string',docType:'DTD',forms:'HTMLCollection',getElementById:'Element',head:'Element',hidden:'boolean',links:'HTMLCollection',scrollingElement:'Element',visibilityState:'string'};const INDENT=3;var _level=-INDENT;function _trace(t,n){function _rj(s,w){s=''+s;if(s.length<w){s=' '.repeat(w-s.length)+s}return s}_level+=t==='E'?INDENT:0;if(t==='E')console.log(`${_rj(n.loc.start.line,4)}] ${' '.repeat(_level)} ${n.type}`);else console.log(`${' '.repeat(4)} ${' '.repeat(_level)} ${n.type}`);_level-=t==='L'?INDENT:0};class Scope{constructor(msgCtx,config){this._msgCtx=msgCtx;this._config=config;this.reset()}reset(){this._fStack=[];this._bStack=[];this._imports=[];this._funcStack=[];this._idxStack=0;this._parents=[];this._blockStack=[];this._idxBlkStack=0;this._blkParents=[];this._nextAnonId=0;this._varKind;this._level=-INDENT}build(ast){this.reset();try{walker.traverse(ast,{enter:this._enter.bind(this),leave:this._leave.bind(this)})}catch(e){console.log(e.stack)}return{funcs:this._fStack,blocks:this._bStack}}_buildFuncIndexesToBlocks(){var i,j;for(i=0;i<this._fStack.length;i++){for(j=0;j<this._bStack.length;j++){if(this._bStack[j].func==i){this._fStack[i].blocks.push(j)}}}}getAccessor(){return new _scope(this._fStack,this._bStack)}_enter(node){var type;if(this._msgCtx.isDebug){_trace('E',node)}type=node.type;if(this._isNewScope(node)){this._addNewFunc(node)}else if(type==='VariableDeclarator'||type==='ClassProperty'){this._varDecl(node)}else if(type==='VariableDeclaration'){this._varKind=node.kind}else if(type==='BlockStatement'){this._addNewBlock(node)}else if(type==='ClassDeclaration'){this._inClass=true;this._className=node.id.name}else if(type==='ImportDeclaration'){this._addImport(node)}}_leave(node){if(this._msgCtx.isDebug){_trace('L',node)}if(this._isNewScope(node)){if(this._parents.length){this._parents.pop()}this._funcStack.pop()}else if(node.type==='BlockStatement'){if(this._blkParents.length){this._blkParents.pop()}this._blockStack.pop()}else if(node.type==='ClassDeclaration'){this._inClass=false;this._className=null}}_addNewFunc(node){var type,func,curParent,x;type=node.type;if(type===PROGRAM){func=GLOBAL_SCOPE}else if(node.kind==='method'||node.kind==='constructor'){func=node.key.name}else if(node.id){func=node.id.name}else if(type==='ClassBody'){func=this._className}else{this._getNextAnon()}if(this._parents.length){curParent=this._fStack[this._parents[this._parents.length-1]]}x=this._fStack.push({func:func,node:node,vars:{},args:{},blocks:[],children:[],parent:this._parents.length?this._parents[this._parents.length-1]:-1});x--;this._parents.push(x);if(curParent){curParent.children.push(x)}this._funcStack.push(x);this._addFuncArgs(node)}_addNewBlock(node){var func,curParent,x;var func=this._fStack[this._getCurFunc()];let n=this._fStack[this._getCurFunc()].node;if((n.kind==='method'||n.kind==='constructor')&&this._isMethodRange(n,node)||n.kind!=='method'&&n.kind!=='constructor'&&node.range===n.body.range){return}if(this._blkParents.length){curParent=this._bStack[this._blkParents[this._blkParents.length-1]]}x=this._bStack.push({func:this._getCurFunc(),node:node,lets:{},children:[],parent:this._blkParents.length?this._blkParents[this._blkParents.length-1]:-1});x--;this._blkParents.push(x);if(curParent){curParent.children.push(x)}this._blockStack.push(x);func.blocks.push(x)}_addImport(node){var src,local,o;src=node.source.value;if(!src.startsWith('ojs/')){return}o={src:src};if(node.specifiers.length){node.specifiers.forEach(s=>{if(!local)local=[];local.push(s.local.name)});if(local){o.local=local}}this._imports.push(o)}_getCurFunc(){return this._funcStack[this._funcStack.length-1]}_getCurBlock(){return this._blockStack[this._blockStack.length-1]}_addFuncArgs(node){var vt,curScope;if(node.params){curScope=this._fStack[this._getCurFunc()];node.params.forEach(function(n){if(n.type==='Identifier'){vt=this._getVarType(n);curScope.args[n.name]={type:vt}}else{if(n.type==='AssignmentPattern'){if(n.left&&n.left.name){curScope.args[n.left.name]={type:'???'}}else{console.log('scopes nt = n.type')}}}},this)}}_isNewScope(node){var type=node.type;return type==='FunctionDeclaration'||type==='MethodDefinition'||type==='FunctionExpression'&&!this._inClass||type==='ClassBody'||type==='Program'}_varDecl(node){var curScope,vt,name;function _declVar(vt,self){curScope=self._fStack[self._getCurFunc()];if(node.id){name=node.id.name}else{name=node.key.name}curScope.vars[name]={type:vt,node:node}};vt=this._getVarType(node);if(this._varKind==='let'||this._varKind==='const'){if(this._blockStack.length===0){this._varKind='var'}}if(this._varKind==='var'||node.type==='ClassProperty'){_declVar(vt,this)}else if(this._varKind==='let'||this._varKind==='const'){let b=this._getCurBlock();if(b>=0){let block=this._bStack[b];let br=block.node.range;let start=node.range;if(start[0]>=br[0]&&start[1]<=br[1]){block.lets[node.id.name]={type:vt,node:node}}}else{_declVar(vt,this)}}}_getVarType(node){var vt,ta,et,ty;if(node.type==='ClassProperty'){if(node.value){if(node.value.type==='ArrowFunctionExpression'){return'function'}else if(node.value.type==='CallExpression'){if(node.value.callee.object.name==='ko'){if(node.value.callee.property.name==='observable'){return'KO_Observable'}else if(node.value.callee.property.name==='computed'){return'KO_computed'}else{return'KO_Unknown'}}}}}ta=node.id&&node.id.typeAnnotation?node.id.typeAnnotation:node.typeAnnotation;if(!ta){ty=node.init?this._getInitType(node.init):ANY}else{vt=ta.typeAnnotation.type;if(vt===TS_TYPEREF){if(ta.typeAnnotation.typeName.name){ty=ta.typeAnnotation.typeName.name}else{if(ta.typeAnnotation.typeName.left){if(ta.typeAnnotation.typeName.left.name){ty=ta.typeAnnotation.typeName.left.name;if(ta.typeAnnotation.typeName.right&&ta.typeAnnotation.typeName.right.name){ty+='.'+ta.typeAnnotation.typeName.right.name}}else if(ta.typeAnnotation.typeName.left.left.name){ty+='.'+ta.typeAnnotation.typeName.left.left.name;if(ta.typeAnnotation.typeName.left.right.name){ty+='.'+ta.typeAnnotation.typeName.left.right.name}if(ta.typeAnnotation.typeName.right.name){ty+='.'+ta.typeAnnotation.typeName.right.name}}}}}else if(vt===TS_ARRAY){et=ta.typeAnnotation.elementType.type;if(et===TS_TYPEREF){ty=ta.typeAnnotation.elementType.typeName.name+'[]'}else{ty=et+'[]'}}else{ty=vt}}if(ty){ty=_transformType(ty)}if(!ty){console.log('[ASSERT]: scopes: ty not defined')}return ty}_getInitType(init){var vt,raw;if(init.type==='Literal'&&init.raw){raw=init.raw;if(raw.charAt(0)==='"'||raw.charAt(0)==='\''){vt=STRING}else if(raw==='true'||raw==='false'){vt=BOOLEAN}else if(!isNaN(raw)){vt=NUMBER}else if(raw==='null'){vt=NULL}else{console.log('[ASSERT]: SCOPES - UNKNOWN VAR INIT LITERAL = '+raw);vt=UNKNOWN}}else if(init.type==='ObjectExpression'){vt=OBJECT}else if(init.type==='NewExpression'){if(init.callee&&init.callee.name){vt=init.callee.name}}else if(init.type==='CallExpression'){if(init.callee&&init.callee.object){let o=init.callee.object;if(o.type==='Identifier'&&o.name==='document'){o=init.callee.property;if(o=DOCUMENT_METHODS[o.name]){return o}else{return'unknown document function'}}if(o.type==='MemberExpression'){vt=this._unravelCallME(o)}if(init.callee&&init.callee.object&&init.callee.object.type==='FunctionExpression'){vt='function'}}}else if(init.type==='MemberExpression'){if(init.object.type==='TSAsExpression'){vt=UNKNOWN}}else if(init.type==='TSAsExpression'){if(init.typeAnnotation&&init.typeAnnotation.type==='TSTypeReference'){vt=init.typeAnnotation.typeName.name}else{vt=UNKNOWN}}else if(init.type==='TSTypeAssertion'){if(init.typeAnnotation){vt=init.typeAnnotation.type}}else{vt=init.type}if(!vt){vt=UNKNOWN}return vt}_isMethodRange(n,node){return n.value&&n.value.body&&n.value.body.range===node.range}_unravelCallME(o){var prop;if(o.object.type==='ThisExpression'){prop=o.property.name;return this._getClassPropType(o,prop)}}_getClassPropType(o,prop){var c,ret;c=this._getContainingClass(o);if(c&&c.vars){ret=c.vars[prop];if(ret){ret=ret.type}}return ret}_getContainingClass(node){var c=this._getCurFunc(node);if(c<0){return}do{c=this._fStack[c];if(c.node.type==='ClassBody'){break}c=c.parent}while(c>=0);return c}_dumpEnter(node){let funcName=node.id?node.id.name:'anon';console.log(`ENTER=${funcName} ${node.type}`)}_dumpLeave(node){let funcName=node.id?node.id.name:'anon';console.log(`LEAVE=${funcName} ${node.type}`)}dumpStacks(){this.dumpFuncStack();this.dumpBlockStack()}dumpFuncStack(){var st,v,o,s,i,title;console.log('\n-------- Function/Class Scope Map --------');st=this._fStack;for(i=0;i<st.length;i++){o=st[i];s=(o.children.length?'children='+_dumpArrayIndices(o.children):'')+' blocks='+_dumpArrayIndices(o.blocks);console.log(`\n[${i}] "${o.func}" ${_dumpStackType(o)} parent=${o.parent} ${s}`);title=false;if(_hasProps(o.args)){for(v in o.args){console.log((!title?' Args: ':' ')+v+': '+o.args[v].type);title=true}}else{console.log(' Args: none')}title=false;if(_hasProps(o.vars)){for(v in o.vars){console.log((!title?' Vars: ':' ')+v+': '+o.vars[v].type+' ('+(o.vars[v].node.type==='ClassProperty'?'class prop':'var')+')');title=true}}else{console.log(' Vars: none')}}}dumpBlockStack(){var st,v,o,ch,i,title;console.log('\n-------- Internal Block Scope Map --------');st=this._bStack;if(!st.length){console.log('\nNo blocks.');return''}for(i=0;i<st.length;i++){o=st[i];ch=o.children.length?'children='+_dumpArrayIndices(o.children):'';console.log(`\n[${i}] ${this._dumpBlkOwner(o)}="${this._fStack[o.func].func}" parent=${o.parent} ${ch}`);title=false;if(_hasProps(o.lets)){for(v in o.lets){console.log((!title?' Lets: ':' ')+v+': '+o.lets[v].type);title=true}}else{console.log(' Lets: none')}}}_dumpBlkOwner(o){var f=this._fStack[o.func];return f.node.type==='FunctionDeclaration'?'func':'meth'}_getNextAnon(){return ANON+ ++this._nextAnonId}};function _hasProps(obj){var ret=false;for(var prop in obj){if(obj.hasOwnProperty(prop)){ret=true;break}}return ret};function _dumpArrayIndices(a){var ret='[';a.forEach(function(v,i){ret+=(i?', ':'')+v});return ret+']'}function _dumpStackType(o){var s='';switch(o.node.type){case'ClassBody':s='class';break;case'MethodDefinition':s='method';break;case'FunctionDeclaration':s='func';break;}return s.length?'('+s+')':s};function _transformType(ty){const list={TSStringKeyword:'string',TSNumberKeyword:'number',TSBooleanKeyword:'boolean',TSNullKeyword:'null',TSObjectKeyword:'object',TSUnknownKeyword:'unknown',TSAnyKeyword:'any'};return list[ty]||ty};class _scope{constructor(fs,bs){this._fstk=fs;this._bstk=bs}getVarType(node){var name,func,block,v;name=node.name;if(!node.name){return null}block=this.getContainingBlock(node);if(block){v=block.lets[name];if(v){return v.type}while(block.parent>=0){block=this._bstk[block.parent];if(block){v=block.lets[name];if(v){return v.type}}}}func=this.getContainingFunc(node);do{if(func.vars&&func.vars[name]){v=func.vars[name].type}else if(func.args&&func.args[name]){v=func.args[name].type}if(v){break}if(func.parent>=0){func=this._fstk[func.parent]}else{func=null}}while(func);return v}getContainingFunc(node){var start,fnRange,fnIndex,func,fr,i;start=node.range[0];for(i=0;i<this._fstk.length;i++){func=this._fstk[i];fr=func.node.range;if(start>=fr[0]&&start<=fr[1]){if(fnRange){if(fr[0]>=fnRange[0]&&fr[1]<=fnRange[1]){fnRange=fr;fnIndex=i}}else{fnRange=fr;fnIndex=i}}}return typeof fnIndex==='number'?this._fstk[fnIndex]:null}getContainingBlock(node){var nrange,brange,range,bindex,blocks,block,i;if(!this._bstk.length)return;var blocks=this.getContainingFunc(node).blocks;nrange=node.range;for(i=0;i<blocks.length;i++){block=this._bstk[i];brange=block.node.range;if(nrange[0]>=brange[0]&&nrange[1]<=brange[1]){if(range){if(brange[0]>=range[0]&&brange[1]<=range[1]){range=nrange;bindex=i}}else{range=brange;bindex=i}}}return typeof bindex==='number'?this._bstk[bindex]:null}getContainingClass(node){}getGlobals(){return this._fstk[0]}getFuncStack(){return this._fstk}getBlockStack(){return this._bstk}};module.exports=Scope;
package/lib/SemVer.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  const _SV=require("semver");function SemVer(){this._reference=null};SemVer.prototype.parse=function(semver){return _SV.parse(semver)};SemVer.prototype.match=function(semver){return _SV.satisfies(this._reference,semver)};SemVer.prototype.isValid=function(semver){var ret;try{ret=!!_SV.valid(semver)}catch(e){ret=false};return ret};SemVer.prototype.isValidRange=function(range){var ret;try{ret=!!_SV.validRange(range)}catch(e){ret=false};return ret};SemVer.prototype.satisfiesRange=function(semver,range){var ret;try{ret=_SV.satisfies(semver,range)}catch(e){ret=false};return ret};SemVer.prototype.minVersion=function(semver){var ret;try{ret=_SV.minVersion(semver)}catch(e){ret=null}return ret};SemVer.prototype.prerelease=function(semver){var ret;try{ret=_SV.prerelease(semver)}catch(e){ret=null}return ret};SemVer.prototype.eq=function(semver1,semver2){return _SV.eq(semver1,semver2)};SemVer.prototype.lt=function(semver1,semver2){return _SV.lt(semver1,semver2)};SemVer.prototype.lte=function(semver1,semver2){return _SV.lte(semver1,semver2)};SemVer.prototype.gt=function(semver1,semver2){return _SV.gt(semver1,semver2)};SemVer.prototype.gte=function(semver1,semver2){return _SV.gte(semver1,semver2)};SemVer.prototype.getReference=function(){return this._reference};SemVer.prototype.setReference=function(refSemVer,minSemVer){var ret=_SV.satisfies(refSemVer,">="+minSemVer);if(ret){this._reference=refSemVer}return ret};SemVer.prototype.major=function(semVer){return _SV.major(semVer)};SemVer.prototype.minor=function(semVer){return _SV.minor(semVer)};SemVer.prototype.patch=function(semVer){return _SV.patch(semVer)};module.exports=SemVer;
package/lib/Server.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  var Server=function(port,filebase){var Server=require("mock-http-server");this._filebase=filebase;this._server=new Server({host:"localhost",port:port||8135});this._setRoutes()};Server.prototype.start=function(cb){this._server.start(cb)};Server.prototype.stop=function(cb){this._server.stop(cb)};Server.prototype._setRoutes=function(){this._server.on({method:"GET",path:"/test",reply:{status:200,headers:{"content-type":"application/json"},body:JSON.stringify({"hello":"world"})}});this._server.on({method:"GET",path:"/",reply:{status:200,headers:{"content-type":"application/json"},body:JSON.stringify({"hello":"world"})}})};Server.prototype.getRequests=function(){return this._server.requests()};module.exports=Server;
package/lib/SevLib.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  class SevLib{constructor(sev){this._ps=sev}map(sev){return this._ps.map(sev)}unmap(sev){return this._ps.unmap(sev)}isMapped(sev){return this._ps.isMapped(sev)}getList(){return this._ps.getSevList()}getMap(){return this._ps.getSevMap()}getInvertedMap(){return this._ps.getInvertedSevMap()}isBlocker(sev){return this._ps.isBlocker(sev)}isCritical(sev){return this._ps.isCritical(sev)}isMajor(sev){return this._ps.isMajor(sev)}isMinor(sev){return this._ps.isMinor(sev)}isInfo(sev){return this._ps.isInfo(sev)}isSev(sev){return this._ps.isSev(sev)}getMsgSev(msgId){return this._ps.getMsgSev(msgId)}matchSeverityLevel(sev){return this._ps.matchSeverityLevel(sev)}}module.exports=SevLib;
package/lib/Severity.js CHANGED
@@ -1 +1,6 @@
1
- const CRITICAL="critical";const BLOCKER="blocker";const MAJOR="major";const MINOR="minor";const INFO="info";const ALL="all";const DEFAULT=CRITICAL;const SEVERITY=[INFO,MINOR,MAJOR,CRITICAL,BLOCKER];const SevLib=require("./SevLib");function Severity(){this._sevMap=null;this._sevSet=null;this._sevInv=null;this._sevExpr=null;this._sevMsg=null;this._sevLib=null;this._sevInvArray=null;this.CRITICAL=CRITICAL;this.BLOCKER=BLOCKER;this.MAJOR=MAJOR;this.MINOR=MINOR;this.INFO=INFO;this.ALL=ALL;this.DEFAULT=DEFAULT};Severity.prototype.isValidRuleSeverity=function(sev){return SEVERITY.indexOf(sev)>=0};Severity.prototype.isValidConfigSeverity=function(sev){var o=this.getSevExpr(sev);if(o.op&&o.sev==="all")return false;return SEVERITY.indexOf(o.sev)>=0||o.sev===ALL||this.isMapped(o.sev)};Severity.prototype.matchSeverityLevel=function(sev,sevExpr){var level,op,ret;sevExpr=sevExpr||this._sevExpr;if(!sevExpr){return}op=sevExpr.op;if(op){level=this._assignLevel(sev);if(op===">")ret=level>sevExpr.lev;else if(op===">=")ret=level>=sevExpr.lev;else if(op==="<")ret=level<sevExpr.lev;else if(op==="<=")ret=level<=sevExpr.lev;else if(op==="=")ret=level===sevExpr.lev}else{if(sevExpr.sev==="all")ret=true;else ret=sev===sevExpr.sev}return ret};Severity.prototype.isBlocker=function(sev){return this.unmap(sev)===BLOCKER};Severity.prototype.isCritical=function(sev){return this.unmap(sev)===CRITICAL};Severity.prototype.isMajor=function(sev){return this.unmap(sev)===MAJOR};Severity.prototype.isMinor=function(sev){return this.unmap(sev)===MINOR};Severity.prototype.isInfo=function(sev){return this.unmap(sev)===INFO};Severity.prototype.map=function(sev){var ret;if(this._sevSet){ret=this._sevSet[sev]}return ret||sev};Severity.prototype.unmap=function(sev){var ret;if(this._sevInv){ret=this._sevInv[sev]}return ret||sev};Severity.prototype.isMapped=function(sev){return!!(this._sevInv&&this._sevInv[sev])};Severity.prototype.isSev=function(sev){return SEVERITY.includes(sev)||!!(this._sevInv&&this._sevInv[sev])};Severity.prototype.getSevExpr=function(sev){var origSev,ret={};ret.sev=origSev=_stripOp(sev);ret.sev=this.unmap(ret.sev);ret.op=sev.replace(origSev,"");ret.op=ret.op.length?ret.op:null;if(ret.op&&ret.op==="=="){ret.op="="}ret.lev=this._assignLevel(ret.sev);return ret};Severity.prototype.getMsgSev=function(msgId){return this._sevMsg?this._sevMsg[msgId]:null};Severity.prototype.getConfigSevExpr=function(){return this._sevExpr};Severity.prototype.getSevList=function(){return SEVERITY};Severity.prototype.getSevMap=function(){return this._sevSet};Severity.prototype.getInvertedSevMap=function(){return this._sevInv};Severity.prototype.getMappedArray=function(){if(!this._sevInvArray){if(this._sevInv){let a,i;this._sevInvArray=a=[];for(i=0;i<SEVERITY.length;i++){a.push(this.map(SEVERITY[i]))}}}return this._sevInvArray};Severity.prototype.setSevExpr=function(expr){this._sevExpr=expr};Severity.prototype.setSevMap=function(sevMap,sevInv){this._sevMap=sevMap;this._sevSet=sevMap.sevSet;this._sevInv=sevInv};Severity.prototype.setSevMsg=function(sevMsg){this._sevMsg=sevMsg};Severity.prototype.getSevLib=function(){if(!this._sevLib){this._sevLib=new SevLib(this)}return this._sevLib};Severity.prototype._assignLevel=function(sev){var lev=SEVERITY.indexOf(sev);if(lev<0&&sev!=="all"){sev=this.unmap(sev);lev=SEVERITY.indexOf(sev)}return lev};function _stripOp(sev){var c,x,s=sev;if(sev){c=sev.charAt(0);if(c===">"||c==="<"||c==="="){x=1;if(sev.charAt(1)==="="){x=2}s=sev.substr(x)}}return s};module.exports=Severity;
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 CRITICAL="critical";const BLOCKER="blocker";const MAJOR="major";const MINOR="minor";const INFO="info";const ALL="all";const DEFAULT=CRITICAL;const SEVERITY=[INFO,MINOR,MAJOR,CRITICAL,BLOCKER];const SevLib=require("./SevLib");function Severity(){this._sevMap=null;this._sevSet=null;this._sevInv=null;this._sevExpr=null;this._sevMsg=null;this._sevLib=null;this._sevInvArray=null;this.CRITICAL=CRITICAL;this.BLOCKER=BLOCKER;this.MAJOR=MAJOR;this.MINOR=MINOR;this.INFO=INFO;this.ALL=ALL;this.DEFAULT=DEFAULT};Severity.prototype.isValidRuleSeverity=function(sev){return SEVERITY.indexOf(sev)>=0};Severity.prototype.isValidConfigSeverity=function(sev){var o=this.getSevExpr(sev);if(o.op&&o.sev==="all")return false;return SEVERITY.indexOf(o.sev)>=0||o.sev===ALL||this.isMapped(o.sev)};Severity.prototype.matchSeverityLevel=function(sev,sevExpr){var level,op,ret;sevExpr=sevExpr||this._sevExpr;if(!sevExpr){return}op=sevExpr.op;if(op){level=this._assignLevel(sev);if(op===">")ret=level>sevExpr.lev;else if(op===">=")ret=level>=sevExpr.lev;else if(op==="<")ret=level<sevExpr.lev;else if(op==="<=")ret=level<=sevExpr.lev;else if(op==="=")ret=level===sevExpr.lev}else{if(sevExpr.sev==="all")ret=true;else ret=sev===sevExpr.sev}return ret};Severity.prototype.isBlocker=function(sev){return this.unmap(sev)===BLOCKER};Severity.prototype.isCritical=function(sev){return this.unmap(sev)===CRITICAL};Severity.prototype.isMajor=function(sev){return this.unmap(sev)===MAJOR};Severity.prototype.isMinor=function(sev){return this.unmap(sev)===MINOR};Severity.prototype.isInfo=function(sev){return this.unmap(sev)===INFO};Severity.prototype.map=function(sev){var ret;if(this._sevSet){ret=this._sevSet[sev]}return ret||sev};Severity.prototype.unmap=function(sev){var ret;if(this._sevInv){ret=this._sevInv[sev]}return ret||sev};Severity.prototype.isMapped=function(sev){return!!(this._sevInv&&this._sevInv[sev])};Severity.prototype.isSev=function(sev){return SEVERITY.includes(sev)||this.isMapped(sev)};Severity.prototype.getSevExpr=function(sev){var origSev,ret={};ret.sev=origSev=_stripOp(sev);ret.sev=this.unmap(ret.sev);ret.op=sev.replace(origSev,"");ret.op=ret.op.length?ret.op:null;if(ret.op&&ret.op==="=="){ret.op="="}ret.lev=this._assignLevel(ret.sev);return ret};Severity.prototype.getMsgSev=function(msgId){return this._sevMsg?this._sevMsg[msgId]:null};Severity.prototype.getConfigSevExpr=function(){return this._sevExpr};Severity.prototype.getSevList=function(){return SEVERITY};Severity.prototype.getSevMap=function(){return this._sevSet};Severity.prototype.getInvertedSevMap=function(){return this._sevInv};Severity.prototype.getMappedArray=function(){if(!this._sevInvArray&&this._sevInv){let a,i;this._sevInvArray=a=[];for(i=0;i<SEVERITY.length;i++){a.push(this.map(SEVERITY[i]))}}return this._sevInvArray};Severity.prototype.setSevExpr=function(expr){this._sevExpr=expr};Severity.prototype.setSevMap=function(sevMap,sevInv){this._sevMap=sevMap;this._sevSet=sevMap.sevSet;this._sevInv=sevInv};Severity.prototype.setSevMsg=function(sevMsg){this._sevMsg=sevMsg};Severity.prototype.getSevLib=function(){if(!this._sevLib){this._sevLib=new SevLib(this)}return this._sevLib};Severity.prototype._assignLevel=function(sev){var lev=SEVERITY.indexOf(sev);if(lev<0&&sev!=="all"){sev=this.unmap(sev);lev=SEVERITY.indexOf(sev)}return lev};function _stripOp(sev){var c,x,s=sev;if(sev){c=sev.charAt(0);if(c===">"||c==="<"||c==="="){x=1;if(sev.charAt(1)==="="){x=2}s=sev.substr(x)}}return s};module.exports=Severity;
package/lib/Stats.js ADDED
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ var Stats=function(){this.errors=0;this.warnings=0;this.asserts=0;this.totalFilesSelected=0;this.totalFilesAudited=0;this.totalIssues=0;this.totalIssueFiles=0;this.errorFiles=0;this.parseErrors=0;this.totalUrlsAudited=0;this.sevStats={critical:0,blocker:0,major:0,minor:0,info:0};this.totalSevStats={critical:0,blocker:0,major:0,minor:0,info:0};this.rulesFired=0;this.hooksFired=0;this.packRulesFired};Stats.prototype.clearAll=function(){this.clearErrWarnAsserts();this.clearFileStats();this.clearSevStats();this.clearTotalSevStats();this.clearRulesFired();this.clearPackRulesFired()};Stats.prototype.clearErrWarnAsserts=function(){this.errors=this.warnings=this.asserts=0};Stats.prototype.clearSevStats=function(){this.sevStats.critical=this.sevStats.blocker=this.sevStats.major=this.sevStats.minor=this.sevStats.info=0};Stats.prototype.clearTotalSevStats=function(){this.totalSevStats.critical=this.totalSevStats.blocker=this.totalSevStats.major=this.totalSevStats.minor=this.totalSevStats.info=0};Stats.prototype.clearFileStats=function(){this.totalIssues=this.totalIssueFiles=this.errorFiles=this.parseErrors=this.totalFilesSelected=this.totalFilesAudited=this.totalUrlsAudited=0};Stats.prototype.clearRulesFired=function(){this.rulesFired=this.hooksFired=0};Stats.prototype.clearPackRulesFired=function(){if(this.packRulesFired){for(let i=0;i<this.packRulesFired.length;i++){let pack=this.packRulesFired[i];if(Object.keys(pack.rules).length){pack.rules={}}}}};Stats.prototype.addSevStatsToTotals=function(clear){this.totalSevStats.critical+=this.sevStats.critical;this.totalSevStats.blocker+=this.sevStats.blocker;this.totalSevStats.major+=this.sevStats.major;this.totalSevStats.minor+=this.sevStats.minor;this.totalSevStats.info+=this.sevStats.info;if(clear){this.clearSevStats()}};module.exports=Stats;
package/lib/Ts.js CHANGED
@@ -1 +1,6 @@
1
- var AST=require("../lib/AST_Ts");var Comments=require("../lib/Comments");function Ts(parser,nd,rules,fileIndex,appCtx,msgCtx){this._parser=parser;this._rules=rules;this._Issue=appCtx.Issue;this._reporter=appCtx.reporter;this._fileIndex=fileIndex;this._utils=appCtx.utils;this._msgCtx=msgCtx;this._nd=nd;this._Ast=null;this._debugMode=msgCtx.debugMode;this._debug=msgCtx.debug;this._error=msgCtx.error;this._info=msgCtx.info;this._verboseMode=msgCtx.verboseMode;this._ecmaVer=appCtx.config.getEcmaVer();this._isComments=appCtx.config.getComments();this._reportJafIssue=appCtx.reportJafIssue;this._flushIssues=appCtx.flushIssues};Ts.prototype.parse=function(data){var self=this,rc;this._parseIt(data,function(treenode){rc=self._parser.fireHookFileRules(treenode,null,false)});this._parser.fireHookFileRules(null,null)};Ts.prototype.getAst=function(){return this._Ast.getAst()};Ts.prototype.getAstUtils=function(){return this._Ast.getUtils()};Ts.prototype._parseIt=function(data,cb){var ret=false,rowNow,colNow,issue,opts,arRawComs,startPos;try{this._debug("Parsing TS...");this._Ast=new AST(data,this._nd,this._ecmaVer,this._isComments);ret=!!this._Ast.getAst()}catch(e){startPos=this._parser.startJsPosition;opts=this._rules.getRuleOptions(this._parser.RULE_JS_DIAGNOSE,this._parser.JAF_RSI);if(opts&&opts.enabled){rowNow=e.lineNumber+(startPos.row===0?0:startPos.row-2);colNow=e.column+(startPos.col===0?0:startPos.col-1);issue=new this._Issue("JavaScript syntax - "+e.message);this._reportJafIssue(issue,this._parser.RULE_JS_DIAGNOSE,rowNow,colNow,e.index+startPos.startIndex,e.index+startPos.startIndex+1)}else{rowNow=e.lineNumber+(startPos.row===0?0:startPos.row-2);colNow=e.column+(startPos.col===0?0:startPos.col-1);console.log("\nJS-DIAGNOSE : ["+rowNow+", "+colNow+"] "+e.message+"\n File -> "+this._curFile)}this._parser.parseErrors++;if(this._debugMode||this._verboseMode){this._info("[PARSE ERROR(4) : FILE "+(this._curFile?this._curFile:"N/A")+" "+this._parser.parseErrors)}}if(ret){if(cb)cb(this._Ast.getProgram());ret=false;try{this._debug("Walking TS...");if(this._isComments){arRawComs=this._Ast.getRawComments();if(arRawComs&&arRawComs.length){if(!this._comments){this._comments=new Comments(this._nd,this._rules,this._msgCtx,this._utils)}this._comments.reset(this._Ast)}}this._Ast.walk(this._AstNodeHandler.bind(this));ret=true}catch(e){this._error("TypeScript walk failure - "+e+" in "+this._curFile)}}return ret};Ts.prototype._AstNodeHandler=function(node){var coms;if(this._rules.isTypeRegistered(node.type)){if(this._comments){coms=this._comments.isDisabled(node);if(coms&&(!coms.rules||coms.rules.length===0)){return}this._rules.setJSCommentCallback(coms?function(ruleName){var b=coms.rules.includes(ruleName);return!coms.invert?b:!b}:null)}this._rules.fireRules({type:node.type,node:node,position:{offset:this._parser.startJsPosition.startIndex,start:node.range[0],end:node.range[1]},data:this._Ast.getData(),utils:{AstUtils:this._Ast.getUtils()}},node,this._parser.curFile,this._parser.curFileType,null)}};Ts.prototype.getTsAst=function(){return this._Ast};Ts.prototype.clear=function(){};module.exports=Ts;
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ var AST=require("../lib/AST_Ts");var Comments=require("../lib/Comments");function Ts(parser,nd,rules,fileIndex,appCtx,msgCtx){this._parser=parser;this._rules=rules;this._Issue=appCtx.Issue;this._reporter=appCtx.reporter;this._fileIndex=fileIndex;this._utils=appCtx.utils;this._msgCtx=msgCtx;this._nd=nd;this._Ast=null;this._debugMode=msgCtx.debugMode;this._debug=msgCtx.debug;this._error=msgCtx.error;this._info=msgCtx.info;this._verboseMode=msgCtx.isVerbose;this._config=appCtx.config;this._ecmaVer=appCtx.config.getEcmaVer();this._isComments=appCtx.config.getComments();this._reportJafIssue=appCtx.reportJafIssue;this._flushIssues=appCtx.flushIssues};Ts.prototype.parse=function(data,fileType){var self=this,rc;this._parseIt(data,fileType,function(treenode){rc=self._parser.fireHookFileRules(treenode,null,false)});this._parser.fireHookFileRules(null,null)};Ts.prototype.getAst=function(){return this._Ast.getAst()};Ts.prototype.getAstUtils=function(){return this._Ast?this._Ast.getUtils():null};Ts.prototype._parseIt=function(data,fileType,cb){var ret=false,rowNow,colNow,issue,opts,arRawComs,startPos;try{this._debug("Parsing TS/X...");this._Ast=new AST(data,fileType,this._nd,this._ecmaVer,this._isComments,this._msgCtx,this._config);ret=!!this._Ast.getAst()}catch(e){startPos=this._parser.startJsPosition;opts=this._rules.getRuleOptions(this._parser.RULE_TS_DIAGNOSE,this._parser.JAF_RSI);if(opts&&opts.enabled){rowNow=e.lineNumber+(startPos.row===0?0:startPos.row-2);colNow=e.column+(startPos.col===0?0:startPos.col-1);issue=new this._Issue("TypeScript syntax - "+e.message);this._reportJafIssue(issue,this._parser.RULE_TS_DIAGNOSE,rowNow,colNow,e.index+startPos.startIndex,e.index+startPos.startIndex+1)}else{rowNow=e.lineNumber+(startPos.row===0?0:startPos.row-2);colNow=e.column+(startPos.col===0?0:startPos.col-1);console.log(`\nTS-DIAGNOSE : [${rowNow}, ${colNow}] ${e.message}\n File -> ${this._curFile}`)}this._parser.parseErrors++;if(this._debugMode||this._verboseMode){this._info(`[TS PARSE ERROR(4) #${this._parser.parseErrors} : '${e.message}' File -> ${this._parser.curFile?this._parser.curFile:"n/a"}`)}}if(!ret){return ret}if(cb)cb(this._Ast.getProgram());ret=false;try{this._debug("Walking TS...");if(this._isComments){arRawComs=this._Ast.getRawComments();if(arRawComs&&arRawComs.length){if(!this._comments){this._comments=new Comments(this._nd,this._rules,this._msgCtx,this._utils,true)}this._comments.reset(this._Ast)}}this._Ast.walk(this._AstNodeHandler.bind(this));ret=true}catch(e){this._error(`TypeScript walk failure - ${e} in ${this._parser.curFile}`)}return ret};Ts.prototype._AstNodeHandler=function(node){var coms;if(this._rules.isTypeRegistered(node.type)){if(this._comments){coms=this._comments.isDisabled(node);if(coms&&(!coms.rules||coms.rules.length===0)){return}this._rules.setJSCommentCallback(coms?function(ruleName){var b=coms.rules.includes(ruleName);return!coms.invert?b:!b}:null)}this._rules.fireRules({type:node.type,node:node,position:{offset:this._parser.startJsPosition.startIndex,start:node.range[0],end:node.range[1]},data:this._Ast.getData(),utils:{AstUtils:this._Ast.getUtils()}},node,this._parser.curFile,this._parser.curFileType,null)}};Ts.prototype.getAst=function(){return this._Ast};Ts.prototype.clear=function(){};module.exports=Ts;
package/lib/Utils.js CHANGED
@@ -1 +1,6 @@
1
- const daysOfWeek=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];const WHITESPACE=" \t\n\r\x0B";const DOT=".";function Utils(){this._tabHandler=null};Utils.prototype.isObject=function(value){return typeof value==="object"&&!Array.isArray(value)};Utils.prototype.isArrayContentsType=function(ar,type){var i,ret=true;for(i=0;i<ar.length;i++){if(this.getType(ar[i])!==type){ret=false;break}}return ret};Utils.prototype.extend=function(from,internal,to){var prop,what;to=to||{};for(prop in from){if(!internal&&(prop.startsWith("_")||prop==="$builtin")){continue}what=from[prop];if(Array.isArray(what)){to[prop]=what.slice()}else{to[prop]=what}}return to};Utils.prototype.hasAnyProps=function(obj){var ret=false;for(var prop in obj){if(obj.hasOwnProperty(prop)){ret=true;break}}return ret};Utils.prototype.isProperty=function(obj,propName){var a,i;a=this.splitString(propName,".");for(i=0;i<a.length;i++){if(this.getType(obj)!=="object"||!obj.hasOwnProperty(a[i])){break}obj=obj[a[i]]}return i>=a.length};Utils.prototype.getProperty=function(obj,propName){var a,i;a=this.splitString(propName,".");for(i=0;i<a.length;i++){if(this.getType(obj)!=="object"||!obj.hasOwnProperty(a[i])){break}obj=obj[a[i]]}return i>=a.length?obj:undefined};Utils.prototype.splitString=function(s,sep){var a=s.split(sep);a.forEach(function(val,index){a[index]=a[index].trim()});return a};Utils.prototype.getType=function(val){var t=typeof val;if(val===undefined){t="undefined"}else if(val===null){t="null"}else if(t==="object"){if(Array.isArray(val)){t="array"}else if(this.isObject(val)){t="object"}else{console.log("[ASSERT] unknown object type' "+t+"'");t="?"}}return t};Utils.prototype.format=function(msg,vars){var v,k,k2,i;for(v in vars){k="${"+v+"}";k2=new RegExp("\\$\\{"+v+"\\}","g");i=msg.indexOf(k);if(i>=0){msg=msg.replace(k2,vars[v])}}return msg};Utils.prototype.removeMarkup=function(m){var s;if(!m){return m}s=m.replace(/<[^>]+>/g,"");s=s.replace(/\s\s+/g," ");return s};Utils.prototype.getRowColFromIndex=function(data,disp,fileType,tabs){var row=1,col=1,i,c,len=data.length;var oTabs=tabs?tabs:this._tabHandler;for(i=0;i<len;i++){if(i===disp)break;c=data.charAt(i);if(c==="\n"){row++;col=1}else if(c==="\t"){if(oTabs){col=oTabs.getTabCol(col,fileType)}else{col++}}else if(c!=="\r"){col++}}return{row:row,col:col}};Utils.prototype.eatLine=function(str,index){var ret,i,c;index=index||0;if(index>str.length){ret=""}for(i=index;i<str.length;i++){c=str.charAt(i);if(c=="\n"){ret=str.substring(i+1);break}}return ret};Utils.prototype.getIndexToWhitespace=function(str,startIndex){var i,len,ret=-1;startIndex=startIndex>=0?startIndex:0;len=str?str.length:0;for(i=startIndex;i<len;i++){if(this.isWhitespace(str.charAt(i))){ret=i;break}}return ret};Utils.prototype.eatWhitespace=function(str,startIndex){var i,len,ret=-1;startIndex=startIndex>=0?startIndex:0;len=str?str.length:0;for(i=startIndex;i<len;i++){if(WHITESPACE.indexOf(str[i])<0){ret=i;break}}return ret};Utils.prototype.isWhitespace=function(c){return WHITESPACE.indexOf(c)>=0};Utils.prototype.isAlpha=function(c){return c>="a"&&c<="z"||c>="A"&&c<="Z"};Utils.prototype.isDigit=function(c){return c>="0"&&c<="9"};Utils.prototype.isAlphaNum=function(c){return this.isAlpha(c)||this.isDigit(c)};Utils.prototype.getCurrentDate=function(dateObj){var date,dayOfweek,tmp;date=dateObj?dateObj:new Date;dayOfweek=daysOfWeek[date.getDay()];date=date.toString();tmp=date.split(" ");tmp[0]=dayOfweek;return dayOfweek+" "+tmp[1]+" "+tmp[2]+", "+tmp[3]};Utils.prototype.getCurrentTime=function(dateObj){var time,hours,mins,zone;var ampm="am";time=dateObj?dateObj:new Date;hours=time.getHours();mins=time.getMinutes();if(hours>12){hours-=12;ampm="pm"}zone=time.toLocaleTimeString("en-us",{timeZoneName:"short"}).split(" ")[2];return hours+":"+(mins<=9?"0":"")+mins+ampm+" "+zone};Utils.prototype.setTabHandler=function(oTabs){this._tabHandler=oTabs};module.exports=Utils;
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 daysOfWeek=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];const WHITESPACE=" \t\n\r\x0B";const NL="\n";const CR="\r";const DOT=".";function Utils(nd){this._nd=nd;this._tabHandler=null};Utils.prototype.isObject=function(value){return typeof value==="object"&&!Array.isArray(value)};Utils.prototype.isArrayContentsType=function(ar,type){var i,elemType,ret=true;var isAr=Array.isArray(type);for(i=0;i<ar.length;i++){elemType=this.getType(ar[i]);if(isAr&&!type.includes(elemType)||!isAr&&elemType!==type){ret=false;break}}return ret};Utils.prototype.extend=function(from,internal,to){var prop,what;to=to||{};for(prop in from){if(!internal&&(prop.startsWith("_")||prop==="$builtin")){continue}what=from[prop];if(Array.isArray(what)){to[prop]=what.slice()}else{to[prop]=what}}return to};Utils.prototype.hasAnyProps=function(obj){var ret=false;if(obj){for(var prop in obj){if(obj.hasOwnProperty(prop)){ret=true;break}}}return ret};Utils.prototype.isProperty=function(obj,propName){var a,i;a=this.splitString(propName,DOT);for(i=0;i<a.length;i++){if(this.getType(obj)!=="object"||!obj.hasOwnProperty(a[i])){break}obj=obj[a[i]]}return i>=a.length};Utils.prototype.getProperty=function(obj,propName){var a,i;a=this.splitString(propName,DOT);for(i=0;i<a.length;i++){if(this.getType(obj)!=="object"||!obj.hasOwnProperty(a[i])){break}obj=obj[a[i]]}return i>=a.length?obj:undefined};Utils.prototype.splitString=function(s,sep){var a=s.split(sep);a.forEach(function(val,index){a[index]=a[index].trim()});return a};Utils.prototype.getType=function(val){var t=typeof val;if(val===undefined){t="undefined"}else if(val===null){t="null"}else if(t==="object"){if(Array.isArray(val)){t="array"}else if(this.isObject(val)){t="object"}else{console.log("[ASSERT] unknown object type' "+t+"'");t="?"}}return t};Utils.prototype.format=function(msg,vars){var v,k,k2,i;for(v in vars){k="${"+v+"}";k2=new RegExp("\\$\\{"+v+"\\}","g");i=msg.indexOf(k);if(i>=0){msg=msg.replace(k2,vars[v])}}return msg};Utils.prototype.removeMarkup=function(m){var s;if(!m){return m}s=m.replace(/<[^>]+>/g,"");s=s.replace(/\s\s+/g," ");return s};Utils.prototype.getRowColFromIndex=function(data,disp,fileType,tabs){var row=1,col=1,i,c,len=data.length;var oTabs=tabs?tabs:this._tabHandler;for(i=0;i<len;i++){if(i===disp)break;c=data.charAt(i);if(c==="\n"){row++;col=1}else if(c==="\t"){if(oTabs){col=oTabs.getTabCol(col,fileType)}else{col++}}else if(c!=="\r"){col++}}return{row:row,col:col}};Utils.prototype.decommentJson=function(text){return this._nd.decomment(text)};Utils.prototype.parseJson=function(data,comments){var obj,ret;comments=typeof comments!=="undefined"?!!comments:true;if(comments){data=this._nd.decomment(data)}try{let x=this.eatWhitespace(data);if(x>=0){let c=data.charAt(x);if(c!=="{"&&c!=="["){return this._convertJsonPosToRowCol("Invalid JSON - unexpected start character '"+c+"' at position "+x,data)}}obj=JSON.parse(data);ret={obj:obj,msg:null,startIndex:undefined,endIndex:undefined}}catch(e){if(e.toString().startsWith("SyntaxError")){ret=this._convertJsonPosToRowCol(e.message,data)}else{ret.msg=e.message}ret.obj=null}return ret};Utils.prototype._convertJsonPosToRowCol=function(msg,data){var x,n,rc;x=msg.indexOf("position");if(x<0){return null}n=parseInt(msg.substr(x+8).trim());rc=this.getRowColFromIndex(data,n);x=msg.indexOf("at");if(x>=0){msg=msg.substring(0,x).trimRight()}x=msg.indexOf("token");if(x>=0){x+=6;let c=msg.charAt(x);let q=c==="'"?"\"":"'";msg=msg.substring(0,x)+q+c+q+msg.substring(x+1)}return{msg:msg,line:rc.row,col:rc.col,startIndex:n,endIndex:n}};Utils.prototype.eatLine=function(str,index){var ret,i,c;index=index||0;if(index>str.length){ret=""}for(i=index;i<str.length;i++){c=str.charAt(i);if(c=="\n"){ret=str.substring(i+1);break}}return ret};Utils.prototype.getLineStart=function(data,index){var c;if(data.length&&index>0&&index<data.length){while(--index){c=data.charAt(index);if(c===NL||c===CR){return index+1}}}return 0};Utils.prototype.getIndexToWhitespace=function(str,startIndex){var i,len,ret=-1;startIndex=startIndex>=0?startIndex:0;len=str?str.length:0;for(i=startIndex;i<len;i++){if(this.isWhitespace(str.charAt(i))){ret=i;break}}return ret};Utils.prototype.eatWhitespace=function(str,startIndex){var i,len,ret=-1;startIndex=startIndex>=0?startIndex:0;len=str?str.length:0;for(i=startIndex;i<len;i++){if(WHITESPACE.indexOf(str[i])<0){ret=i;break}}return ret};Utils.prototype.isWhitespace=function(c){return WHITESPACE.indexOf(c)>=0};Utils.prototype.isAlpha=function(c){return c>="a"&&c<="z"||c>="A"&&c<="Z"};Utils.prototype.isDigit=function(c){return c>="0"&&c<="9"};Utils.prototype.isAlphaNum=function(c){return this.isAlpha(c)||this.isDigit(c)};Utils.prototype.getCurrentDate=function(dateObj){var date,dayOfweek,tmp;date=dateObj?dateObj:new Date;dayOfweek=daysOfWeek[date.getDay()];date=date.toString();tmp=date.split(" ");tmp[0]=dayOfweek;return dayOfweek+" "+tmp[1]+" "+tmp[2]+", "+tmp[3]};Utils.prototype.getCurrentTime=function(dateObj){var time,hours,mins,zone;var ampm="am";time=dateObj?dateObj:new Date;hours=time.getHours();mins=time.getMinutes();if(hours>12){hours-=12;ampm="pm"}zone=time.toLocaleTimeString("en-us",{timeZoneName:"short"}).split(" ")[2];return hours+":"+(mins<=9?"0":"")+mins+ampm+" "+zone};Utils.prototype.setTabHandler=function(oTabs){this._tabHandler=oTabs};module.exports=Utils;
package/lib/Watch.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  var Watch=function(folder,cb,nd,ctxMsg){this._folder=folder;this._cd=cb;this._ctxMsg=ctxMsg;this._nd=nd;this._fs=nd.fs;this._watcher=null};Watch.prototype.watchFiles=function(){this._watcher=this._fs.watch("d:/testaudit/Jet_webapp2/src",{recursive:true},this._watchEvent)};Watch.prototype.stop=function(){try{if(this._watcher){this._watcher.close()}}catch(e){}this._watcher=null};Watch.prototype._watchEvent=function(event,filename){let target,fsWait,s;console.log("\nEVENT: '"+event+"', fsWait ="+fsWait+" "+filename);return;if(event==="close"){this._CB(event);return}if(event==="error"){this._watcher=null;this._CB(event);return}if(!filename||!event||fsWait){console.log("1");return}if(event!=="rename"){fsWait=setTimeout(function(){fsWait=false},100)}console.log("2");target=this._isDir?this._nd.path.join(this._folder,filename):filename;s=null;if(event==="rename"){console.log("A");s=this._readfile(target);if(s==null){return};console.log("B")}try{console.log("C");s=s||this._readfile(target);if(s===null){console.log("D");return}if(event!=="rename"){console.log("E")}console.log("\n--> "+filename+" event="+event+" ("+target+")")}catch(e){console.log("FAIL : "+e)}};Watch.prototype._readFile=function(file){if(!this._isFile(file)){return null}var s=null;try{console.log("reading..."+file);s=this._fs.readFileSync(file,"utf8");console.log("* "+typeof s+" "+(typeof s==="string"?s.length:""))}catch(e){console.log("read -> "+e)}return s};Watch.prototype._isFile=function(file){var stat,ret=false;try{stat=this._fs.statSync(file);ret=stat.isFile()}catch(e){console.log("isFile - > "+e)}console.log("isFile("+file+") - > "+ret);return ret};module.exports=Watch;
package/lib/Writer.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  function Writer(nd,msgCtx){this._logFile=false;this._toFile=false;this._toCon=msgCtx.console;this._toError=msgCtx.error;this._nd=nd};Writer.prototype.put=function(msg){if(this._toFile){try{this._nd.fs.appendFileSync(this._logFile,msg+"\r\n",{encoding:"utf8"})}catch(e){this._toError("[Error]: writing to output - reason ["+e.message+"]");this._toCon(msg)}}else{this._toCon(msg)}};Writer.prototype.open=function(filePath){var ret=null;if(filePath){this._logFile=filePath;if(this._nd.fs.existsSync(filePath)){this._nd.fs.unlinkSync(filePath)}try{this._nd.fs.openSync(filePath,"a");this._toFile=true}catch(err){ret=err}}return ret};module.exports=Writer;
package/lib/ZipUtils.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  const TEMP_ZIP_TEMPLATE='@@ziptmp-XXXXXX.zip';const fsUtils=require('../lib/FsUtils');var ZipUtils=function(nd){if(!this._unzipper){this._unzipper=require('adm-zip')}this._zip=null;this._nd=nd};ZipUtils.prototype.loadZip=function(zipPath){var ret;this._assertNoCurrentZip();this._zip=null;try{this._zip=new this._unzipper(zipPath);ret=true}catch(e){ret=e}return ret};ZipUtils.prototype.extractAll=function(to,zipPath,overwrite){var ret=false;try{this._assertNoCurrentZip();this._zip=null;this._zip=new this._unzipper(zipPath);if(this._zip){this._zip.extractAllTo(to,!!overwrite);ret=true}}catch(e){ret={message:e}}this._zip=null;return ret};ZipUtils.prototype.extractFileFromZip=function(filePath,zipPath){var text;try{if(zipPath){this._assertNoCurrentZip();this._zip=null;this._zip=new this._unzipper(zipPath)}if(this._zip){text=this._zip.readAsText(filePath);text=text?text.trim():''}}catch(e){text=e}return text};ZipUtils.prototype.getContents=function(zipPath){var entries,ret=[];if(typeof zipPath==='string'){try{this._assertNoCurrentZip();this._zip=null;this._zip=new this._unzipper(zipPath)}catch(e){ret=e}}if(this._zip){ret=[];entries=this._zip.getEntries();this._hierIndex=0;this._createHierarchy(entries,'',ret)}return ret};ZipUtils.prototype._createHierarchy=function(entries,subdir,ar){var entry,arDir,temp,x;for(;this._hierIndex<entries.length;this._hierIndex++){entry=entries[this._hierIndex];if(entry.isDirectory){if(entry.entryName.startsWith(subdir)||!subdir){arDir=[];temp=entry.entryName.substr(0,entry.entryName.length-1);x=temp.lastIndexOf('/');temp=x>=0?temp.substring(x+1):temp;ar.push({name:temp,path:entry.entryName,isFile:false,files:arDir});this._hierIndex++;this._createHierarchy(entries,entry.entryName,arDir)}else{this._hierIndex--;return}}else{if(entry.entryName.startsWith(subdir)||!subdir){ar.push({name:entry.name,isFile:true})}else{this._hierIndex--;return}}}};ZipUtils.prototype.writeBufferToFile=function(buffer,fpath){var ret;try{this._lastFile=fpath;this._nd.fs.writeFileSync(fpath,buffer);ret=true}catch(e){this._lastFile=null;ret=e}return ret};ZipUtils.prototype.deleteFile=function(fpath){var ret=null;try{fpath=fpath?fpath:this._lastFile;if(fpath){this._nd.fs.unlinkSync(fpath)}}catch(e){ret=e}this._zip=null;return ret};ZipUtils.prototype.getLastFilepath=function(){return this._lastFile};ZipUtils.prototype.createTempZipFilename=function(){return fsUtils.getUniqueFileName(TEMP_ZIP_TEMPLATE)};ZipUtils.prototype._assertNoCurrentZip=function(){if(this._zip){this._assert('loadZip but Zip EXISTS')}};module.exports=ZipUtils;
package/lib/api.js ADDED
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 OUTFMT=require("./outFormat");const UNDEF="undefined";var core;var nd;var stats;function Api(nodeDeps,JafCore){core=JafCore;stats=JafCore.getStats();nd=nodeDeps};Api.prototype.startSync=function(apiContext){core._ctxCB=apiContext;if(apiContext.config){let t=typeof apiContext.config;if(t==="string"){core._configPath=nd.path.join(core._curDir,apiContext.config)}else if(t==="object"){core._configPath=apiContext.config}else{core._error("Invalid config argument in init() : type is "+t);return 1}}if(apiContext.format&&apiContext.format!==OUTFMT.PROSE){apiContext.format=OUTFMT.PROSE}return core.start()};Api.prototype.start=function(apiContext,AmdMeta,AmdRulePacks){var t,_self,rc;core._isAsync=true;core._ctxCB=apiContext;_self=this;return new Promise(function(resolve,reject){if(apiContext.config){t=typeof apiContext.config;if(t==="string"){core._configPath=nd.path.join(core._curDir,apiContext.config)}else if(t==="object"){core._configPath=apiContext.config}else{core._error("Invalid config argument in init() : type is "+t);reject(1)}}if(!core._isAMD){core._isAsync=false;core._isAsyncTemp=true;rc=_self.startSync(apiContext);core._isAsync=true;rc===0?resolve(rc):reject(core._messageStack)}else{if(apiContext.format&&apiContext.format!==OUTFMT.PROSE){apiContext.format=OUTFMT.PROSE}core._isAsync=false;core._isAsyncTemp=true;core._AmdMeta=AmdMeta;core._AmdRulePacks=AmdRulePacks;if(AmdRulePacks&&!Array.isArray(AmdRulePacks)){core._error("init() : AMD rule packs must be specified as an array!");reject(1);return}rc=_self.startSync(apiContext);core._isAsync=true;rc===0?resolve(rc):reject(core._messageStack)}})};Api.prototype.auditSync=function(filespec){core._isAsync=false;stats.clearAll();if(core._regListenerTypesSet||core._rules&&core._rules.getActiveRuleCount()===0){if(core._rules){core._emitApiRunSummary()}return}if(filespec){if(!Array.isArray(filespec)){filespec=[filespec]}core._fileSet.setFiles(filespec,core._config.getExclude(),core._getMsgCtx())}core._startLifeCycle();core._emitApiRunSummary()};Api.prototype.audit=function(filespec){var obj;core._isAsync=true;core._totalIssues=core._totalIssueFiles=core._errorFiles=core._parseErrors=core._totalFilesSelected=core._totalFilesAudited=core._totalUrlsAudited=0;if(filespec){if(!Array.isArray(filespec)){filespec=[filespec]}core._fileSet.setFiles(filespec,core._config.getExclude(),core._getMsgCtx())}return new Promise(function(resolve){core._isAsync=false;obj=core._startLifeCycle();core._isAsync=true;core._emitApiRunSummary();resolve(obj)})};Api.prototype.on=function(evName,fn,obj){if(core._listenerSetup()){core._events.setListener(evName,fn,obj)}};Api.prototype.removeListener=function(evName,fn){if(core._listenerSetup()){core._events.removeListener(evName,fn)}};Api.prototype.removeAllListeners=function(evName){if(core._listenerSetup()){core._events.removeAllListeners(evName)}};Api.prototype.getDescription=function(arg1,arg2,arg3){var issue,short,ruleName,sig=0,ret="";var arg1Type=core._Utils.getType(arg1);var arg2Type=core._Utils.getType(arg2);if(arg1Type==="object"){issue=arg1;if(arg2==="boolean"||arg2Type===UNDEF){short=arg2;sig=1;ruleName=issue.rule;msgId=issue.msgId}}else if(arg1Type==="string"){if(arg2Type==="string"){msgId=arg1;ruleName=arg2;short=!!arg3;sig=2}}var loadedRule,rsi,msgId,fn;if(sig){rsi=core._ruleSets.getRsiFromMsgId(msgId);if(rsi<0){return""}loadedRule=core._ruleSets.getLoadedRule(rsi,ruleName);fn=short?loadedRule.getShortDescription.bind(loadedRule):loadedRule.getDescription.bind(loadedRule);ret=fn()}return ret};Api.prototype.getActiveRulesetInfo=function(fmt){var ret;if(fmt===OUTFMT.JSON)ret=core._rules.getRulesJson();else if(fmt===OUTFMT.PROSE||fmt===OUTFMT.LINE)ret=core._rules.getRulesProse();else ret=core._rules.getRulesSonar();return ret};Api.prototype.enableMsgId=function(msgid,state){var ret=false;if(core._config.setMessages(msgid,state)){core._reporter.setMessageFilter(core._config._config.messages);ret=true}return ret};Api.prototype.getConfig=function(){return core._config.getConfig()};Api.prototype.getSevLib=function(){return core._severity.getSevLib()};Api.prototype.setVsCodeExtHint=function(isVsCodeExt){core._VsCodeExtHint=isVsCodeExt};module.exports=Api;
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 Histo=require("./Histo");var Stats;class cliStats{constructor(nd,stats,severity,isColor,oConsole,info,isUnitTest,useStdErr){this._nd=nd;this._severity=severity;this._isColor=isColor;this._console=oConsole;this._info=info;this._isUnitTest=isUnitTest;this._useStdErr=useStdErr;Stats=stats}displayStatsAndHisto(elapsed){var colors=this._nd.colors;var isColor=this._isColor;var msg,msg2,sevs,n,m,l;n=Stats.errorFiles||Stats.parseErrors;m=Stats.totalIssues;msg="JET Audit: "+m+" issue"+(m!==1?"s":"")+(m!==1?" were":" was")+" found"+(m?" in "+Stats.totalIssueFiles+" file"+(Stats.totalIssueFiles!==1?"s":""):"")+".";msg="\n"+(m?isColor?colors.BLACKONRED(msg):msg:isColor?colors.GREEN(msg):msg);if(n){n=Stats.errorFiles;m=Stats.parseErrors;msg2=(n?" "+n+" file"+(n!==1?"s":"")+" could not be read.":"")+(m?" "+m+" parse error"+(m!==1?"s":"")+" "+(m===1?"was":"were")+" found.":"");msg+=isColor?colors.BLACKONRED(msg2):msg2}this._console(msg);if(this._useStdErr){process.stderr.write(msg+"\n")}n=Stats.totalFilesSelected;msg=_right(n,6)+" file"+(n===1?" ":"s ")+(n===1?"was":"were")+" selected.";n=Stats.totalFilesAudited;msg+="\n"+_right(n,6)+" file"+(n===1?" ":"s ")+(n===1?"was":"were")+" audited.";n=Stats.totalUrlsAudited;msg+="\n"+_right(n,6)+" URL"+(n===1?" ":"s ")+(n===1?"was":"were")+" audited.";n=Stats.rulesFired;msg+="\n"+_right(n,6)+" rule"+(n===1?" ":"s ")+(n===1?"was":"were")+" fired.";n=Stats.hooksFired;msg+="\n"+_right(n,6)+" hook rule"+(n===1?" ":"s ")+(n===1?"was":"were")+" fired.";sevs=this._severity.getMappedArray()||this._severity.getSevList();sevs=sevs.filter((val,x)=>sevs.indexOf(val)===x);l=0;sevs.forEach(v=>{n=v.length;l=n>l?n:l});l+=2;let sev,sevTotals;sevTotals=this._getSevTotals(Stats.totalSevStats);var histo=new Histo(sevTotals,40,isColor,colors);msg+="\n\n"+"-".repeat(10)+"Severities"+"-".repeat(10);for(sev in sevTotals){n=sevTotals[sev];msg+="\n"+_left(sev,l)+": "+_right(n,6)+" |"+histo.bar(n)}msg+="\n"+"-".repeat(30);n=Stats.warnings;if(n){msg2="Note: "+n+" warning"+(n!==1?"s":"")+(n===1?" was":" were")+" reported";if(isColor){msg2=colors.BLACKONRED(msg2)}msg+="\n\n"+msg2+"\n"}if(elapsed){msg+="\n[Elapsed: "+elapsed[0]+(elapsed[1]/1000000000).toString().substr(1,3)+"s]"}this._console(msg)}displayErrorsAndAsserts(){var colors=this._nd.colors;var isColor=this._isColor;var msg="";if(Stats.errors){msg+="[Error]: "+Stats.errors+" error";msg+=(Stats.errors===1?" was":"s were")+" found."}if(Stats.warnings){if(msg.length){msg+="\n"}msg+="[Warn]: "+Stats.warnings+" warning";msg+=(Stats.warnings===1?" was":"s were")+" found."}if(Stats.asserts){if(msg.length){msg+="\n"}msg+="[Warn]: "+Stats.asserts+" assert";msg+=(Stats.asserts===1?" was":"s were")+" found."}msg+="\n";if(!this._isUnitTest){this._info("\n"+(isColor?colors.BLACKONRED(msg):msg))}else{this._nd.fs.writeSync(process.stdout.fd,"\n"+(isColor?colors.BLACKONRED(msg):msg))}if(this._useStderr){process.stderr.write(msg+"\n")}}_getSevTotals(totalSevStats){var sevMap,sevTotals,sev,val,n=0;var sevTotals={};if(sevMap=this._severity.getInvertedSevMap()){for(sev in sevMap){val=sevMap[sev];if(!Array.isArray(val)){n+=totalSevStats[val]}else{val.forEach(v=>{n+=totalSevStats[v]})}sevTotals[sev]=n;n=0}}else{sevTotals=totalSevStats}return sevTotals}};function _right(num,len){var s=""+num;return len>s.length?" ".repeat(len-s.length)+s:s};function _left(num,len){var s=""+num;return len>s.length?s+" ".repeat(len-s.length):s};module.exports=cliStats;
package/lib/clone.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  function cloneOptions(opts){var o={},p;for(p in opts){if(p.startsWith("$")||p.startsWith("_")){continue}o[p]=cloneProperty(opts[p])}return o};function cloneProperty(p){var i;var t=typeof p;if(Array.isArray(p)){let a=[],i;for(i=0;i<p.length;i++){a.push(cloneProperty(p[i]))}return a}else if(t==="object"){return JSON.parse(JSON.stringify(p))}else if(t==="string"){return""+p}return p}module.exports={cloneOptions,cloneProperty};
package/lib/cmdline.js CHANGED
@@ -1 +1,6 @@
1
- const ARG_CONFIG="--config";const ARG_CONFIG_SHORT="-c";const ARG_BASE="--base";const ARG_BASE_SHORT="-b";const ARG_SEVERITY="--severity";const ARG_SEVERITY_SHORT="-s";const ARG_FORMAT="--format";const ARG_FORMAT_SHORT="-t";const ARG_RULEPATH="--rulepath";const ARG_RULEPATH_SHORT="-rp";const ARG_FOLLOWLINKS="--followlinks";const ARG_FOLLOWLINKS_SHORT="-fl";const ARG_NOFOLLOWLINKS="--nofollowlinks";const ARG_NOFOLLOWLINKS_SHORT="-nfl";const ARG_SHOWRULES="--rules";const ARG_SHOWRULES_SHORT="-r";const ARG_SHOWRULESJSON="--rulesjson";const ARG_SHOWRULESJSON_SHORT="-rj";const ARG_SHOWRULESSONAR="--rulessonar";const ARG_SHOWRULESSONAR_SHORT="-rs";const ARG_SHOWRULES_INTERNAL="-rx";const ARG_OUTPATH="--outpath";const ARG_OUTPATH_SHORT="-o";const ARG_NO_OUT="--noout";const ARG_NO_OUT_SHORT="-no";const ARG_NOCOLOR="--nocolor";const ARG_NOCOLOR_SHORT="-nc";const ARG_GROUPS="--groups";const ARG_GROUPS_SHORT="-g";const ARG_MSGID="--msgid";const ARG_MSGID_SHORT="-id";const ARG_WATCH="--watch";const ARG_WATCH_SHORT="-w";const ARG_VERSION="--version";const ARG_VERSION_SHORT="-v";const ARG_JETLIST="--jetlist";const ARG_JETLIST_SHORT="-jl";const ARG_JETVER="--jetver";const ARG_JETVER_SHORT="-jv";const ARG_NAMESPACE_LIST="--nslist";const ARG_NAMESPACE_LIST_SHORT="-nsl";const ARG_METAHIST="--metahist";const ARG_METAHIST_SHORT="-mh";const ARG_RC="--retcode";const ARG_RC_SHORT="-rc";const ARG_DRYRUN="--dryrun";const ARG_DRYRUN_SHORT="-dr";const ARG_REG="--reg";const ARG_REG_SHORT="-reg";const ARG_HELP="--help";const ARG_HELP_SHORT="-h";const ARG_HELP_SHORT_S="-hs";const ARG_EXTRA="--extra";const ARG_EXTRA_SHORT="-e";const ARG_DEBUG="--debug";const ARG_DEBUG_SHORT="-d";const ARG_SCAFFOLD="--init";const ARG_SCAFFOLD_SHORT="-i";const ARG_SCAFFOLD_RULE="--initrule";const ARG_SCAFFOLD_RULE_SHORT="-ir";const ARG_UNIT_TEST="-ut";const ARG_OJET="--ojet";const ARG_OJET_SHORT="-ojet";const ARG_EXPERIMENTAL="--x";const ARG_EXPERIMENTAL_SHORT="-x";const ARG_EXPERIMENTAL_TS="--xts";const ARG_EXPERIMENTAL_TS_SHORT="-xts";var configSet,baseSet,rulePathSet,formatSet,outPathSet;var JafCore;module.exports.checkArgs=function(nodeDeps,Core,Severity,macros,FORMAT_PROSE,FORMAT_JSON,FORMAT_LINE){var argLen,argOrig,arg,dontRun,ftype,temp,bArgsOk=true,bWantHelp=false,debugTitle;JafCore=Core;JafCore._jetauditdir=nodeDeps.process.argv[1];JafCore._jetauditdir=nodeDeps.path.dirname(JafCore._jetauditdir);_checkBaseOptions(Core);argLen=process.argv.length;for(var i=2;i<argLen;i++){argOrig=process.argv[i];arg=argOrig.toLowerCase().trim();if(arg.length===0){continue}if(arg.charAt(0)!=="-"){if(!JafCore._srcStack){JafCore._srcStack=[]}arg=process.argv[i];arg=_handleQuotes(arg);arg=nodeDeps.path.normalize(arg);arg=nodeDeps.path.resolve(arg);JafCore._srcStack.push(arg);if(JafCore._debugMode||JafCore._verboseMode){if(!debugTitle){JafCore._info("Command line files specified:");debugTitle=true}JafCore._info(" "+arg)}continue}if(arg===ARG_EXTRA||arg===ARG_EXTRA_SHORT){continue}else if(arg===ARG_DEBUG||arg===ARG_DEBUG_SHORT){continue}else if(arg===ARG_NOCOLOR||arg===ARG_NOCOLOR_SHORT){continue}else if(arg===ARG_MSGID||arg===ARG_MSGID_SHORT){JafCore._msgIdMode=true;JafCore._msgIdModeSet=true}else if(arg===ARG_VERSION||arg===ARG_VERSION_SHORT){JafCore._showVersion();dontRun=true}else if(arg===ARG_HELP||arg===ARG_HELP_SHORT||arg===ARG_HELP_SHORT_S){if(i+1<argLen){temp=process.argv[i+1];if(arg===ARG_HELP||arg===ARG_HELP_SHORT){JafCore._manCheckL=temp}else{JafCore._manCheckS=temp}JafCore._isManual=true;if(configSet){break}}else{JafCore._showHelp();dontRun=true;break}}else if(arg===ARG_JETLIST||arg===ARG_JETLIST_SHORT){JafCore._jetverList=true;break}else if(arg===ARG_NAMESPACE_LIST||arg===ARG_NAMESPACE_LIST_SHORT){JafCore._cmdNSList=true;break}else if(arg===ARG_METAHIST||arg===ARG_METAHIST_SHORT){JafCore._cmdMetaHist=true;break}else if(arg===ARG_CONFIG||arg===ARG_CONFIG_SHORT){i++;if(i<argLen){arg=process.argv[i];JafCore._configPath=nodeDeps.path.normalize(arg);JafCore._configPath=nodeDeps.path.resolve(JafCore._configPath);configSet=true;if(JafCore._isManual){break}}else{JafCore._error("Invalid --config option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_BASE||arg===ARG_BASE_SHORT){i++;if(i<argLen){JafCore._base=process.argv[i];if(JafCore._base===macros.cwd||nodeDeps.fsUtils.getFileType(JafCore._base)==="d"){JafCore._baseSet=true}else{JafCore._error("'--base' "+JafCore._base+" is not a directory!!");bArgsOk=false;bWantHelp=true}}else{JafCore._error("Invalid --base option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_SEVERITY||arg===ARG_SEVERITY_SHORT){i++;if(i<argLen){JafCore._severitySet=true;JafCore._cliSev=process.argv[i]}else{JafCore._error("Invalid --severity option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_JETVER||arg===ARG_JETVER_SHORT){i++;argOrig=i<argLen?process.argv[i]:null;arg=nodeDeps.jetver.validate(argOrig);if(arg){JafCore._error(arg);bArgsOk=false;break}arg=nodeDeps.jetver.getBestVersion(argOrig);if(!arg){JafCore._error("'"+argOrig+"' is not a valid JET version");bArgsOk=false;break}JafCore._jetverSet=arg;if((JafCore._verboseMode||JafCore._debugMode)&&arg!==argOrig){JafCore._info("[Info]: JET version '"+argOrig+"' was promoted to '"+arg+"'")}}else if(arg===ARG_RULEPATH||arg===ARG_RULEPATH_SHORT){i++;if(i<argLen){JafCore._rulePath=process.argv[i];ftype=nodeDeps.fsUtils.getFileType(JafCore._rulePath);if(ftype==="d"){rulePathSet=true}else{JafCore._error("'--rulepath' "+JafCore._rulepath+" not a directory!!");bArgsOk=false;bWantHelp=true}}else{JafCore._error("Invalid --rulepath option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_FORMAT||arg===ARG_FORMAT_SHORT){i++;if(i<argLen){argOrig=process.argv[i];arg=argOrig.toLowerCase();if(arg!==FORMAT_JSON&&arg!==FORMAT_PROSE&&arg!==FORMAT_LINE){JafCore._error("Invalid --format(-t) option '"+argOrig+"'");bArgsOk=false;bWantHelp=true}else{JafCore._outFormat=arg;formatSet=true}}else{JafCore._error("Invalid --format option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_OUTPATH||arg===ARG_OUTPATH_SHORT){i++;if(outPathSet){JafCore._error("--outPath and --noout are mutually exclusive");bArgsOk=false;bWantHelp=true}else{if(i<argLen){arg=process.argv[i];arg=nodeDeps.path.normalize(arg);JafCore._outPath=nodeDeps.path.resolve(arg);outPathSet=true}else{JafCore._error("Invalid --outPath option");bArgsOk=false;bWantHelp=true}}}else if(arg===ARG_NO_OUT||arg===ARG_NO_OUT_SHORT){if(outPathSet){JafCore._error("--outPath and --noout are mutually exclusive");bArgsOk=false;bWantHelp=true}else{JafCore._outPath="$noout";outPathSet=true}}else if(arg===ARG_FOLLOWLINKS||arg===ARG_FOLLOWLINKS_SHORT){JafCore._followLinks=true;JafCore._followLinksSet=true}else if(arg===ARG_NOFOLLOWLINKS||arg===ARG_NOFOLLOWLINKS_SHORT){JafCore._followLinks=false;JafCore._followLinksSet=true}else if(arg===ARG_GROUPS||arg===ARG_GROUPS_SHORT){JafCore._groupsSet=_checkGroups(process.argv,i+1);if(!JafCore._groupsSet.groups||JafCore._groupsSet.groups.length===0){JafCore._error(!JafCore._groupsSet.groups?"groups missing after flag "+argOrig:"Invalid "+argOrig+" specification");bArgsOk=false;bWantHelp=true}i=JafCore._groupsSet.next;JafCore._groupsSet=JafCore._groupsSet.groups}else if(arg===ARG_RC||arg===ARG_RC_SHORT){i++;if(i<argLen){temp=process.argv[i];if(temp==="auto"||temp==="errors"){JafCore._retCode=temp}else{temp=parseInt(temp);if(!isNaN(temp)){JafCore._retCode=temp}else{JafCore._error(`--retCode '${process.argv[i]}' is invalid!`);bArgsOk=false;bWantHelp=true}}}else{JafCore._error("Invalid --retCode option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_SHOWRULES||arg===ARG_SHOWRULES_SHORT){JafCore._dumpRulesSet=true}else if(arg===ARG_SHOWRULESJSON||arg===ARG_SHOWRULESJSON_SHORT){JafCore._dumpRulesJsonSet=true}else if(arg===ARG_SHOWRULESSONAR||arg===ARG_SHOWRULESSONAR_SHORT){JafCore._dumpRulesSonarSet=true}else if(arg===ARG_SHOWRULES_INTERNAL){JafCore._dumpRulesInternalSet=true}else if(arg===ARG_DRYRUN||arg===ARG_DRYRUN_SHORT){JafCore._dryRunSet=true;JafCore._verboseMode=true;JafCore._verboseSet=true;JafCore._dumpRulesSet=true}else if(arg===ARG_REG||arg===ARG_REG_SHORT){JafCore._regListenerTypesSet=true}else if(arg===ARG_UNIT_TEST){JafCore._unitTest=true}else if(arg===ARG_OJET||arg===ARG_OJET_SHORT){JafCore._isOJETCLI=true}else if(arg===ARG_EXPERIMENTAL||arg===ARG_EXPERIMENTAL_SHORT){JafCore._experimentalSet=true}else if(arg===ARG_EXPERIMENTAL_TS||arg===ARG_EXPERIMENTAL_TS_SHORT){JafCore._experimentalTsSet=true}else if(arg===ARG_WATCH||arg===ARG_WATCH_SHORT){if(JafCore._experimentalSet){JafCore._watchSet=true}}else if(arg===ARG_SCAFFOLD||arg===ARG_SCAFFOLD_SHORT){JafCore._scaffoldSet=true}else if(arg===ARG_SCAFFOLD_RULE||arg===ARG_SCAFFOLD_RULE_SHORT){i++;if(i<argLen){JafCore._scaffoldRuleSet=process.argv[i]}else{JafCore._error("Invalid --initrule argument: rule name missing ");bArgsOk=false;bWantHelp=true}}else if(arg==="-z"){}else{JafCore._error("Invalid command flag \""+argOrig+"\"");bArgsOk=false;bWantHelp=true}}if(!dontRun&&bWantHelp){nodeDeps.help(JafCore._showVersion.bind(JafCore),JafCore._getMsgCtx())}return dontRun?"end":bArgsOk};module.exports.displayCmdLineOptionsSet=function(){JafCore._console("\n** Command line options:");if(JafCore._dryRunSet){JafCore._console(" - Dry run ON")}if(JafCore._verboseMode){JafCore._console(" - Verbose mode ON")}if(JafCore._debugMode){JafCore._console(" - Debug mode ON")}if(JafCore._watchSet){JafCore._console(" - watch mode ON")}if(JafCore._groupsSet){JafCore._console(" - Groups set to "+JafCore._groupsSet)}if(JafCore._colorSet){JafCore._console(" - Color mode "+(JafCore._colorMode?"ON":"OFF"))}if(JafCore._msgIdModeSet){JafCore._console(" - Show msg ID's "+(JafCore._msgIdModeSet?"ON":"OFF"))}if(formatSet){JafCore._console(" - Output in "+JafCore._outFormat.toUpperCase()+" format")}if(configSet){JafCore._console(" - Config set to "+JafCore._configPath)}if(JafCore._severitySet){JafCore._console(" - Severity set to '"+JafCore._severity+"'")}if(outPathSet){JafCore._console(" - Outpath set to "+(JafCore._outPath==="$noout"?"'none'":JafCore._outPath))}if(baseSet){JafCore._console(" - Base set to "+JafCore._base)}if(JafCore._jetverSet){JafCore._console(" - JET version set to "+JafCore._jetverSet)}if(JafCore._followLinksSet){JafCore._console(" - following stylesheet links is "+(JafCore._followLinks?"ON":"OFF"))}if(JafCore._dumpRulesSet||JafCore._dumpRulesJsonSet||JafCore._dumRulesSonarSet){JafCore._console(" - Dump Rules ON")}if(JafCore._retCode){JafCore._console(` - retCode set to ${JafCore._retCode}`)}JafCore._console("\n");return true};module.exports.isCmdLineOptionsSet=function(JafCore){return JafCore._verboseMode||JafCore._debugMode||JafCore._colorSet||configSet||baseSet||JafCore._dumpRulesSet||JafCore._dumpRulesJsonSet||JafCore._dumpRulesSonarSet||JafCore._dumpRulesInternalSet||formatSet||JafCore._configSet||JafCore._msgIdModeSet||outPathSet||JafCore._severitySet||rulePathSet||JafCore._watchSet||JafCore._jetverSet||JafCore._followLinksSet||JafCore._dryRunSet};function _checkBaseOptions(JafCore){var i,arg,argLen=process.argv.length;for(i=2;i<argLen;i++){arg=process.argv[i];if(arg.length===0||arg.charAt(0)!=="-"){continue}arg=arg.toLowerCase();if(arg===ARG_EXTRA||arg===ARG_EXTRA_SHORT){JafCore._verboseMode=true;JafCore._verboseSet=true}else if(arg===ARG_DEBUG||arg===ARG_DEBUG_SHORT){JafCore._debugMode=true;JafCore._debugSet=true}else if(arg===ARG_NOCOLOR||arg===ARG_NOCOLOR_SHORT){JafCore._colorMode=false;JafCore._colorSet=true}}};function _checkGroups(args,i){var arg,a,x,last,bound,groups;x=i;for(;;i++){if(i>=args.length||args[i].charAt(0)==="-"||last){break}arg=args[i].trim();if(x===i){bound=arg.startsWith("[")||arg.startsWith("(")}last=bound&&(arg.endsWith("]")||arg.endsWith(")"));arg=arg.replace(/[\[\(\)\]]/g,"").trim();if(!arg.length){break}arg=arg.replace(/,/g," ");arg=arg.replace(/ +(?= )/g,"").trim();if(!groups){groups=[]}a=arg.split(" ");groups=groups.concat(a)}return{next:bound?i:x,groups:groups}};function _handleQuotes(s){return s.replace(/[\"\']/g,"")};
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 OUTFMT=require("../lib/outFormat");const MACROS=require("../lib/macros");const ARG_CONFIG="--config";const ARG_CONFIG_SHORT="-c";const ARG_BASE="--base";const ARG_BASE_SHORT="-b";const ARG_SEVERITY="--severity";const ARG_SEVERITY_SHORT="-s";const ARG_FORMAT="--format";const ARG_FORMAT_SHORT="-t";const ARG_RULEPATH="--rulepath";const ARG_RULEPATH_SHORT="-rp";const ARG_FOLLOWLINKS="--followlinks";const ARG_FOLLOWLINKS_SHORT="-fl";const ARG_NOFOLLOWLINKS="--nofollowlinks";const ARG_NOFOLLOWLINKS_SHORT="-nfl";const ARG_SHOWRULES="--rules";const ARG_SHOWRULES_SHORT="-r";const ARG_SHOWRULESJSON="--rulesjson";const ARG_SHOWRULESJSON_SHORT="-rj";const ARG_SHOWRULESSONAR="--rulessonar";const ARG_SHOWRULESSONAR_SHORT="-rs";const ARG_SHOWRULES_INTERNAL="-rx";const ARG_OUTPATH="--outpath";const ARG_OUTPATH_SHORT="-o";const ARG_NO_OUT="--noout";const ARG_NO_OUT_SHORT="-no";const ARG_NOCOLOR="--nocolor";const ARG_NOCOLOR_SHORT="-nc";const ARG_GROUPS="--groups";const ARG_GROUPS_SHORT="-g";const ARG_GROUPS_EQ="--groups=";const ARG_GROUPS_EQ_SHORT="-g=";const ARG_MSGID="--msgid";const ARG_MSGID_SHORT="-id";const ARG_WATCH="--watch";const ARG_WATCH_SHORT="-w";const ARG_VERSION="--version";const ARG_VERSION_SHORT="-v";const ARG_JETLIST="--jetlist";const ARG_JETLIST_SHORT="-jl";const ARG_JETVER="--jetver";const ARG_JETVER_SHORT="-jv";const ARG_NAMESPACE_LIST="--nslist";const ARG_NAMESPACE_LIST_SHORT="-nsl";const ARG_METAHIST="--metahist";const ARG_METAHIST_SHORT="-mh";const ARG_RC="--retcode";const ARG_RC_EQ="--retcode=";const ARG_RC_SHORT="-rc";const ARG_RC_EQ_SHORT="-rc=";const ARG_DRYRUN="--dryrun";const ARG_DRYRUN_SHORT="-dr";const ARG_DAC="--daconfig";const ARG_DAC_SHORT="-dac";const ARG_REG="--reg";const ARG_REG_SHORT="-reg";const ARG_HELP="--help";const ARG_HELP_SHORT="-h";const ARG_HELP_SHORT_S="-hs";const ARG_EXTRA="--extra";const ARG_EXTRA_SHORT="-e";const ARG_DEBUG="--debug";const ARG_DEBUG_SHORT="-d";const ARG_SCAFFOLD="--init";const ARG_SCAFFOLD_SHORT="-i";const ARG_SCAFFOLD_RULE="--initrule";const ARG_SCAFFOLD_RULE_SHORT="-ir";const ARG_UNIT_TEST="-ut";const ARG_OJET="--ojet";const ARG_OJET_SHORT="-ojet";const ARG_EXPERIMENTAL="--x";const ARG_EXPERIMENTAL_SHORT="-x";var configSet,baseSet,rulePathSet,formatSet,outPathSet,retCodeSet;var JafCore;module.exports.checkArgs=function(nodeDeps,Core,Severity){var argLen,argOrig,arg,dontRun,ftype,temp,x,t,bArgsOk=true,bWantHelp=false,debugTitle;JafCore=Core;JafCore._jetauditdir=nodeDeps.process.argv[1];JafCore._jetauditdir=nodeDeps.path.dirname(JafCore._jetauditdir);_checkBaseOptions(Core);if(JafCore._debugSet){_dumpCmdLine()}argLen=process.argv.length;for(var i=2;i<argLen;i++){argOrig=process.argv[i];arg=argOrig.toLowerCase().trim();if(arg.length===0){continue}if(arg.charAt(0)!=="-"){if(!JafCore._srcStack){JafCore._srcStack=[]}arg=process.argv[i];arg=_handleQuotes(arg);arg=nodeDeps.path.normalize(arg);arg=nodeDeps.path.resolve(arg);JafCore._srcStack.push(arg);if(JafCore._debugMode||JafCore._verboseMode){if(!debugTitle){JafCore._info("Command line files specified:");debugTitle=true}JafCore._info(" "+arg)}continue}if(arg===ARG_EXTRA||arg===ARG_EXTRA_SHORT){continue}else if(arg===ARG_DEBUG||arg===ARG_DEBUG_SHORT){continue}else if(arg===ARG_NOCOLOR||arg===ARG_NOCOLOR_SHORT){continue}else if(arg===ARG_MSGID||arg===ARG_MSGID_SHORT){JafCore._msgIdMode=true;JafCore._msgIdModeSet=true}else if(arg===ARG_VERSION||arg===ARG_VERSION_SHORT){JafCore._showVersion();dontRun=true}else if(arg===ARG_HELP||arg===ARG_HELP_SHORT||arg===ARG_HELP_SHORT_S){if(i+1<argLen){temp=process.argv[i+1];if(temp.charAt(0)==="-"){JafCore._showHelp();dontRun=true;break}i++;if(arg===ARG_HELP||arg===ARG_HELP_SHORT){JafCore._manCheckL=temp}else{JafCore._manCheckS=temp}JafCore._isManual=true;if(configSet){break}}else{JafCore._showHelp();dontRun=true;break}}else if(arg===ARG_JETLIST||arg===ARG_JETLIST_SHORT){JafCore._jetverList=true;break}else if(arg===ARG_NAMESPACE_LIST||arg===ARG_NAMESPACE_LIST_SHORT){JafCore._cmdNSList=true;break}else if(arg===ARG_METAHIST||arg===ARG_METAHIST_SHORT){JafCore._cmdMetaHist=true;break}else if(arg===ARG_CONFIG||arg===ARG_CONFIG_SHORT){i++;if(i<argLen){arg=process.argv[i];JafCore._configPath=nodeDeps.path.normalize(arg);JafCore._configPath=nodeDeps.path.resolve(JafCore._configPath);configSet=true;if(JafCore._isManual){break}}else{JafCore._error("Invalid --config option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_BASE||arg===ARG_BASE_SHORT){i++;if(i<argLen){JafCore._base=process.argv[i];if(JafCore._base===MACROS.cwd||nodeDeps.fsUtils.getFileType(JafCore._base)==="d"){JafCore._baseSet=true}else{JafCore._error("'--base' "+JafCore._base+" is not a directory!!");bArgsOk=false;bWantHelp=true}}else{JafCore._error("Invalid --base option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_SEVERITY||arg===ARG_SEVERITY_SHORT){i++;if(i<argLen){JafCore._severitySet=true;JafCore._cliSev=process.argv[i]}else{JafCore._error("Invalid --severity option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_JETVER||arg===ARG_JETVER_SHORT){i++;argOrig=i<argLen?process.argv[i]:null;arg=nodeDeps.jetver.validate(argOrig);if(arg){JafCore._error(arg);bArgsOk=false;break}arg=nodeDeps.jetver.getBestVersion(argOrig);if(!arg){JafCore._error("'"+argOrig+"' is not a valid JET version");bArgsOk=false;break}JafCore._jetverSet=arg;if((JafCore._verboseMode||JafCore._debugMode)&&arg!==argOrig){JafCore._info("[Info]: JET version '"+argOrig+"' was promoted to '"+arg+"'")}}else if(arg===ARG_RULEPATH||arg===ARG_RULEPATH_SHORT){i++;if(i<argLen){JafCore._rulePath=process.argv[i];ftype=nodeDeps.fsUtils.getFileType(JafCore._rulePath);if(ftype==="d"){rulePathSet=true}else{JafCore._error("'--rulepath' "+JafCore._rulepath+" not a directory!!");bArgsOk=false;bWantHelp=true}}else{JafCore._error("Invalid --rulepath option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_FORMAT||arg===ARG_FORMAT_SHORT){i++;if(i<argLen){argOrig=process.argv[i];arg=argOrig.toLowerCase();if(arg!==OUTFMT.JSON&&arg!==OUTFMT.PROSE&&arg!==OUTFMT.LINE){JafCore._error("Invalid --format(-t) option '"+argOrig+"'");bArgsOk=false;bWantHelp=true}else{JafCore._outFormat=arg;formatSet=true}}else{JafCore._error("Invalid --format option");bArgsOk=false;bWantHelp=true}}else if(arg===ARG_OUTPATH||arg===ARG_OUTPATH_SHORT){i++;if(outPathSet){JafCore._error("--outPath and --noout are mutually exclusive");bArgsOk=false;bWantHelp=true}else{if(i<argLen){arg=process.argv[i];arg=nodeDeps.path.normalize(arg);JafCore._outPath=nodeDeps.path.resolve(arg);outPathSet=true}else{JafCore._error("Invalid --outPath option");bArgsOk=false;bWantHelp=true}}}else if(arg===ARG_NO_OUT||arg===ARG_NO_OUT_SHORT){if(outPathSet){JafCore._error("--outPath and --noout are mutually exclusive");bArgsOk=false;bWantHelp=true}else{JafCore._outPath="$noout";outPathSet=true}}else if(arg===ARG_FOLLOWLINKS||arg===ARG_FOLLOWLINKS_SHORT){JafCore._followLinks=true;JafCore._followLinksSet=true}else if(arg===ARG_NOFOLLOWLINKS||arg===ARG_NOFOLLOWLINKS_SHORT){JafCore._followLinks=false;JafCore._followLinksSet=true}else if(arg.startsWith(ARG_GROUPS_EQ)||arg.startsWith(ARG_GROUPS_EQ_SHORT)){x=arg.indexOf("=");if(temp=_convertToArray(argOrig.substring(x+1))){JafCore._groupsSet=temp}else{JafCore._error(`Invalid 'groups' declaration '${argOrig}`);bArgsOk=false;bWantHelp=true}}else if(arg===ARG_GROUPS||arg===ARG_GROUPS_SHORT){JafCore._groupsSet=_checkGroups(process.argv,i+1);if(!JafCore._groupsSet.groups||JafCore._groupsSet.groups.length===0){JafCore._error(!JafCore._groupsSet.groups?"groups missing after flag "+argOrig:"Invalid "+argOrig+" specification");bArgsOk=false;bWantHelp=true}i=JafCore._groupsSet.next;JafCore._groupsSet=JafCore._groupsSet.groups}else if(arg.startsWith(ARG_RC_EQ)||arg.startsWith(ARG_RC_EQ_SHORT)||arg===ARG_RC||arg===ARG_RC_SHORT){arg=argOrig;x=arg.indexOf("=");if(x>0){temp=argOrig.substring(0,x);arg=argOrig.substring(x+1)}else{temp=arg;i++;if(i<argLen){arg=process.argv[i]}else{JafCore._error(`missing arguments after '${argOrig}'`);bArgsOk=false;bWantHelp=true}}if(bArgsOk){temp=_processRetCode(temp,arg);if(temp||typeof temp==="number"){JafCore._retCode=temp;retCodeSet=true}else{JafCore._error(`${argOrig}' : ${arg.length?"'${arg}' is invalid":"missing argument?"}`);bArgsOk=false;bWantHelp=true}}}else if(arg===ARG_SHOWRULES||arg===ARG_SHOWRULES_SHORT){JafCore._dumpRulesSet=true}else if(arg===ARG_SHOWRULESJSON||arg===ARG_SHOWRULESJSON_SHORT){JafCore._dumpRulesJsonSet=true}else if(arg===ARG_SHOWRULESSONAR||arg===ARG_SHOWRULESSONAR_SHORT){JafCore._dumpRulesSonarSet=true}else if(arg===ARG_SHOWRULES_INTERNAL){JafCore._dumpRulesInternalSet=true}else if(arg===ARG_DRYRUN||arg===ARG_DRYRUN_SHORT){JafCore._dryRunSet=true;JafCore._dacSet=true;JafCore._verboseMode=true;JafCore._verboseSet=true;JafCore._dumpRulesSet=true}else if(arg===ARG_DAC||arg===ARG_DAC_SHORT){JafCore._dacSet=true}else if(arg===ARG_REG||arg===ARG_REG_SHORT){JafCore._regListenerTypesSet=true}else if(arg===ARG_UNIT_TEST){JafCore._unitTest=true}else if(arg===ARG_OJET||arg===ARG_OJET_SHORT){JafCore._isOJETCLI=true}else if(arg===ARG_EXPERIMENTAL||arg===ARG_EXPERIMENTAL_SHORT){JafCore._experimentalSet=true}else if(arg===ARG_WATCH||arg===ARG_WATCH_SHORT){if(JafCore._experimentalSet){JafCore._watchSet=true}}else if(arg===ARG_SCAFFOLD||arg===ARG_SCAFFOLD_SHORT){JafCore._scaffoldSet=true}else if(arg===ARG_SCAFFOLD_RULE||arg===ARG_SCAFFOLD_RULE_SHORT){i++;if(i<argLen){JafCore._scaffoldRuleSet=process.argv[i]}else{JafCore._error("Invalid --initrule argument: rule name missing ");bArgsOk=false;bWantHelp=true}}else if(arg==="-z"){}else{JafCore._error("Invalid command flag \""+argOrig+"\"");bArgsOk=false;bWantHelp=true}}if(!dontRun&&bWantHelp){nodeDeps.help(JafCore._showVersion.bind(JafCore),JafCore._getMsgCtx())}return dontRun?"end":bArgsOk};module.exports.displayCmdLineOptionsSet=function(){var s="\n** Command line options:\n";if(JafCore._dryRunSet){s+=" - Dry run ON\n"}if(JafCore._dacSet){s+=" - Display active config ON\n"}if(JafCore._verboseMode){s+=" - Verbose mode ON\n"}if(JafCore._debugMode){s+=" - Debug mode ON\n"}if(JafCore._watchSet){s+=" - watch mode ON\n"}if(JafCore._groupsSet){s+=" - Groups set to "+JafCore._groupsSet+"\n"}if(retCodeSet){s+=" - retCode set to "+JafCore._retCode+"\n"}if(JafCore._colorSet){s+=" - Color mode "+(JafCore._colorMode?"ON":"OFF")+"\n"}if(JafCore._msgIdModeSet){s+=" - Show msg ID's "+(JafCore._msgIdModeSet?"ON":"OFF")+"\n"}if(formatSet){s+=" - Output in "+JafCore._outFormat.toUpperCase()+" format\n"}if(configSet){s+=" - Config set to "+JafCore._configPath+"\n"}if(JafCore._severitySet){s+=" - Severity set to '"+JafCore._severity+"'\n"}if(outPathSet){s+=" - Outpath set to "+(JafCore._outPath==="$noout"?"'none'":JafCore._outPath)+"\n"}if(baseSet){s+=" - Base set to "+JafCore._base+"\n"}if(JafCore._jetverSet){s+=" - JET version set to "+JafCore._jetverSet+"\n"}if(JafCore._followLinksSet){s+=" - following stylesheet links is "+(JafCore._followLinks?"ON":"OFF")+"\n"}if(JafCore._dumpRulesSet||JafCore._dumpRulesJsonSet||JafCore._dumRulesSonarSet){s+=" - Dump Rules ON\n"}JafCore._console(s+"\n")};module.exports.isCmdLineOptionsSet=function(JafCore){return JafCore._verboseMode||JafCore._debugMode||JafCore._colorSet||configSet||baseSet||JafCore._dumpRulesSet||JafCore._dumpRulesJsonSet||JafCore._dumpRulesSonarSet||JafCore._dumpRulesInternalSet||formatSet||JafCore._configSet||JafCore._msgIdModeSet||outPathSet||JafCore._severitySet||rulePathSet||JafCore._watchSet||JafCore._jetverSet||retCodeSet||JafCore._followLinksSet||JafCore._dryRunSet||JafCore._dacSet};function _checkBaseOptions(JafCore){var i,arg,argLen=process.argv.length;for(i=2;i<argLen;i++){arg=process.argv[i];if(arg.length===0||arg.charAt(0)!=="-"){continue}arg=arg.toLowerCase();if(arg===ARG_EXTRA||arg===ARG_EXTRA_SHORT){JafCore._verboseMode=JafCore._verboseSet=true}else if(arg===ARG_DEBUG||arg===ARG_DEBUG_SHORT){JafCore._debugMode=JafCore._debugSet=true}else if(arg===ARG_NOCOLOR||arg===ARG_NOCOLOR_SHORT){JafCore._colorMode=false;JafCore._colorSet=true}}};function _checkGroups(args,i){var arg,a,x,last,bound,groups;x=i;for(;;i++){if(i>=args.length||args[i].charAt(0)==="-"||last){break}arg=args[i].trim();if(x===i){bound=arg.startsWith("[")||arg.startsWith("(")}last=bound&&(arg.endsWith("]")||arg.endsWith(")"));arg=arg.replace(/[\[\(\)\]]/g,"").trim();if(!arg.length){break}arg=arg.replace(/,/g," ");arg=arg.replace(/ +(?= )/g,"").trim();if(!groups){groups=[]}a=arg.split(" ");groups=groups.concat(a)}return{next:bound?i:x,groups:groups}};function _processRetCode(arg,val){var temp,ret;if(val==="auto"||val==="errors"){ret=val}else{temp=parseInt(val);if(!isNaN(temp)){ret=temp}else{if(temp=_convertToArray(val)){ret=temp}}}return ret};function _convertToArray(s){var a,n,i;if(s.charAt(0)==="["){s=s.substring(1);if(!s.length){return null}}if(s.charAt(s.length-1)==="]"){s=s.substring(0,s.length-1)}s=s.trim();if(!s.length){return null}s=s.replace(/\,/g," ");s=s.replace(/\s\s+/g," ").trim();a=s.split(" ");n=0;for(i=0;i<a.length;i++){if(a[i].length){n++}else{a=a.splice(i,1);i--}}return n?a:null};function _handleQuotes(s){return s.replace(/[\"\']/g,"")};function _dumpCmdLine(){var s="";for(var i=0;i<process.argv.length;i++){s+=`[${i}]: |${process.argv[i]}|\n`}console.log(s)}
package/lib/colors.js CHANGED
@@ -1 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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
+ */
1
6
  function RED(s){return _set(_color.RED,s)};function BRIGHTRED(s){return _set(_color.BRIGHTRED,s)};function GREEN(s){return _set(_color.GREEN,s)};function BRIGHTGREEN(s){return _set(_color.BRIGHTGREEN,s)}function BLUE(s){return _set(_color.BLUE,s)};function BRIGHTBLUE(s){return _set(_color.BLUE,s)};function CYAN(s){return _set(_color.CYAN,s)};function BRIGHTCYAN(s){return _set(_color.BRIGHTCYAN,s)};function YELLOW(s){return _set(_color.YELLOW,s)};function BRIGHTYELLOW(s){return _set(_color.BRIGHTYELLOW,s)};function PINK(s){return _set(_color.PINK,s)}function WHITE(s){return _set(_color.WHITE,s)};function WHITEONBLUE(s){return _set(_color.WHITEONBLUE,s)};function WHITEONRED(s){return _set(_color.WHITEONRED,s)};function BLACKONRED(s){return _set(_color.BLACKONRED,s)};const _color={BLACK:"30m",RED:"31m",BRIGHTRED:"91m",GREEN:"32m",BRIGHTGREEN:"92m",YELLOW:"33m",BRIGHTYELLOW:"93m",BLUE:"34m",BRIGHTBLUE:"94m",PURPLE:"35m",PINK:"95m",CYAN:"36m",BRIGHTCYAN:"96m",WHITE:"37m",WHITEONBLUE:"104m",WHITEONRED:"101m",BLACKONRED:"101;30m"};const START="\x1B[";const RESET="\x1B[0m";function _set(c,s){return c?START+c+s+RESET:s};module.exports.RED=RED;module.exports.BRIGHTRED=BRIGHTRED;module.exports.GREEN=GREEN;module.exports.BRIGHTGREEN=BRIGHTGREEN;module.exports.BLUE=BLUE;module.exports.BRIGHTBLUE=BRIGHTBLUE;module.exports.CYAN=CYAN;module.exports.BRIGHTCYAN=BRIGHTCYAN;module.exports.PINK=PINK;module.exports.YELLOW=YELLOW;module.exports.BRIGHTYELLOW=BRIGHTYELLOW;module.exports.WHITEONBLUE=WHITEONBLUE;module.exports.WHITEONRED=WHITEONRED;module.exports.BLACKONRED=BLACKONRED;
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2018, 2021, 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 ELLIPSIS="...";const INDENT=" ";const INDENT2=" ";const INDENT3=" ";const proseIndent=4;const SPACER=" ".repeat(proseIndent);const SPACER2=" ".repeat(proseIndent+3);const SPACER3=" ".repeat(proseIndent+5);const NL="\n";var utils;var out;var severity;var jsonRules;var haveProseRules=false;function getXml(){return out+"</rules>"};function getProse(){return out};function getJson(){return out};function ruleToXml(ruleName,rule,options){var ruleName,val,opt,xml,i;xml=INDENT+"<rule>\n";xml+=INDENT2+"<key>"+ruleName+"</key>\n";xml+=INDENT2+"<name>"+_limitLength(_escapeChevrons(rule.getShortDescription()),utils)+"</name>\n";xml+=INDENT2+"<description>\n";xml+=INDENT3+"<![CDATA["+_escapeCData(rule.getDescription())+"]]>\n";xml+=INDENT2+"</description>\n";for(opt in options){val=options[opt];if(opt==="severity"){xml+=INDENT2+"<severity>"+val.toUpperCase()+"</severity>\n"}else if(opt==="status"){val=val.toUpperCase();val=val==="PRODUCTION"?"READY":val;xml+=INDENT2+"<status>"+val+"</status>\n"}else if(opt==="group"){if(typeof val==="string"){xml+=INDENT2+"<tag>"+val+"</tag>\n"}else{for(i=0;i<val.length;i++){xml+=INDENT2+"<tag>"+val[i]+"</tag>\n"}}}}out+=xml+INDENT+"</rule>\n"};function setupRulesToXml(fnUtils){utils=fnUtils;out="<rules>\n"};function setupRulesToProse(severity,fnUtils){utils=fnUtils;out="\n------------ Rules Currently Active (rule severity: "+severity+") ---------------\n"};function setupRulesToJson(obj,sev,fnUtils){out=obj||{};severity=sev;out.rulesets=[];utils=fnUtils};function packToProse(rules,path,rsi){if(!rules){out+=SPACER2+"* No enabled rules available for this severity."+NL+NL}else{out+="["+(rsi+1)+"] "+rules.title+NL;out+=SPACER+"version : "+rules.version+NL;out+=SPACER+"prefix : "+rules.prefix+NL;out+=SPACER+"path : "+path+NL}haveProseRules=false};function ruleToProse(ruleName,rule,opts){out+=!haveProseRules?SPACER+"Rules:"+NL:"";out+=SPACER2+"* "+ruleName+" :"+NL;out+=SPACER3+"options : "+JSON.stringify(opts)+NL;out+=SPACER3+"short : "+rule.getShortDescription()+NL;out+=SPACER3+"long : "+rule.getDescription()+NL;out+=NL;haveProseRules=true};function getJson(){out.meta={"severity":severity};return out};function packToJson(rulePack){var ruleset;ruleset={};out.rulesets.push(ruleset);ruleset.title=rulePack.rulesJson.title;ruleset.path=rulePack.path;ruleset.prefix=rulePack.rulesJson.prefix;ruleset.version=rulePack.rulesJson.version;ruleset.rules=jsonRules={}};function ruleToJson(ruleName,rule,opts){jsonRules[ruleName]=opts;opts.shortDescription=rule.getShortDescription();opts.description=rule.getDescription()};function _limitLength(s,utils){if(s.length>200){for(let i=196;i>0;i--){if(utils.isWhitespace(s.charAt(i))){return s.substring(0,i+1)+ELLIPSIS}}s=ELLIPSIS}return s};function _escapeChevrons(s){let ret=s.replace(/\</g,"&lt;");ret=ret.replace(/\>/g,"&gt;");return ret.replace(/&nbsp;/g," ")};function _escapeCData(s){var i,bChange;while(true){bChange=false;i=s.indexOf("<oj-");if(i>=0){s=s.substr(0,i)+"&lt;"+s.substr(i+1);bChange=true;i=s.indexOf(">",i+1);if(i>=0){s=s.substr(0,i)+"&gt;"+s.substr(i+1)}i=s.indexOf("</oj-",i);if(i>=0){s=s.substr(0,i)+"&lt;"+s.substr(i+1);bChange=true;i=s.indexOf(">",i+1);if(i>=0){s=s.substr(0,i)+"&gt;"+s.substr(i+1)}}}i=s.indexOf("<!DOCTYPE");if(i>=0){s=s.substr(0,i)+"&lt;"+s.substr(i+1);i=s.indexOf(">",i+1);if(i>=0){s=s.substr(0,i)+"&gt;"+s.substr(i+1);bChange=true}}if(!bChange){break}}return s.replace(/&nbsp;/g," ")};module.exports={getXml:getXml,getProse:getProse,getJson:getJson,ruleToXml:ruleToXml,ruleToProse:ruleToProse,packToProse:packToProse,packToJson:packToJson,ruleToJson:ruleToJson,setupRulesToXml:setupRulesToXml,setupRulesToProse:setupRulesToProse,setupRulesToJson:setupRulesToJson};