@codelaw/rules-js 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/NOTICE +10 -0
- package/README.md +57 -2
- package/codelaw-pack.toml +6 -0
- package/corpus.toml +76 -0
- package/data/globals/browser.json +1209 -0
- package/data/globals/commonjs.json +6 -0
- package/data/globals/jest.json +15 -0
- package/data/globals/mocha.json +22 -0
- package/data/globals/node.json +83 -0
- package/data/globals/serviceworker.json +328 -0
- package/data/globals/shared-node-browser.json +73 -0
- package/data/globals/vitest.json +19 -0
- package/data/globals/worker.json +349 -0
- package/package.json +14 -4
- package/presets/js/conventions.toml +6 -0
- package/presets/js/project.toml +4 -0
- package/presets/js/recommended.toml +67 -0
- package/presets/js/typescript.toml +7 -0
- package/rules/graph/no-unused-exports.md +135 -0
- package/rules/js/constructor-super.md +77 -0
- package/rules/js/exports-at-end.md +134 -0
- package/rules/js/for-direction.md +106 -0
- package/rules/js/getter-return.md +74 -0
- package/rules/js/import-groups.md +117 -0
- package/rules/js/no-async-promise-executor.md +95 -0
- package/rules/js/no-case-declarations.md +134 -0
- package/rules/js/no-class-assign.md +61 -0
- package/rules/js/no-compare-neg-zero.md +105 -0
- package/rules/js/no-cond-assign.md +135 -0
- package/rules/js/no-const-assign.md +61 -0
- package/rules/js/no-constant-binary-expression.md +83 -0
- package/rules/js/no-constant-condition.md +150 -0
- package/rules/js/no-control-regex.md +84 -0
- package/rules/js/no-debugger.md +99 -0
- package/rules/js/no-default-export.md +88 -0
- package/rules/js/no-delete-var.md +93 -0
- package/rules/js/no-dupe-args.md +61 -0
- package/rules/js/no-dupe-class-members.md +82 -0
- package/rules/js/no-dupe-else-if.md +113 -0
- package/rules/js/no-dupe-keys.md +66 -0
- package/rules/js/no-duplicate-case.md +137 -0
- package/rules/js/no-empty-character-class.md +98 -0
- package/rules/js/no-empty-pattern.md +86 -0
- package/rules/js/no-empty-static-block.md +99 -0
- package/rules/js/no-empty.md +116 -0
- package/rules/js/no-ex-assign.md +121 -0
- package/rules/js/no-extra-boolean-cast.md +107 -0
- package/rules/js/no-fallthrough.md +178 -0
- package/rules/js/no-func-assign.md +62 -0
- package/rules/js/no-global-assign.md +85 -0
- package/rules/js/no-import-assign.md +60 -0
- package/rules/js/no-invalid-regexp.md +86 -0
- package/rules/js/no-irregular-whitespace.md +87 -0
- package/rules/js/no-loss-of-precision.md +82 -0
- package/rules/js/no-misleading-character-class.md +83 -0
- package/rules/js/no-new-native-nonconstructor.md +55 -0
- package/rules/js/no-nonoctal-decimal-escape.md +84 -0
- package/rules/js/no-obj-calls.md +61 -0
- package/rules/js/no-octal.md +84 -0
- package/rules/js/no-prototype-builtins.md +99 -0
- package/rules/js/no-redeclare.md +61 -0
- package/rules/js/no-regex-spaces.md +75 -0
- package/rules/js/no-self-assign.md +91 -0
- package/rules/js/no-setter-return.md +69 -0
- package/rules/js/no-shadow-restricted-names.md +102 -0
- package/rules/js/no-sparse-arrays.md +82 -0
- package/rules/js/no-this-before-super.md +74 -0
- package/rules/js/no-unassigned-vars.md +102 -0
- package/rules/js/no-undef.md +76 -0
- package/rules/js/no-unexpected-multiline.md +91 -0
- package/rules/js/no-unreachable.md +59 -0
- package/rules/js/no-unsafe-finally.md +145 -0
- package/rules/js/no-unsafe-negation.md +71 -0
- package/rules/js/no-unsafe-optional-chaining.md +83 -0
- package/rules/js/no-unused-labels.md +102 -0
- package/rules/js/no-unused-private-class-members.md +126 -0
- package/rules/js/no-unused-vars.md +69 -0
- package/rules/js/no-useless-assignment.md +115 -0
- package/rules/js/no-useless-backreference.md +83 -0
- package/rules/js/no-useless-catch.md +105 -0
- package/rules/js/no-useless-escape.md +81 -0
- package/rules/js/no-var.md +76 -0
- package/rules/js/no-with.md +60 -0
- package/rules/js/prefer-const.md +83 -0
- package/rules/js/prefer-rest-params.md +103 -0
- package/rules/js/prefer-spread.md +95 -0
- package/rules/js/preserve-caught-error.md +122 -0
- package/rules/js/require-yield.md +107 -0
- package/rules/js/use-isnan.md +105 -0
- package/rules/js/valid-typeof.md +111 -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,10 @@
|
|
|
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
|
+
The rules are reimplementations written for codelaw. Their `ported_from:`
|
|
9
|
+
fields name the ESLint rules (https://eslint.org, MIT License) whose documented
|
|
10
|
+
behaviour they reproduce; no ESLint code or documentation text is included.
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @codelaw/rules-js · codelaw-rules-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
codelaw's core JavaScript rules, which also run on TypeScript, JSX and TSX — one of codelaw's first-party rule packs
|
|
4
|
+
([SR-RULE-PACKS](../../records/0101_rule-packs.md)). The
|
|
5
|
+
same files ship on npm as `@codelaw/rules-js` and on PyPI as `codelaw-rules-js`.
|
|
6
|
+
|
|
7
|
+
```toml
|
|
8
|
+
# codelaw.toml
|
|
9
|
+
extends = ["codelaw:js/recommended"]
|
|
10
|
+
preview = true # every rule is `preview` until a corpus run promotes it
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Presets
|
|
14
|
+
|
|
15
|
+
<!-- docs-sync:presets -->
|
|
16
|
+
|
|
17
|
+
| preset | rules | ported from |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `js/recommended` | 64 | ESLint `js.configs.recommended`, `@eslint/js` 10.0.1 — all 64 rules |
|
|
20
|
+
| `js/typescript` | 4 | the four core rules typescript-eslint 8.71.2's `eslint-recommended` switches on for TypeScript: `js/no-var`, `js/prefer-const`, `js/prefer-rest-params`, `js/prefer-spread`; use it with `codelaw:ts/recommended` |
|
|
21
|
+
| `js/conventions` | 3 | codelaw's starter catalogue: `js/exports-at-end`, `js/import-groups`, `js/no-default-export` — opt in |
|
|
22
|
+
| `js/project` | 1 | `graph/no-unused-exports`, the rule that reads the whole repo, from knip's `exports` and `types` — opt in |
|
|
23
|
+
|
|
24
|
+
<!-- /docs-sync:presets -->
|
|
25
|
+
|
|
26
|
+
Rules that typescript-eslint's `eslint-recommended` switches off for TypeScript
|
|
27
|
+
(`no-undef`, `no-redeclare`, `no-dupe-class-members` and the rest, which the
|
|
28
|
+
compiler checks) declare only `javascript` and `jsx` here. The four rules in
|
|
29
|
+
`js/typescript` declare all four languages, so they also run on JavaScript
|
|
30
|
+
files when that preset is on.
|
|
31
|
+
|
|
32
|
+
Every rule is **reimplemented**, not vendored: the matchers, messages and docs
|
|
33
|
+
are written fresh, and each rule's `ported_from:` names the source rule.
|
|
34
|
+
|
|
35
|
+
## How the ports differ
|
|
36
|
+
|
|
37
|
+
Every rule matches its source's documented behaviour on the source's own
|
|
38
|
+
examples. Where codelaw differs, the rule's `## Differences from the source`
|
|
39
|
+
section says so. The larger ones:
|
|
40
|
+
|
|
41
|
+
| rule | difference |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `js/constructor-super`, `js/no-this-before-super` | follow the constructor's statements in straight-line order; a `super()` on any branch counts |
|
|
44
|
+
| `js/no-constant-condition` | literal conditions only; ESLint also folds `typeof x`, `!1` and similar |
|
|
45
|
+
| `js/no-extra-boolean-cast` | `!!x` in a condition; `Boolean(x)` in a condition is not checked yet |
|
|
46
|
+
| `js/no-invalid-regexp` | structural problems only (brackets, groups, quantifiers, flags) |
|
|
47
|
+
| `js/no-useless-assignment` | dead stores a straight-line reading proves; ESLint follows every code path |
|
|
48
|
+
| `js/no-useless-escape` | strings and templates; escapes inside regular expressions are not checked yet |
|
|
49
|
+
| `js/no-undef` | environments come from the `env` option (`shared-node-browser` by default), using the `globals` data tables |
|
|
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
|
+
|
|
53
|
+
Nothing from `js.configs.recommended` is left out.
|
|
54
|
+
|
|
55
|
+
## Data
|
|
56
|
+
|
|
57
|
+
`data/globals/*.json` — the globals of each environment `js/no-undef`'s `env`
|
|
58
|
+
option names, from the `globals` package 17.13.0 (MIT). See `NOTICE`.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
name = "@codelaw/rules-js"
|
|
2
|
+
version = "0.2.0"
|
|
3
|
+
min_codelaw = "0.1.0"
|
|
4
|
+
languages = ["javascript", "jsx", "typescript", "tsx"]
|
|
5
|
+
presets = ["js/recommended", "js/typescript", "js/conventions", "js/project"]
|
|
6
|
+
description = "codelaw's rules for JavaScript, and the core JavaScript rules on TypeScript, JSX and TSX (SR-RULE-PACKS)"
|
package/corpus.toml
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# `codelaw test --corpus` finding counts (SR-RULE-AUTHORING decision 4).
|
|
2
|
+
# Rewrite with --update-snapshot, and review the change.
|
|
3
|
+
|
|
4
|
+
[findings]
|
|
5
|
+
"graph/no-unused-exports" = 118
|
|
6
|
+
"js/constructor-super" = 0
|
|
7
|
+
"js/exports-at-end" = 436
|
|
8
|
+
"js/for-direction" = 0
|
|
9
|
+
"js/getter-return" = 0
|
|
10
|
+
"js/import-groups" = 76
|
|
11
|
+
"js/no-async-promise-executor" = 0
|
|
12
|
+
"js/no-case-declarations" = 0
|
|
13
|
+
"js/no-class-assign" = 0
|
|
14
|
+
"js/no-compare-neg-zero" = 0
|
|
15
|
+
"js/no-cond-assign" = 0
|
|
16
|
+
"js/no-const-assign" = 0
|
|
17
|
+
"js/no-constant-binary-expression" = 0
|
|
18
|
+
"js/no-constant-condition" = 0
|
|
19
|
+
"js/no-control-regex" = 0
|
|
20
|
+
"js/no-debugger" = 0
|
|
21
|
+
"js/no-default-export" = 61
|
|
22
|
+
"js/no-delete-var" = 0
|
|
23
|
+
"js/no-dupe-args" = 0
|
|
24
|
+
"js/no-dupe-class-members" = 0
|
|
25
|
+
"js/no-dupe-else-if" = 0
|
|
26
|
+
"js/no-dupe-keys" = 0
|
|
27
|
+
"js/no-duplicate-case" = 0
|
|
28
|
+
"js/no-empty" = 0
|
|
29
|
+
"js/no-empty-character-class" = 0
|
|
30
|
+
"js/no-empty-pattern" = 0
|
|
31
|
+
"js/no-empty-static-block" = 0
|
|
32
|
+
"js/no-ex-assign" = 0
|
|
33
|
+
"js/no-extra-boolean-cast" = 0
|
|
34
|
+
"js/no-fallthrough" = 0
|
|
35
|
+
"js/no-func-assign" = 0
|
|
36
|
+
"js/no-global-assign" = 0
|
|
37
|
+
"js/no-import-assign" = 0
|
|
38
|
+
"js/no-invalid-regexp" = 0
|
|
39
|
+
"js/no-irregular-whitespace" = 0
|
|
40
|
+
"js/no-loss-of-precision" = 0
|
|
41
|
+
"js/no-misleading-character-class" = 0
|
|
42
|
+
"js/no-new-native-nonconstructor" = 0
|
|
43
|
+
"js/no-nonoctal-decimal-escape" = 0
|
|
44
|
+
"js/no-obj-calls" = 0
|
|
45
|
+
"js/no-octal" = 0
|
|
46
|
+
"js/no-prototype-builtins" = 0
|
|
47
|
+
"js/no-redeclare" = 0
|
|
48
|
+
"js/no-regex-spaces" = 0
|
|
49
|
+
"js/no-self-assign" = 0
|
|
50
|
+
"js/no-setter-return" = 0
|
|
51
|
+
"js/no-shadow-restricted-names" = 0
|
|
52
|
+
"js/no-sparse-arrays" = 0
|
|
53
|
+
"js/no-this-before-super" = 0
|
|
54
|
+
"js/no-unassigned-vars" = 0
|
|
55
|
+
"js/no-undef" = 61
|
|
56
|
+
"js/no-unexpected-multiline" = 0
|
|
57
|
+
"js/no-unreachable" = 0
|
|
58
|
+
"js/no-unsafe-finally" = 0
|
|
59
|
+
"js/no-unsafe-negation" = 0
|
|
60
|
+
"js/no-unsafe-optional-chaining" = 0
|
|
61
|
+
"js/no-unused-labels" = 0
|
|
62
|
+
"js/no-unused-private-class-members" = 0
|
|
63
|
+
"js/no-unused-vars" = 2
|
|
64
|
+
"js/no-useless-assignment" = 14
|
|
65
|
+
"js/no-useless-backreference" = 0
|
|
66
|
+
"js/no-useless-catch" = 0
|
|
67
|
+
"js/no-useless-escape" = 0
|
|
68
|
+
"js/no-var" = 0
|
|
69
|
+
"js/no-with" = 0
|
|
70
|
+
"js/prefer-const" = 0
|
|
71
|
+
"js/prefer-rest-params" = 0
|
|
72
|
+
"js/prefer-spread" = 0
|
|
73
|
+
"js/preserve-caught-error" = 0
|
|
74
|
+
"js/require-yield" = 0
|
|
75
|
+
"js/use-isnan" = 0
|
|
76
|
+
"js/valid-typeof" = 0
|