bahlint 28.58.6934-dev-001

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 (420) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +354 -0
  3. package/bin/bahlint.js +267 -0
  4. package/bin/eslint.js +194 -0
  5. package/conf/ecma-version.js +16 -0
  6. package/conf/globals.js +169 -0
  7. package/conf/replacements.json +26 -0
  8. package/conf/rule-type-list.json +91 -0
  9. package/lib/api.js +39 -0
  10. package/lib/cli-engine/formatters/formatters-meta.json +18 -0
  11. package/lib/cli-engine/formatters/html.js +359 -0
  12. package/lib/cli-engine/formatters/json-with-metadata.js +16 -0
  13. package/lib/cli-engine/formatters/json.js +13 -0
  14. package/lib/cli-engine/formatters/stylish.js +153 -0
  15. package/lib/cli-engine/hash.js +35 -0
  16. package/lib/cli-engine/lint-result-cache.js +220 -0
  17. package/lib/cli.js +521 -0
  18. package/lib/config/config-loader.js +668 -0
  19. package/lib/config/config.js +674 -0
  20. package/lib/config/default-config.js +78 -0
  21. package/lib/config/flat-config-array.js +217 -0
  22. package/lib/config/flat-config-schema.js +598 -0
  23. package/lib/config-api.js +12 -0
  24. package/lib/eslint/eslint-helpers.js +1462 -0
  25. package/lib/eslint/eslint.js +1364 -0
  26. package/lib/eslint/index.js +7 -0
  27. package/lib/eslint/worker.js +173 -0
  28. package/lib/languages/js/index.js +336 -0
  29. package/lib/languages/js/source-code/index.js +7 -0
  30. package/lib/languages/js/source-code/source-code.js +1178 -0
  31. package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +61 -0
  32. package/lib/languages/js/source-code/token-store/backward-token-cursor.js +57 -0
  33. package/lib/languages/js/source-code/token-store/cursor.js +76 -0
  34. package/lib/languages/js/source-code/token-store/cursors.js +120 -0
  35. package/lib/languages/js/source-code/token-store/decorative-cursor.js +38 -0
  36. package/lib/languages/js/source-code/token-store/filter-cursor.js +42 -0
  37. package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +65 -0
  38. package/lib/languages/js/source-code/token-store/forward-token-cursor.js +62 -0
  39. package/lib/languages/js/source-code/token-store/index.js +695 -0
  40. package/lib/languages/js/source-code/token-store/limit-cursor.js +39 -0
  41. package/lib/languages/js/source-code/token-store/padded-token-cursor.js +45 -0
  42. package/lib/languages/js/source-code/token-store/skip-cursor.js +41 -0
  43. package/lib/languages/js/source-code/token-store/utils.js +131 -0
  44. package/lib/languages/js/validate-language-options.js +196 -0
  45. package/lib/linter/apply-disable-directives.js +583 -0
  46. package/lib/linter/code-path-analysis/code-path-analyzer.js +828 -0
  47. package/lib/linter/code-path-analysis/code-path-segment.js +262 -0
  48. package/lib/linter/code-path-analysis/code-path-state.js +2370 -0
  49. package/lib/linter/code-path-analysis/code-path.js +332 -0
  50. package/lib/linter/code-path-analysis/debug-helpers.js +223 -0
  51. package/lib/linter/code-path-analysis/fork-context.js +374 -0
  52. package/lib/linter/code-path-analysis/id-generator.js +44 -0
  53. package/lib/linter/esquery.js +332 -0
  54. package/lib/linter/file-context.js +88 -0
  55. package/lib/linter/file-report.js +604 -0
  56. package/lib/linter/index.js +11 -0
  57. package/lib/linter/interpolate.js +50 -0
  58. package/lib/linter/linter.js +1614 -0
  59. package/lib/linter/rule-fixer.js +199 -0
  60. package/lib/linter/source-code-fixer.js +154 -0
  61. package/lib/linter/source-code-traverser.js +333 -0
  62. package/lib/linter/source-code-visitor.js +81 -0
  63. package/lib/linter/timing.js +209 -0
  64. package/lib/linter/vfile.js +115 -0
  65. package/lib/options.js +416 -0
  66. package/lib/rule-tester/index.js +7 -0
  67. package/lib/rule-tester/rule-tester.js +1989 -0
  68. package/lib/rules/accessor-pairs.js +420 -0
  69. package/lib/rules/array-bracket-newline.js +291 -0
  70. package/lib/rules/array-bracket-spacing.js +301 -0
  71. package/lib/rules/array-callback-return.js +493 -0
  72. package/lib/rules/array-element-newline.js +374 -0
  73. package/lib/rules/arrow-body-style.js +418 -0
  74. package/lib/rules/arrow-parens.js +237 -0
  75. package/lib/rules/arrow-spacing.js +188 -0
  76. package/lib/rules/block-scoped-var.js +137 -0
  77. package/lib/rules/block-spacing.js +202 -0
  78. package/lib/rules/brace-style.js +278 -0
  79. package/lib/rules/callback-return.js +216 -0
  80. package/lib/rules/camelcase.js +422 -0
  81. package/lib/rules/capitalized-comments.js +325 -0
  82. package/lib/rules/class-methods-use-this.js +250 -0
  83. package/lib/rules/comma-dangle.js +424 -0
  84. package/lib/rules/comma-spacing.js +205 -0
  85. package/lib/rules/comma-style.js +391 -0
  86. package/lib/rules/complexity.js +201 -0
  87. package/lib/rules/computed-property-spacing.js +251 -0
  88. package/lib/rules/consistent-return.js +221 -0
  89. package/lib/rules/consistent-this.js +179 -0
  90. package/lib/rules/constructor-super.js +453 -0
  91. package/lib/rules/curly.js +425 -0
  92. package/lib/rules/default-case-last.js +51 -0
  93. package/lib/rules/default-case.js +103 -0
  94. package/lib/rules/default-param-last.js +78 -0
  95. package/lib/rules/dot-location.js +138 -0
  96. package/lib/rules/dot-notation.js +216 -0
  97. package/lib/rules/eol-last.js +135 -0
  98. package/lib/rules/eqeqeq.js +210 -0
  99. package/lib/rules/for-direction.js +168 -0
  100. package/lib/rules/func-call-spacing.js +281 -0
  101. package/lib/rules/func-name-matching.js +338 -0
  102. package/lib/rules/func-names.js +194 -0
  103. package/lib/rules/func-style.js +221 -0
  104. package/lib/rules/function-call-argument-newline.js +166 -0
  105. package/lib/rules/function-paren-newline.js +368 -0
  106. package/lib/rules/generator-star-spacing.js +246 -0
  107. package/lib/rules/getter-return.js +242 -0
  108. package/lib/rules/global-require.js +117 -0
  109. package/lib/rules/grouped-accessor-pairs.js +268 -0
  110. package/lib/rules/guard-for-in.js +85 -0
  111. package/lib/rules/handle-callback-err.js +122 -0
  112. package/lib/rules/id-blacklist.js +241 -0
  113. package/lib/rules/id-denylist.js +223 -0
  114. package/lib/rules/id-length.js +217 -0
  115. package/lib/rules/id-match.js +363 -0
  116. package/lib/rules/implicit-arrow-linebreak.js +125 -0
  117. package/lib/rules/indent-legacy.js +1369 -0
  118. package/lib/rules/indent.js +2334 -0
  119. package/lib/rules/index.js +332 -0
  120. package/lib/rules/init-declarations.js +172 -0
  121. package/lib/rules/jsx-quotes.js +128 -0
  122. package/lib/rules/key-spacing.js +822 -0
  123. package/lib/rules/keyword-spacing.js +701 -0
  124. package/lib/rules/line-comment-position.js +157 -0
  125. package/lib/rules/linebreak-style.js +135 -0
  126. package/lib/rules/lines-around-comment.js +581 -0
  127. package/lib/rules/lines-around-directive.js +249 -0
  128. package/lib/rules/lines-between-class-members.js +358 -0
  129. package/lib/rules/logical-assignment-operators.js +688 -0
  130. package/lib/rules/max-classes-per-file.js +90 -0
  131. package/lib/rules/max-depth.js +159 -0
  132. package/lib/rules/max-len.js +497 -0
  133. package/lib/rules/max-lines-per-function.js +238 -0
  134. package/lib/rules/max-lines.js +189 -0
  135. package/lib/rules/max-nested-callbacks.js +115 -0
  136. package/lib/rules/max-params.js +148 -0
  137. package/lib/rules/max-statements-per-line.js +224 -0
  138. package/lib/rules/max-statements.js +188 -0
  139. package/lib/rules/multiline-comment-style.js +652 -0
  140. package/lib/rules/multiline-ternary.js +257 -0
  141. package/lib/rules/new-cap.js +277 -0
  142. package/lib/rules/new-parens.js +120 -0
  143. package/lib/rules/newline-after-var.js +307 -0
  144. package/lib/rules/newline-before-return.js +242 -0
  145. package/lib/rules/newline-per-chained-call.js +159 -0
  146. package/lib/rules/no-alert.js +149 -0
  147. package/lib/rules/no-array-constructor.js +195 -0
  148. package/lib/rules/no-async-promise-executor.js +45 -0
  149. package/lib/rules/no-await-in-loop.js +115 -0
  150. package/lib/rules/no-bitwise.js +145 -0
  151. package/lib/rules/no-buffer-constructor.js +74 -0
  152. package/lib/rules/no-caller.js +52 -0
  153. package/lib/rules/no-case-declarations.js +80 -0
  154. package/lib/rules/no-catch-shadow.js +96 -0
  155. package/lib/rules/no-class-assign.js +66 -0
  156. package/lib/rules/no-compare-neg-zero.js +74 -0
  157. package/lib/rules/no-cond-assign.js +175 -0
  158. package/lib/rules/no-confusing-arrow.js +127 -0
  159. package/lib/rules/no-console.js +221 -0
  160. package/lib/rules/no-const-assign.js +73 -0
  161. package/lib/rules/no-constant-binary-expression.js +603 -0
  162. package/lib/rules/no-constant-condition.js +177 -0
  163. package/lib/rules/no-constructor-return.js +62 -0
  164. package/lib/rules/no-continue.js +38 -0
  165. package/lib/rules/no-control-regex.js +142 -0
  166. package/lib/rules/no-debugger.js +41 -0
  167. package/lib/rules/no-delete-var.js +42 -0
  168. package/lib/rules/no-div-regex.js +60 -0
  169. package/lib/rules/no-dupe-args.js +92 -0
  170. package/lib/rules/no-dupe-class-members.js +117 -0
  171. package/lib/rules/no-dupe-else-if.js +145 -0
  172. package/lib/rules/no-dupe-keys.js +165 -0
  173. package/lib/rules/no-duplicate-case.js +78 -0
  174. package/lib/rules/no-duplicate-imports.js +368 -0
  175. package/lib/rules/no-else-return.js +450 -0
  176. package/lib/rules/no-empty-character-class.js +83 -0
  177. package/lib/rules/no-empty-function.js +236 -0
  178. package/lib/rules/no-empty-pattern.js +85 -0
  179. package/lib/rules/no-empty-static-block.js +73 -0
  180. package/lib/rules/no-empty.js +153 -0
  181. package/lib/rules/no-eq-null.js +51 -0
  182. package/lib/rules/no-eval.js +295 -0
  183. package/lib/rules/no-ex-assign.js +57 -0
  184. package/lib/rules/no-extend-native.js +180 -0
  185. package/lib/rules/no-extra-bind.js +224 -0
  186. package/lib/rules/no-extra-boolean-cast.js +420 -0
  187. package/lib/rules/no-extra-label.js +169 -0
  188. package/lib/rules/no-extra-parens.js +1669 -0
  189. package/lib/rules/no-extra-semi.js +167 -0
  190. package/lib/rules/no-fallthrough.js +260 -0
  191. package/lib/rules/no-floating-decimal.js +99 -0
  192. package/lib/rules/no-func-assign.js +77 -0
  193. package/lib/rules/no-global-assign.js +101 -0
  194. package/lib/rules/no-implicit-coercion.js +468 -0
  195. package/lib/rules/no-implicit-globals.js +187 -0
  196. package/lib/rules/no-implied-eval.js +170 -0
  197. package/lib/rules/no-import-assign.js +227 -0
  198. package/lib/rules/no-inline-comments.js +115 -0
  199. package/lib/rules/no-inner-declarations.js +147 -0
  200. package/lib/rules/no-invalid-regexp.js +244 -0
  201. package/lib/rules/no-invalid-this.js +178 -0
  202. package/lib/rules/no-irregular-whitespace.js +292 -0
  203. package/lib/rules/no-iterator.js +48 -0
  204. package/lib/rules/no-label-var.js +78 -0
  205. package/lib/rules/no-labels.js +156 -0
  206. package/lib/rules/no-lone-blocks.js +140 -0
  207. package/lib/rules/no-lonely-if.js +126 -0
  208. package/lib/rules/no-loop-func.js +267 -0
  209. package/lib/rules/no-loss-of-precision.js +249 -0
  210. package/lib/rules/no-magic-numbers.js +365 -0
  211. package/lib/rules/no-misleading-character-class.js +595 -0
  212. package/lib/rules/no-mixed-operators.js +253 -0
  213. package/lib/rules/no-mixed-requires.js +267 -0
  214. package/lib/rules/no-mixed-spaces-and-tabs.js +148 -0
  215. package/lib/rules/no-multi-assign.js +66 -0
  216. package/lib/rules/no-multi-spaces.js +179 -0
  217. package/lib/rules/no-multi-str.js +67 -0
  218. package/lib/rules/no-multiple-empty-lines.js +210 -0
  219. package/lib/rules/no-native-reassign.js +114 -0
  220. package/lib/rules/no-negated-condition.js +100 -0
  221. package/lib/rules/no-negated-in-lhs.js +59 -0
  222. package/lib/rules/no-nested-ternary.js +46 -0
  223. package/lib/rules/no-new-func.js +96 -0
  224. package/lib/rules/no-new-native-nonconstructor.js +70 -0
  225. package/lib/rules/no-new-object.js +76 -0
  226. package/lib/rules/no-new-require.js +67 -0
  227. package/lib/rules/no-new-symbol.js +74 -0
  228. package/lib/rules/no-new-wrappers.js +62 -0
  229. package/lib/rules/no-new.js +42 -0
  230. package/lib/rules/no-nonoctal-decimal-escape.js +176 -0
  231. package/lib/rules/no-obj-calls.js +99 -0
  232. package/lib/rules/no-object-constructor.js +124 -0
  233. package/lib/rules/no-octal-escape.js +53 -0
  234. package/lib/rules/no-octal.js +42 -0
  235. package/lib/rules/no-param-reassign.js +248 -0
  236. package/lib/rules/no-path-concat.js +79 -0
  237. package/lib/rules/no-plusplus.js +102 -0
  238. package/lib/rules/no-process-env.js +68 -0
  239. package/lib/rules/no-process-exit.js +67 -0
  240. package/lib/rules/no-promise-executor-return.js +264 -0
  241. package/lib/rules/no-proto.js +45 -0
  242. package/lib/rules/no-prototype-builtins.js +181 -0
  243. package/lib/rules/no-redeclare.js +173 -0
  244. package/lib/rules/no-regex-spaces.js +219 -0
  245. package/lib/rules/no-restricted-exports.js +227 -0
  246. package/lib/rules/no-restricted-globals.js +266 -0
  247. package/lib/rules/no-restricted-imports.js +892 -0
  248. package/lib/rules/no-restricted-modules.js +249 -0
  249. package/lib/rules/no-restricted-properties.js +233 -0
  250. package/lib/rules/no-restricted-syntax.js +74 -0
  251. package/lib/rules/no-return-assign.js +87 -0
  252. package/lib/rules/no-return-await.js +162 -0
  253. package/lib/rules/no-script-url.js +68 -0
  254. package/lib/rules/no-self-assign.js +186 -0
  255. package/lib/rules/no-self-compare.js +77 -0
  256. package/lib/rules/no-sequences.js +158 -0
  257. package/lib/rules/no-setter-return.js +224 -0
  258. package/lib/rules/no-shadow-restricted-names.js +113 -0
  259. package/lib/rules/no-shadow.js +624 -0
  260. package/lib/rules/no-spaced-func.js +105 -0
  261. package/lib/rules/no-sparse-arrays.js +68 -0
  262. package/lib/rules/no-sync.js +81 -0
  263. package/lib/rules/no-tabs.js +110 -0
  264. package/lib/rules/no-template-curly-in-string.js +45 -0
  265. package/lib/rules/no-ternary.js +38 -0
  266. package/lib/rules/no-this-before-super.js +365 -0
  267. package/lib/rules/no-throw-literal.js +46 -0
  268. package/lib/rules/no-trailing-spaces.js +227 -0
  269. package/lib/rules/no-unassigned-vars.js +80 -0
  270. package/lib/rules/no-undef-init.js +101 -0
  271. package/lib/rules/no-undef.js +84 -0
  272. package/lib/rules/no-undefined.js +85 -0
  273. package/lib/rules/no-underscore-dangle.js +383 -0
  274. package/lib/rules/no-unexpected-multiline.js +130 -0
  275. package/lib/rules/no-unmodified-loop-condition.js +360 -0
  276. package/lib/rules/no-unneeded-ternary.js +232 -0
  277. package/lib/rules/no-unreachable-loop.js +190 -0
  278. package/lib/rules/no-unreachable.js +300 -0
  279. package/lib/rules/no-unsafe-finally.js +119 -0
  280. package/lib/rules/no-unsafe-negation.js +152 -0
  281. package/lib/rules/no-unsafe-optional-chaining.js +221 -0
  282. package/lib/rules/no-unused-expressions.js +227 -0
  283. package/lib/rules/no-unused-labels.js +158 -0
  284. package/lib/rules/no-unused-private-class-members.js +219 -0
  285. package/lib/rules/no-unused-vars.js +1739 -0
  286. package/lib/rules/no-use-before-define.js +446 -0
  287. package/lib/rules/no-useless-assignment.js +657 -0
  288. package/lib/rules/no-useless-backreference.js +263 -0
  289. package/lib/rules/no-useless-call.js +95 -0
  290. package/lib/rules/no-useless-catch.js +57 -0
  291. package/lib/rules/no-useless-computed-key.js +204 -0
  292. package/lib/rules/no-useless-concat.js +121 -0
  293. package/lib/rules/no-useless-constructor.js +262 -0
  294. package/lib/rules/no-useless-escape.js +406 -0
  295. package/lib/rules/no-useless-rename.js +202 -0
  296. package/lib/rules/no-useless-return.js +401 -0
  297. package/lib/rules/no-var.js +367 -0
  298. package/lib/rules/no-void.js +69 -0
  299. package/lib/rules/no-warning-comments.js +209 -0
  300. package/lib/rules/no-whitespace-before-property.js +150 -0
  301. package/lib/rules/no-with.js +37 -0
  302. package/lib/rules/nonblock-statement-body-position.js +164 -0
  303. package/lib/rules/object-curly-newline.js +383 -0
  304. package/lib/rules/object-curly-spacing.js +369 -0
  305. package/lib/rules/object-property-newline.js +151 -0
  306. package/lib/rules/object-shorthand.js +652 -0
  307. package/lib/rules/one-var-declaration-per-line.js +117 -0
  308. package/lib/rules/one-var.js +717 -0
  309. package/lib/rules/operator-assignment.js +270 -0
  310. package/lib/rules/operator-linebreak.js +315 -0
  311. package/lib/rules/padded-blocks.js +366 -0
  312. package/lib/rules/padding-line-between-statements.js +612 -0
  313. package/lib/rules/prefer-arrow-callback.js +437 -0
  314. package/lib/rules/prefer-const.js +546 -0
  315. package/lib/rules/prefer-destructuring.js +332 -0
  316. package/lib/rules/prefer-exponentiation-operator.js +235 -0
  317. package/lib/rules/prefer-named-capture-group.js +197 -0
  318. package/lib/rules/prefer-numeric-literals.js +157 -0
  319. package/lib/rules/prefer-object-has-own.js +148 -0
  320. package/lib/rules/prefer-object-spread.js +319 -0
  321. package/lib/rules/prefer-promise-reject-errors.js +154 -0
  322. package/lib/rules/prefer-reflect.js +150 -0
  323. package/lib/rules/prefer-regex-literals.js +605 -0
  324. package/lib/rules/prefer-rest-params.js +117 -0
  325. package/lib/rules/prefer-spread.js +91 -0
  326. package/lib/rules/prefer-template.js +347 -0
  327. package/lib/rules/preserve-caught-error.js +535 -0
  328. package/lib/rules/quote-props.js +394 -0
  329. package/lib/rules/quotes.js +416 -0
  330. package/lib/rules/radix.js +193 -0
  331. package/lib/rules/require-atomic-updates.js +365 -0
  332. package/lib/rules/require-await.js +184 -0
  333. package/lib/rules/require-unicode-regexp.js +317 -0
  334. package/lib/rules/require-yield.js +86 -0
  335. package/lib/rules/rest-spread-spacing.js +150 -0
  336. package/lib/rules/semi-spacing.js +297 -0
  337. package/lib/rules/semi-style.js +218 -0
  338. package/lib/rules/semi.js +476 -0
  339. package/lib/rules/sort-imports.js +319 -0
  340. package/lib/rules/sort-keys.js +268 -0
  341. package/lib/rules/sort-vars.js +140 -0
  342. package/lib/rules/space-before-blocks.js +232 -0
  343. package/lib/rules/space-before-function-paren.js +202 -0
  344. package/lib/rules/space-in-parens.js +374 -0
  345. package/lib/rules/space-infix-ops.js +249 -0
  346. package/lib/rules/space-unary-ops.js +400 -0
  347. package/lib/rules/spaced-comment.js +447 -0
  348. package/lib/rules/strict.js +314 -0
  349. package/lib/rules/switch-colon-spacing.js +158 -0
  350. package/lib/rules/symbol-description.js +70 -0
  351. package/lib/rules/template-curly-spacing.js +168 -0
  352. package/lib/rules/template-tag-spacing.js +121 -0
  353. package/lib/rules/unicode-bom.js +73 -0
  354. package/lib/rules/use-isnan.js +268 -0
  355. package/lib/rules/utils/ast-utils.js +2828 -0
  356. package/lib/rules/utils/char-source.js +247 -0
  357. package/lib/rules/utils/fix-tracker.js +125 -0
  358. package/lib/rules/utils/keywords.js +67 -0
  359. package/lib/rules/utils/lazy-loading-rule-map.js +118 -0
  360. package/lib/rules/utils/regular-expressions.js +58 -0
  361. package/lib/rules/utils/unicode/index.js +16 -0
  362. package/lib/rules/utils/unicode/is-combining-character.js +13 -0
  363. package/lib/rules/utils/unicode/is-emoji-modifier.js +13 -0
  364. package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +13 -0
  365. package/lib/rules/utils/unicode/is-surrogate-pair.js +14 -0
  366. package/lib/rules/valid-typeof.js +171 -0
  367. package/lib/rules/vars-on-top.js +165 -0
  368. package/lib/rules/wrap-iife.js +238 -0
  369. package/lib/rules/wrap-regex.js +91 -0
  370. package/lib/rules/yield-star-spacing.js +158 -0
  371. package/lib/rules/yoda.js +362 -0
  372. package/lib/services/parser-service.js +64 -0
  373. package/lib/services/processor-service.js +100 -0
  374. package/lib/services/suppressions-service.js +302 -0
  375. package/lib/services/warning-service.js +87 -0
  376. package/lib/shared/ajv.js +34 -0
  377. package/lib/shared/assert.js +21 -0
  378. package/lib/shared/ast-utils.js +30 -0
  379. package/lib/shared/deep-merge-arrays.js +62 -0
  380. package/lib/shared/directives.js +16 -0
  381. package/lib/shared/flags.js +89 -0
  382. package/lib/shared/logging.js +38 -0
  383. package/lib/shared/naming.js +109 -0
  384. package/lib/shared/option-utils.js +63 -0
  385. package/lib/shared/relative-module-resolver.js +28 -0
  386. package/lib/shared/runtime-info.js +177 -0
  387. package/lib/shared/serialization.js +78 -0
  388. package/lib/shared/severity.js +49 -0
  389. package/lib/shared/stats.js +30 -0
  390. package/lib/shared/string-utils.js +58 -0
  391. package/lib/shared/text-table.js +68 -0
  392. package/lib/shared/translate-cli-options.js +223 -0
  393. package/lib/shared/traverser.js +202 -0
  394. package/lib/types/config-api.d.ts +12 -0
  395. package/lib/types/index.d.ts +1482 -0
  396. package/lib/types/rules.d.ts +5603 -0
  397. package/lib/types/universal.d.ts +6 -0
  398. package/lib/types/use-at-your-own-risk.d.ts +34 -0
  399. package/lib/universal.js +10 -0
  400. package/lib/unsupported-api.js +26 -0
  401. package/messages/all-files-ignored.js +16 -0
  402. package/messages/all-matched-files-ignored.js +21 -0
  403. package/messages/config-file-missing.js +16 -0
  404. package/messages/config-plugin-missing.js +14 -0
  405. package/messages/config-serialize-function.js +30 -0
  406. package/messages/eslintrc-incompat.js +117 -0
  407. package/messages/eslintrc-plugins.js +27 -0
  408. package/messages/extend-config-missing.js +13 -0
  409. package/messages/failed-to-read-json.js +11 -0
  410. package/messages/file-not-found.js +10 -0
  411. package/messages/invalid-rule-options.js +17 -0
  412. package/messages/invalid-rule-severity.js +13 -0
  413. package/messages/no-config-found.js +15 -0
  414. package/messages/plugin-conflict.js +22 -0
  415. package/messages/plugin-invalid.js +16 -0
  416. package/messages/plugin-missing.js +19 -0
  417. package/messages/print-config-with-directory-path.js +8 -0
  418. package/messages/shared.js +23 -0
  419. package/messages/whitespace-found.js +11 -0
  420. package/package.json +220 -0
@@ -0,0 +1,1989 @@
1
+ /**
2
+ * @fileoverview Mocha/Jest test wrapper
3
+ * @author Ilya Volodin
4
+ */
5
+ "use strict";
6
+
7
+ /* globals describe, it -- Mocha globals */
8
+
9
+ //------------------------------------------------------------------------------
10
+ // Requirements
11
+ //------------------------------------------------------------------------------
12
+
13
+ const assert = require("node:assert"),
14
+ { existsSync, readFileSync } = require("node:fs"),
15
+ util = require("node:util"),
16
+ path = require("node:path"),
17
+ equal = require("fast-deep-equal"),
18
+ Traverser = require("../shared/traverser"),
19
+ { Config } = require("../config/config"),
20
+ { Linter, SourceCodeFixer } = require("../linter"),
21
+ { interpolate, getPlaceholderMatcher } = require("../linter/interpolate"),
22
+ stringify = require("json-stable-stringify-without-jsonify"),
23
+ { isSerializable } = require("../shared/serialization");
24
+
25
+ const { FlatConfigArray } = require("../config/flat-config-array");
26
+ const {
27
+ defaultConfig,
28
+ defaultRuleTesterConfig,
29
+ } = require("../config/default-config");
30
+
31
+ const ajv = require("../shared/ajv")({ strictDefaults: true });
32
+
33
+ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
34
+ const { ConfigArraySymbol } = require("@eslint/config-array");
35
+
36
+ const jslang = require("../languages/js");
37
+ const { SourceCode } = require("../languages/js/source-code");
38
+
39
+ //------------------------------------------------------------------------------
40
+ // Typedefs
41
+ //------------------------------------------------------------------------------
42
+
43
+ /** @import { LanguageOptions, RuleDefinition } from "@eslint/core" */
44
+
45
+ /** @typedef {import("../types").Linter.Parser} Parser */
46
+
47
+ /**
48
+ * A test case that is expected to pass lint.
49
+ * @typedef {Object} ValidTestCase
50
+ * @property {string} [name] Name for the test case.
51
+ * @property {string} code Code for the test case.
52
+ * @property {any[]} [options] Options for the test case.
53
+ * @property {Function} [before] Function to execute before testing the case.
54
+ * @property {Function} [after] Function to execute after testing the case regardless of its result.
55
+ * @property {LanguageOptions} [languageOptions] The language options to use in the test case.
56
+ * @property {{ [name: string]: any }} [settings] Settings for the test case.
57
+ * @property {string} [filename] The fake filename for the test case. Useful for rules that make assertion about filenames.
58
+ * @property {boolean} [only] Run only this test case or the subset of test cases with this property.
59
+ */
60
+
61
+ /**
62
+ * A test case that is expected to fail lint.
63
+ * @typedef {Object} InvalidTestCase
64
+ * @property {string} [name] Name for the test case.
65
+ * @property {string} code Code for the test case.
66
+ * @property {number | Array<TestCaseError | string | RegExp>} errors Expected errors.
67
+ * @property {string | null} [output] The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
68
+ * @property {any[]} [options] Options for the test case.
69
+ * @property {Function} [before] Function to execute before testing the case.
70
+ * @property {Function} [after] Function to execute after testing the case regardless of its result.
71
+ * @property {{ [name: string]: any }} [settings] Settings for the test case.
72
+ * @property {string} [filename] The fake filename for the test case. Useful for rules that make assertion about filenames.
73
+ * @property {LanguageOptions} [languageOptions] The language options to use in the test case.
74
+ * @property {boolean} [only] Run only this test case or the subset of test cases with this property.
75
+ */
76
+
77
+ /**
78
+ * A description of a reported error used in a rule tester test.
79
+ * @typedef {Object} TestCaseError
80
+ * @property {string | RegExp} [message] Message.
81
+ * @property {string} [messageId] Message ID.
82
+ * @property {{ [name: string]: string }} [data] The data used to fill the message template.
83
+ * @property {number} [line] The 1-based line number of the reported start location.
84
+ * @property {number} [column] The 1-based column number of the reported start location.
85
+ * @property {number} [endLine] The 1-based line number of the reported end location.
86
+ * @property {number} [endColumn] The 1-based column number of the reported end location.
87
+ */
88
+
89
+ //------------------------------------------------------------------------------
90
+ // Private Members
91
+ //------------------------------------------------------------------------------
92
+
93
+ /*
94
+ * testerDefaultConfig must not be modified as it allows to reset the tester to
95
+ * the initial default configuration
96
+ */
97
+ const testerDefaultConfig = { rules: {} };
98
+
99
+ /*
100
+ * RuleTester uses this config as its default. This can be overwritten via
101
+ * setDefaultConfig().
102
+ */
103
+ let sharedDefaultConfig = { rules: {} };
104
+
105
+ /*
106
+ * List every parameters possible on a test case that are not related to eslint
107
+ * configuration
108
+ */
109
+ const RuleTesterParameters = [
110
+ "name",
111
+ "code",
112
+ "filename",
113
+ "options",
114
+ "before",
115
+ "after",
116
+ "errors",
117
+ "output",
118
+ "only",
119
+ ];
120
+
121
+ /*
122
+ * All allowed property names in error objects.
123
+ */
124
+ const errorObjectParameters = new Set([
125
+ "message",
126
+ "messageId",
127
+ "data",
128
+ "line",
129
+ "column",
130
+ "endLine",
131
+ "endColumn",
132
+ "suggestions",
133
+ ]);
134
+ const friendlyErrorObjectParameterList = `[${[...errorObjectParameters].map(key => `'${key}'`).join(", ")}]`;
135
+
136
+ /*
137
+ * All allowed property names in suggestion objects.
138
+ */
139
+ const suggestionObjectParameters = new Set([
140
+ "desc",
141
+ "messageId",
142
+ "data",
143
+ "output",
144
+ ]);
145
+ const friendlySuggestionObjectParameterList = `[${[...suggestionObjectParameters].map(key => `'${key}'`).join(", ")}]`;
146
+
147
+ const forbiddenMethods = [
148
+ "applyInlineConfig",
149
+ "applyLanguageOptions",
150
+ "finalize",
151
+ ];
152
+
153
+ /** @type {Map<string,WeakSet>} */
154
+ const forbiddenMethodCalls = new Map(
155
+ forbiddenMethods.map(methodName => [methodName, new WeakSet()]),
156
+ );
157
+
158
+ const hasOwnProperty = Function.call.bind(Object.hasOwnProperty);
159
+
160
+ /**
161
+ * Clones a given value deeply.
162
+ * Note: This ignores `parent` property.
163
+ * @param {any} x A value to clone.
164
+ * @returns {any} A cloned value.
165
+ */
166
+ function cloneDeeplyExcludesParent(x) {
167
+ if (typeof x === "object" && x !== null) {
168
+ if (Array.isArray(x)) {
169
+ return x.map(cloneDeeplyExcludesParent);
170
+ }
171
+
172
+ const retv = {};
173
+
174
+ for (const key in x) {
175
+ if (key !== "parent" && hasOwnProperty(x, key)) {
176
+ retv[key] = cloneDeeplyExcludesParent(x[key]);
177
+ }
178
+ }
179
+
180
+ return retv;
181
+ }
182
+
183
+ return x;
184
+ }
185
+
186
+ /**
187
+ * Freezes a given value deeply.
188
+ * @param {any} x A value to freeze.
189
+ * @param {Set<Object>} seenObjects Objects already seen during the traversal.
190
+ * @returns {void}
191
+ */
192
+ function freezeDeeply(x, seenObjects = new Set()) {
193
+ if (typeof x === "object" && x !== null) {
194
+ if (seenObjects.has(x)) {
195
+ return; // skip to avoid infinite recursion
196
+ }
197
+ seenObjects.add(x);
198
+
199
+ if (Array.isArray(x)) {
200
+ x.forEach(element => {
201
+ freezeDeeply(element, seenObjects);
202
+ });
203
+ } else {
204
+ for (const key in x) {
205
+ if (key !== "parent" && hasOwnProperty(x, key)) {
206
+ freezeDeeply(x[key], seenObjects);
207
+ }
208
+ }
209
+ }
210
+ Object.freeze(x);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Replace control characters by `\u00xx` form.
216
+ * @param {string} text The text to sanitize.
217
+ * @returns {string} The sanitized text.
218
+ */
219
+ function sanitize(text) {
220
+ if (typeof text !== "string") {
221
+ return "";
222
+ }
223
+ return text.replace(
224
+ /[\u0000-\u0009\u000b-\u001a]/gu,
225
+ c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`,
226
+ );
227
+ }
228
+
229
+ /**
230
+ * Define `start`/`end` properties as throwing error.
231
+ * @param {string} objName Object name used for error messages.
232
+ * @param {ASTNode} node The node to define.
233
+ * @returns {void}
234
+ */
235
+ function defineStartEndAsError(objName, node) {
236
+ Object.defineProperties(node, {
237
+ start: {
238
+ get() {
239
+ throw new Error(
240
+ `Use ${objName}.range[0] instead of ${objName}.start`,
241
+ );
242
+ },
243
+ configurable: true,
244
+ enumerable: false,
245
+ },
246
+ end: {
247
+ get() {
248
+ throw new Error(
249
+ `Use ${objName}.range[1] instead of ${objName}.end`,
250
+ );
251
+ },
252
+ configurable: true,
253
+ enumerable: false,
254
+ },
255
+ });
256
+ }
257
+
258
+ /**
259
+ * Define `start`/`end` properties of all nodes of the given AST as throwing error.
260
+ * @param {ASTNode} ast The root node to errorize `start`/`end` properties.
261
+ * @param {Object} [visitorKeys] Visitor keys to be used for traversing the given ast.
262
+ * @returns {void}
263
+ */
264
+ function defineStartEndAsErrorInTree(ast, visitorKeys) {
265
+ Traverser.traverse(ast, {
266
+ visitorKeys,
267
+ enter: defineStartEndAsError.bind(null, "node"),
268
+ });
269
+ ast.tokens.forEach(defineStartEndAsError.bind(null, "token"));
270
+ ast.comments.forEach(defineStartEndAsError.bind(null, "token"));
271
+ }
272
+
273
+ /**
274
+ * Wraps the given parser in order to intercept and modify return values from the `parse` and `parseForESLint` methods, for test purposes.
275
+ * In particular, to modify ast nodes, tokens and comments to throw on access to their `start` and `end` properties.
276
+ * @param {Parser} parser Parser object.
277
+ * @returns {Parser} Wrapped parser object.
278
+ */
279
+ function wrapParser(parser) {
280
+ if (typeof parser.parseForESLint === "function") {
281
+ return {
282
+ [parserSymbol]: parser,
283
+ parseForESLint(...args) {
284
+ const ret = parser.parseForESLint(...args);
285
+
286
+ defineStartEndAsErrorInTree(ret.ast, ret.visitorKeys);
287
+ return ret;
288
+ },
289
+ };
290
+ }
291
+
292
+ return {
293
+ [parserSymbol]: parser,
294
+ parse(...args) {
295
+ const ast = parser.parse(...args);
296
+
297
+ defineStartEndAsErrorInTree(ast);
298
+ return ast;
299
+ },
300
+ };
301
+ }
302
+
303
+ /**
304
+ * Function to replace forbidden `SourceCode` methods. Allows just one call per method.
305
+ * @param {string} methodName The name of the method to forbid.
306
+ * @param {Function} prototype The prototype with the original method to call.
307
+ * @returns {Function} The function that throws the error.
308
+ */
309
+ function throwForbiddenMethodError(methodName, prototype) {
310
+ const original = prototype[methodName];
311
+
312
+ return function (...args) {
313
+ const called = forbiddenMethodCalls.get(methodName);
314
+
315
+
316
+ if (!called.has(this)) {
317
+ called.add(this);
318
+
319
+ return original.apply(this, args);
320
+ }
321
+
322
+
323
+ throw new Error(
324
+ `\`SourceCode#${methodName}()\` cannot be called inside a rule.`,
325
+ );
326
+ };
327
+ }
328
+
329
+ /**
330
+ * Extracts names of {{ placeholders }} from the reported message.
331
+ * @param {string} message Reported message
332
+ * @returns {string[]} Array of placeholder names
333
+ */
334
+ function getMessagePlaceholders(message) {
335
+ const matcher = getPlaceholderMatcher();
336
+
337
+ return Array.from(message.matchAll(matcher), ([, name]) => name.trim());
338
+ }
339
+
340
+ /**
341
+ * Returns the placeholders in the reported messages but
342
+ * only includes the placeholders available in the raw message and not in the provided data.
343
+ * @param {string} message The reported message
344
+ * @param {string} raw The raw message specified in the rule meta.messages
345
+ * @param {undefined|Record<unknown, unknown>} data The passed
346
+ * @returns {string[]} Missing placeholder names
347
+ */
348
+ function getUnsubstitutedMessagePlaceholders(message, raw, data = {}) {
349
+ const unsubstituted = getMessagePlaceholders(message);
350
+
351
+ if (unsubstituted.length === 0) {
352
+ return [];
353
+ }
354
+
355
+ // Remove false positives by only counting placeholders in the raw message, which were not provided in the data matcher or added with a data property
356
+ const known = getMessagePlaceholders(raw);
357
+ const provided = Object.keys(data);
358
+
359
+ return unsubstituted.filter(
360
+ name => known.includes(name) && !provided.includes(name),
361
+ );
362
+ }
363
+
364
+ const metaSchemaDescription = `
365
+ \t- If the rule has options, set \`meta.schema\` to an array or non-empty object to enable options validation.
366
+ \t- If the rule doesn't have options, omit \`meta.schema\` to enforce that no options can be passed to the rule.
367
+ \t- You can also set \`meta.schema\` to \`false\` to opt-out of options validation (not recommended).
368
+
369
+ \thttps://eslint.org/docs/latest/extend/custom-rules#options-schemas
370
+ `;
371
+
372
+ /*
373
+ * Ignored test case properties when checking for test case duplicates.
374
+ */
375
+ const duplicationIgnoredParameters = new Set(["name", "errors", "output"]);
376
+
377
+ /**
378
+ * Normalizes a test case item, ensuring it is an object with a 'code' property.
379
+ * If the item is not an object, it returns an object with the 'code' property set to the item.
380
+ * @param {any} item The test case item to normalize.
381
+ * @returns {Object} The normalized test case object.
382
+ */
383
+ function normalizeTestCase(item) {
384
+ return item && typeof item === "object" ? item : { code: item };
385
+ }
386
+
387
+ /**
388
+ * Asserts that the `errors` property of an invalid test case is valid.
389
+ * @param {number | string[]} errors The `errors` property of the invalid test case.
390
+ * @param {string} ruleName The name of the rule being tested.
391
+ * @param {Object} [assertionOptions] The assertion options for the test case.
392
+ * @returns {void}
393
+ */
394
+ function assertErrorsProperty(errors, ruleName, assertionOptions = {}) {
395
+ const isNumber = typeof errors === "number";
396
+ const isArray = Array.isArray(errors);
397
+
398
+ if (!isNumber && !isArray) {
399
+ if (errors === void 0) {
400
+ assert.fail(
401
+ `Did not specify errors for an invalid test of ${ruleName}`,
402
+ );
403
+ } else {
404
+ assert.fail(
405
+ `Invalid 'errors' property for invalid test of ${ruleName}: expected a number or an array but got ${
406
+ errors === null ? "null" : typeof errors
407
+ }`,
408
+ );
409
+ }
410
+ }
411
+
412
+ const { requireMessage = false, requireLocation = false } =
413
+ assertionOptions;
414
+
415
+ if (isArray) {
416
+ assert.ok(
417
+ errors.length !== 0,
418
+ "Invalid cases must have at least one error",
419
+ );
420
+
421
+ for (const [number, error] of errors.entries()) {
422
+ if (typeof error === "string" || error instanceof RegExp) {
423
+ // Just an error message.
424
+ assert.ok(
425
+ requireMessage !== "messageId" && !requireLocation,
426
+ `errors[${number}] should be an object when 'assertionOptions.requireMessage' is 'messageId' or 'assertionOptions.requireLocation' is true.`,
427
+ );
428
+ } else if (typeof error === "object" && error !== null) {
429
+ /*
430
+ * Error object.
431
+ * This may have a message, messageId, data, line, and/or column.
432
+ */
433
+
434
+ for (const propertyName of Object.keys(error)) {
435
+ assert.ok(
436
+ errorObjectParameters.has(propertyName),
437
+ `Invalid error property name '${propertyName}'. Expected one of ${friendlyErrorObjectParameterList}.`,
438
+ );
439
+ }
440
+
441
+ if (requireMessage === "message") {
442
+ assert.ok(
443
+ !hasOwnProperty(error, "messageId") &&
444
+ hasOwnProperty(error, "message"),
445
+ `errors[${number}] should specify 'message' (and not 'messageId') when 'assertionOptions.requireMessage' is 'message'.`,
446
+ );
447
+ } else if (requireMessage === "messageId") {
448
+ assert.ok(
449
+ !hasOwnProperty(error, "message") &&
450
+ hasOwnProperty(error, "messageId"),
451
+ `errors[${number}] should specify 'messageId' (and not 'message') when 'assertionOptions.requireMessage' is 'messageId'.`,
452
+ );
453
+ }
454
+
455
+ if (hasOwnProperty(error, "message")) {
456
+ assert.ok(
457
+ !hasOwnProperty(error, "messageId"),
458
+ `errors[${number}] should not specify both 'message' and 'messageId'.`,
459
+ );
460
+ assert.ok(
461
+ !hasOwnProperty(error, "data"),
462
+ `errors[${number}] should not specify both 'data' and 'message'.`,
463
+ );
464
+ } else {
465
+ assert.ok(
466
+ hasOwnProperty(error, "messageId"),
467
+ `errors[${number}] must specify either 'messageId' or 'message'.`,
468
+ );
469
+ }
470
+ } else {
471
+ assert.fail(
472
+ `errors[${number}] must be a string, RegExp, or an object.`,
473
+ );
474
+ }
475
+ }
476
+ } else {
477
+ assert.ok(
478
+ !requireMessage && !requireLocation,
479
+ "Invalid cases must have 'errors' value as an array",
480
+ );
481
+ assert.ok(
482
+ errors > 0,
483
+ "Invalid cases must have 'error' value greater than 0",
484
+ );
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Check if this test case is a duplicate of one we have seen before.
490
+ * @param {Object} item test case object
491
+ * @param {Set<string>} seenTestCases set of serialized test cases we have seen so far (managed by this function)
492
+ * @returns {void}
493
+ */
494
+ function checkDuplicateTestCase(item, seenTestCases) {
495
+ if (!isSerializable(item)) {
496
+ /*
497
+ * If we can't serialize a test case (because it contains a function, RegExp, etc), skip the check.
498
+ * This might happen with properties like: options, plugins, settings, languageOptions.parser, languageOptions.parserOptions.
499
+ */
500
+ return;
501
+ }
502
+
503
+ const serializedTestCase = stringify(item, {
504
+ replacer(key, value) {
505
+ // "this" is the currently stringified object --> only ignore top-level properties
506
+ return item !== this || !duplicationIgnoredParameters.has(key)
507
+ ? value
508
+ : void 0;
509
+ },
510
+ });
511
+
512
+ assert(
513
+ !seenTestCases.has(serializedTestCase),
514
+ "detected duplicate test case",
515
+ );
516
+ seenTestCases.add(serializedTestCase);
517
+ }
518
+
519
+ /**
520
+ * Asserts that a rule is valid.
521
+ * A valid rule must be an object with a `create` method.
522
+ * @param {Object} rule The rule to check.
523
+ * @param {string} ruleName The name of the rule.
524
+ * @returns {void}
525
+ * @throws {AssertionError} If the rule is not valid.
526
+ */
527
+ function assertRule(rule, ruleName) {
528
+ assert.ok(
529
+ rule && typeof rule === "object" && typeof rule.create === "function",
530
+ `Rule ${ruleName} must be an object with a \`create\` method`,
531
+ );
532
+ }
533
+
534
+ /**
535
+ * Asserts that a test scenario object is valid.
536
+ * A valid test scenario object must have `valid` and `invalid` properties, both of
537
+ * which must be arrays.
538
+ * @param {Object} test The test scenario object to check.
539
+ * @param {string} ruleName The name of the rule being tested.
540
+ * @returns {void}
541
+ * @throws {AssertionError} If the test scenario object is not valid.
542
+ */
543
+ function assertTest(test, ruleName) {
544
+ assert.ok(
545
+ test && typeof test === "object",
546
+ `Test Scenarios for rule ${ruleName} : Could not find test scenario object`,
547
+ );
548
+
549
+ const hasValid = Array.isArray(test.valid);
550
+ const hasInvalid = Array.isArray(test.invalid);
551
+
552
+ assert.ok(
553
+ hasValid,
554
+ `Test Scenarios for rule ${ruleName} is invalid: Could not find any valid test scenarios`,
555
+ );
556
+
557
+ assert.ok(
558
+ hasInvalid,
559
+ `Test Scenarios for rule ${ruleName} is invalid: Could not find any invalid test scenarios`,
560
+ );
561
+ }
562
+
563
+ /**
564
+ * Asserts that the common properties of a valid/invalid test case have the correct types.
565
+ * @param {Object} item The test case object to check.
566
+ * @returns {void}
567
+ */
568
+ function assertTestCommonProperties(item) {
569
+ assert.ok(
570
+ typeof item.code === "string",
571
+ "Test case must specify a string value for 'code'",
572
+ );
573
+
574
+ // optional properties
575
+ if (item.name) {
576
+ assert.ok(
577
+ typeof item.name === "string",
578
+ "Optional test case property 'name' must be a string",
579
+ );
580
+ }
581
+ if (hasOwnProperty(item, "only")) {
582
+ assert.ok(
583
+ typeof item.only === "boolean",
584
+ "Optional test case property 'only' must be a boolean",
585
+ );
586
+ }
587
+ if (hasOwnProperty(item, "filename")) {
588
+ assert.ok(
589
+ typeof item.filename === "string",
590
+ "Optional test case property 'filename' must be a string",
591
+ );
592
+ }
593
+ if (hasOwnProperty(item, "options")) {
594
+ assert.ok(
595
+ Array.isArray(item.options),
596
+ "Optional test case property 'options' must be an array",
597
+ );
598
+ }
599
+ }
600
+
601
+ /**
602
+ * Asserts that a valid test case object is valid.
603
+ * A valid test case must specify a string value for 'code'.
604
+ * Optional properties are checked for correct types.
605
+ * @param {Object} item The valid test case object to check.
606
+ * @param {Set<string>} seenTestCases Set of serialized test cases to check for duplicates.
607
+ * @returns {void}
608
+ * @throws {AssertionError} If the test case is not valid.
609
+ */
610
+ function assertValidTestCase(item, seenTestCases) {
611
+ // must not have properties of invalid test cases
612
+ assert.ok(
613
+ item.errors === void 0,
614
+ "Valid test case must not have 'errors' property",
615
+ );
616
+ assert.ok(
617
+ item.output === void 0,
618
+ "Valid test case must not have 'output' property",
619
+ );
620
+
621
+ assertTestCommonProperties(item);
622
+ checkDuplicateTestCase(item, seenTestCases);
623
+ }
624
+
625
+ /**
626
+ * Asserts that the invalid test case object is valid.
627
+ * An invalid test case must specify a string value for 'code' and must have 'errors' property.
628
+ * Optional properties are checked for correct types.
629
+ * @param {Object} item The invalid test case object to check.
630
+ * @param {Set<string>} seenTestCases Set of serialized test cases to check for duplicates.
631
+ * @param {string} ruleName The name of the rule being tested.
632
+ * @param {Object} [assertionOptions] The assertion options for the test case.
633
+ * @returns {void}
634
+ * @throws {AssertionError} If the test case is not valid.
635
+ */
636
+ function assertInvalidTestCase(
637
+ item,
638
+ seenTestCases,
639
+ ruleName,
640
+ assertionOptions = {},
641
+ ) {
642
+ assertTestCommonProperties(item);
643
+
644
+ assertErrorsProperty(item.errors, ruleName, assertionOptions);
645
+
646
+ // 'output' is optional, but if it exists it must be a string or null
647
+ if (hasOwnProperty(item, "output")) {
648
+ assert.ok(
649
+ item.output === null || typeof item.output === "string",
650
+ "Test property 'output', if specified, must be a string or null. If no autofix is expected, then omit the 'output' property or set it to null.",
651
+ );
652
+ }
653
+
654
+ checkDuplicateTestCase(item, seenTestCases);
655
+ }
656
+
657
+ /**
658
+ * Gets the invocation location from the stack trace for later use.
659
+ * @param {Function} relative The function before the invocation point.
660
+ * @returns {string} The invocation location.
661
+ */
662
+ function getInvocationLocation(relative = getInvocationLocation) {
663
+ const dummyObject = {};
664
+ Error.captureStackTrace(dummyObject, relative);
665
+ const { stack } = dummyObject;
666
+
667
+ return stack.split("\n")[1].replace(/.*?\(/u, "").replace(/\)$/u, "");
668
+ }
669
+
670
+ /**
671
+ * Estimates the location of the test case in the source file.
672
+ * @param {Function} invoker The method that runs the tests.
673
+ * @returns {(key: string) => string} The lazy resolver for the estimated location of the test case.
674
+ */
675
+ function buildLazyTestLocationEstimator(invoker) {
676
+ const invocationLocation = getInvocationLocation(invoker);
677
+ let testLocations = null;
678
+ return key => {
679
+ if (testLocations === null) {
680
+ let [sourceFile, sourceLine = "1", sourceColumn = "1"] =
681
+ invocationLocation
682
+ .replace(/:\\/u, "\\\\") // Windows workaround for C:\\
683
+ .split(":");
684
+ sourceFile = sourceFile.replace(/\\\\/u, ":\\");
685
+ sourceLine = Number(sourceLine);
686
+ sourceColumn = Number(sourceColumn);
687
+ testLocations = { root: invocationLocation };
688
+
689
+ if (existsSync(sourceFile)) {
690
+ let content = readFileSync(sourceFile, "utf8")
691
+ .split("\n")
692
+ .slice(sourceLine - 1);
693
+ content[0] = content[0].slice(Math.max(0, sourceColumn - 1));
694
+ content = content.map(
695
+ l =>
696
+ l
697
+ .trim() // Remove whitespace
698
+ .replace(/\s*\/\/.*$(?<!,)/u, ""), // and trailing in-line comments that aren't part of the test `code`
699
+ );
700
+
701
+ // Roots
702
+ const validStartIndex = content.findIndex(line =>
703
+ /\bvalid:/u.test(line),
704
+ );
705
+ const invalidStartIndex = content.findIndex(line =>
706
+ /\binvalid:/u.test(line),
707
+ );
708
+
709
+ testLocations.valid = `${sourceFile}:${
710
+ sourceLine + validStartIndex
711
+ }`;
712
+ testLocations.invalid = `${sourceFile}:${
713
+ sourceLine + invalidStartIndex
714
+ }`;
715
+
716
+ // Scenario basics
717
+ const validEndIndex =
718
+ validStartIndex < invalidStartIndex
719
+ ? invalidStartIndex
720
+ : content.length;
721
+ const invalidEndIndex =
722
+ validStartIndex < invalidStartIndex
723
+ ? content.length
724
+ : validStartIndex;
725
+
726
+ const validLines = content.slice(
727
+ validStartIndex,
728
+ validEndIndex,
729
+ );
730
+ const invalidLines = content.slice(
731
+ invalidStartIndex,
732
+ invalidEndIndex,
733
+ );
734
+
735
+ let objectDepth = 0;
736
+ const validLineIndexes = validLines
737
+ .map((l, i) => {
738
+ // matches `key: {` and `{`
739
+ if (/^(?:\w+\s*:\s*)?\{/u.test(l)) {
740
+ objectDepth++;
741
+ }
742
+
743
+ if (objectDepth > 0) {
744
+ if (l.endsWith("}") || l.endsWith("},")) {
745
+ objectDepth--;
746
+ }
747
+
748
+ return objectDepth <= 1 && l.includes("code:")
749
+ ? i
750
+ : null;
751
+ }
752
+
753
+ return l.endsWith(",") ? i : null;
754
+ })
755
+ .filter(Boolean);
756
+ const invalidLineIndexes = invalidLines
757
+ .map((l, i) =>
758
+ l.trimStart().startsWith("errors:") ? i : null,
759
+ )
760
+ .filter(Boolean);
761
+
762
+ Object.assign(
763
+ testLocations,
764
+ {
765
+ [`valid[0]`]: `${sourceFile}:${
766
+ sourceLine + validStartIndex
767
+ }`,
768
+ },
769
+ Object.fromEntries(
770
+ validLineIndexes.map((location, validIndex) => [
771
+ `valid[${validIndex}]`,
772
+ `${sourceFile}:${
773
+ sourceLine + validStartIndex + location
774
+ }`,
775
+ ]),
776
+ ),
777
+ Object.fromEntries(
778
+ invalidLineIndexes.map((location, invalidIndex) => [
779
+ `invalid[${invalidIndex}]`,
780
+ `${sourceFile}:${
781
+ sourceLine + invalidStartIndex + location
782
+ }`,
783
+ ]),
784
+ ),
785
+ );
786
+
787
+ // Indexes for errors inside each invalid test case
788
+ invalidLineIndexes.push(invalidLines.length);
789
+
790
+ for (let i = 0; i < invalidLineIndexes.length - 1; i++) {
791
+ const start = invalidLineIndexes[i];
792
+ const end = invalidLineIndexes[i + 1];
793
+ const errorLines = invalidLines.slice(start, end);
794
+ let errorObjectDepth = 0;
795
+ const errorLineIndexes = errorLines
796
+ .map((l, j) => {
797
+ if (l.startsWith("{") || l.endsWith("{")) {
798
+ errorObjectDepth++;
799
+
800
+ if (l.endsWith("}") || l.endsWith("},")) {
801
+ errorObjectDepth--;
802
+ }
803
+
804
+ return errorObjectDepth <= 1 ? j : null;
805
+ }
806
+
807
+ if (errorObjectDepth > 0) {
808
+ if (l.endsWith("}") || l.endsWith("},")) {
809
+ errorObjectDepth--;
810
+ }
811
+
812
+ return null;
813
+ }
814
+
815
+ return l.endsWith(",") ? j : null;
816
+ })
817
+ .filter(Boolean);
818
+
819
+ Object.assign(
820
+ testLocations,
821
+ Object.fromEntries(
822
+ errorLineIndexes.map((line, errorIndex) => [
823
+ `invalid[${i}].errors[${errorIndex}]`,
824
+ `${sourceFile}:${
825
+ sourceLine +
826
+ invalidStartIndex +
827
+ start +
828
+ line
829
+ }`,
830
+ ]),
831
+ ),
832
+ );
833
+ }
834
+ }
835
+ }
836
+
837
+ return testLocations[key] || "unknown source";
838
+ };
839
+ }
840
+
841
+ //------------------------------------------------------------------------------
842
+ // Public Interface
843
+ //------------------------------------------------------------------------------
844
+
845
+ // default separators for testing
846
+ const DESCRIBE = Symbol("describe");
847
+ const IT = Symbol("it");
848
+ const IT_ONLY = Symbol("itOnly");
849
+
850
+ /**
851
+ * This is `it` default handler if `it` don't exist.
852
+ * @this {Mocha}
853
+ * @param {string} text The description of the test case.
854
+ * @param {Function} method The logic of the test case.
855
+ * @throws {Error} Any error upon execution of `method`.
856
+ * @returns {any} Returned value of `method`.
857
+ */
858
+ function itDefaultHandler(text, method) {
859
+ try {
860
+ return method.call(this);
861
+ } catch (err) {
862
+ if (err instanceof assert.AssertionError) {
863
+ err.message += ` (${util.inspect(err.actual)} ${err.operator} ${util.inspect(err.expected)})`;
864
+ }
865
+ throw err;
866
+ }
867
+ }
868
+
869
+ /**
870
+ * This is `describe` default handler if `describe` don't exist.
871
+ * @this {Mocha}
872
+ * @param {string} text The description of the test case.
873
+ * @param {Function} method The logic of the test case.
874
+ * @returns {any} Returned value of `method`.
875
+ */
876
+ function describeDefaultHandler(text, method) {
877
+ return method.call(this);
878
+ }
879
+
880
+ /**
881
+ * Mocha test wrapper.
882
+ */
883
+ class RuleTester {
884
+ /**
885
+ * Creates a new instance of RuleTester.
886
+ * @param {Object} [testerConfig] Optional, extra configuration for the tester
887
+ */
888
+ constructor(testerConfig = {}) {
889
+ /**
890
+ * The configuration to use for this tester. Combination of the tester
891
+ * configuration and the default configuration.
892
+ * @type {Object}
893
+ */
894
+ this.testerConfig = [
895
+ sharedDefaultConfig,
896
+ testerConfig,
897
+ { rules: { "rule-tester/validate-ast": "error" } },
898
+ ];
899
+
900
+ this.linter = new Linter({ configType: "flat" });
901
+ }
902
+
903
+ /**
904
+ * Set the configuration to use for all future tests
905
+ * @param {Object} config the configuration to use.
906
+ * @throws {TypeError} If non-object config.
907
+ * @returns {void}
908
+ */
909
+ static setDefaultConfig(config) {
910
+ if (typeof config !== "object" || config === null) {
911
+ throw new TypeError(
912
+ "RuleTester.setDefaultConfig: config must be an object",
913
+ );
914
+ }
915
+ sharedDefaultConfig = config;
916
+
917
+ // Make sure the rules object exists since it is assumed to exist later
918
+ sharedDefaultConfig.rules = sharedDefaultConfig.rules || {};
919
+ }
920
+
921
+ /**
922
+ * Get the current configuration used for all tests
923
+ * @returns {Object} the current configuration
924
+ */
925
+ static getDefaultConfig() {
926
+ return sharedDefaultConfig;
927
+ }
928
+
929
+ /**
930
+ * Reset the configuration to the initial configuration of the tester removing
931
+ * any changes made until now.
932
+ * @returns {void}
933
+ */
934
+ static resetDefaultConfig() {
935
+ sharedDefaultConfig = {
936
+ rules: {
937
+ ...testerDefaultConfig.rules,
938
+ },
939
+ };
940
+ }
941
+
942
+ /*
943
+ * If people use `mocha test.js --watch` command, `describe` and `it` function
944
+ * instances are different for each execution. So `describe` and `it` should get fresh instance
945
+ * always.
946
+ */
947
+ static get describe() {
948
+ return (
949
+ this[DESCRIBE] ||
950
+ (typeof describe === "function" ? describe : describeDefaultHandler)
951
+ );
952
+ }
953
+
954
+ static set describe(value) {
955
+ this[DESCRIBE] = value;
956
+ }
957
+
958
+ static get it() {
959
+ return this[IT] || (typeof it === "function" ? it : itDefaultHandler);
960
+ }
961
+
962
+ static set it(value) {
963
+ this[IT] = value;
964
+ }
965
+
966
+ /**
967
+ * Adds the `only` property to a test to run it in isolation.
968
+ * @param {string | ValidTestCase | InvalidTestCase} item A single test to run by itself.
969
+ * @returns {ValidTestCase | InvalidTestCase} The test with `only` set.
970
+ */
971
+ static only(item) {
972
+ if (typeof item === "string") {
973
+ return { code: item, only: true };
974
+ }
975
+
976
+ return { ...item, only: true };
977
+ }
978
+
979
+ static get itOnly() {
980
+ if (typeof this[IT_ONLY] === "function") {
981
+ return this[IT_ONLY];
982
+ }
983
+ if (
984
+ typeof this[IT] === "function" &&
985
+ typeof this[IT].only === "function"
986
+ ) {
987
+ return Function.bind.call(this[IT].only, this[IT]);
988
+ }
989
+ if (typeof it === "function" && typeof it.only === "function") {
990
+ return Function.bind.call(it.only, it);
991
+ }
992
+
993
+ if (
994
+ typeof this[DESCRIBE] === "function" ||
995
+ typeof this[IT] === "function"
996
+ ) {
997
+ throw new Error(
998
+ "Set `RuleTester.itOnly` to use `only` with a custom test framework.\n" +
999
+ "See https://eslint.org/docs/latest/integrate/nodejs-api#customizing-ruletester for more.",
1000
+ );
1001
+ }
1002
+ if (typeof it === "function") {
1003
+ throw new Error(
1004
+ "The current test framework does not support exclusive tests with `only`.",
1005
+ );
1006
+ }
1007
+ throw new Error(
1008
+ "To use `only`, use RuleTester with a test framework that provides `it.only()` like Mocha.",
1009
+ );
1010
+ }
1011
+
1012
+ static set itOnly(value) {
1013
+ this[IT_ONLY] = value;
1014
+ }
1015
+
1016
+ /**
1017
+ * Adds a new rule test to execute.
1018
+ * @param {string} ruleName The name of the rule to run.
1019
+ * @param {RuleDefinition} rule The rule to test.
1020
+ * @param {{
1021
+ * assertionOptions?: {
1022
+ * requireMessage?: boolean | "message" | "messageId",
1023
+ * requireLocation?: boolean
1024
+ * requireData?: boolean | "error" | "suggestion"
1025
+ * },
1026
+ * valid: (ValidTestCase | string)[],
1027
+ * invalid: InvalidTestCase[]
1028
+ * }} test The collection of tests to run.
1029
+ * @throws {TypeError|Error} If `rule` is not an object with a `create` method,
1030
+ * or if non-object `test`, or if a required scenario of the given type is missing.
1031
+ * @returns {void}
1032
+ */
1033
+ run(ruleName, rule, test) {
1034
+ const testerConfig = this.testerConfig,
1035
+ linter = this.linter,
1036
+ ruleId = `rule-to-test/${ruleName}`;
1037
+
1038
+ assertRule(rule, ruleName);
1039
+ assertTest(test, ruleName);
1040
+
1041
+ const estimateTestLocation = buildLazyTestLocationEstimator(this.run);
1042
+
1043
+ const baseConfig = [
1044
+ {
1045
+ plugins: {
1046
+ // copy root plugin over
1047
+ "@": {
1048
+ /*
1049
+ * Parsers are wrapped to detect more errors, so this needs
1050
+ * to be a new object for each call to run(), otherwise the
1051
+ * parsers will be wrapped multiple times.
1052
+ */
1053
+ parsers: {
1054
+ ...defaultConfig[0].plugins["@"].parsers,
1055
+ },
1056
+
1057
+ /*
1058
+ * The rules key on the default plugin is a proxy to lazy-load
1059
+ * just the rules that are needed. So, don't create a new object
1060
+ * here, just use the default one to keep that performance
1061
+ * enhancement.
1062
+ */
1063
+ rules: defaultConfig[0].plugins["@"].rules,
1064
+ languages: defaultConfig[0].plugins["@"].languages,
1065
+ },
1066
+ "rule-to-test": {
1067
+ rules: {
1068
+ [ruleName]: Object.assign({}, rule, {
1069
+ // Create a wrapper rule that freezes the `context` properties.
1070
+ create(context) {
1071
+ freezeDeeply(context.options);
1072
+ freezeDeeply(context.settings);
1073
+ freezeDeeply(context.parserOptions);
1074
+
1075
+ // freezeDeeply(context.languageOptions);
1076
+
1077
+ return rule.create(context);
1078
+ },
1079
+ }),
1080
+ },
1081
+ },
1082
+ },
1083
+ language: defaultConfig[0].language,
1084
+ },
1085
+ ...defaultRuleTesterConfig,
1086
+ ];
1087
+
1088
+ /**
1089
+ * Runs a hook on the given item when it's assigned to the given property
1090
+ * @param {Object} item Item to run the hook on
1091
+ * @param {string} prop The property having the hook assigned to
1092
+ * @throws {Error} If the property is not a function or that function throws an error
1093
+ * @returns {void}
1094
+ * @private
1095
+ */
1096
+ function runHook(item, prop) {
1097
+ if (hasOwnProperty(item, prop)) {
1098
+ assert.strictEqual(
1099
+ typeof item[prop],
1100
+ "function",
1101
+ `Optional test case property '${prop}' must be a function`,
1102
+ );
1103
+ item[prop]();
1104
+ }
1105
+ }
1106
+ /**
1107
+ * Run the rule for the given item
1108
+ * @param {Object} item Item to run the rule against
1109
+ * @throws {Error} If an invalid schema.
1110
+ * @returns {Object} Eslint run result
1111
+ * @private
1112
+ */
1113
+ function runRuleForItem(item) {
1114
+ const code = item.code;
1115
+ const filename = hasOwnProperty(item, "filename")
1116
+ ? item.filename
1117
+ : void 0;
1118
+ const options = hasOwnProperty(item, "options") ? item.options : [];
1119
+ const flatConfigArrayOptions = {
1120
+ baseConfig,
1121
+ };
1122
+
1123
+ if (filename) {
1124
+ flatConfigArrayOptions.basePath =
1125
+ path.parse(filename).root || void 0;
1126
+ }
1127
+
1128
+ const configs = new FlatConfigArray(
1129
+ testerConfig,
1130
+ flatConfigArrayOptions,
1131
+ );
1132
+
1133
+ /*
1134
+ * Modify the returned config so that the parser is wrapped to catch
1135
+ * access of the start/end properties. This method is called just
1136
+ * once per code snippet being tested, so each test case gets a clean
1137
+ * parser.
1138
+ */
1139
+ configs[ConfigArraySymbol.finalizeConfig] = function (...args) {
1140
+ // can't do super here :(
1141
+ const proto = Object.getPrototypeOf(this);
1142
+ const calculatedConfig = proto[
1143
+ ConfigArraySymbol.finalizeConfig
1144
+ ].apply(this, args);
1145
+
1146
+ // wrap the parser to catch start/end property access
1147
+ if (calculatedConfig.language === jslang) {
1148
+ calculatedConfig.languageOptions.parser = wrapParser(
1149
+ calculatedConfig.languageOptions.parser,
1150
+ );
1151
+ }
1152
+
1153
+ return calculatedConfig;
1154
+ };
1155
+
1156
+ let output, beforeAST, afterAST;
1157
+
1158
+ /*
1159
+ * Assumes everything on the item is a config except for the
1160
+ * parameters used by this tester
1161
+ */
1162
+ const itemConfig = { ...item };
1163
+
1164
+ for (const parameter of RuleTesterParameters) {
1165
+ delete itemConfig[parameter];
1166
+ }
1167
+
1168
+ /*
1169
+ * Create the config object from the tester config and this item
1170
+ * specific configurations.
1171
+ */
1172
+ configs.push(itemConfig);
1173
+
1174
+ configs.push({
1175
+ rules: {
1176
+ [ruleId]: [1, ...options],
1177
+ },
1178
+ });
1179
+
1180
+ let schema;
1181
+
1182
+ try {
1183
+ schema = Config.getRuleOptionsSchema(rule);
1184
+ } catch (err) {
1185
+ err.message += metaSchemaDescription;
1186
+ throw err;
1187
+ }
1188
+
1189
+ /*
1190
+ * Check and throw an error if the schema is an empty object (`schema:{}`), because such schema
1191
+ * doesn't validate or enforce anything and is therefore considered a possible error. If the intent
1192
+ * was to skip options validation, `schema:false` should be set instead (explicit opt-out).
1193
+ *
1194
+ * For this purpose, a schema object is considered empty if it doesn't have any own enumerable string-keyed
1195
+ * properties. While `ajv.compile()` does use enumerable properties from the prototype chain as well,
1196
+ * it caches compiled schemas by serializing only own enumerable properties, so it's generally not a good idea
1197
+ * to use inherited properties in schemas because schemas that differ only in inherited properties would end up
1198
+ * having the same cache entry that would be correct for only one of them.
1199
+ *
1200
+ * At this point, `schema` can only be an object or `null`.
1201
+ */
1202
+ if (schema && Object.keys(schema).length === 0) {
1203
+ throw new Error(
1204
+ `\`schema: {}\` is a no-op${metaSchemaDescription}`,
1205
+ );
1206
+ }
1207
+
1208
+ /*
1209
+ * Setup AST getters.
1210
+ * The goal is to check whether or not AST was modified when
1211
+ * running the rule under test.
1212
+ */
1213
+ configs.push({
1214
+ plugins: {
1215
+ "rule-tester": {
1216
+ rules: {
1217
+ "validate-ast": {
1218
+ create() {
1219
+ return {
1220
+ Program(node) {
1221
+ beforeAST =
1222
+ cloneDeeplyExcludesParent(node);
1223
+ },
1224
+ "Program:exit"(node) {
1225
+ afterAST = node;
1226
+ },
1227
+ };
1228
+ },
1229
+ },
1230
+ },
1231
+ },
1232
+ },
1233
+ });
1234
+
1235
+ if (schema) {
1236
+ ajv.validateSchema(schema);
1237
+
1238
+ if (ajv.errors) {
1239
+ const errors = ajv.errors
1240
+ .map(error => {
1241
+ const field =
1242
+ error.dataPath[0] === "."
1243
+ ? error.dataPath.slice(1)
1244
+ : error.dataPath;
1245
+
1246
+ return `\t${field}: ${error.message}`;
1247
+ })
1248
+ .join("\n");
1249
+
1250
+ throw new Error([
1251
+ `Schema for rule ${ruleName} is invalid:`,
1252
+ errors,
1253
+ ]);
1254
+ }
1255
+
1256
+ /*
1257
+ * `ajv.validateSchema` checks for errors in the structure of the schema (by comparing the schema against a "meta-schema"),
1258
+ * and it reports those errors individually. However, there are other types of schema errors that only occur when compiling
1259
+ * the schema (e.g. using invalid defaults in a schema), and only one of these errors can be reported at a time. As a result,
1260
+ * the schema is compiled here separately from checking for `validateSchema` errors.
1261
+ */
1262
+ try {
1263
+ ajv.compile(schema);
1264
+ } catch (err) {
1265
+ throw new Error(
1266
+ `Schema for rule ${ruleName} is invalid: ${err.message}`,
1267
+ {
1268
+ cause: err,
1269
+ },
1270
+ );
1271
+ }
1272
+ }
1273
+
1274
+ // check for validation errors
1275
+ try {
1276
+ configs.normalizeSync();
1277
+ configs.getConfig("test.js");
1278
+ } catch (error) {
1279
+ error.message = `ESLint configuration in rule-tester is invalid: ${error.message}`;
1280
+ throw error;
1281
+ }
1282
+
1283
+ // Verify the code.
1284
+ const { applyLanguageOptions, applyInlineConfig, finalize } =
1285
+ SourceCode.prototype;
1286
+ let messages;
1287
+
1288
+ try {
1289
+ forbiddenMethods.forEach(methodName => {
1290
+ SourceCode.prototype[methodName] =
1291
+ throwForbiddenMethodError(
1292
+ methodName,
1293
+ SourceCode.prototype,
1294
+ );
1295
+ });
1296
+
1297
+ messages = linter.verify(code, configs, filename);
1298
+ } finally {
1299
+ SourceCode.prototype.applyInlineConfig = applyInlineConfig;
1300
+ SourceCode.prototype.applyLanguageOptions =
1301
+ applyLanguageOptions;
1302
+ SourceCode.prototype.finalize = finalize;
1303
+ }
1304
+
1305
+ const fatalErrorMessage = messages.find(m => m.fatal);
1306
+
1307
+ assert(
1308
+ !fatalErrorMessage,
1309
+ `A fatal parsing error occurred: ${fatalErrorMessage && fatalErrorMessage.message}`,
1310
+ );
1311
+
1312
+ // Verify if autofix makes a syntax error or not.
1313
+ if (messages.some(m => m.fix)) {
1314
+ output = SourceCodeFixer.applyFixes(code, messages).output;
1315
+ const errorMessageInFix = linter
1316
+ .verify(output, configs, filename)
1317
+ .find(m => m.fatal);
1318
+
1319
+ assert(
1320
+ !errorMessageInFix,
1321
+ [
1322
+ "A fatal parsing error occurred in autofix.",
1323
+ `Error: ${errorMessageInFix && errorMessageInFix.message}`,
1324
+ "Autofix output:",
1325
+ output,
1326
+ ].join("\n"),
1327
+ );
1328
+ } else {
1329
+ output = code;
1330
+ }
1331
+
1332
+ return {
1333
+ messages,
1334
+ output,
1335
+ beforeAST,
1336
+ afterAST: cloneDeeplyExcludesParent(afterAST),
1337
+ configs,
1338
+ filename,
1339
+ };
1340
+ }
1341
+
1342
+ /**
1343
+ * Check if the AST was changed
1344
+ * @param {ASTNode} beforeAST AST node before running
1345
+ * @param {ASTNode} afterAST AST node after running
1346
+ * @returns {void}
1347
+ * @private
1348
+ */
1349
+ function assertASTDidntChange(beforeAST, afterAST) {
1350
+ if (!equal(beforeAST, afterAST)) {
1351
+ assert.fail("Rule should not modify AST.");
1352
+ }
1353
+ }
1354
+
1355
+ /**
1356
+ * Check if the template is valid or not
1357
+ * all valid cases go through this
1358
+ * @param {Object} item Item to run the rule against
1359
+ * @returns {void}
1360
+ * @private
1361
+ */
1362
+ function testValidTemplate(item) {
1363
+ const result = runRuleForItem(item);
1364
+ const messages = result.messages;
1365
+
1366
+ assert.strictEqual(
1367
+ messages.length,
1368
+ 0,
1369
+ util.format(
1370
+ "Should have no errors but had %d: %s",
1371
+ messages.length,
1372
+ util.inspect(messages),
1373
+ ),
1374
+ );
1375
+
1376
+ assertASTDidntChange(result.beforeAST, result.afterAST);
1377
+ }
1378
+
1379
+ /**
1380
+ * Asserts that the message matches its expected value. If the expected
1381
+ * value is a regular expression, it is checked against the actual
1382
+ * value.
1383
+ * @param {string} actual Actual value
1384
+ * @param {string|RegExp} expected Expected value
1385
+ * @returns {void}
1386
+ * @private
1387
+ */
1388
+ function assertMessageMatches(actual, expected) {
1389
+ if (expected instanceof RegExp) {
1390
+ // assert.js doesn't have a built-in RegExp match function
1391
+ assert.ok(
1392
+ expected.test(actual),
1393
+ `Expected '${actual}' to match ${expected}`,
1394
+ );
1395
+ } else {
1396
+ assert.strictEqual(actual, expected);
1397
+ }
1398
+ }
1399
+
1400
+ /**
1401
+ * Check if the template is invalid or not
1402
+ * all invalid cases go through this.
1403
+ * @param {Object} item Item to run the rule against
1404
+ * @returns {void}
1405
+ * @private
1406
+ * @throws {Error} If the test case is invalid or has an invalid error.
1407
+ */
1408
+ function testInvalidTemplate(item) {
1409
+ const {
1410
+ requireMessage = false,
1411
+ requireLocation = false,
1412
+ requireData = false,
1413
+ } = test.assertionOptions ?? {};
1414
+
1415
+ const ruleHasMetaMessages =
1416
+ hasOwnProperty(rule, "meta") &&
1417
+ hasOwnProperty(rule.meta, "messages");
1418
+ const friendlyIDList = ruleHasMetaMessages
1419
+ ? `[${Object.keys(rule.meta.messages)
1420
+ .map(key => `'${key}'`)
1421
+ .join(", ")}]`
1422
+ : null;
1423
+
1424
+ assert.ok(
1425
+ ruleHasMetaMessages || requireMessage !== "messageId",
1426
+ `Assertion options can not use 'requireMessage: "messageId"' if rule under test doesn't define 'meta.messages'.`,
1427
+ );
1428
+
1429
+ const result = runRuleForItem(item);
1430
+ const messages = result.messages;
1431
+
1432
+ for (const message of messages) {
1433
+ if (hasOwnProperty(message, "suggestions")) {
1434
+ /** @type {Map<string, number>} */
1435
+ const seenMessageIndices = new Map();
1436
+
1437
+ for (let i = 0; i < message.suggestions.length; i += 1) {
1438
+ const suggestionMessage = message.suggestions[i].desc;
1439
+ const previous =
1440
+ seenMessageIndices.get(suggestionMessage);
1441
+
1442
+ assert.ok(
1443
+ !seenMessageIndices.has(suggestionMessage),
1444
+ `Suggestion message '${suggestionMessage}' reported from suggestion ${i} was previously reported by suggestion ${previous}. Suggestion messages should be unique within an error.`,
1445
+ );
1446
+ seenMessageIndices.set(suggestionMessage, i);
1447
+ }
1448
+ }
1449
+ }
1450
+
1451
+ if (typeof item.errors === "number") {
1452
+ assert.strictEqual(
1453
+ messages.length,
1454
+ item.errors,
1455
+ util.format(
1456
+ "Should have %d error%s but had %d: %s",
1457
+ item.errors,
1458
+ item.errors === 1 ? "" : "s",
1459
+ messages.length,
1460
+ util.inspect(messages),
1461
+ ),
1462
+ );
1463
+ } else {
1464
+ assert.strictEqual(
1465
+ messages.length,
1466
+ item.errors.length,
1467
+ util.format(
1468
+ "Should have %d error%s but had %d: %s",
1469
+ item.errors.length,
1470
+ item.errors.length === 1 ? "" : "s",
1471
+ messages.length,
1472
+ util.inspect(messages),
1473
+ ),
1474
+ );
1475
+
1476
+ const hasMessageOfThisRule = messages.some(
1477
+ m => m.ruleId === ruleId,
1478
+ );
1479
+
1480
+ for (let i = 0, l = item.errors.length; i < l; i++) {
1481
+ try {
1482
+ const error = item.errors[i];
1483
+ const message = messages[i];
1484
+
1485
+ assert(
1486
+ hasMessageOfThisRule,
1487
+ "Error rule name should be the same as the name of the rule being tested",
1488
+ );
1489
+
1490
+ if (
1491
+ typeof error === "string" ||
1492
+ error instanceof RegExp
1493
+ ) {
1494
+ // Just an error message.
1495
+ assertMessageMatches(message.message, error);
1496
+ assert.ok(
1497
+ message.suggestions === void 0,
1498
+ `Error at index ${i} has suggestions. Please convert the test error into an object and specify 'suggestions' property on it to test suggestions.`,
1499
+ );
1500
+ } else if (
1501
+ typeof error === "object" &&
1502
+ error !== null
1503
+ ) {
1504
+ /*
1505
+ * Error object.
1506
+ * This may have a message, messageId, data, line, and/or column.
1507
+ */
1508
+
1509
+ if (hasOwnProperty(error, "message")) {
1510
+ assertMessageMatches(
1511
+ message.message,
1512
+ error.message,
1513
+ );
1514
+ } else if (hasOwnProperty(error, "messageId")) {
1515
+ assert.ok(
1516
+ ruleHasMetaMessages,
1517
+ "Error can not use 'messageId' if rule under test doesn't define 'meta.messages'.",
1518
+ );
1519
+ if (
1520
+ !hasOwnProperty(
1521
+ rule.meta.messages,
1522
+ error.messageId,
1523
+ )
1524
+ ) {
1525
+ assert(
1526
+ false,
1527
+ `Invalid messageId '${error.messageId}'. Expected one of ${friendlyIDList}.`,
1528
+ );
1529
+ }
1530
+ assert.strictEqual(
1531
+ message.messageId,
1532
+ error.messageId,
1533
+ `messageId '${message.messageId}' does not match expected messageId '${error.messageId}'.`,
1534
+ );
1535
+
1536
+ const unsubstitutedPlaceholders =
1537
+ getUnsubstitutedMessagePlaceholders(
1538
+ message.message,
1539
+ rule.meta.messages[message.messageId],
1540
+ error.data,
1541
+ );
1542
+
1543
+ assert.ok(
1544
+ unsubstitutedPlaceholders.length === 0,
1545
+ `The reported message has ${unsubstitutedPlaceholders.length > 1 ? `unsubstituted placeholders: ${unsubstitutedPlaceholders.map(name => `'${name}'`).join(", ")}` : `an unsubstituted placeholder '${unsubstitutedPlaceholders[0]}'`}. Please provide the missing ${unsubstitutedPlaceholders.length > 1 ? "values" : "value"} via the 'data' property in the context.report() call.`,
1546
+ );
1547
+
1548
+ if (hasOwnProperty(error, "data")) {
1549
+ /*
1550
+ * if data was provided, then directly compare the returned message to a synthetic
1551
+ * interpolated message using the same message ID and data provided in the test.
1552
+ * See https://github.com/eslint/eslint/issues/9890 for context.
1553
+ */
1554
+ const unformattedOriginalMessage =
1555
+ rule.meta.messages[error.messageId];
1556
+ const rehydratedMessage = interpolate(
1557
+ unformattedOriginalMessage,
1558
+ error.data,
1559
+ );
1560
+
1561
+ assert.strictEqual(
1562
+ message.message,
1563
+ rehydratedMessage,
1564
+ `Hydrated message "${rehydratedMessage}" does not match "${message.message}"`,
1565
+ );
1566
+ } else {
1567
+ const requiresDataProperty =
1568
+ requireData === true ||
1569
+ requireData === "error";
1570
+ const hasPlaceholders =
1571
+ getMessagePlaceholders(
1572
+ rule.meta.messages[error.messageId],
1573
+ ).length > 0;
1574
+ assert.ok(
1575
+ !requiresDataProperty ||
1576
+ !hasPlaceholders,
1577
+ `Error should specify the 'data' property as the referenced message has placeholders.`,
1578
+ );
1579
+ }
1580
+ }
1581
+
1582
+ const locationProperties = [
1583
+ "line",
1584
+ "column",
1585
+ "endLine",
1586
+ "endColumn",
1587
+ ];
1588
+ const actualLocation = {};
1589
+ const expectedLocation = {};
1590
+
1591
+ for (const key of locationProperties) {
1592
+ if (hasOwnProperty(error, key)) {
1593
+ actualLocation[key] = message[key];
1594
+ expectedLocation[key] = error[key];
1595
+ }
1596
+ }
1597
+
1598
+ if (requireLocation) {
1599
+ const missingKeys = locationProperties.filter(
1600
+ key =>
1601
+ !hasOwnProperty(error, key) &&
1602
+ hasOwnProperty(message, key),
1603
+ );
1604
+ assert.ok(
1605
+ missingKeys.length === 0,
1606
+ `Error is missing expected location properties: ${missingKeys.join(", ")}`,
1607
+ );
1608
+ }
1609
+
1610
+ if (Object.keys(expectedLocation).length > 0) {
1611
+ assert.deepStrictEqual(
1612
+ actualLocation,
1613
+ expectedLocation,
1614
+ "Actual error location does not match expected error location.",
1615
+ );
1616
+ }
1617
+
1618
+ assert.ok(
1619
+ !message.suggestions ||
1620
+ hasOwnProperty(error, "suggestions"),
1621
+ `Error at index ${i} has suggestions. Please specify 'suggestions' property on the test error object.`,
1622
+ );
1623
+ if (hasOwnProperty(error, "suggestions")) {
1624
+ // Support asserting there are no suggestions
1625
+ const expectsSuggestions = Array.isArray(
1626
+ error.suggestions,
1627
+ )
1628
+ ? error.suggestions.length > 0
1629
+ : Boolean(error.suggestions);
1630
+ const hasSuggestions =
1631
+ message.suggestions !== void 0;
1632
+
1633
+ if (!hasSuggestions && expectsSuggestions) {
1634
+ assert.ok(
1635
+ !error.suggestions,
1636
+ `Error should have suggestions on error with message: "${message.message}"`,
1637
+ );
1638
+ } else if (hasSuggestions) {
1639
+ assert.ok(
1640
+ expectsSuggestions,
1641
+ `Error should have no suggestions on error with message: "${message.message}"`,
1642
+ );
1643
+ if (typeof error.suggestions === "number") {
1644
+ assert.strictEqual(
1645
+ message.suggestions.length,
1646
+ error.suggestions,
1647
+ `Error should have ${error.suggestions} suggestions. Instead found ${message.suggestions.length} suggestions`,
1648
+ );
1649
+ } else if (
1650
+ Array.isArray(error.suggestions)
1651
+ ) {
1652
+ assert.strictEqual(
1653
+ message.suggestions.length,
1654
+ error.suggestions.length,
1655
+ `Error should have ${error.suggestions.length} suggestions. Instead found ${message.suggestions.length} suggestions`,
1656
+ );
1657
+
1658
+ error.suggestions.forEach(
1659
+ (expectedSuggestion, index) => {
1660
+ assert.ok(
1661
+ typeof expectedSuggestion ===
1662
+ "object" &&
1663
+ expectedSuggestion !==
1664
+ null,
1665
+ "Test suggestion in 'suggestions' array must be an object.",
1666
+ );
1667
+ Object.keys(
1668
+ expectedSuggestion,
1669
+ ).forEach(propertyName => {
1670
+ assert.ok(
1671
+ suggestionObjectParameters.has(
1672
+ propertyName,
1673
+ ),
1674
+ `Invalid suggestion property name '${propertyName}'. Expected one of ${friendlySuggestionObjectParameterList}.`,
1675
+ );
1676
+ });
1677
+
1678
+ const actualSuggestion =
1679
+ message.suggestions[index];
1680
+ const suggestionPrefix = `Error Suggestion at index ${index}:`;
1681
+
1682
+ if (
1683
+ hasOwnProperty(
1684
+ expectedSuggestion,
1685
+ "desc",
1686
+ )
1687
+ ) {
1688
+ assert.ok(
1689
+ !hasOwnProperty(
1690
+ expectedSuggestion,
1691
+ "data",
1692
+ ),
1693
+ `${suggestionPrefix} Test should not specify both 'desc' and 'data'.`,
1694
+ );
1695
+ assert.ok(
1696
+ !hasOwnProperty(
1697
+ expectedSuggestion,
1698
+ "messageId",
1699
+ ),
1700
+ `${suggestionPrefix} Test should not specify both 'desc' and 'messageId'.`,
1701
+ );
1702
+ assert.strictEqual(
1703
+ actualSuggestion.desc,
1704
+ expectedSuggestion.desc,
1705
+ `${suggestionPrefix} desc should be "${expectedSuggestion.desc}" but got "${actualSuggestion.desc}" instead.`,
1706
+ );
1707
+ } else if (
1708
+ hasOwnProperty(
1709
+ expectedSuggestion,
1710
+ "messageId",
1711
+ )
1712
+ ) {
1713
+ assert.ok(
1714
+ ruleHasMetaMessages,
1715
+ `${suggestionPrefix} Test can not use 'messageId' if rule under test doesn't define 'meta.messages'.`,
1716
+ );
1717
+ assert.ok(
1718
+ hasOwnProperty(
1719
+ rule.meta.messages,
1720
+ expectedSuggestion.messageId,
1721
+ ),
1722
+ `${suggestionPrefix} Test has invalid messageId '${expectedSuggestion.messageId}', the rule under test allows only one of ${friendlyIDList}.`,
1723
+ );
1724
+ assert.strictEqual(
1725
+ actualSuggestion.messageId,
1726
+ expectedSuggestion.messageId,
1727
+ `${suggestionPrefix} messageId should be '${expectedSuggestion.messageId}' but got '${actualSuggestion.messageId}' instead.`,
1728
+ );
1729
+
1730
+ const rawSuggestionMessage =
1731
+ rule.meta.messages[
1732
+ expectedSuggestion
1733
+ .messageId
1734
+ ];
1735
+ const unsubstitutedPlaceholders =
1736
+ getUnsubstitutedMessagePlaceholders(
1737
+ actualSuggestion.desc,
1738
+ rawSuggestionMessage,
1739
+ expectedSuggestion.data,
1740
+ );
1741
+
1742
+ assert.ok(
1743
+ unsubstitutedPlaceholders.length ===
1744
+ 0,
1745
+ `The message of the suggestion has ${unsubstitutedPlaceholders.length > 1 ? `unsubstituted placeholders: ${unsubstitutedPlaceholders.map(name => `'${name}'`).join(", ")}` : `an unsubstituted placeholder '${unsubstitutedPlaceholders[0]}'`}. Please provide the missing ${unsubstitutedPlaceholders.length > 1 ? "values" : "value"} via the 'data' property for the suggestion in the context.report() call.`,
1746
+ );
1747
+
1748
+ if (
1749
+ hasOwnProperty(
1750
+ expectedSuggestion,
1751
+ "data",
1752
+ )
1753
+ ) {
1754
+ const unformattedMetaMessage =
1755
+ rule.meta.messages[
1756
+ expectedSuggestion
1757
+ .messageId
1758
+ ];
1759
+ const rehydratedDesc =
1760
+ interpolate(
1761
+ unformattedMetaMessage,
1762
+ expectedSuggestion.data,
1763
+ );
1764
+
1765
+ assert.strictEqual(
1766
+ actualSuggestion.desc,
1767
+ rehydratedDesc,
1768
+ `${suggestionPrefix} Hydrated test desc "${rehydratedDesc}" does not match received desc "${actualSuggestion.desc}".`,
1769
+ );
1770
+ } else {
1771
+ const requiresDataProperty =
1772
+ requireData ===
1773
+ true ||
1774
+ requireData ===
1775
+ "suggestion";
1776
+ const hasPlaceholders =
1777
+ getMessagePlaceholders(
1778
+ rawSuggestionMessage,
1779
+ ).length > 0;
1780
+ assert.ok(
1781
+ !requiresDataProperty ||
1782
+ !hasPlaceholders,
1783
+ `${suggestionPrefix} Suggestion should specify the 'data' property as the referenced message has placeholders.`,
1784
+ );
1785
+ }
1786
+ } else if (
1787
+ hasOwnProperty(
1788
+ expectedSuggestion,
1789
+ "data",
1790
+ )
1791
+ ) {
1792
+ assert.fail(
1793
+ `${suggestionPrefix} Test must specify 'messageId' if 'data' is used.`,
1794
+ );
1795
+ } else {
1796
+ assert.fail(
1797
+ `${suggestionPrefix} Test must specify either 'messageId' or 'desc'.`,
1798
+ );
1799
+ }
1800
+
1801
+ assert.ok(
1802
+ hasOwnProperty(
1803
+ expectedSuggestion,
1804
+ "output",
1805
+ ),
1806
+ `${suggestionPrefix} The "output" property is required.`,
1807
+ );
1808
+ const codeWithAppliedSuggestion =
1809
+ SourceCodeFixer.applyFixes(
1810
+ item.code,
1811
+ [actualSuggestion],
1812
+ ).output;
1813
+
1814
+ // Verify if suggestion fix makes a syntax error or not.
1815
+ const errorMessageInSuggestion =
1816
+ linter
1817
+ .verify(
1818
+ codeWithAppliedSuggestion,
1819
+ result.configs,
1820
+ result.filename,
1821
+ )
1822
+ .find(m => m.fatal);
1823
+
1824
+ assert(
1825
+ !errorMessageInSuggestion,
1826
+ [
1827
+ "A fatal parsing error occurred in suggestion fix.",
1828
+ `Error: ${errorMessageInSuggestion && errorMessageInSuggestion.message}`,
1829
+ "Suggestion output:",
1830
+ codeWithAppliedSuggestion,
1831
+ ].join("\n"),
1832
+ );
1833
+
1834
+ assert.strictEqual(
1835
+ codeWithAppliedSuggestion,
1836
+ expectedSuggestion.output,
1837
+ `Expected the applied suggestion fix to match the test suggestion output for suggestion at index: ${index} on error with message: "${message.message}"`,
1838
+ );
1839
+ assert.notStrictEqual(
1840
+ expectedSuggestion.output,
1841
+ item.code,
1842
+ `The output of a suggestion should differ from the original source code for suggestion at index: ${index} on error with message: "${message.message}"`,
1843
+ );
1844
+ },
1845
+ );
1846
+ } else {
1847
+ assert.fail(
1848
+ "Test error object property 'suggestions' should be an array or a number",
1849
+ );
1850
+ }
1851
+ }
1852
+ }
1853
+ }
1854
+ } catch (error) {
1855
+ if (error instanceof Error) {
1856
+ error.errorIndex = i;
1857
+ }
1858
+ throw error;
1859
+ }
1860
+ }
1861
+ }
1862
+
1863
+ if (hasOwnProperty(item, "output")) {
1864
+ if (item.output === null) {
1865
+ assert.strictEqual(
1866
+ result.output,
1867
+ item.code,
1868
+ "Expected no autofixes to be suggested",
1869
+ );
1870
+ } else {
1871
+ assert.strictEqual(
1872
+ result.output,
1873
+ item.output,
1874
+ "Output is incorrect.",
1875
+ );
1876
+ assert.notStrictEqual(
1877
+ item.code,
1878
+ item.output,
1879
+ "Test property 'output' matches 'code'. If no autofix is expected, then omit the 'output' property or set it to null.",
1880
+ );
1881
+ }
1882
+ } else {
1883
+ assert.strictEqual(
1884
+ result.output,
1885
+ item.code,
1886
+ "The rule fixed the code. Please add 'output' property.",
1887
+ );
1888
+ }
1889
+
1890
+ assertASTDidntChange(result.beforeAST, result.afterAST);
1891
+ }
1892
+
1893
+ /*
1894
+ * This creates a mocha test suite and pipes all supplied info through
1895
+ * one of the templates above.
1896
+ * The test suites for valid/invalid are created conditionally as
1897
+ * test runners (eg. vitest) fail for empty test suites.
1898
+ */
1899
+ this.constructor.describe(ruleName, () => {
1900
+ if (test.valid.length > 0) {
1901
+ this.constructor.describe("valid", () => {
1902
+ const seenTestCases = new Set();
1903
+ test.valid.forEach((valid, index) => {
1904
+ const item = normalizeTestCase(valid);
1905
+ this.constructor[valid.only ? "itOnly" : "it"](
1906
+ sanitize(item.name || item.code),
1907
+ () => {
1908
+ try {
1909
+ runHook(item, "before");
1910
+ assertValidTestCase(item, seenTestCases);
1911
+ testValidTemplate(item);
1912
+ } catch (error) {
1913
+ if (error instanceof Error) {
1914
+ error.scenarioType = "valid";
1915
+ error.scenarioIndex = index;
1916
+ error.stack = error.stack.replace(
1917
+ /^ +at /mu,
1918
+ [
1919
+ ` roughly at RuleTester.run.valid[${index}] (${estimateTestLocation(`valid[${index}]`)})`,
1920
+ ` roughly at RuleTester.run.valid (${estimateTestLocation("valid")})`,
1921
+ ` at RuleTester.run (${estimateTestLocation("root")})`,
1922
+ " at ",
1923
+ ].join("\n"),
1924
+ );
1925
+ }
1926
+ throw error;
1927
+ } finally {
1928
+ runHook(item, "after");
1929
+ }
1930
+ },
1931
+ );
1932
+ });
1933
+ });
1934
+ }
1935
+
1936
+ if (test.invalid.length > 0) {
1937
+ this.constructor.describe("invalid", () => {
1938
+ const seenTestCases = new Set();
1939
+ test.invalid.forEach((invalid, index) => {
1940
+ const item = normalizeTestCase(invalid);
1941
+ this.constructor[item.only ? "itOnly" : "it"](
1942
+ sanitize(item.name || item.code),
1943
+ () => {
1944
+ try {
1945
+ runHook(item, "before");
1946
+ assertInvalidTestCase(
1947
+ item,
1948
+ seenTestCases,
1949
+ ruleName,
1950
+ test.assertionOptions,
1951
+ );
1952
+ testInvalidTemplate(item);
1953
+ } catch (error) {
1954
+ if (error instanceof Error) {
1955
+ error.scenarioType = "invalid";
1956
+ error.scenarioIndex = index;
1957
+ const errorIndex = error.errorIndex;
1958
+ error.stack = error.stack.replace(
1959
+ /^ +at /mu,
1960
+ [
1961
+ ...(typeof errorIndex ===
1962
+ "number"
1963
+ ? [
1964
+ ` roughly at RuleTester.run.invalid[${index}].error[${errorIndex}] (${estimateTestLocation(`invalid[${index}].errors[${errorIndex}]`)})`,
1965
+ ]
1966
+ : []),
1967
+ ` roughly at RuleTester.run.invalid[${index}] (${estimateTestLocation(`invalid[${index}]`)})`,
1968
+ ` roughly at RuleTester.run.invalid (${estimateTestLocation("invalid")})`,
1969
+ ` at RuleTester.run (${estimateTestLocation("root")})`,
1970
+ " at ",
1971
+ ].join("\n"),
1972
+ );
1973
+ }
1974
+ throw error;
1975
+ } finally {
1976
+ runHook(item, "after");
1977
+ }
1978
+ },
1979
+ );
1980
+ });
1981
+ });
1982
+ }
1983
+ });
1984
+ }
1985
+ }
1986
+
1987
+ RuleTester[DESCRIBE] = RuleTester[IT] = RuleTester[IT_ONLY] = null;
1988
+
1989
+ module.exports = RuleTester;