@codelaw/rules-js 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/LICENSE +23 -0
  2. package/NOTICE +19 -0
  3. package/README.md +90 -2
  4. package/codelaw-pack.toml +6 -0
  5. package/data/globals/browser.json +1209 -0
  6. package/data/globals/commonjs.json +6 -0
  7. package/data/globals/jest.json +15 -0
  8. package/data/globals/mocha.json +22 -0
  9. package/data/globals/node.json +83 -0
  10. package/data/globals/serviceworker.json +328 -0
  11. package/data/globals/shared-node-browser.json +73 -0
  12. package/data/globals/vitest.json +19 -0
  13. package/data/globals/worker.json +349 -0
  14. package/data/node/deprecated-api.json +83 -0
  15. package/data/react/dom-property-aliases.json +131 -0
  16. package/package.json +14 -4
  17. package/presets/js/conventions.toml +10 -0
  18. package/presets/js/recommended.toml +67 -0
  19. package/presets/node/recommended.toml +13 -0
  20. package/presets/react/recommended.toml +22 -0
  21. package/presets/stencil/recommended.toml +18 -0
  22. package/presets/ts/recommended.toml +27 -0
  23. package/rules/graph/no-unused-exports.md +135 -0
  24. package/rules/js/constructor-super.md +77 -0
  25. package/rules/js/exports-at-end.md +134 -0
  26. package/rules/js/for-direction.md +106 -0
  27. package/rules/js/getter-return.md +74 -0
  28. package/rules/js/import-groups.md +117 -0
  29. package/rules/js/no-async-promise-executor.md +95 -0
  30. package/rules/js/no-case-declarations.md +134 -0
  31. package/rules/js/no-class-assign.md +61 -0
  32. package/rules/js/no-compare-neg-zero.md +105 -0
  33. package/rules/js/no-cond-assign.md +135 -0
  34. package/rules/js/no-const-assign.md +61 -0
  35. package/rules/js/no-constant-binary-expression.md +83 -0
  36. package/rules/js/no-constant-condition.md +150 -0
  37. package/rules/js/no-control-regex.md +84 -0
  38. package/rules/js/no-debugger.md +99 -0
  39. package/rules/js/no-default-export.md +88 -0
  40. package/rules/js/no-delete-var.md +93 -0
  41. package/rules/js/no-dupe-args.md +61 -0
  42. package/rules/js/no-dupe-class-members.md +82 -0
  43. package/rules/js/no-dupe-else-if.md +113 -0
  44. package/rules/js/no-dupe-keys.md +66 -0
  45. package/rules/js/no-duplicate-case.md +137 -0
  46. package/rules/js/no-empty-character-class.md +98 -0
  47. package/rules/js/no-empty-pattern.md +86 -0
  48. package/rules/js/no-empty-static-block.md +99 -0
  49. package/rules/js/no-empty.md +116 -0
  50. package/rules/js/no-ex-assign.md +121 -0
  51. package/rules/js/no-extra-boolean-cast.md +107 -0
  52. package/rules/js/no-fallthrough.md +178 -0
  53. package/rules/js/no-func-assign.md +62 -0
  54. package/rules/js/no-global-assign.md +85 -0
  55. package/rules/js/no-import-assign.md +60 -0
  56. package/rules/js/no-invalid-regexp.md +86 -0
  57. package/rules/js/no-irregular-whitespace.md +87 -0
  58. package/rules/js/no-loss-of-precision.md +82 -0
  59. package/rules/js/no-misleading-character-class.md +83 -0
  60. package/rules/js/no-new-native-nonconstructor.md +55 -0
  61. package/rules/js/no-nonoctal-decimal-escape.md +84 -0
  62. package/rules/js/no-obj-calls.md +61 -0
  63. package/rules/js/no-octal.md +84 -0
  64. package/rules/js/no-prototype-builtins.md +99 -0
  65. package/rules/js/no-redeclare.md +61 -0
  66. package/rules/js/no-regex-spaces.md +75 -0
  67. package/rules/js/no-self-assign.md +91 -0
  68. package/rules/js/no-setter-return.md +69 -0
  69. package/rules/js/no-shadow-restricted-names.md +102 -0
  70. package/rules/js/no-sparse-arrays.md +82 -0
  71. package/rules/js/no-this-before-super.md +74 -0
  72. package/rules/js/no-unassigned-vars.md +102 -0
  73. package/rules/js/no-undef.md +76 -0
  74. package/rules/js/no-unexpected-multiline.md +91 -0
  75. package/rules/js/no-unreachable.md +59 -0
  76. package/rules/js/no-unsafe-finally.md +145 -0
  77. package/rules/js/no-unsafe-negation.md +71 -0
  78. package/rules/js/no-unsafe-optional-chaining.md +83 -0
  79. package/rules/js/no-unused-labels.md +102 -0
  80. package/rules/js/no-unused-private-class-members.md +126 -0
  81. package/rules/js/no-unused-vars.md +69 -0
  82. package/rules/js/no-useless-assignment.md +115 -0
  83. package/rules/js/no-useless-backreference.md +83 -0
  84. package/rules/js/no-useless-catch.md +105 -0
  85. package/rules/js/no-useless-escape.md +81 -0
  86. package/rules/js/no-var.md +76 -0
  87. package/rules/js/no-with.md +60 -0
  88. package/rules/js/prefer-const.md +83 -0
  89. package/rules/js/prefer-rest-params.md +103 -0
  90. package/rules/js/prefer-spread.md +95 -0
  91. package/rules/js/preserve-caught-error.md +122 -0
  92. package/rules/js/require-yield.md +107 -0
  93. package/rules/js/use-isnan.md +105 -0
  94. package/rules/js/valid-typeof.md +111 -0
  95. package/rules/node/hashbang.md +71 -0
  96. package/rules/node/no-deprecated-api.md +91 -0
  97. package/rules/node/no-exports-assign.md +92 -0
  98. package/rules/node/no-extraneous-import.md +118 -0
  99. package/rules/node/no-extraneous-require.md +117 -0
  100. package/rules/node/no-missing-import.md +118 -0
  101. package/rules/node/no-missing-require.md +117 -0
  102. package/rules/node/no-process-exit.md +99 -0
  103. package/rules/node/no-unpublished-import.md +134 -0
  104. package/rules/node/no-unpublished-require.md +133 -0
  105. package/rules/react/display-name.md +91 -0
  106. package/rules/react/exhaustive-deps.md +116 -0
  107. package/rules/react/hook-prefix.md +108 -0
  108. package/rules/react/jsx-key.md +99 -0
  109. package/rules/react/jsx-no-comment-textnodes.md +87 -0
  110. package/rules/react/jsx-no-duplicate-props.md +66 -0
  111. package/rules/react/jsx-no-target-blank.md +78 -0
  112. package/rules/react/jsx-no-undef.md +78 -0
  113. package/rules/react/no-children-prop.md +80 -0
  114. package/rules/react/no-danger-with-children.md +83 -0
  115. package/rules/react/no-deprecated.md +84 -0
  116. package/rules/react/no-direct-mutation-state.md +102 -0
  117. package/rules/react/no-find-dom-node.md +72 -0
  118. package/rules/react/no-is-mounted.md +109 -0
  119. package/rules/react/no-render-return-value.md +75 -0
  120. package/rules/react/no-string-refs.md +72 -0
  121. package/rules/react/no-unescaped-entities.md +69 -0
  122. package/rules/react/no-unknown-property.md +69 -0
  123. package/rules/react/props-type-name.md +43 -0
  124. package/rules/react/require-render-return.md +91 -0
  125. package/rules/react/rules-of-hooks.md +128 -0
  126. package/rules/stencil/ban-default-true.md +70 -0
  127. package/rules/stencil/ban-exported-const-enums.md +60 -0
  128. package/rules/stencil/ban-prefix.md +76 -0
  129. package/rules/stencil/decorators-context.md +61 -0
  130. package/rules/stencil/host-data-deprecated.md +73 -0
  131. package/rules/stencil/methods-must-be-public.md +69 -0
  132. package/rules/stencil/no-unused-watch.md +68 -0
  133. package/rules/stencil/own-methods-must-be-private.md +68 -0
  134. package/rules/stencil/own-props-must-be-private.md +60 -0
  135. package/rules/stencil/prefer-vdom-listener.md +67 -0
  136. package/rules/stencil/prop-readonly.md +63 -0
  137. package/rules/stencil/props-must-be-public.md +68 -0
  138. package/rules/stencil/required-jsdoc.md +66 -0
  139. package/rules/stencil/reserved-member-names.md +70 -0
  140. package/rules/stencil/strict-mutable.md +75 -0
  141. package/rules/stencil/tag-prefix.md +75 -0
  142. package/rules/ts/ban-ts-comment.md +64 -0
  143. package/rules/ts/no-array-constructor.md +58 -0
  144. package/rules/ts/no-duplicate-enum-values.md +65 -0
  145. package/rules/ts/no-empty-object-type.md +65 -0
  146. package/rules/ts/no-explicit-any.md +61 -0
  147. package/rules/ts/no-extra-non-null-assertion.md +50 -0
  148. package/rules/ts/no-misused-new.md +70 -0
  149. package/rules/ts/no-namespace.md +65 -0
  150. package/rules/ts/no-non-null-asserted-optional-chain.md +55 -0
  151. package/rules/ts/no-require-imports.md +54 -0
  152. package/rules/ts/no-this-alias.md +68 -0
  153. package/rules/ts/no-unnecessary-type-constraint.md +64 -0
  154. package/rules/ts/no-unsafe-declaration-merging.md +73 -0
  155. package/rules/ts/no-unsafe-function-type.md +57 -0
  156. package/rules/ts/no-unused-expressions.md +61 -0
  157. package/rules/ts/no-unused-vars.md +68 -0
  158. package/rules/ts/no-wrapper-object-types.md +49 -0
  159. package/rules/ts/prefer-as-const.md +47 -0
  160. package/rules/ts/prefer-namespace-keyword.md +63 -0
  161. package/rules/ts/triple-slash-reference.md +60 -0
  162. package/rules/ts/type-only-imports.md +57 -0
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arpit Arya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ SPDX-License-Identifier: MIT
package/NOTICE ADDED
@@ -0,0 +1,19 @@
1
+ @codelaw/rules-js / codelaw-rules-js
2
+
3
+ data/globals/*.json are derived from the `globals` package, version 17.13.0,
4
+ https://github.com/sindresorhus/globals — Copyright (c) Sindre Sorhus
5
+ <sindresorhus@gmail.com> (https://sindresorhus.com), released under the MIT
6
+ License.
7
+
8
+ data/node/deprecated-api.json was written for this pack: the Node.js APIs that
9
+ the Node.js documentation deprecates (https://nodejs.org/api/deprecations.html),
10
+ each with its documented replacement, in codelaw's own words. No text or code
11
+ is copied from Node.js.
12
+
13
+ data/react/dom-property-aliases.json was written for this pack: HTML attribute
14
+ names and the React DOM prop names that replace them (`class` -> `className`),
15
+ as React documents them. No React code is included.
16
+
17
+ The rules are reimplementations written for codelaw. Their `ported_from:`
18
+ fields name the ESLint rules (https://eslint.org, MIT License) whose documented
19
+ behaviour they reproduce; no ESLint code or documentation text is included.
package/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # @codelaw/rules-js · codelaw-rules-js
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ codelaw's rules for JavaScript, TypeScript, JSX and TSX — one of the five
4
+ first-party rule packs ([SR-RULE-PACKS](../../records/0101_rule-packs.md)). The
5
+ same files ship on npm as `@codelaw/rules-js` and on PyPI as
6
+ `codelaw-rules-js`.
7
+
8
+ ```toml
9
+ # codelaw.toml
10
+ extends = ["codelaw:js/recommended"]
11
+ preview = true # every rule is `preview` until a corpus run promotes it
12
+ ```
13
+
14
+ ## Presets
15
+
16
+ | preset | rules | ported from |
17
+ |---|---|---|
18
+ | `js/recommended` | 64 | ESLint `js.configs.recommended`, `@eslint/js` 10.0.1 — all 64 rules |
19
+ | `ts/recommended` | 24 | typescript-eslint `recommended` 8.71.2 (not type-checked) — all 20 rules — plus the four core rules its `eslint-recommended` switches on for TypeScript: `js/no-var`, `js/prefer-const`, `js/prefer-rest-params`, `js/prefer-spread` |
20
+ | `react/recommended` | 19 | eslint-plugin-react 7.37.5 `recommended` + `jsx-runtime` (17 of its 20 active rules), and eslint-plugin-react-hooks 7.1.1's `rules-of-hooks` and `exhaustive-deps` |
21
+ | `node/recommended` | 10 | eslint-plugin-n 18.5.0 `recommended-module` — 10 of its 14 rules: the 3 that need no `package.json`, `node/hashbang`, which reads the nearest `package.json`'s `bin`, and the 6 import rules, which run on the project graph |
22
+ | `stencil/recommended` | 15 | @stencil/eslint-plugin 1.4.0 `recommended` — 15 of its 21 rules |
23
+ | `js/conventions` | 7 | codelaw's starter catalogue: `js/exports-at-end`, `js/import-groups`, `js/no-default-export`, `ts/type-only-imports`, `react/hook-prefix`, `react/props-type-name`, `stencil/tag-prefix` — opt in |
24
+
25
+ Rules that typescript-eslint's `eslint-recommended` switches off for TypeScript
26
+ (`no-undef`, `no-redeclare`, `no-dupe-class-members` and the rest, which the
27
+ compiler checks) declare only `javascript` and `jsx` here. The four core rules
28
+ `ts/recommended` adds declare all four languages, so they also run on
29
+ JavaScript files when that preset is on.
30
+
31
+ Every rule is **reimplemented**, not vendored: the matchers, messages and docs
32
+ are written fresh, and each rule's `ported_from:` names the source rule.
33
+
34
+ ## How the ports differ
35
+
36
+ Every rule matches its source's documented behaviour on the source's own
37
+ examples. Where codelaw differs, the rule's `## Differences from the source`
38
+ section says so. The larger ones:
39
+
40
+ | rule | difference |
41
+ |---|---|
42
+ | `js/constructor-super`, `js/no-this-before-super` | follow the constructor's statements in straight-line order; a `super()` on any branch counts |
43
+ | `js/no-constant-condition` | literal conditions only; ESLint also folds `typeof x`, `!1` and similar |
44
+ | `js/no-extra-boolean-cast` | `!!x` in a condition; `Boolean(x)` in a condition is not checked yet |
45
+ | `js/no-invalid-regexp` | structural problems only (brackets, groups, quantifiers, flags) |
46
+ | `js/no-useless-assignment` | dead stores a straight-line reading proves; ESLint follows every code path |
47
+ | `js/no-useless-escape` | strings and templates; escapes inside regular expressions are not checked yet |
48
+ | `js/no-undef` | environments come from the `env` option (`shared-node-browser` by default), using the `globals` data tables |
49
+ | `ts/no-unused-expressions` | `x satisfies T;` is a compile-time type test and is allowed |
50
+ | `js/prefer-spread` | only `f.apply(null, args)` on a plain function name |
51
+ | `js/no-var` | `suggest`, not `auto`: `let` is block-scoped, so the swap can change meaning |
52
+ | `react/jsx-key` | elements returned from a `.map()` callback's block body are not checked yet |
53
+ | `react/no-unknown-property` | renames HTML spellings (`class`, `onclick`, `tabindex`); in `.js`/`.jsx` the JavaScript grammar can't parse `class=` and `for=` |
54
+ | `react/exhaustive-deps` | dependencies compared by root name; setters, dispatchers and refs are stable |
55
+ | `react/rules-of-hooks` | an early `return` anywhere before a hook counts as making it conditional |
56
+ | `node/no-deprecated-api` | the APIs come from the pack's `node/deprecated-api` table; the supported Node.js version is not read |
57
+ | `node/no-missing-import`, `node/no-missing-require` | `scope: project` rules on the project graph, which never reads `node_modules`: only the project's own paths are judged (relative, absolute, tsconfig `paths`), and only extensionless or JavaScript/TypeScript ones; a package name is not looked up |
58
+ | `node/no-extraneous-import`, `node/no-extraneous-require` | the nearest `package.json` only; a type-only import is satisfied by its `@types/` package |
59
+ | `node/no-unpublished-import`, `node/no-unpublished-require` | only in a package that is not `private` and lists `files`; `.npmignore` and the `convertPath` option are not read, so source files that build into `files` are not judged |
60
+ | `node/hashbang` | JavaScript and JSX only (no `convertPath` for TypeScript sources); `suggest`, since removing a hashbang can stop a script that is run directly |
61
+ | `stencil/tag-prefix` | with no `prefix` option set, a tag only needs some prefix |
62
+ | `stencil/prop-readonly` | the starter id for upstream `props-must-be-readonly` |
63
+
64
+ ## Not ported, and why
65
+
66
+ | rule | why |
67
+ |---|---|
68
+ | `react/prop-types` | needs the component's declared prop types matched to its uses; TypeScript types do this job |
69
+ | `react/jsx-uses-vars` | marks JSX names as used for `no-unused-vars`; codelaw's semantic model already counts them |
70
+ | `react/react-in-jsx-scope`, `react/jsx-uses-react` | turned off by `jsx-runtime` |
71
+ | eslint-plugin-react-hooks' 14 React Compiler rules | need the React Compiler's analysis |
72
+ | `node/no-unsupported-features/es-builtins`, `/es-syntax`, `/node-builtins` | need the project's Node.js version from `package.json` and per-version feature tables |
73
+ | `node/process-exit-as-throw` | reports nothing; it only changes ESLint's code-path analysis |
74
+ | `stencil/async-methods`, `stencil/render-returns-host`, `stencil/single-export`, `stencil/strict-boolean-conditions` | need type information |
75
+ | `stencil/element-type` | needs the component's tag mapped to its element type name |
76
+ | `stencil/decorators-style` | layout: the formatter owns it |
77
+ | `stencil/dependency-suggestions` | advisory, with no fixed check to port |
78
+
79
+ Nothing from `js.configs.recommended` or typescript-eslint's non-type-checked
80
+ `recommended` is left out. Every `*-type-checked` typescript-eslint config is
81
+ out of scope: those rules need type information (L3).
82
+
83
+ ## Data
84
+
85
+ `data/node/deprecated-api.json` — Node.js APIs the Node.js documentation deprecates, with their replacements, written for this pack.
86
+
87
+ `data/react/dom-property-aliases.json` — HTML attribute names and the React prop names that replace them, written for this pack.
88
+
89
+
90
+ `data/globals/*.json` — the globals of each environment `js/no-undef`'s `env`
91
+ option names, from the `globals` package 17.13.0 (MIT). See `NOTICE`.
@@ -0,0 +1,6 @@
1
+ name = "@codelaw/rules-js"
2
+ version = "0.1.0"
3
+ min_codelaw = "0.1.0"
4
+ languages = ["javascript", "jsx", "typescript", "tsx"]
5
+ presets = ["js/recommended", "ts/recommended", "react/recommended", "node/recommended", "stencil/recommended", "js/conventions"]
6
+ description = "codelaw's rules for JavaScript, TypeScript, JSX and TSX (SR-RULE-PACKS)"