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/src/types.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Minimal ESTree-compatible types for oxlint JS plugin API
|
|
2
|
+
|
|
3
|
+
export interface Node {
|
|
4
|
+
type: string;
|
|
5
|
+
loc?: { start: { line: number; column: number }; end: { line: number; column: number } };
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Context {
|
|
10
|
+
report(descriptor: { message: string; node: Node }): void;
|
|
11
|
+
sourceCode: { text: string };
|
|
12
|
+
filename?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Rule {
|
|
16
|
+
create(context: Context): Record<string, (node: Node) => void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// --- Helpers ---
|
|
20
|
+
|
|
21
|
+
export function isLiteral(node: Node | null | undefined, value?: unknown): boolean {
|
|
22
|
+
if (!node || node.type !== "Literal") return false;
|
|
23
|
+
return value === undefined ? true : node.value === value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isBoolLiteral(node: Node | null | undefined): node is Node {
|
|
27
|
+
return isLiteral(node) && typeof node!.value === "boolean";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isIdentifier(node: Node | null | undefined, name?: string): boolean {
|
|
31
|
+
if (!node || node.type !== "Identifier") return false;
|
|
32
|
+
return name === undefined ? true : node.name === name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isCallOf(node: Node, object: string, method: string): boolean {
|
|
36
|
+
if (node.type !== "CallExpression") return false;
|
|
37
|
+
const callee = node.callee;
|
|
38
|
+
if (callee.type !== "MemberExpression") return false;
|
|
39
|
+
return isIdentifier(callee.object, object) && isIdentifier(callee.property, method);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isMethodCall(node: Node, method: string): boolean {
|
|
43
|
+
if (node.type !== "CallExpression") return false;
|
|
44
|
+
const callee = node.callee;
|
|
45
|
+
return (
|
|
46
|
+
callee.type === "MemberExpression" && !callee.computed && isIdentifier(callee.property, method)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Unwrap a BlockStatement to its single statement, or return the statement itself */
|
|
51
|
+
export function unwrapBlock(node: Node | null | undefined): Node | null {
|
|
52
|
+
if (!node) return null;
|
|
53
|
+
if (node.type === "BlockStatement") {
|
|
54
|
+
return node.body.length === 1 ? node.body[0] : null;
|
|
55
|
+
}
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Get the body statements of a function node */
|
|
60
|
+
export function getFunctionBody(node: Node): Node[] | null {
|
|
61
|
+
const body = node.body;
|
|
62
|
+
if (!body) return null;
|
|
63
|
+
if (body.type === "BlockStatement") return body.body;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Get the declared variable name from a ForOfStatement */
|
|
68
|
+
export function getForOfVar(node: Node): string | null {
|
|
69
|
+
const left = node.left;
|
|
70
|
+
if (left.type === "VariableDeclaration" && left.declarations.length === 1) {
|
|
71
|
+
const decl = left.declarations[0];
|
|
72
|
+
if (decl.id && decl.id.type === "Identifier") return decl.id.name;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|