eslint-plugin-absolute 0.11.0-beta.4 → 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.
Files changed (2) hide show
  1. package/dist/index.js +41 -3
  2. 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
@@ -2032,6 +2061,12 @@ var visitImmediateReferences = (node, onReference) => {
2032
2061
  };
2033
2062
  visit(node);
2034
2063
  };
2064
+ var getDeclarationDecorators = (declaration) => {
2065
+ if (declaration && "decorators" in declaration && Array.isArray(declaration.decorators)) {
2066
+ return declaration.decorators;
2067
+ }
2068
+ return [];
2069
+ };
2035
2070
  var getImmediateDependencyNames = (node) => {
2036
2071
  const names = new Set;
2037
2072
  const { declaration } = node;
@@ -2047,6 +2082,7 @@ var getImmediateDependencyNames = (node) => {
2047
2082
  }
2048
2083
  if (declaration.type === "ClassDeclaration") {
2049
2084
  visitImmediateReferences(declaration.superClass, addName);
2085
+ getDeclarationDecorators(declaration).forEach((decorator) => visitImmediateReferences(decorator, addName));
2050
2086
  declaration.body.body.forEach(addClassElementDependencies);
2051
2087
  }
2052
2088
  return names;
@@ -2060,7 +2096,9 @@ var sortExports = createRule({
2060
2096
  const natural = option && typeof option.natural === "boolean" ? option.natural : false;
2061
2097
  const minKeys = option && typeof option.minKeys === "number" ? option.minKeys : 2;
2062
2098
  const variablesBeforeFunctions = option && typeof option.variablesBeforeFunctions === "boolean" ? option.variablesBeforeFunctions : false;
2063
- const generateExportText = (node) => sourceCode.getText(node).trim().replace(/\s*;?\s*$/, ";");
2099
+ const getNodeStart = (node) => getDeclarationDecorators(node.declaration).reduce((start, decorator) => Math.min(start, decorator.range[0]), node.range[0]);
2100
+ const getNodeText = (node) => sourceCode.getText().slice(getNodeStart(node), node.range[1]);
2101
+ const generateExportText = (node) => getNodeText(node).trim().replace(/\s*;?\s*$/, ";");
2064
2102
  const compareStrings = (strLeft, strRight) => {
2065
2103
  let left = strLeft;
2066
2104
  let right = strRight;
@@ -2115,7 +2153,7 @@ var sortExports = createRule({
2115
2153
  isFunction: isFunctionExport(node),
2116
2154
  name,
2117
2155
  node,
2118
- text: sourceCode.getText(node)
2156
+ text: getNodeText(node)
2119
2157
  };
2120
2158
  return item;
2121
2159
  }).filter((item) => item !== null);
@@ -2208,7 +2246,7 @@ var sortExports = createRule({
2208
2246
  }
2209
2247
  const sortedText = sortedItems.map((item) => generateExportText(item.node)).join(`
2210
2248
  `);
2211
- const [rangeStart] = firstNode.range;
2249
+ const rangeStart = getNodeStart(firstNode);
2212
2250
  const [, rangeEnd] = lastNode.range;
2213
2251
  const fullText = sourceCode.getText();
2214
2252
  const originalText = fullText.slice(rangeStart, rangeEnd);
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "typecheck": "bun run tsc --noEmit"
41
41
  },
42
42
  "type": "module",
43
- "version": "0.11.0-beta.4"
43
+ "version": "0.11.1"
44
44
  }