@exadev/eslint-config 1.4.1 → 2.0.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/README.md +45 -44
- package/dist/index.cjs +287 -2
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +259 -2
- package/package.json +1 -14
- package/dist/plugin-BscQLyGY.cjs +0 -46
- package/dist/plugin-DYny7gdb.js +0 -45
- package/dist/plugin.cjs +0 -2
- package/dist/plugin.d.cts +0 -4
- package/dist/plugin.d.ts +0 -5
- package/dist/plugin.js +0 -2
- package/dist/recommended-type-checked.cjs +0 -52
- package/dist/recommended-type-checked.d.cts +0 -5
- package/dist/recommended-type-checked.d.ts +0 -6
- package/dist/recommended-type-checked.js +0 -29
- package/dist/rules/no-non-barrel-index.cjs +0 -24
- package/dist/rules/no-non-barrel-index.d.cts +0 -4
- package/dist/rules/no-non-barrel-index.d.ts +0 -5
- package/dist/rules/no-non-barrel-index.js +0 -24
- package/dist/rules/no-non-barrel-reexport.cjs +0 -89
- package/dist/rules/no-non-barrel-reexport.d.cts +0 -4
- package/dist/rules/no-non-barrel-reexport.d.ts +0 -5
- package/dist/rules/no-non-barrel-reexport.js +0 -89
- package/dist/rules/no-pointless-reassignment.cjs +0 -57
- package/dist/rules/no-pointless-reassignment.d.cts +0 -4
- package/dist/rules/no-pointless-reassignment.d.ts +0 -5
- package/dist/rules/no-pointless-reassignment.js +0 -57
- package/dist/rules/no-side-effects-in-index.cjs +0 -24
- package/dist/rules/no-side-effects-in-index.d.cts +0 -4
- package/dist/rules/no-side-effects-in-index.d.ts +0 -5
- package/dist/rules/no-side-effects-in-index.js +0 -24
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
//#region src/rules/no-non-barrel-reexport.ts
|
|
2
|
-
function removeListMember(fixer, sourceCode, declaration, members, target) {
|
|
3
|
-
if (members.length === 1) return fixer.remove(declaration);
|
|
4
|
-
const targetIndex = members.indexOf(target);
|
|
5
|
-
const isLast = targetIndex === members.length - 1;
|
|
6
|
-
const neighbor = members[isLast ? targetIndex - 1 : targetIndex + 1];
|
|
7
|
-
if (neighbor === void 0) throw new Error("Unreachable: a list with more than one member always has a neighbor either side of any member within it.");
|
|
8
|
-
return isLast ? fixer.removeRange([sourceCode.getRange(neighbor)[1], sourceCode.getRange(target)[1]]) : fixer.removeRange([sourceCode.getRange(target)[0], sourceCode.getRange(neighbor)[0]]);
|
|
9
|
-
}
|
|
10
|
-
function importIsOnlyUsedByThisExport(sourceCode, trackedImport, usageIdentifier) {
|
|
11
|
-
const variable = sourceCode.getDeclaredVariables(trackedImport.declaration).find((candidate) => candidate.defs.some((def) => def.node === trackedImport.specifier));
|
|
12
|
-
if (variable === void 0) return false;
|
|
13
|
-
if (variable.references.length !== 1) return false;
|
|
14
|
-
const [onlyReference] = variable.references;
|
|
15
|
-
if (onlyReference === void 0) throw new Error("Unreachable: the length check above guarantees exactly one element.");
|
|
16
|
-
return onlyReference.identifier === usageIdentifier;
|
|
17
|
-
}
|
|
18
|
-
const noNonBarrelReexport = {
|
|
19
|
-
meta: {
|
|
20
|
-
type: "problem",
|
|
21
|
-
fixable: "code",
|
|
22
|
-
schema: [],
|
|
23
|
-
messages: {
|
|
24
|
-
splitStatementReexport: "'{{ name }}' is imported here and handed straight back out via a bare export -- the identical re-export 'export { {{ name }} } from ...' would be, just split across two statements. Re-exports belong only in src/index.ts (the public barrel).",
|
|
25
|
-
splitStatementDefaultReexport: "'{{ name }}' is imported here and handed straight back out via `export default` -- the identical re-export 'export { {{ name }} as default } from ...' would be, just split across two statements. Re-exports belong only in src/index.ts (the public barrel)."
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
create(context) {
|
|
29
|
-
if (context.filename.endsWith("/src/index.ts")) return {};
|
|
30
|
-
const importsByName = /* @__PURE__ */ new Map();
|
|
31
|
-
const bareExportSpecifiers = [];
|
|
32
|
-
const defaultExportDeclarations = [];
|
|
33
|
-
return {
|
|
34
|
-
ImportDeclaration(node) {
|
|
35
|
-
for (const specifier of node.specifiers) importsByName.set(specifier.local.name, {
|
|
36
|
-
declaration: node,
|
|
37
|
-
specifier
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
ExportNamedDeclaration(node) {
|
|
41
|
-
if (node.source !== null && node.source !== void 0) return;
|
|
42
|
-
for (const specifier of node.specifiers) bareExportSpecifiers.push({
|
|
43
|
-
declaration: node,
|
|
44
|
-
specifier
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
ExportDefaultDeclaration(node) {
|
|
48
|
-
defaultExportDeclarations.push(node);
|
|
49
|
-
},
|
|
50
|
-
"Program:exit"() {
|
|
51
|
-
const { sourceCode } = context;
|
|
52
|
-
for (const { declaration, specifier } of bareExportSpecifiers) {
|
|
53
|
-
const name = specifier.local.type === "Identifier" ? specifier.local.name : void 0;
|
|
54
|
-
if (name === void 0) continue;
|
|
55
|
-
const trackedImport = importsByName.get(name);
|
|
56
|
-
if (trackedImport === void 0) continue;
|
|
57
|
-
context.report({
|
|
58
|
-
node: specifier,
|
|
59
|
-
messageId: "splitStatementReexport",
|
|
60
|
-
data: { name },
|
|
61
|
-
fix(fixer) {
|
|
62
|
-
const fixes = [removeListMember(fixer, sourceCode, declaration, declaration.specifiers, specifier)];
|
|
63
|
-
if (specifier.local.type === "Identifier" && importIsOnlyUsedByThisExport(sourceCode, trackedImport, specifier.local)) fixes.push(removeListMember(fixer, sourceCode, trackedImport.declaration, trackedImport.declaration.specifiers, trackedImport.specifier));
|
|
64
|
-
return fixes;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
for (const declarationNode of defaultExportDeclarations) {
|
|
69
|
-
const name = declarationNode.declaration.type === "Identifier" ? declarationNode.declaration.name : void 0;
|
|
70
|
-
if (name === void 0) continue;
|
|
71
|
-
const trackedImport = importsByName.get(name);
|
|
72
|
-
if (trackedImport === void 0) continue;
|
|
73
|
-
context.report({
|
|
74
|
-
node: declarationNode,
|
|
75
|
-
messageId: "splitStatementDefaultReexport",
|
|
76
|
-
data: { name },
|
|
77
|
-
fix(fixer) {
|
|
78
|
-
const fixes = [fixer.remove(declarationNode)];
|
|
79
|
-
if (declarationNode.declaration.type === "Identifier" && importIsOnlyUsedByThisExport(sourceCode, trackedImport, declarationNode.declaration)) fixes.push(removeListMember(fixer, sourceCode, trackedImport.declaration, trackedImport.declaration.specifiers, trackedImport.specifier));
|
|
80
|
-
return fixes;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
//#endregion
|
|
89
|
-
export { noNonBarrelReexport as default };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/rules/no-pointless-reassignment.ts
|
|
2
|
-
function isIdentifierReference(reference) {
|
|
3
|
-
return reference.identifier.type === "Identifier";
|
|
4
|
-
}
|
|
5
|
-
const noPointlessReassignment = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
fixable: "code",
|
|
9
|
-
schema: [],
|
|
10
|
-
messages: { pointlessReassignment: "Pointless reassignment: '{{ name }}' is just an alias for '{{ value }}'. Use the original directly." }
|
|
11
|
-
},
|
|
12
|
-
create(context) {
|
|
13
|
-
return { VariableDeclarator(node) {
|
|
14
|
-
if (node.id.type !== "Identifier" || node.init?.type !== "Identifier" || node.id.name.startsWith("_")) return;
|
|
15
|
-
if (node.parent.type !== "VariableDeclaration" || node.parent.kind !== "const") return;
|
|
16
|
-
const scope = context.sourceCode.getScope(node);
|
|
17
|
-
const sourceVariable = scope.references.find((reference) => reference.identifier === node.init)?.resolved;
|
|
18
|
-
if (!sourceVariable || sourceVariable.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
19
|
-
const aliasName = node.id.name;
|
|
20
|
-
const originalName = node.init.name;
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "pointlessReassignment",
|
|
24
|
-
data: {
|
|
25
|
-
name: aliasName,
|
|
26
|
-
value: originalName
|
|
27
|
-
},
|
|
28
|
-
fix(fixer) {
|
|
29
|
-
const variable = scope.set.get(aliasName);
|
|
30
|
-
if (!variable) return null;
|
|
31
|
-
if (variable.references.filter((reference) => reference.isWrite() && reference.identifier !== node.id).length > 0) return null;
|
|
32
|
-
const readRefs = variable.references.filter((reference) => reference.isRead() && isIdentifierReference(reference));
|
|
33
|
-
if (readRefs.some((reference) => {
|
|
34
|
-
const afterToken = context.sourceCode.getTokenAfter(reference.identifier);
|
|
35
|
-
if (afterToken?.value === ":") return false;
|
|
36
|
-
if (afterToken?.value !== "}" && afterToken?.value !== ",") return false;
|
|
37
|
-
let token = context.sourceCode.getTokenBefore(reference.identifier);
|
|
38
|
-
while (token) {
|
|
39
|
-
if (token.value === "{") return true;
|
|
40
|
-
if (token.value === "[" || token.value === "(") return false;
|
|
41
|
-
if (token.value === ":") return false;
|
|
42
|
-
token = context.sourceCode.getTokenBefore(token);
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
})) return null;
|
|
46
|
-
const fixes = readRefs.map((reference) => fixer.replaceText(reference.identifier, originalName));
|
|
47
|
-
const declaration = node.parent;
|
|
48
|
-
if (declaration.type !== "VariableDeclaration" || declaration.declarations.length !== 1) return null;
|
|
49
|
-
fixes.push(fixer.remove(declaration));
|
|
50
|
-
return fixes;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
} };
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
module.exports = noPointlessReassignment;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/rules/no-pointless-reassignment.ts
|
|
2
|
-
function isIdentifierReference(reference) {
|
|
3
|
-
return reference.identifier.type === "Identifier";
|
|
4
|
-
}
|
|
5
|
-
const noPointlessReassignment = {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem",
|
|
8
|
-
fixable: "code",
|
|
9
|
-
schema: [],
|
|
10
|
-
messages: { pointlessReassignment: "Pointless reassignment: '{{ name }}' is just an alias for '{{ value }}'. Use the original directly." }
|
|
11
|
-
},
|
|
12
|
-
create(context) {
|
|
13
|
-
return { VariableDeclarator(node) {
|
|
14
|
-
if (node.id.type !== "Identifier" || node.init?.type !== "Identifier" || node.id.name.startsWith("_")) return;
|
|
15
|
-
if (node.parent.type !== "VariableDeclaration" || node.parent.kind !== "const") return;
|
|
16
|
-
const scope = context.sourceCode.getScope(node);
|
|
17
|
-
const sourceVariable = scope.references.find((reference) => reference.identifier === node.init)?.resolved;
|
|
18
|
-
if (!sourceVariable || sourceVariable.references.some((reference) => reference.isWrite() && !reference.init)) return;
|
|
19
|
-
const aliasName = node.id.name;
|
|
20
|
-
const originalName = node.init.name;
|
|
21
|
-
context.report({
|
|
22
|
-
node,
|
|
23
|
-
messageId: "pointlessReassignment",
|
|
24
|
-
data: {
|
|
25
|
-
name: aliasName,
|
|
26
|
-
value: originalName
|
|
27
|
-
},
|
|
28
|
-
fix(fixer) {
|
|
29
|
-
const variable = scope.set.get(aliasName);
|
|
30
|
-
if (!variable) return null;
|
|
31
|
-
if (variable.references.filter((reference) => reference.isWrite() && reference.identifier !== node.id).length > 0) return null;
|
|
32
|
-
const readRefs = variable.references.filter((reference) => reference.isRead() && isIdentifierReference(reference));
|
|
33
|
-
if (readRefs.some((reference) => {
|
|
34
|
-
const afterToken = context.sourceCode.getTokenAfter(reference.identifier);
|
|
35
|
-
if (afterToken?.value === ":") return false;
|
|
36
|
-
if (afterToken?.value !== "}" && afterToken?.value !== ",") return false;
|
|
37
|
-
let token = context.sourceCode.getTokenBefore(reference.identifier);
|
|
38
|
-
while (token) {
|
|
39
|
-
if (token.value === "{") return true;
|
|
40
|
-
if (token.value === "[" || token.value === "(") return false;
|
|
41
|
-
if (token.value === ":") return false;
|
|
42
|
-
token = context.sourceCode.getTokenBefore(token);
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
})) return null;
|
|
46
|
-
const fixes = readRefs.map((reference) => fixer.replaceText(reference.identifier, originalName));
|
|
47
|
-
const declaration = node.parent;
|
|
48
|
-
if (declaration.type !== "VariableDeclaration" || declaration.declarations.length !== 1) return null;
|
|
49
|
-
fixes.push(fixer.remove(declaration));
|
|
50
|
-
return fixes;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
} };
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
export { noPointlessReassignment as default };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region src/rules/no-side-effects-in-index.ts
|
|
2
|
-
function isPureReexport(statement) {
|
|
3
|
-
if (statement.type === "ExportAllDeclaration") return true;
|
|
4
|
-
return statement.type === "ExportNamedDeclaration" && statement.source !== null && statement.source !== void 0;
|
|
5
|
-
}
|
|
6
|
-
const noSideEffectsInIndex = {
|
|
7
|
-
meta: {
|
|
8
|
-
type: "problem",
|
|
9
|
-
schema: [],
|
|
10
|
-
messages: { notAPureReexport: "The public barrel (src/index.ts) may contain only re-export statements ('export * from ...' / 'export { x } from ...' / 'export type { x } from ...') -- nothing else, so it can never have a side effect at import time by construction. Found: {{ description }}." }
|
|
11
|
-
},
|
|
12
|
-
create(context) {
|
|
13
|
-
if (!context.filename.endsWith("/src/index.ts")) return {};
|
|
14
|
-
return { Program(node) {
|
|
15
|
-
for (const statement of node.body) if (!isPureReexport(statement)) context.report({
|
|
16
|
-
node: statement,
|
|
17
|
-
messageId: "notAPureReexport",
|
|
18
|
-
data: { description: statement.type }
|
|
19
|
-
});
|
|
20
|
-
} };
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
24
|
-
module.exports = noSideEffectsInIndex;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region src/rules/no-side-effects-in-index.ts
|
|
2
|
-
function isPureReexport(statement) {
|
|
3
|
-
if (statement.type === "ExportAllDeclaration") return true;
|
|
4
|
-
return statement.type === "ExportNamedDeclaration" && statement.source !== null && statement.source !== void 0;
|
|
5
|
-
}
|
|
6
|
-
const noSideEffectsInIndex = {
|
|
7
|
-
meta: {
|
|
8
|
-
type: "problem",
|
|
9
|
-
schema: [],
|
|
10
|
-
messages: { notAPureReexport: "The public barrel (src/index.ts) may contain only re-export statements ('export * from ...' / 'export { x } from ...' / 'export type { x } from ...') -- nothing else, so it can never have a side effect at import time by construction. Found: {{ description }}." }
|
|
11
|
-
},
|
|
12
|
-
create(context) {
|
|
13
|
-
if (!context.filename.endsWith("/src/index.ts")) return {};
|
|
14
|
-
return { Program(node) {
|
|
15
|
-
for (const statement of node.body) if (!isPureReexport(statement)) context.report({
|
|
16
|
-
node: statement,
|
|
17
|
-
messageId: "notAPureReexport",
|
|
18
|
-
data: { description: statement.type }
|
|
19
|
-
});
|
|
20
|
-
} };
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
24
|
-
export { noSideEffectsInIndex as default };
|