eslint-plugin-nextfriday 5.0.0 → 5.0.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/CHANGELOG.md +6 -0
- package/docs/rules/NO_INLINE_NESTED_OBJECT.md +49 -49
- package/lib/index.cjs +42 -23
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +42 -23
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "path";
|
|
|
4
4
|
import emojiRegex from "emoji-regex";
|
|
5
5
|
//#region package.json
|
|
6
6
|
var name = "eslint-plugin-nextfriday";
|
|
7
|
-
var version = "5.0.
|
|
7
|
+
var version = "5.0.1";
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/rules/boolean-naming-prefix.ts
|
|
10
10
|
const createRule$26 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
@@ -1750,9 +1750,6 @@ const noHelperFunctionInTest = ESLintUtils.RuleCreator((name) => `https://github
|
|
|
1750
1750
|
//#endregion
|
|
1751
1751
|
//#region src/rules/no-inline-nested-object.ts
|
|
1752
1752
|
const createRule$11 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1753
|
-
function isObjectOrArray(node) {
|
|
1754
|
-
return node.type === AST_NODE_TYPES.ObjectExpression || node.type === AST_NODE_TYPES.ArrayExpression || node.type === AST_NODE_TYPES.TSAsExpression;
|
|
1755
|
-
}
|
|
1756
1753
|
function getInnerExpression(node) {
|
|
1757
1754
|
if (node.type === AST_NODE_TYPES.TSAsExpression) return getInnerExpression(node.expression);
|
|
1758
1755
|
return node;
|
|
@@ -1775,7 +1772,7 @@ const noInlineNestedObject = createRule$11({
|
|
|
1775
1772
|
name: "no-inline-nested-object",
|
|
1776
1773
|
meta: {
|
|
1777
1774
|
type: "layout",
|
|
1778
|
-
docs: { description: "Require object or array values
|
|
1775
|
+
docs: { description: "Require object or array values passed to functions, returned, or used as JSX attributes to span multiple lines when they contain nested objects or arrays" },
|
|
1779
1776
|
fixable: "whitespace",
|
|
1780
1777
|
messages: { requireMultiline: "Inline collections containing nested objects or arrays should span multiple lines" },
|
|
1781
1778
|
schema: []
|
|
@@ -1783,32 +1780,54 @@ const noInlineNestedObject = createRule$11({
|
|
|
1783
1780
|
defaultOptions: [],
|
|
1784
1781
|
create(context) {
|
|
1785
1782
|
const { sourceCode } = context;
|
|
1786
|
-
|
|
1787
|
-
if (!node
|
|
1788
|
-
const
|
|
1789
|
-
if (
|
|
1790
|
-
if (!
|
|
1791
|
-
if (
|
|
1792
|
-
if (!containsNestedStructure(
|
|
1793
|
-
const elements =
|
|
1783
|
+
function checkValue(node) {
|
|
1784
|
+
if (!node) return;
|
|
1785
|
+
const inner = getInnerExpression(node);
|
|
1786
|
+
if (inner.type !== AST_NODE_TYPES.ObjectExpression && inner.type !== AST_NODE_TYPES.ArrayExpression) return;
|
|
1787
|
+
if (!inner.loc) return;
|
|
1788
|
+
if (inner.loc.start.line !== inner.loc.end.line) return;
|
|
1789
|
+
if (!containsNestedStructure(inner)) return;
|
|
1790
|
+
const elements = inner.type === AST_NODE_TYPES.ObjectExpression ? inner.properties : inner.elements;
|
|
1794
1791
|
context.report({
|
|
1795
|
-
node:
|
|
1792
|
+
node: inner,
|
|
1796
1793
|
messageId: "requireMultiline",
|
|
1797
1794
|
fix(fixer) {
|
|
1798
|
-
const
|
|
1799
|
-
const
|
|
1800
|
-
|
|
1801
|
-
const indent = " ".repeat(node.loc?.start.column ?? 0);
|
|
1802
|
-
const innerIndent = `${indent} `;
|
|
1795
|
+
const lineIndentMatch = (sourceCode.lines[inner.loc.start.line - 1] ?? "").match(/^(\s*)/);
|
|
1796
|
+
const lineIndent = lineIndentMatch ? lineIndentMatch[1] : "";
|
|
1797
|
+
const innerIndent = `${lineIndent} `;
|
|
1803
1798
|
const elementTexts = elements.filter((el) => el !== null).map((el) => sourceCode.getText(el));
|
|
1804
|
-
const isObject =
|
|
1799
|
+
const isObject = inner.type === AST_NODE_TYPES.ObjectExpression;
|
|
1805
1800
|
const openChar = isObject ? "{" : "[";
|
|
1806
1801
|
const closeChar = isObject ? "}" : "]";
|
|
1807
|
-
const newContent = `${openChar}\n${elementTexts.map((text) => `${innerIndent}${text},`).join("\n")}\n${
|
|
1808
|
-
return fixer.replaceText(
|
|
1802
|
+
const newContent = `${openChar}\n${elementTexts.map((text) => `${innerIndent}${text},`).join("\n")}\n${lineIndent}${closeChar}`;
|
|
1803
|
+
return fixer.replaceText(inner, newContent);
|
|
1809
1804
|
}
|
|
1810
1805
|
});
|
|
1811
|
-
}
|
|
1806
|
+
}
|
|
1807
|
+
function checkArguments(args) {
|
|
1808
|
+
args.forEach((arg) => {
|
|
1809
|
+
if (arg.type === AST_NODE_TYPES.SpreadElement) return;
|
|
1810
|
+
checkValue(arg);
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
return {
|
|
1814
|
+
CallExpression(node) {
|
|
1815
|
+
checkArguments(node.arguments);
|
|
1816
|
+
},
|
|
1817
|
+
NewExpression(node) {
|
|
1818
|
+
checkArguments(node.arguments);
|
|
1819
|
+
},
|
|
1820
|
+
ReturnStatement(node) {
|
|
1821
|
+
checkValue(node.argument);
|
|
1822
|
+
},
|
|
1823
|
+
ArrowFunctionExpression(node) {
|
|
1824
|
+
if (node.body.type !== AST_NODE_TYPES.BlockStatement) checkValue(node.body);
|
|
1825
|
+
},
|
|
1826
|
+
JSXExpressionContainer(node) {
|
|
1827
|
+
if (node.expression.type === AST_NODE_TYPES.JSXEmptyExpression) return;
|
|
1828
|
+
checkValue(node.expression);
|
|
1829
|
+
}
|
|
1830
|
+
};
|
|
1812
1831
|
}
|
|
1813
1832
|
});
|
|
1814
1833
|
//#endregion
|