eslint-plugin-nextfriday 4.3.1 → 4.4.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/CHANGELOG.md +16 -0
- package/README.md +7 -9
- package/docs/rules/PREFER_PROPS_WITH_CHILDREN.md +17 -35
- package/lib/index.cjs +80 -117
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +0 -42
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.ts +0 -42
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +80 -117
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/docs/rules/PREFER_INLINE_TYPE_EXPORT.md +0 -64
package/lib/index.js
CHANGED
|
@@ -4,10 +4,10 @@ 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 = "4.
|
|
7
|
+
var version = "4.4.0";
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/rules/boolean-naming-prefix.ts
|
|
10
|
-
const createRule$
|
|
10
|
+
const createRule$31 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
11
11
|
const BOOLEAN_PREFIXES = [
|
|
12
12
|
"is",
|
|
13
13
|
"has",
|
|
@@ -56,7 +56,7 @@ const hasBooleanTypeAnnotation = (node) => {
|
|
|
56
56
|
}
|
|
57
57
|
return false;
|
|
58
58
|
};
|
|
59
|
-
const booleanNamingPrefix = createRule$
|
|
59
|
+
const booleanNamingPrefix = createRule$31({
|
|
60
60
|
name: "boolean-naming-prefix",
|
|
61
61
|
meta: {
|
|
62
62
|
type: "suggestion",
|
|
@@ -117,7 +117,7 @@ const booleanNamingPrefix = createRule$32({
|
|
|
117
117
|
});
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/rules/enforce-camel-case.ts
|
|
120
|
-
const createRule$
|
|
120
|
+
const createRule$30 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
121
121
|
const SNAKE_CASE_REGEX$2 = /^[a-z]+_[a-z0-9_]*$/;
|
|
122
122
|
const PASCAL_CASE_REGEX = /^[A-Z][a-zA-Z0-9]*$/;
|
|
123
123
|
const REACT_WRAPPERS = [
|
|
@@ -161,7 +161,7 @@ const isStaticValue$1 = (init) => {
|
|
|
161
161
|
if (init.type === AST_NODE_TYPES.TSAsExpression && init.typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && init.typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && init.typeAnnotation.typeName.name === "const") return true;
|
|
162
162
|
return false;
|
|
163
163
|
};
|
|
164
|
-
const enforceCamelCase = createRule$
|
|
164
|
+
const enforceCamelCase = createRule$30({
|
|
165
165
|
name: "enforce-camel-case",
|
|
166
166
|
meta: {
|
|
167
167
|
type: "suggestion",
|
|
@@ -222,7 +222,7 @@ const isConfigFile = (filename) => {
|
|
|
222
222
|
};
|
|
223
223
|
//#endregion
|
|
224
224
|
//#region src/rules/enforce-constant-case.ts
|
|
225
|
-
const createRule$
|
|
225
|
+
const createRule$29 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
226
226
|
const SCREAMING_SNAKE_CASE_REGEX$2 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
227
227
|
const SNAKE_CASE_REGEX$1 = /^[a-z]+_[a-z0-9_]*$/;
|
|
228
228
|
const toScreamingSnakeCase = (str) => str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toUpperCase();
|
|
@@ -240,7 +240,7 @@ const isGlobalScope$1 = (node) => {
|
|
|
240
240
|
if (parent.type === AST_NODE_TYPES.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES.Program) return true;
|
|
241
241
|
return false;
|
|
242
242
|
};
|
|
243
|
-
const enforceConstantCase = createRule$
|
|
243
|
+
const enforceConstantCase = createRule$29({
|
|
244
244
|
name: "enforce-constant-case",
|
|
245
245
|
meta: {
|
|
246
246
|
type: "suggestion",
|
|
@@ -364,7 +364,7 @@ const enforceHookNaming = ESLintUtils.RuleCreator((name) => `https://github.com/
|
|
|
364
364
|
});
|
|
365
365
|
//#endregion
|
|
366
366
|
//#region src/rules/enforce-property-case.ts
|
|
367
|
-
const createRule$
|
|
367
|
+
const createRule$28 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
368
368
|
const SNAKE_CASE_REGEX = /^[a-z]+_[a-z0-9_]*$/;
|
|
369
369
|
const SCREAMING_SNAKE_CASE_REGEX$1 = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
370
370
|
const isInsideAsConst = (node) => {
|
|
@@ -376,7 +376,7 @@ const isInsideAsConst = (node) => {
|
|
|
376
376
|
}
|
|
377
377
|
return false;
|
|
378
378
|
};
|
|
379
|
-
const enforcePropertyCase = createRule$
|
|
379
|
+
const enforcePropertyCase = createRule$28({
|
|
380
380
|
name: "enforce-property-case",
|
|
381
381
|
meta: {
|
|
382
382
|
type: "suggestion",
|
|
@@ -450,6 +450,7 @@ const enforceReadonlyComponentProps = ESLintUtils.RuleCreator((name) => `https:/
|
|
|
450
450
|
},
|
|
451
451
|
defaultOptions: [],
|
|
452
452
|
create(context) {
|
|
453
|
+
if (!isJsxFile(context.filename)) return {};
|
|
453
454
|
function hasJSXInConditional(node) {
|
|
454
455
|
return node.consequent.type === AST_NODE_TYPES.JSXElement || node.consequent.type === AST_NODE_TYPES.JSXFragment || node.alternate.type === AST_NODE_TYPES.JSXElement || node.alternate.type === AST_NODE_TYPES.JSXFragment;
|
|
455
456
|
}
|
|
@@ -508,7 +509,7 @@ const enforceReadonlyComponentProps = ESLintUtils.RuleCreator((name) => `https:/
|
|
|
508
509
|
});
|
|
509
510
|
//#endregion
|
|
510
511
|
//#region src/rules/enforce-render-naming.ts
|
|
511
|
-
const createRule$
|
|
512
|
+
const createRule$27 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
512
513
|
const ARRAY_RETURNING_METHODS = new Set([
|
|
513
514
|
"map",
|
|
514
515
|
"flatMap",
|
|
@@ -557,7 +558,7 @@ function isComponentFunction(node) {
|
|
|
557
558
|
if (parent?.type === AST_NODE_TYPES.VariableDeclarator && parent.id.type === AST_NODE_TYPES.Identifier && isPascalCase$1(parent.id.name)) return true;
|
|
558
559
|
return false;
|
|
559
560
|
}
|
|
560
|
-
const enforceRenderNaming = createRule$
|
|
561
|
+
const enforceRenderNaming = createRule$27({
|
|
561
562
|
name: "enforce-render-naming",
|
|
562
563
|
meta: {
|
|
563
564
|
type: "problem",
|
|
@@ -609,7 +610,7 @@ const enforceRenderNaming = createRule$28({
|
|
|
609
610
|
});
|
|
610
611
|
//#endregion
|
|
611
612
|
//#region src/rules/enforce-service-naming.ts
|
|
612
|
-
const createRule$
|
|
613
|
+
const createRule$26 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
613
614
|
const BANNED_PREFIXES = {
|
|
614
615
|
delete: ["remove", "archive"],
|
|
615
616
|
do: ["submit", "process"],
|
|
@@ -620,7 +621,7 @@ const BANNED_PREFIXES = {
|
|
|
620
621
|
"patch"
|
|
621
622
|
]
|
|
622
623
|
};
|
|
623
|
-
const enforceServiceNaming = createRule$
|
|
624
|
+
const enforceServiceNaming = createRule$26({
|
|
624
625
|
name: "enforce-service-naming",
|
|
625
626
|
meta: {
|
|
626
627
|
type: "suggestion",
|
|
@@ -658,7 +659,7 @@ const enforceServiceNaming = createRule$27({
|
|
|
658
659
|
});
|
|
659
660
|
//#endregion
|
|
660
661
|
//#region src/rules/enforce-test-filename.ts
|
|
661
|
-
const createRule$
|
|
662
|
+
const createRule$25 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
662
663
|
const TEST_GLOBALS = new Set([
|
|
663
664
|
"describe",
|
|
664
665
|
"it",
|
|
@@ -668,7 +669,7 @@ const TEST_GLOBALS = new Set([
|
|
|
668
669
|
"afterEach",
|
|
669
670
|
"afterAll"
|
|
670
671
|
]);
|
|
671
|
-
const enforceTestFilename = createRule$
|
|
672
|
+
const enforceTestFilename = createRule$25({
|
|
672
673
|
name: "enforce-test-filename",
|
|
673
674
|
meta: {
|
|
674
675
|
type: "suggestion",
|
|
@@ -748,7 +749,7 @@ const enforceSortedDestructuring = ESLintUtils.RuleCreator((name) => `https://gi
|
|
|
748
749
|
});
|
|
749
750
|
//#endregion
|
|
750
751
|
//#region src/rules/enforce-type-declaration-order.ts
|
|
751
|
-
const createRule$
|
|
752
|
+
const createRule$24 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
752
753
|
function getTypeDeclarationName(node) {
|
|
753
754
|
if (node.type === AST_NODE_TYPES.TSInterfaceDeclaration && node.id.type === AST_NODE_TYPES.Identifier) return {
|
|
754
755
|
name: node.id.name,
|
|
@@ -760,7 +761,7 @@ function getTypeDeclarationName(node) {
|
|
|
760
761
|
};
|
|
761
762
|
return null;
|
|
762
763
|
}
|
|
763
|
-
const enforceTypeDeclarationOrder = createRule$
|
|
764
|
+
const enforceTypeDeclarationOrder = createRule$24({
|
|
764
765
|
name: "enforce-type-declaration-order",
|
|
765
766
|
meta: {
|
|
766
767
|
type: "suggestion",
|
|
@@ -815,7 +816,7 @@ const enforceTypeDeclarationOrder = createRule$25({
|
|
|
815
816
|
});
|
|
816
817
|
//#endregion
|
|
817
818
|
//#region src/rules/index-export-only.ts
|
|
818
|
-
const createRule$
|
|
819
|
+
const createRule$23 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
819
820
|
const isIndexFile = (filename) => getBaseName(filename) === "index";
|
|
820
821
|
const isAllowedExportNamed = (node) => {
|
|
821
822
|
if (!node.declaration) return true;
|
|
@@ -834,7 +835,7 @@ const isAllowedTopLevel = (node) => {
|
|
|
834
835
|
default: return false;
|
|
835
836
|
}
|
|
836
837
|
};
|
|
837
|
-
const indexExportOnly = createRule$
|
|
838
|
+
const indexExportOnly = createRule$23({
|
|
838
839
|
name: "index-export-only",
|
|
839
840
|
meta: {
|
|
840
841
|
type: "suggestion",
|
|
@@ -869,6 +870,7 @@ const jsxNewlineBetweenElements = ESLintUtils.RuleCreator((name) => `https://git
|
|
|
869
870
|
},
|
|
870
871
|
defaultOptions: [],
|
|
871
872
|
create(context) {
|
|
873
|
+
if (!isJsxFile(context.filename)) return {};
|
|
872
874
|
const { sourceCode } = context;
|
|
873
875
|
function isSignificantJSXChild(node) {
|
|
874
876
|
return node.type === AST_NODE_TYPES.JSXElement || node.type === AST_NODE_TYPES.JSXFragment || node.type === AST_NODE_TYPES.JSXExpressionContainer;
|
|
@@ -907,7 +909,7 @@ const jsxNewlineBetweenElements = ESLintUtils.RuleCreator((name) => `https://git
|
|
|
907
909
|
});
|
|
908
910
|
//#endregion
|
|
909
911
|
//#region src/rules/jsx-no-data-array.ts
|
|
910
|
-
const createRule$
|
|
912
|
+
const createRule$22 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
911
913
|
function isObjectLikeElement(node) {
|
|
912
914
|
if (!node) return false;
|
|
913
915
|
if (node.type === AST_NODE_TYPES.ObjectExpression) return true;
|
|
@@ -920,7 +922,7 @@ function getArrayInitializer(init) {
|
|
|
920
922
|
if (init.type === AST_NODE_TYPES.TSAsExpression || init.type === AST_NODE_TYPES.TSSatisfiesExpression) return getArrayInitializer(init.expression);
|
|
921
923
|
return null;
|
|
922
924
|
}
|
|
923
|
-
const jsxNoDataArray = createRule$
|
|
925
|
+
const jsxNoDataArray = createRule$22({
|
|
924
926
|
name: "jsx-no-data-array",
|
|
925
927
|
meta: {
|
|
926
928
|
type: "problem",
|
|
@@ -961,7 +963,7 @@ const jsxNoDataArray = createRule$23({
|
|
|
961
963
|
});
|
|
962
964
|
//#endregion
|
|
963
965
|
//#region src/rules/jsx-no-data-object.ts
|
|
964
|
-
const createRule$
|
|
966
|
+
const createRule$21 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
965
967
|
function unwrapAssertion(node) {
|
|
966
968
|
if (!node) return null;
|
|
967
969
|
if (node.type === AST_NODE_TYPES.TSAsExpression || node.type === AST_NODE_TYPES.TSSatisfiesExpression) return unwrapAssertion(node.expression);
|
|
@@ -991,7 +993,7 @@ function getObjectInitializer(init) {
|
|
|
991
993
|
if (unwrapped.type === AST_NODE_TYPES.ObjectExpression) return unwrapped;
|
|
992
994
|
return null;
|
|
993
995
|
}
|
|
994
|
-
const jsxNoDataObject = createRule$
|
|
996
|
+
const jsxNoDataObject = createRule$21({
|
|
995
997
|
name: "jsx-no-data-object",
|
|
996
998
|
meta: {
|
|
997
999
|
type: "problem",
|
|
@@ -1033,6 +1035,7 @@ const jsxNoInlineObjectProp = ESLintUtils.RuleCreator((name) => `https://github.
|
|
|
1033
1035
|
},
|
|
1034
1036
|
defaultOptions: [],
|
|
1035
1037
|
create(context) {
|
|
1038
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1036
1039
|
return { JSXAttribute(node) {
|
|
1037
1040
|
if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && node.value.expression.type === AST_NODE_TYPES.ObjectExpression) context.report({
|
|
1038
1041
|
node: node.value,
|
|
@@ -1043,14 +1046,14 @@ const jsxNoInlineObjectProp = ESLintUtils.RuleCreator((name) => `https://github.
|
|
|
1043
1046
|
});
|
|
1044
1047
|
//#endregion
|
|
1045
1048
|
//#region src/rules/jsx-no-newline-single-line-elements.ts
|
|
1046
|
-
const createRule$
|
|
1049
|
+
const createRule$20 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1047
1050
|
function isJSXElementOrFragment(node) {
|
|
1048
1051
|
return node.type === AST_NODE_TYPES.JSXElement || node.type === AST_NODE_TYPES.JSXFragment;
|
|
1049
1052
|
}
|
|
1050
1053
|
function isSingleLine(node) {
|
|
1051
1054
|
return node.loc.start.line === node.loc.end.line;
|
|
1052
1055
|
}
|
|
1053
|
-
const jsxNoNewlineSingleLineElements = createRule$
|
|
1056
|
+
const jsxNoNewlineSingleLineElements = createRule$20({
|
|
1054
1057
|
name: "jsx-no-newline-single-line-elements",
|
|
1055
1058
|
meta: {
|
|
1056
1059
|
type: "layout",
|
|
@@ -1061,6 +1064,7 @@ const jsxNoNewlineSingleLineElements = createRule$21({
|
|
|
1061
1064
|
},
|
|
1062
1065
|
defaultOptions: [],
|
|
1063
1066
|
create(context) {
|
|
1067
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1064
1068
|
const { sourceCode } = context;
|
|
1065
1069
|
function checkSiblings(children) {
|
|
1066
1070
|
const nonWhitespace = children.filter((child) => !(child.type === AST_NODE_TYPES.JSXText && child.value.trim() === ""));
|
|
@@ -1148,7 +1152,7 @@ const jsxNoNonComponentFunction = ESLintUtils.RuleCreator((name) => `https://git
|
|
|
1148
1152
|
});
|
|
1149
1153
|
//#endregion
|
|
1150
1154
|
//#region src/rules/jsx-no-sub-interface.ts
|
|
1151
|
-
const createRule$
|
|
1155
|
+
const createRule$19 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1152
1156
|
const PROPS_WRAPPER_NAMES = new Set([
|
|
1153
1157
|
"Readonly",
|
|
1154
1158
|
"Required",
|
|
@@ -1180,7 +1184,7 @@ function getDeclarationFromExportWrapper(node) {
|
|
|
1180
1184
|
if (node.type === AST_NODE_TYPES.ExportDefaultDeclaration) return node.declaration;
|
|
1181
1185
|
return node;
|
|
1182
1186
|
}
|
|
1183
|
-
const jsxNoSubInterface = createRule$
|
|
1187
|
+
const jsxNoSubInterface = createRule$19({
|
|
1184
1188
|
name: "jsx-no-sub-interface",
|
|
1185
1189
|
meta: {
|
|
1186
1190
|
type: "problem",
|
|
@@ -1247,13 +1251,13 @@ const jsxNoSubInterface = createRule$20({
|
|
|
1247
1251
|
});
|
|
1248
1252
|
//#endregion
|
|
1249
1253
|
//#region src/rules/jsx-no-ternary-null.ts
|
|
1250
|
-
const createRule$
|
|
1254
|
+
const createRule$18 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1251
1255
|
function isNullOrUndefined(node) {
|
|
1252
1256
|
if (node.type === AST_NODE_TYPES.Literal && node.value === null) return true;
|
|
1253
1257
|
if (node.type === AST_NODE_TYPES.Identifier && node.name === "undefined") return true;
|
|
1254
1258
|
return false;
|
|
1255
1259
|
}
|
|
1256
|
-
const jsxNoTernaryNull = createRule$
|
|
1260
|
+
const jsxNoTernaryNull = createRule$18({
|
|
1257
1261
|
name: "jsx-no-ternary-null",
|
|
1258
1262
|
meta: {
|
|
1259
1263
|
type: "suggestion",
|
|
@@ -1264,6 +1268,7 @@ const jsxNoTernaryNull = createRule$19({
|
|
|
1264
1268
|
},
|
|
1265
1269
|
defaultOptions: [],
|
|
1266
1270
|
create(context) {
|
|
1271
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1267
1272
|
return { JSXExpressionContainer(node) {
|
|
1268
1273
|
const { expression } = node;
|
|
1269
1274
|
if (expression.type !== AST_NODE_TYPES.ConditionalExpression) return;
|
|
@@ -1304,6 +1309,7 @@ const jsxNoVariableInCallback = ESLintUtils.RuleCreator((name) => `https://githu
|
|
|
1304
1309
|
},
|
|
1305
1310
|
defaultOptions: [],
|
|
1306
1311
|
create(context) {
|
|
1312
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1307
1313
|
function isInsideJSX(node) {
|
|
1308
1314
|
let current = node.parent;
|
|
1309
1315
|
while (current) {
|
|
@@ -1350,6 +1356,7 @@ const jsxRequireSuspense = ESLintUtils.RuleCreator((name) => `https://github.com
|
|
|
1350
1356
|
},
|
|
1351
1357
|
defaultOptions: [],
|
|
1352
1358
|
create(context) {
|
|
1359
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1353
1360
|
const lazyComponents = /* @__PURE__ */ new Set();
|
|
1354
1361
|
const isInsideSuspense = (node) => {
|
|
1355
1362
|
let current = node.parent;
|
|
@@ -1391,6 +1398,7 @@ const jsxSimpleProps = ESLintUtils.RuleCreator((name) => `https://github.com/nex
|
|
|
1391
1398
|
},
|
|
1392
1399
|
defaultOptions: [],
|
|
1393
1400
|
create(context) {
|
|
1401
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1394
1402
|
const allowedExpressionTypes = new Set([
|
|
1395
1403
|
AST_NODE_TYPES.Identifier,
|
|
1396
1404
|
AST_NODE_TYPES.Literal,
|
|
@@ -1416,7 +1424,7 @@ const jsxSimpleProps = ESLintUtils.RuleCreator((name) => `https://github.com/nex
|
|
|
1416
1424
|
});
|
|
1417
1425
|
//#endregion
|
|
1418
1426
|
//#region src/rules/jsx-sort-props.ts
|
|
1419
|
-
const createRule$
|
|
1427
|
+
const createRule$17 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1420
1428
|
const TYPE_GROUP = {
|
|
1421
1429
|
STRING: 1,
|
|
1422
1430
|
HYPHENATED_STRING: 2,
|
|
@@ -1499,7 +1507,7 @@ function getSegments(attributes) {
|
|
|
1499
1507
|
if (current.length > 0) result.push(current);
|
|
1500
1508
|
return result;
|
|
1501
1509
|
}
|
|
1502
|
-
const jsxSortProps = createRule$
|
|
1510
|
+
const jsxSortProps = createRule$17({
|
|
1503
1511
|
name: "jsx-sort-props",
|
|
1504
1512
|
meta: {
|
|
1505
1513
|
type: "suggestion",
|
|
@@ -1510,6 +1518,7 @@ const jsxSortProps = createRule$18({
|
|
|
1510
1518
|
},
|
|
1511
1519
|
defaultOptions: [],
|
|
1512
1520
|
create(context) {
|
|
1521
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1513
1522
|
const { sourceCode } = context;
|
|
1514
1523
|
return { JSXOpeningElement(node) {
|
|
1515
1524
|
if (!hasUnsortedProps(node.attributes)) return;
|
|
@@ -1535,6 +1544,7 @@ const jsxSpreadPropsLast = ESLintUtils.RuleCreator((name) => `https://github.com
|
|
|
1535
1544
|
},
|
|
1536
1545
|
defaultOptions: [],
|
|
1537
1546
|
create(context) {
|
|
1547
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1538
1548
|
return { JSXOpeningElement(node) {
|
|
1539
1549
|
const { attributes } = node;
|
|
1540
1550
|
let lastNonSpreadIndex = -1;
|
|
@@ -1552,7 +1562,7 @@ const jsxSpreadPropsLast = ESLintUtils.RuleCreator((name) => `https://github.com
|
|
|
1552
1562
|
});
|
|
1553
1563
|
//#endregion
|
|
1554
1564
|
//#region src/rules/newline-after-multiline-block.ts
|
|
1555
|
-
const createRule$
|
|
1565
|
+
const createRule$16 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1556
1566
|
function isImportDeclaration(node) {
|
|
1557
1567
|
return node.type === AST_NODE_TYPES.ImportDeclaration;
|
|
1558
1568
|
}
|
|
@@ -1577,7 +1587,7 @@ function checkStatements(statements, context) {
|
|
|
1577
1587
|
});
|
|
1578
1588
|
});
|
|
1579
1589
|
}
|
|
1580
|
-
const newlineAfterMultilineBlock = createRule$
|
|
1590
|
+
const newlineAfterMultilineBlock = createRule$16({
|
|
1581
1591
|
name: "newline-after-multiline-block",
|
|
1582
1592
|
meta: {
|
|
1583
1593
|
type: "layout",
|
|
@@ -1763,12 +1773,12 @@ const noEnvFallback = ESLintUtils.RuleCreator((name) => `https://github.com/next
|
|
|
1763
1773
|
});
|
|
1764
1774
|
//#endregion
|
|
1765
1775
|
//#region src/rules/no-ghost-wrapper.ts
|
|
1766
|
-
const createRule$
|
|
1776
|
+
const createRule$15 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1767
1777
|
const GHOST_TAGS = new Set(["div", "span"]);
|
|
1768
1778
|
function isKeyAttribute(attribute) {
|
|
1769
1779
|
return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.type === AST_NODE_TYPES.JSXIdentifier && attribute.name.name === "key";
|
|
1770
1780
|
}
|
|
1771
|
-
const noGhostWrapper = createRule$
|
|
1781
|
+
const noGhostWrapper = createRule$15({
|
|
1772
1782
|
name: "no-ghost-wrapper",
|
|
1773
1783
|
meta: {
|
|
1774
1784
|
type: "problem",
|
|
@@ -1778,6 +1788,7 @@ const noGhostWrapper = createRule$16({
|
|
|
1778
1788
|
},
|
|
1779
1789
|
defaultOptions: [],
|
|
1780
1790
|
create(context) {
|
|
1791
|
+
if (!isJsxFile(context.filename)) return {};
|
|
1781
1792
|
return { JSXOpeningElement(node) {
|
|
1782
1793
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) return;
|
|
1783
1794
|
const tagName = node.name.name;
|
|
@@ -1802,6 +1813,8 @@ const noHelperFunctionInHook = ESLintUtils.RuleCreator((name) => `https://github
|
|
|
1802
1813
|
},
|
|
1803
1814
|
defaultOptions: [],
|
|
1804
1815
|
create(context) {
|
|
1816
|
+
const basename = path.basename(context.filename);
|
|
1817
|
+
if (!(basename.endsWith(".hook.ts") || basename.endsWith(".hooks.ts"))) return {};
|
|
1805
1818
|
function isAtProgramLevel(node) {
|
|
1806
1819
|
const { parent } = node;
|
|
1807
1820
|
if (parent === void 0) return false;
|
|
@@ -1843,6 +1856,8 @@ const noHelperFunctionInTest = ESLintUtils.RuleCreator((name) => `https://github
|
|
|
1843
1856
|
},
|
|
1844
1857
|
defaultOptions: [],
|
|
1845
1858
|
create(context) {
|
|
1859
|
+
const basename = path.basename(context.filename);
|
|
1860
|
+
if (!(basename.endsWith(".test.ts") || basename.endsWith(".test.tsx"))) return {};
|
|
1846
1861
|
return {
|
|
1847
1862
|
FunctionDeclaration(node) {
|
|
1848
1863
|
if (node.parent.type === AST_NODE_TYPES.Program) context.report({
|
|
@@ -1935,7 +1950,7 @@ const noInlineDefaultExport = ESLintUtils.RuleCreator((name) => `https://github.
|
|
|
1935
1950
|
});
|
|
1936
1951
|
//#endregion
|
|
1937
1952
|
//#region src/rules/no-inline-nested-object.ts
|
|
1938
|
-
const createRule$
|
|
1953
|
+
const createRule$14 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
1939
1954
|
function isObjectOrArray(node) {
|
|
1940
1955
|
return node.type === AST_NODE_TYPES.ObjectExpression || node.type === AST_NODE_TYPES.ArrayExpression || node.type === AST_NODE_TYPES.TSAsExpression;
|
|
1941
1956
|
}
|
|
@@ -1957,7 +1972,7 @@ function containsNestedStructure(node) {
|
|
|
1957
1972
|
return isNestedStructure(el);
|
|
1958
1973
|
});
|
|
1959
1974
|
}
|
|
1960
|
-
const noInlineNestedObject = createRule$
|
|
1975
|
+
const noInlineNestedObject = createRule$14({
|
|
1961
1976
|
name: "no-inline-nested-object",
|
|
1962
1977
|
meta: {
|
|
1963
1978
|
type: "layout",
|
|
@@ -1999,13 +2014,13 @@ const noInlineNestedObject = createRule$15({
|
|
|
1999
2014
|
});
|
|
2000
2015
|
//#endregion
|
|
2001
2016
|
//#region src/rules/no-inline-return-properties.ts
|
|
2002
|
-
const createRule$
|
|
2017
|
+
const createRule$13 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2003
2018
|
const isShorthandProperty = (property) => {
|
|
2004
2019
|
if (property.type === AST_NODE_TYPES.SpreadElement) return true;
|
|
2005
2020
|
if (property.type !== AST_NODE_TYPES.Property) return false;
|
|
2006
2021
|
return property.shorthand;
|
|
2007
2022
|
};
|
|
2008
|
-
const noInlineReturnProperties = createRule$
|
|
2023
|
+
const noInlineReturnProperties = createRule$13({
|
|
2009
2024
|
name: "no-inline-return-properties",
|
|
2010
2025
|
meta: {
|
|
2011
2026
|
type: "suggestion",
|
|
@@ -2034,9 +2049,9 @@ const noInlineReturnProperties = createRule$14({
|
|
|
2034
2049
|
});
|
|
2035
2050
|
//#endregion
|
|
2036
2051
|
//#region src/rules/no-inline-type-import.ts
|
|
2037
|
-
const createRule$
|
|
2052
|
+
const createRule$12 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2038
2053
|
const isInlineTypeSpecifier = (specifier) => specifier.type === AST_NODE_TYPES.ImportSpecifier && specifier.importKind === "type";
|
|
2039
|
-
const noInlineTypeImport = createRule$
|
|
2054
|
+
const noInlineTypeImport = createRule$12({
|
|
2040
2055
|
name: "no-inline-type-import",
|
|
2041
2056
|
meta: {
|
|
2042
2057
|
type: "suggestion",
|
|
@@ -2078,7 +2093,7 @@ const noInlineTypeImport = createRule$13({
|
|
|
2078
2093
|
});
|
|
2079
2094
|
//#endregion
|
|
2080
2095
|
//#region src/rules/no-lazy-identifiers.ts
|
|
2081
|
-
const createRule$
|
|
2096
|
+
const createRule$11 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2082
2097
|
const KEYBOARD_ROWS = [
|
|
2083
2098
|
"qwertyuiop",
|
|
2084
2099
|
"asdfghjkl",
|
|
@@ -2109,7 +2124,7 @@ const isLazyIdentifier = (name) => {
|
|
|
2109
2124
|
if (hasKeyboardSequence(name)) return true;
|
|
2110
2125
|
return false;
|
|
2111
2126
|
};
|
|
2112
|
-
const noLazyIdentifiers = createRule$
|
|
2127
|
+
const noLazyIdentifiers = createRule$11({
|
|
2113
2128
|
name: "no-lazy-identifiers",
|
|
2114
2129
|
meta: {
|
|
2115
2130
|
type: "problem",
|
|
@@ -2228,7 +2243,7 @@ const noLogicInParams = ESLintUtils.RuleCreator((name) => `https://github.com/ne
|
|
|
2228
2243
|
});
|
|
2229
2244
|
//#endregion
|
|
2230
2245
|
//#region src/rules/no-misleading-constant-case.ts
|
|
2231
|
-
const createRule$
|
|
2246
|
+
const createRule$10 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2232
2247
|
const SCREAMING_SNAKE_CASE_REGEX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
|
|
2233
2248
|
const isAsConstAssertion = (node) => node.type === AST_NODE_TYPES.TSAsExpression && node.typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && node.typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && node.typeAnnotation.typeName.name === "const";
|
|
2234
2249
|
const isStaticValue = (init) => {
|
|
@@ -2246,7 +2261,7 @@ const isGlobalScope = (node) => {
|
|
|
2246
2261
|
if (parent.type === AST_NODE_TYPES.ExportNamedDeclaration && parent.parent?.type === AST_NODE_TYPES.Program) return true;
|
|
2247
2262
|
return false;
|
|
2248
2263
|
};
|
|
2249
|
-
const noMisleadingConstantCase = createRule$
|
|
2264
|
+
const noMisleadingConstantCase = createRule$10({
|
|
2250
2265
|
name: "no-misleading-constant-case",
|
|
2251
2266
|
meta: {
|
|
2252
2267
|
type: "suggestion",
|
|
@@ -2360,7 +2375,7 @@ const noNestedTernary = ESLintUtils.RuleCreator((name) => `https://github.com/ne
|
|
|
2360
2375
|
});
|
|
2361
2376
|
//#endregion
|
|
2362
2377
|
//#region src/rules/no-redundant-fragment.ts
|
|
2363
|
-
const createRule$
|
|
2378
|
+
const createRule$9 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2364
2379
|
function isFragmentName(name) {
|
|
2365
2380
|
if (name.type === AST_NODE_TYPES.JSXIdentifier && name.name === "Fragment") return true;
|
|
2366
2381
|
if (name.type === AST_NODE_TYPES.JSXMemberExpression && name.object.type === AST_NODE_TYPES.JSXIdentifier && name.object.name === "React" && name.property.type === AST_NODE_TYPES.JSXIdentifier && name.property.name === "Fragment") return true;
|
|
@@ -2375,7 +2390,7 @@ function countMeaningfulChildren(children) {
|
|
|
2375
2390
|
return true;
|
|
2376
2391
|
}).length;
|
|
2377
2392
|
}
|
|
2378
|
-
const noRedundantFragment = createRule$
|
|
2393
|
+
const noRedundantFragment = createRule$9({
|
|
2379
2394
|
name: "no-redundant-fragment",
|
|
2380
2395
|
meta: {
|
|
2381
2396
|
type: "problem",
|
|
@@ -2385,6 +2400,7 @@ const noRedundantFragment = createRule$10({
|
|
|
2385
2400
|
},
|
|
2386
2401
|
defaultOptions: [],
|
|
2387
2402
|
create(context) {
|
|
2403
|
+
if (!isJsxFile(context.filename)) return {};
|
|
2388
2404
|
return {
|
|
2389
2405
|
JSXFragment(node) {
|
|
2390
2406
|
const count = countMeaningfulChildren(node.children);
|
|
@@ -2444,7 +2460,7 @@ const noRelativeImports = ESLintUtils.RuleCreator((name) => `https://github.com/
|
|
|
2444
2460
|
});
|
|
2445
2461
|
//#endregion
|
|
2446
2462
|
//#region src/rules/no-single-char-variables.ts
|
|
2447
|
-
const createRule$
|
|
2463
|
+
const createRule$8 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2448
2464
|
const ALLOWED_IN_FOR_LOOPS = new Set([
|
|
2449
2465
|
"i",
|
|
2450
2466
|
"j",
|
|
@@ -2470,7 +2486,7 @@ const isAllowedInContext = (name, node) => {
|
|
|
2470
2486
|
if (ALLOWED_IN_FOR_LOOPS.has(name) && isForLoopInit(node)) return true;
|
|
2471
2487
|
return false;
|
|
2472
2488
|
};
|
|
2473
|
-
const noSingleCharVariables = createRule$
|
|
2489
|
+
const noSingleCharVariables = createRule$8({
|
|
2474
2490
|
name: "no-single-char-variables",
|
|
2475
2491
|
meta: {
|
|
2476
2492
|
type: "suggestion",
|
|
@@ -2592,7 +2608,7 @@ const preferDestructuringParams = ESLintUtils.RuleCreator((name) => `https://git
|
|
|
2592
2608
|
});
|
|
2593
2609
|
//#endregion
|
|
2594
2610
|
//#region src/rules/prefer-function-declaration.ts
|
|
2595
|
-
const createRule$
|
|
2611
|
+
const createRule$7 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2596
2612
|
const isTsFile = (filename) => filename.endsWith(".ts") && !filename.endsWith(".d.ts");
|
|
2597
2613
|
const isCallbackContext = (node) => {
|
|
2598
2614
|
const { parent } = node;
|
|
@@ -2607,7 +2623,7 @@ const isCallbackContext = (node) => {
|
|
|
2607
2623
|
if (parent.type === AST_NODE_TYPES.AssignmentExpression && parent.left !== node) return true;
|
|
2608
2624
|
return false;
|
|
2609
2625
|
};
|
|
2610
|
-
const preferFunctionDeclaration = createRule$
|
|
2626
|
+
const preferFunctionDeclaration = createRule$7({
|
|
2611
2627
|
name: "prefer-function-declaration",
|
|
2612
2628
|
meta: {
|
|
2613
2629
|
type: "suggestion",
|
|
@@ -2722,6 +2738,7 @@ const preferImportType = ESLintUtils.RuleCreator((name) => `https://github.com/n
|
|
|
2722
2738
|
switch (parent.type) {
|
|
2723
2739
|
case AST_NODE_TYPES.CallExpression:
|
|
2724
2740
|
case AST_NODE_TYPES.NewExpression:
|
|
2741
|
+
case AST_NODE_TYPES.JSXMemberExpression:
|
|
2725
2742
|
case AST_NODE_TYPES.JSXOpeningElement:
|
|
2726
2743
|
case AST_NODE_TYPES.JSXClosingElement:
|
|
2727
2744
|
case AST_NODE_TYPES.MemberExpression:
|
|
@@ -2775,12 +2792,12 @@ const preferImportType = ESLintUtils.RuleCreator((name) => `https://github.com/n
|
|
|
2775
2792
|
});
|
|
2776
2793
|
//#endregion
|
|
2777
2794
|
//#region src/rules/prefer-inline-literal-union.ts
|
|
2778
|
-
const createRule$
|
|
2795
|
+
const createRule$6 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2779
2796
|
function isLiteralUnionType(node) {
|
|
2780
2797
|
if (node.type !== AST_NODE_TYPES.TSUnionType) return false;
|
|
2781
2798
|
return node.types.every((member) => member.type === AST_NODE_TYPES.TSLiteralType || member.type === AST_NODE_TYPES.TSNullKeyword || member.type === AST_NODE_TYPES.TSUndefinedKeyword);
|
|
2782
2799
|
}
|
|
2783
|
-
const preferInlineLiteralUnion = createRule$
|
|
2800
|
+
const preferInlineLiteralUnion = createRule$6({
|
|
2784
2801
|
name: "prefer-inline-literal-union",
|
|
2785
2802
|
meta: {
|
|
2786
2803
|
type: "suggestion",
|
|
@@ -2818,65 +2835,6 @@ const preferInlineLiteralUnion = createRule$7({
|
|
|
2818
2835
|
}
|
|
2819
2836
|
});
|
|
2820
2837
|
//#endregion
|
|
2821
|
-
//#region src/rules/prefer-inline-type-export.ts
|
|
2822
|
-
const createRule$6 = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`);
|
|
2823
|
-
const isTypeDeclaration = (node) => node.type === AST_NODE_TYPES.TSInterfaceDeclaration || node.type === AST_NODE_TYPES.TSTypeAliasDeclaration;
|
|
2824
|
-
const preferInlineTypeExport = createRule$6({
|
|
2825
|
-
name: "prefer-inline-type-export",
|
|
2826
|
-
meta: {
|
|
2827
|
-
type: "suggestion",
|
|
2828
|
-
docs: { description: "Require type and interface declarations to be exported inline rather than via a separate export statement" },
|
|
2829
|
-
fixable: "code",
|
|
2830
|
-
messages: { preferInlineExport: "Export '{{name}}' inline at its declaration instead of using a separate export statement." },
|
|
2831
|
-
schema: []
|
|
2832
|
-
},
|
|
2833
|
-
defaultOptions: [],
|
|
2834
|
-
create(context) {
|
|
2835
|
-
const typeDeclarations = /* @__PURE__ */ new Map();
|
|
2836
|
-
function collectDeclaration(node) {
|
|
2837
|
-
if (node.parent.type !== AST_NODE_TYPES.ExportNamedDeclaration) typeDeclarations.set(node.id.name, node);
|
|
2838
|
-
}
|
|
2839
|
-
function reportSpecifier(specifier, statement, declarationNode) {
|
|
2840
|
-
if (specifier.local.type !== AST_NODE_TYPES.Identifier) return;
|
|
2841
|
-
const { name } = specifier.local;
|
|
2842
|
-
context.report({
|
|
2843
|
-
node: specifier,
|
|
2844
|
-
messageId: "preferInlineExport",
|
|
2845
|
-
data: { name },
|
|
2846
|
-
fix(fixer) {
|
|
2847
|
-
const { sourceCode } = context;
|
|
2848
|
-
const declarationToken = sourceCode.getFirstToken(declarationNode);
|
|
2849
|
-
if (!declarationToken) return null;
|
|
2850
|
-
if (statement.specifiers.length === 1) {
|
|
2851
|
-
const nextToken = sourceCode.getTokenAfter(statement);
|
|
2852
|
-
const end = nextToken ? nextToken.range[0] : statement.range[1];
|
|
2853
|
-
return [fixer.insertTextBefore(declarationToken, "export "), fixer.removeRange([statement.range[0], end])];
|
|
2854
|
-
}
|
|
2855
|
-
const tokenBefore = sourceCode.getTokenBefore(specifier);
|
|
2856
|
-
const tokenAfter = sourceCode.getTokenAfter(specifier);
|
|
2857
|
-
if (!tokenBefore || !tokenAfter) return null;
|
|
2858
|
-
const removalRange = statement.specifiers.at(-1) === specifier && tokenBefore.value === "," ? [tokenBefore.range[0], specifier.range[1]] : [specifier.range[0], tokenAfter.range[1]];
|
|
2859
|
-
return [fixer.insertTextBefore(declarationToken, "export "), fixer.removeRange(removalRange)];
|
|
2860
|
-
}
|
|
2861
|
-
});
|
|
2862
|
-
}
|
|
2863
|
-
return { Program(node) {
|
|
2864
|
-
node.body.forEach((statement) => {
|
|
2865
|
-
if (statement.type === AST_NODE_TYPES.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES.TSTypeAliasDeclaration) collectDeclaration(statement);
|
|
2866
|
-
});
|
|
2867
|
-
node.body.forEach((statement) => {
|
|
2868
|
-
if (statement.type !== AST_NODE_TYPES.ExportNamedDeclaration || statement.declaration !== null) return;
|
|
2869
|
-
statement.specifiers.forEach((specifier) => {
|
|
2870
|
-
if (specifier.local.type !== AST_NODE_TYPES.Identifier) return;
|
|
2871
|
-
const declarationNode = typeDeclarations.get(specifier.local.name);
|
|
2872
|
-
if (!declarationNode || !isTypeDeclaration(declarationNode)) return;
|
|
2873
|
-
reportSpecifier(specifier, statement, declarationNode);
|
|
2874
|
-
});
|
|
2875
|
-
});
|
|
2876
|
-
} };
|
|
2877
|
-
}
|
|
2878
|
-
});
|
|
2879
|
-
//#endregion
|
|
2880
2838
|
//#region src/rules/prefer-interface-for-component-props.ts
|
|
2881
2839
|
const preferInterfaceForComponentProps = ESLintUtils.RuleCreator((name) => `https://github.com/next-friday/eslint-plugin-nextfriday/blob/main/docs/rules/${name.replaceAll("-", "_").toUpperCase()}.md`)({
|
|
2882
2840
|
name: "prefer-interface-for-component-props",
|
|
@@ -2989,6 +2947,7 @@ const preferJSXTemplateLiterals = ESLintUtils.RuleCreator((name) => `https://git
|
|
|
2989
2947
|
},
|
|
2990
2948
|
defaultOptions: [],
|
|
2991
2949
|
create(context) {
|
|
2950
|
+
if (!isJsxFile(context.filename)) return {};
|
|
2992
2951
|
function handleTextBeforeExpression(textNode, exprNode) {
|
|
2993
2952
|
const textValue = textNode.value;
|
|
2994
2953
|
const trimmedText = textValue.trim();
|
|
@@ -3096,10 +3055,11 @@ const preferPropsWithChildren = ESLintUtils.RuleCreator((name) => `https://githu
|
|
|
3096
3055
|
type: "suggestion",
|
|
3097
3056
|
docs: { description: "Prefer PropsWithChildren<T> over manually declaring children: ReactNode in component props" },
|
|
3098
3057
|
schema: [],
|
|
3099
|
-
messages: { usePropsWithChildren: "Use 'PropsWithChildren<T>' instead of manually declaring 'children
|
|
3058
|
+
messages: { usePropsWithChildren: "Use 'PropsWithChildren<T>' instead of manually declaring 'children?: ReactNode'." }
|
|
3100
3059
|
},
|
|
3101
3060
|
defaultOptions: [],
|
|
3102
3061
|
create(context) {
|
|
3062
|
+
if (!isJsxFile(context.filename)) return {};
|
|
3103
3063
|
function isReactNodeType(typeNode) {
|
|
3104
3064
|
if (!typeNode) return false;
|
|
3105
3065
|
if (typeNode.type !== AST_NODE_TYPES.TSTypeReference) return false;
|
|
@@ -3114,7 +3074,7 @@ const preferPropsWithChildren = ESLintUtils.RuleCreator((name) => `https://githu
|
|
|
3114
3074
|
if (member.key.type !== AST_NODE_TYPES.Identifier) continue;
|
|
3115
3075
|
if (member.key.name !== "children") continue;
|
|
3116
3076
|
if (!member.typeAnnotation) continue;
|
|
3117
|
-
if (isReactNodeType(member.typeAnnotation.typeAnnotation)) return member;
|
|
3077
|
+
if (member.optional && isReactNodeType(member.typeAnnotation.typeAnnotation)) return member;
|
|
3118
3078
|
}
|
|
3119
3079
|
}
|
|
3120
3080
|
return {
|
|
@@ -3148,6 +3108,7 @@ const preferReactImportTypes = ESLintUtils.RuleCreator((name) => `https://github
|
|
|
3148
3108
|
},
|
|
3149
3109
|
defaultOptions: [],
|
|
3150
3110
|
create(context) {
|
|
3111
|
+
if (!isJsxFile(context.filename)) return {};
|
|
3151
3112
|
const reactTypes = new Set([
|
|
3152
3113
|
"ReactNode",
|
|
3153
3114
|
"ReactElement",
|
|
@@ -3260,6 +3221,7 @@ const reactPropsDestructure = ESLintUtils.RuleCreator((name) => `https://github.
|
|
|
3260
3221
|
},
|
|
3261
3222
|
defaultOptions: [],
|
|
3262
3223
|
create(context) {
|
|
3224
|
+
if (!isJsxFile(context.filename)) return {};
|
|
3263
3225
|
function hasJSXInConditional(node) {
|
|
3264
3226
|
return node.consequent.type === AST_NODE_TYPES.JSXElement || node.consequent.type === AST_NODE_TYPES.JSXFragment || node.alternate.type === AST_NODE_TYPES.JSXElement || node.alternate.type === AST_NODE_TYPES.JSXFragment;
|
|
3265
3227
|
}
|
|
@@ -3729,7 +3691,6 @@ const rules = {
|
|
|
3729
3691
|
"prefer-guard-clause": preferGuardClause,
|
|
3730
3692
|
"prefer-import-type": preferImportType,
|
|
3731
3693
|
"prefer-inline-literal-union": preferInlineLiteralUnion,
|
|
3732
|
-
"prefer-inline-type-export": preferInlineTypeExport,
|
|
3733
3694
|
"prefer-interface-for-component-props": preferInterfaceForComponentProps,
|
|
3734
3695
|
"prefer-interface-over-inline-types": preferInterfaceOverInlineTypes,
|
|
3735
3696
|
"prefer-jsx-template-literals": preferJSXTemplateLiterals,
|
|
@@ -3765,6 +3726,8 @@ const baseRules = {
|
|
|
3765
3726
|
"nextfriday/no-direct-date": "warn",
|
|
3766
3727
|
"nextfriday/no-emoji": "warn",
|
|
3767
3728
|
"nextfriday/no-env-fallback": "warn",
|
|
3729
|
+
"nextfriday/no-helper-function-in-hook": "warn",
|
|
3730
|
+
"nextfriday/no-helper-function-in-test": "warn",
|
|
3768
3731
|
"nextfriday/no-inline-default-export": "warn",
|
|
3769
3732
|
"nextfriday/no-inline-nested-object": "warn",
|
|
3770
3733
|
"nextfriday/no-inline-return-properties": "warn",
|
|
@@ -3782,7 +3745,6 @@ const baseRules = {
|
|
|
3782
3745
|
"nextfriday/prefer-guard-clause": "warn",
|
|
3783
3746
|
"nextfriday/prefer-import-type": "warn",
|
|
3784
3747
|
"nextfriday/prefer-inline-literal-union": "warn",
|
|
3785
|
-
"nextfriday/prefer-inline-type-export": "warn",
|
|
3786
3748
|
"nextfriday/prefer-named-param-types": "warn",
|
|
3787
3749
|
"nextfriday/prefer-react-import-types": "warn",
|
|
3788
3750
|
"nextfriday/require-explicit-return-type": "warn",
|
|
@@ -3809,6 +3771,8 @@ const baseRecommendedRules = {
|
|
|
3809
3771
|
"nextfriday/no-direct-date": "error",
|
|
3810
3772
|
"nextfriday/no-emoji": "error",
|
|
3811
3773
|
"nextfriday/no-env-fallback": "error",
|
|
3774
|
+
"nextfriday/no-helper-function-in-hook": "error",
|
|
3775
|
+
"nextfriday/no-helper-function-in-test": "error",
|
|
3812
3776
|
"nextfriday/no-inline-default-export": "error",
|
|
3813
3777
|
"nextfriday/no-inline-nested-object": "error",
|
|
3814
3778
|
"nextfriday/no-inline-return-properties": "error",
|
|
@@ -3826,7 +3790,6 @@ const baseRecommendedRules = {
|
|
|
3826
3790
|
"nextfriday/prefer-guard-clause": "error",
|
|
3827
3791
|
"nextfriday/prefer-import-type": "error",
|
|
3828
3792
|
"nextfriday/prefer-inline-literal-union": "error",
|
|
3829
|
-
"nextfriday/prefer-inline-type-export": "error",
|
|
3830
3793
|
"nextfriday/prefer-named-param-types": "error",
|
|
3831
3794
|
"nextfriday/prefer-react-import-types": "error",
|
|
3832
3795
|
"nextfriday/require-explicit-return-type": "error",
|