eslint-plugin-absolute 0.9.0 → 0.10.1
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/dist/index.js +84 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3681,6 +3681,89 @@ var noRedundantTypeAnnotation = {
|
|
|
3681
3681
|
}
|
|
3682
3682
|
};
|
|
3683
3683
|
|
|
3684
|
+
// src/rules/no-trivial-alias.ts
|
|
3685
|
+
var isBareTypeReference = (node) => {
|
|
3686
|
+
if (node.type === "TSTypeReference") {
|
|
3687
|
+
return !node.typeArguments || node.typeArguments.params.length === 0;
|
|
3688
|
+
}
|
|
3689
|
+
switch (node.type) {
|
|
3690
|
+
case "TSStringKeyword":
|
|
3691
|
+
case "TSNumberKeyword":
|
|
3692
|
+
case "TSBooleanKeyword":
|
|
3693
|
+
case "TSNullKeyword":
|
|
3694
|
+
case "TSUndefinedKeyword":
|
|
3695
|
+
case "TSVoidKeyword":
|
|
3696
|
+
case "TSAnyKeyword":
|
|
3697
|
+
case "TSUnknownKeyword":
|
|
3698
|
+
case "TSNeverKeyword":
|
|
3699
|
+
case "TSBigIntKeyword":
|
|
3700
|
+
case "TSSymbolKeyword":
|
|
3701
|
+
case "TSObjectKeyword":
|
|
3702
|
+
return true;
|
|
3703
|
+
default:
|
|
3704
|
+
return false;
|
|
3705
|
+
}
|
|
3706
|
+
};
|
|
3707
|
+
var isBareIdentifierInit = (init) => init.type === "Identifier";
|
|
3708
|
+
var isConstSource = (context, id) => {
|
|
3709
|
+
const scope = context.sourceCode.getScope(id);
|
|
3710
|
+
const variable = scope.references.find((ref) => ref.identifier === id)?.resolved;
|
|
3711
|
+
if (!variable || variable.defs.length === 0)
|
|
3712
|
+
return false;
|
|
3713
|
+
return variable.defs.every((def) => {
|
|
3714
|
+
if (def.type !== "Variable")
|
|
3715
|
+
return false;
|
|
3716
|
+
const parent = def.parent;
|
|
3717
|
+
if (!parent || parent.type !== "VariableDeclaration")
|
|
3718
|
+
return false;
|
|
3719
|
+
return parent.kind === "const";
|
|
3720
|
+
});
|
|
3721
|
+
};
|
|
3722
|
+
var noTrivialAlias = {
|
|
3723
|
+
create(context) {
|
|
3724
|
+
return {
|
|
3725
|
+
TSTypeAliasDeclaration(node) {
|
|
3726
|
+
if (!isBareTypeReference(node.typeAnnotation))
|
|
3727
|
+
return;
|
|
3728
|
+
context.report({
|
|
3729
|
+
data: { name: node.id.name },
|
|
3730
|
+
messageId: "trivialTypeAlias",
|
|
3731
|
+
node
|
|
3732
|
+
});
|
|
3733
|
+
},
|
|
3734
|
+
VariableDeclarator(node) {
|
|
3735
|
+
if (node.id.type !== "Identifier")
|
|
3736
|
+
return;
|
|
3737
|
+
if (node.id.typeAnnotation)
|
|
3738
|
+
return;
|
|
3739
|
+
if (!node.init)
|
|
3740
|
+
return;
|
|
3741
|
+
if (!isBareIdentifierInit(node.init))
|
|
3742
|
+
return;
|
|
3743
|
+
if (!isConstSource(context, node.init))
|
|
3744
|
+
return;
|
|
3745
|
+
context.report({
|
|
3746
|
+
data: { name: node.id.name },
|
|
3747
|
+
messageId: "trivialConstAlias",
|
|
3748
|
+
node
|
|
3749
|
+
});
|
|
3750
|
+
}
|
|
3751
|
+
};
|
|
3752
|
+
},
|
|
3753
|
+
defaultOptions: [],
|
|
3754
|
+
meta: {
|
|
3755
|
+
docs: {
|
|
3756
|
+
description: "Disallow identity aliases that rename a type or value without transforming it \u2014 `type X = Y` and `const x = y`. Pick one name and use it everywhere."
|
|
3757
|
+
},
|
|
3758
|
+
messages: {
|
|
3759
|
+
trivialConstAlias: "`{{name}}` is a trivial rename of another binding. Use the original at the consumer instead \u2014 duplicate aliases drift when one side is updated and the other isn't.",
|
|
3760
|
+
trivialTypeAlias: "`{{name}}` is a pure rename of another type. Use the original type at the consumer instead \u2014 duplicate aliases drift when one side is updated and the other isn't."
|
|
3761
|
+
},
|
|
3762
|
+
schema: [],
|
|
3763
|
+
type: "suggestion"
|
|
3764
|
+
}
|
|
3765
|
+
};
|
|
3766
|
+
|
|
3684
3767
|
// src/rules/no-unnecessary-div.ts
|
|
3685
3768
|
import { AST_NODE_TYPES as AST_NODE_TYPES5 } from "@typescript-eslint/utils";
|
|
3686
3769
|
var noUnnecessaryDiv = {
|
|
@@ -3853,6 +3936,7 @@ var src_default = {
|
|
|
3853
3936
|
"no-or-none-component": noOrNoneComponent,
|
|
3854
3937
|
"no-redundant-type-annotation": noRedundantTypeAnnotation,
|
|
3855
3938
|
"no-transition-cssproperties": noTransitionCSSProperties,
|
|
3939
|
+
"no-trivial-alias": noTrivialAlias,
|
|
3856
3940
|
"no-unnecessary-div": noUnnecessaryDiv,
|
|
3857
3941
|
"no-unnecessary-key": noUnnecessaryKey,
|
|
3858
3942
|
"no-useless-function": noUselessFunction,
|
package/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"@typescript-eslint/rule-tester": "8.56.0",
|
|
9
9
|
"@typescript-eslint/utils": "8.56.0",
|
|
10
10
|
"eslint": "10",
|
|
11
|
+
"knip": "6.11.0",
|
|
11
12
|
"prettier": "3.8.1",
|
|
12
|
-
"ts-prune": "0.10.3",
|
|
13
13
|
"typescript": "5.9.3",
|
|
14
14
|
"typescript-eslint": "8.56.0"
|
|
15
15
|
},
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"build": "rm -rf dist && bun build src/index.ts --outdir dist --splitting --target=bun --external eslint --external @typescript-eslint/utils --external typescript",
|
|
35
35
|
"format": "absolutejs prettier --write",
|
|
36
36
|
"lint": "bun run build && bun run absolutejs eslint",
|
|
37
|
-
"
|
|
37
|
+
"knip": "knip",
|
|
38
38
|
"release": "bun run format && bun run build && bun publish",
|
|
39
39
|
"test": "bun test tests/",
|
|
40
40
|
"typecheck": "bun run tsc --noEmit"
|
|
41
41
|
},
|
|
42
42
|
"type": "module",
|
|
43
|
-
"version": "0.
|
|
43
|
+
"version": "0.10.1"
|
|
44
44
|
}
|