oxclippy 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.
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/oxclippy.js +2428 -0
- package/package.json +53 -0
- package/src/index.ts +1 -0
- package/src/plugin.ts +134 -0
- package/src/rules/almost-swapped.ts +52 -0
- package/src/rules/bool-comparison.ts +38 -0
- package/src/rules/bool-to-int-with-if.ts +30 -0
- package/src/rules/cognitive-complexity.ts +137 -0
- package/src/rules/collapsible-if.ts +38 -0
- package/src/rules/enum-variant-names.ts +45 -0
- package/src/rules/excessive-nesting.ts +84 -0
- package/src/rules/explicit-counter-loop.ts +66 -0
- package/src/rules/filter-then-first.ts +26 -0
- package/src/rules/float-comparison.ts +52 -0
- package/src/rules/float-equality-without-abs.ts +43 -0
- package/src/rules/fn-params-excessive-bools.ts +49 -0
- package/src/rules/identity-op.ts +46 -0
- package/src/rules/if-same-then-else.ts +34 -0
- package/src/rules/int-plus-one.ts +74 -0
- package/src/rules/let-and-return.ts +43 -0
- package/src/rules/manual-clamp.ts +63 -0
- package/src/rules/manual-every.ts +47 -0
- package/src/rules/manual-find.ts +59 -0
- package/src/rules/manual-includes.ts +65 -0
- package/src/rules/manual-is-finite.ts +57 -0
- package/src/rules/manual-some.ts +46 -0
- package/src/rules/manual-strip.ts +96 -0
- package/src/rules/manual-swap.ts +73 -0
- package/src/rules/map-identity.ts +67 -0
- package/src/rules/map-void-return.ts +23 -0
- package/src/rules/match-same-arms.ts +46 -0
- package/src/rules/needless-bool.ts +67 -0
- package/src/rules/needless-continue.ts +47 -0
- package/src/rules/needless-late-init.ts +44 -0
- package/src/rules/needless-range-loop.ts +127 -0
- package/src/rules/neg-multiply.ts +36 -0
- package/src/rules/never-loop.ts +49 -0
- package/src/rules/object-keys-values.ts +67 -0
- package/src/rules/prefer-structured-clone.ts +30 -0
- package/src/rules/promise-new-resolve.ts +59 -0
- package/src/rules/redundant-closure-call.ts +61 -0
- package/src/rules/redundant-closure.ts +81 -0
- package/src/rules/search-is-some.ts +45 -0
- package/src/rules/similar-names.ts +155 -0
- package/src/rules/single-case-switch.ts +27 -0
- package/src/rules/single-element-loop.ts +21 -0
- package/src/rules/struct-field-names.ts +108 -0
- package/src/rules/too-many-arguments.ts +37 -0
- package/src/rules/too-many-lines.ts +45 -0
- package/src/rules/unnecessary-fold.ts +65 -0
- package/src/rules/unnecessary-reduce-collect.ts +109 -0
- package/src/rules/unreadable-literal.ts +59 -0
- package/src/rules/used-underscore-binding.ts +41 -0
- package/src/rules/useless-conversion.ts +115 -0
- package/src/rules/xor-used-as-pow.ts +34 -0
- package/src/rules/zero-divided-by-zero.ts +24 -0
- package/src/types.ts +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rayhan Noufal Arayilakath
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# oxclippy
|
|
2
|
+
|
|
3
|
+
An [oxlint JS plugin](https://oxc.rs/docs/guide/usage/linter/writing-js-plugins.html) that mirrors [Rust Clippy](https://doc.rust-lang.org/clippy/) rules for TypeScript/JavaScript.
|
|
4
|
+
|
|
5
|
+
Every rule is named after its Clippy counterpart and intentionally avoids duplicating anything already built into oxlint's eslint, typescript, unicorn, or oxc plugins.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun install
|
|
11
|
+
bun run build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then configure `.oxlintrc.json` (already included) and run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
oxlint
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Rules (52)
|
|
21
|
+
|
|
22
|
+
### Style
|
|
23
|
+
|
|
24
|
+
| Rule | Clippy | What it catches |
|
|
25
|
+
| -------------------- | -------------------- | ------------------------------------------------------------------ |
|
|
26
|
+
| `needless-bool` | `needless_bool` | `if (c) return true; else return false;` -- simplify to `return c` |
|
|
27
|
+
| `collapsible-if` | `collapsible_if` | `if (a) { if (b) { } }` -- merge to `if (a && b)` |
|
|
28
|
+
| `neg-multiply` | `neg_multiply` | `x * -1` -- use `-x` |
|
|
29
|
+
| `bool-comparison` | `bool_comparison` | `x === true` -- use `x` directly |
|
|
30
|
+
| `single-case-switch` | `single_match` | `switch` with one case -- use `if` |
|
|
31
|
+
| `let-and-return` | `let_and_return` | `const x = f(); return x;` -- return directly |
|
|
32
|
+
| `int-plus-one` | `int_plus_one` | `x >= y + 1` -- simplify to `x > y` |
|
|
33
|
+
| `needless-late-init` | `needless_late_init` | `let x; x = 5;` -- use `const x = 5;` |
|
|
34
|
+
|
|
35
|
+
### Complexity
|
|
36
|
+
|
|
37
|
+
| Rule | Clippy | What it catches |
|
|
38
|
+
| -------------------- | -------------------- | -------------------------------------------------------------- |
|
|
39
|
+
| `identity-op` | `identity_op` | `x + 0`, `x * 1` -- no-op arithmetic |
|
|
40
|
+
| `manual-clamp` | `manual_clamp` | `Math.min(max, Math.max(val, min))` -- extract `clamp` |
|
|
41
|
+
| `manual-strip` | `manual_strip` | `if (s.startsWith(p)) s.slice(p.length)` -- extract helper |
|
|
42
|
+
| `useless-conversion` | `useless_conversion` | `String("str")`, `Number(42)` on matching types |
|
|
43
|
+
| `manual-swap` | `manual_swap` | `tmp = a; a = b; b = tmp;` -- use `[a, b] = [b, a]` |
|
|
44
|
+
| `manual-is-finite` | `manual_is_finite` | `x !== Infinity && x !== -Infinity` -- use `Number.isFinite()` |
|
|
45
|
+
|
|
46
|
+
### Correctness
|
|
47
|
+
|
|
48
|
+
| Rule | Clippy | What it catches |
|
|
49
|
+
| ---------------------------- | ---------------------------- | ------------------------------------------------- |
|
|
50
|
+
| `float-comparison` | `float_cmp` | `x === 0.1 + 0.2` -- use epsilon comparison |
|
|
51
|
+
| `xor-used-as-pow` | `suspicious_xor_used_as_pow` | `2 ^ 8` is XOR (10), not power (256) |
|
|
52
|
+
| `almost-swapped` | `almost_swapped` | `a = b; b = a;` -- broken swap, original `a` lost |
|
|
53
|
+
| `if-same-then-else` | `if_same_then_else` | Identical if/else bodies -- dead code or bug |
|
|
54
|
+
| `never-loop` | `never_loop` | Loop always exits on first iteration |
|
|
55
|
+
| `float-equality-without-abs` | `float_equality_without_abs` | `(a - b) < eps` missing `Math.abs()` |
|
|
56
|
+
| `zero-divided-by-zero` | `zero_divided_by_zero` | `0 / 0` is `NaN` -- use `NaN` directly |
|
|
57
|
+
|
|
58
|
+
### Iterator
|
|
59
|
+
|
|
60
|
+
| Rule | Clippy | What it catches |
|
|
61
|
+
| ------------------------ | ------------------------ | -------------------------------------------------------- |
|
|
62
|
+
| `filter-then-first` | `filter_next` | `.filter(fn)[0]` -- use `.find(fn)` |
|
|
63
|
+
| `map-void-return` | `map_unit_fn` | `.map()` result unused -- use `.forEach()` |
|
|
64
|
+
| `map-identity` | `map_identity` | `.map(x => x)` -- remove or use `.slice()` |
|
|
65
|
+
| `manual-find` | `manual_find` | `for..of` + `if` + `return` -- use `.find()` |
|
|
66
|
+
| `manual-some` | `manual_find` | `for..of` returning `true`/`false` -- use `.some()` |
|
|
67
|
+
| `manual-every` | `manual_find` | `for..of` returning `false`/`true` -- use `.every()` |
|
|
68
|
+
| `manual-includes` | `manual_find` | `for..of` with equality check -- use `.includes()` |
|
|
69
|
+
| `search-is-some` | `search_is_some` | `.find(fn) !== undefined` -- use `.some(fn)` |
|
|
70
|
+
| `needless-range-loop` | `needless_range_loop` | `for (let i = 0; i < arr.length; i++)` -- use `for..of` |
|
|
71
|
+
| `redundant-closure-call` | `redundant_closure_call` | `(() => expr)()` -- use `expr` directly |
|
|
72
|
+
| `explicit-counter-loop` | `explicit_counter_loop` | Manual counter with `for..of` -- use `.entries()` |
|
|
73
|
+
| `unnecessary-fold` | `unnecessary_fold` | `.reduce()` with `\|\|`/`&&` -- use `.some()`/`.every()` |
|
|
74
|
+
| `single-element-loop` | `single_element_loop` | `for (x of [val])` -- use `val` directly |
|
|
75
|
+
|
|
76
|
+
### Functions
|
|
77
|
+
|
|
78
|
+
| Rule | Clippy | What it catches |
|
|
79
|
+
| --------------------------- | --------------------------- | --------------------------------------------- |
|
|
80
|
+
| `too-many-arguments` | `too_many_arguments` | Functions with > 5 parameters |
|
|
81
|
+
| `too-many-lines` | `too_many_lines` | Functions with > 100 lines |
|
|
82
|
+
| `cognitive-complexity` | `cognitive_complexity` | Functions exceeding complexity threshold (25) |
|
|
83
|
+
| `excessive-nesting` | `excessive_nesting` | Code nested > 5 levels deep |
|
|
84
|
+
| `fn-params-excessive-bools` | `fn_params_excessive_bools` | Functions with > 3 boolean params |
|
|
85
|
+
|
|
86
|
+
### Principles
|
|
87
|
+
|
|
88
|
+
| Rule | Clippy | What it catches |
|
|
89
|
+
| ---------------------------- | ------------------- | ---------------------------------------------------------------- |
|
|
90
|
+
| `redundant-closure` | `redundant_closure` | `.map(x => f(x))` -- simplify to `.map(f)` |
|
|
91
|
+
| `unnecessary-reduce-collect` | `unnecessary_fold` | `.reduce()` building array/object -- use `.map()`/`.filter()` |
|
|
92
|
+
| `prefer-structured-clone` | `manual_memcpy` | `JSON.parse(JSON.stringify(x))` -- use `structuredClone()` |
|
|
93
|
+
| `object-keys-values` | `iter_kv_map` | `Object.keys(o).map(k => o[k])` -- use `Object.values()` |
|
|
94
|
+
| `promise-new-resolve` | `unnecessary_wraps` | `new Promise(resolve => resolve(x))` -- use `Promise.resolve(x)` |
|
|
95
|
+
|
|
96
|
+
### Pedantic
|
|
97
|
+
|
|
98
|
+
| Rule | Clippy | What it catches |
|
|
99
|
+
| ------------------------- | ------------------------- | -------------------------------------------------------- |
|
|
100
|
+
| `similar-names` | `similar_names` | Variables with names that differ by one character |
|
|
101
|
+
| `match-same-arms` | `match_same_arms` | Switch cases with identical bodies -- merge them |
|
|
102
|
+
| `used-underscore-binding` | `used_underscore_binding` | `_foo` variables that are actually used |
|
|
103
|
+
| `needless-continue` | `needless_continue` | `continue` as last statement in loop body |
|
|
104
|
+
| `enum-variant-names` | `enum_variant_names` | Enum members that all share a common prefix/suffix |
|
|
105
|
+
| `struct-field-names` | `struct_field_names` | Object type fields that all share a common prefix/suffix |
|
|
106
|
+
| `unreadable-literal` | `unreadable_literal` | Large numbers without underscores -- use `1_000_000` |
|
|
107
|
+
| `bool-to-int-with-if` | `bool_to_int_with_if` | `if (b) 1 else 0` -- use `Number(b)` or `+b` |
|
|
108
|
+
|
|
109
|
+
## Intentionally omitted (already in oxlint)
|
|
110
|
+
|
|
111
|
+
These Clippy rules already have equivalents in oxlint's built-in plugins:
|
|
112
|
+
|
|
113
|
+
- `approx_constant` -- `oxc/approx-constant`
|
|
114
|
+
- `erasing_op` -- `oxc/erasing-op`
|
|
115
|
+
- `eq_op` -- `eslint/no-self-compare`
|
|
116
|
+
- `self_assignment` -- `eslint/no-self-assign`
|
|
117
|
+
- `double_comparisons` -- `oxc/double-comparisons`
|
|
118
|
+
- `impossible_comparisons` -- `oxc/const-comparisons`
|
|
119
|
+
- `misrefactored_assign_op` -- `oxc/misrefactored-assign-op`
|
|
120
|
+
- `only_used_in_recursion` -- `oxc/only-used-in-recursion`
|
|
121
|
+
- `min_max` -- `oxc/bad-min-max-func`
|
|
122
|
+
- `needless_return` -- `eslint/no-useless-return`
|
|
123
|
+
- `redundant_else` -- `eslint/no-else-return`
|
|
124
|
+
- `if_not_else` -- `eslint/no-negated-condition`
|
|
125
|
+
- `ifs_same_cond` -- `eslint/no-dupe-else-if`
|
|
126
|
+
- `needless_bitwise_bool` -- `oxc/bad-bitwise-operator`
|
|
127
|
+
- `map_flatten` -- `unicorn/prefer-array-flat-map`
|
|
128
|
+
- `flat_map_identity` -- `unicorn/prefer-array-flat`
|
|
129
|
+
- `assign_op_pattern` -- `eslint/operator-assignment`
|
|
130
|
+
- `redundant_field_names` -- `eslint/object-shorthand`
|
|
131
|
+
- `get_last_with_len` -- `unicorn/prefer-at`
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
bun test # run unit tests (215 tests)
|
|
137
|
+
bun test --coverage # run with coverage
|
|
138
|
+
bun run build # bundle plugin
|
|
139
|
+
oxlint test/fixture.js # test against sample file
|
|
140
|
+
```
|