eslint-plugin-absolute 0.10.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 +16 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3705,6 +3705,20 @@ var isBareTypeReference = (node) => {
|
|
|
3705
3705
|
}
|
|
3706
3706
|
};
|
|
3707
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
|
+
};
|
|
3708
3722
|
var noTrivialAlias = {
|
|
3709
3723
|
create(context) {
|
|
3710
3724
|
return {
|
|
@@ -3726,6 +3740,8 @@ var noTrivialAlias = {
|
|
|
3726
3740
|
return;
|
|
3727
3741
|
if (!isBareIdentifierInit(node.init))
|
|
3728
3742
|
return;
|
|
3743
|
+
if (!isConstSource(context, node.init))
|
|
3744
|
+
return;
|
|
3729
3745
|
context.report({
|
|
3730
3746
|
data: { name: node.id.name },
|
|
3731
3747
|
messageId: "trivialConstAlias",
|
package/package.json
CHANGED