eslint-plugin-absolute 0.11.0 → 0.11.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 +29 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1714,6 +1714,32 @@ var noExplicitReturnTypes = createRule({
|
|
|
1714
1714
|
const [returnStmt] = returnStatements;
|
|
1715
1715
|
return returnStmt?.argument?.type === "ObjectExpression";
|
|
1716
1716
|
};
|
|
1717
|
+
const getOwnName = (node) => {
|
|
1718
|
+
if (node.id)
|
|
1719
|
+
return node.id.name;
|
|
1720
|
+
const { parent } = node;
|
|
1721
|
+
if (parent.type === "VariableDeclarator" && parent.id.type === "Identifier") {
|
|
1722
|
+
return parent.id.name;
|
|
1723
|
+
}
|
|
1724
|
+
return;
|
|
1725
|
+
};
|
|
1726
|
+
const getDeclaringNode = (node) => {
|
|
1727
|
+
if (node.id)
|
|
1728
|
+
return node;
|
|
1729
|
+
const { parent } = node;
|
|
1730
|
+
if (parent.type === "VariableDeclarator")
|
|
1731
|
+
return parent.parent;
|
|
1732
|
+
return node;
|
|
1733
|
+
};
|
|
1734
|
+
const referencesOwnName = (node) => {
|
|
1735
|
+
const ownName = getOwnName(node);
|
|
1736
|
+
if (!ownName)
|
|
1737
|
+
return false;
|
|
1738
|
+
const variable = context.sourceCode.getDeclaredVariables(getDeclaringNode(node)).find((candidate) => candidate.name === ownName);
|
|
1739
|
+
if (!variable)
|
|
1740
|
+
return false;
|
|
1741
|
+
return variable.references.some((reference) => reference.identifier.range[0] >= node.range[0] && reference.identifier.range[1] <= node.range[1]);
|
|
1742
|
+
};
|
|
1717
1743
|
return {
|
|
1718
1744
|
"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression"(node) {
|
|
1719
1745
|
const { returnType } = node;
|
|
@@ -1730,6 +1756,9 @@ var noExplicitReturnTypes = createRule({
|
|
|
1730
1756
|
if (node.body && node.body.type === "BlockStatement" && hasSingleObjectReturn(node.body)) {
|
|
1731
1757
|
return;
|
|
1732
1758
|
}
|
|
1759
|
+
if (referencesOwnName(node)) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1733
1762
|
context.report({
|
|
1734
1763
|
messageId: "noExplicitReturnType",
|
|
1735
1764
|
node: returnType
|
package/package.json
CHANGED