eslint-plugin-typefest 1.2.0 → 1.2.2
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 +6 -0
- package/dist/_internal/rule-catalog.d.ts.map +1 -1
- package/dist/_internal/rule-catalog.js +6 -0
- package/dist/_internal/rule-catalog.js.map +1 -1
- package/dist/_internal/rules-registry.d.ts.map +1 -1
- package/dist/_internal/rules-registry.js +12 -0
- package/dist/_internal/rules-registry.js.map +1 -1
- package/dist/plugin.cjs +488 -53
- package/dist/plugin.cjs.map +4 -4
- package/dist/rules/prefer-ts-extras-assert-never.d.ts +13 -0
- package/dist/rules/prefer-ts-extras-assert-never.d.ts.map +1 -0
- package/dist/rules/prefer-ts-extras-assert-never.js +116 -0
- package/dist/rules/prefer-ts-extras-assert-never.js.map +1 -0
- package/dist/rules/prefer-ts-extras-is-property-defined.d.ts +13 -0
- package/dist/rules/prefer-ts-extras-is-property-defined.d.ts.map +1 -0
- package/dist/rules/prefer-ts-extras-is-property-defined.js +160 -0
- package/dist/rules/prefer-ts-extras-is-property-defined.js.map +1 -0
- package/dist/rules/prefer-ts-extras-is-property-present.d.ts +13 -0
- package/dist/rules/prefer-ts-extras-is-property-present.d.ts.map +1 -0
- package/dist/rules/prefer-ts-extras-is-property-present.js +114 -0
- package/dist/rules/prefer-ts-extras-is-property-present.js.map +1 -0
- package/dist/rules/prefer-type-fest-absolute.d.ts +13 -0
- package/dist/rules/prefer-type-fest-absolute.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-absolute.js +67 -0
- package/dist/rules/prefer-type-fest-absolute.js.map +1 -0
- package/dist/rules/prefer-type-fest-non-nullable-deep.d.ts +13 -0
- package/dist/rules/prefer-type-fest-non-nullable-deep.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-non-nullable-deep.js +58 -0
- package/dist/rules/prefer-type-fest-non-nullable-deep.js.map +1 -0
- package/dist/rules/prefer-type-fest-union-length.d.ts +13 -0
- package/dist/rules/prefer-type-fest-union-length.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-union-length.js +75 -0
- package/dist/rules/prefer-type-fest-union-length.js.map +1 -0
- package/docs/rules/prefer-ts-extras-assert-never.md +112 -0
- package/docs/rules/prefer-ts-extras-is-property-defined.md +119 -0
- package/docs/rules/prefer-ts-extras-is-property-present.md +118 -0
- package/docs/rules/prefer-type-fest-absolute.md +99 -0
- package/docs/rules/prefer-type-fest-non-nullable-deep.md +105 -0
- package/docs/rules/prefer-type-fest-union-length.md +100 -0
- package/docs/rules/presets/all.md +6 -0
- package/docs/rules/presets/experimental.md +6 -0
- package/docs/rules/presets/index.md +6 -0
- package/docs/rules/presets/minimal.md +2 -0
- package/docs/rules/presets/recommended-type-checked.md +6 -0
- package/docs/rules/presets/recommended.md +6 -0
- package/docs/rules/presets/strict.md +6 -0
- package/docs/rules/presets/ts-extras-type-guards.md +3 -0
- package/docs/rules/presets/type-fest-types.md +3 -0
- package/package.json +26 -21
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
2
|
+
/**
|
|
3
|
+
* ESLint rule definition for `prefer-ts-extras-assert-never`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
7
|
+
*/
|
|
8
|
+
declare const preferTsExtrasAssertNeverRule: ReturnType<typeof createTypedRule>;
|
|
9
|
+
/**
|
|
10
|
+
* Default export for the `prefer-ts-extras-assert-never` rule module.
|
|
11
|
+
*/
|
|
12
|
+
export default preferTsExtrasAssertNeverRule;
|
|
13
|
+
//# sourceMappingURL=prefer-ts-extras-assert-never.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-ts-extras-assert-never.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-ts-extras-assert-never.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;GAKG;AACH,QAAA,MAAM,6BAA6B,EAAE,UAAU,CAAC,OAAO,eAAe,CAyHhE,CAAC;AAEP;;GAEG;AACH,eAAe,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* ESLint rule implementation for `prefer-ts-extras-assert-never`.
|
|
4
|
+
*/
|
|
5
|
+
import { collectDirectNamedValueImportsFromSource, createSafeValueNodeTextReplacementFix, getFunctionCallArgumentText, } from "../_internal/imported-value-symbols.js";
|
|
6
|
+
import { TS_EXTRAS_MODULE_SOURCE } from "../_internal/module-source.js";
|
|
7
|
+
import { reportWithOptionalFix, reportWithTypefestPolicy, } from "../_internal/rule-reporting.js";
|
|
8
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
9
|
+
/**
|
|
10
|
+
* ESLint rule definition for `prefer-ts-extras-assert-never`.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
14
|
+
*/
|
|
15
|
+
const preferTsExtrasAssertNeverRule = createTypedRule({
|
|
16
|
+
create(context) {
|
|
17
|
+
const tsExtrasImports = collectDirectNamedValueImportsFromSource(context.sourceCode, TS_EXTRAS_MODULE_SOURCE);
|
|
18
|
+
return {
|
|
19
|
+
VariableDeclaration(node) {
|
|
20
|
+
// Only handle const statements with a single declarator
|
|
21
|
+
if (node.kind !== "const" ||
|
|
22
|
+
node.declarations.length !== 1) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const [declarator] = node.declarations;
|
|
26
|
+
// Guard: declarator must exist and have an Identifier id
|
|
27
|
+
if (declarator?.id.type !== "Identifier") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Guard: the id must have a `never` type annotation
|
|
31
|
+
const { typeAnnotation } = declarator.id;
|
|
32
|
+
if (typeAnnotation?.typeAnnotation.type !== "TSNeverKeyword") {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// Guard: there must be an initializer
|
|
36
|
+
const { init } = declarator;
|
|
37
|
+
if (!init) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const initArgumentText = getFunctionCallArgumentText({
|
|
41
|
+
argumentNode: init,
|
|
42
|
+
sourceCode: context.sourceCode,
|
|
43
|
+
});
|
|
44
|
+
if (initArgumentText === null) {
|
|
45
|
+
reportWithOptionalFix({
|
|
46
|
+
context,
|
|
47
|
+
fix: null,
|
|
48
|
+
messageId: "preferTsExtrasAssertNever",
|
|
49
|
+
node,
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const replacementFix = createSafeValueNodeTextReplacementFix({
|
|
54
|
+
context,
|
|
55
|
+
importedName: "assertNever",
|
|
56
|
+
imports: tsExtrasImports,
|
|
57
|
+
replacementTextFactory: (replacementName) => `${replacementName}(${initArgumentText})`,
|
|
58
|
+
reportFixIntent: "suggestion",
|
|
59
|
+
sourceModuleName: TS_EXTRAS_MODULE_SOURCE,
|
|
60
|
+
targetNode: node,
|
|
61
|
+
});
|
|
62
|
+
if (replacementFix === null) {
|
|
63
|
+
reportWithOptionalFix({
|
|
64
|
+
context,
|
|
65
|
+
fix: null,
|
|
66
|
+
messageId: "preferTsExtrasAssertNever",
|
|
67
|
+
node,
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
reportWithTypefestPolicy({
|
|
72
|
+
context,
|
|
73
|
+
descriptor: {
|
|
74
|
+
messageId: "preferTsExtrasAssertNever",
|
|
75
|
+
node,
|
|
76
|
+
suggest: [
|
|
77
|
+
{
|
|
78
|
+
fix: replacementFix,
|
|
79
|
+
messageId: "suggestTsExtrasAssertNever",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
meta: {
|
|
88
|
+
deprecated: false,
|
|
89
|
+
docs: {
|
|
90
|
+
description: "require ts-extras assertNever over manual `const _: never = value` exhaustiveness checks.",
|
|
91
|
+
frozen: false,
|
|
92
|
+
recommended: true,
|
|
93
|
+
requiresTypeChecking: false,
|
|
94
|
+
typefestConfigs: [
|
|
95
|
+
"typefest.configs.recommended",
|
|
96
|
+
"typefest.configs.strict",
|
|
97
|
+
"typefest.configs.all",
|
|
98
|
+
"typefest.configs.ts-extras/type-guards",
|
|
99
|
+
],
|
|
100
|
+
url: "https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-ts-extras-assert-never",
|
|
101
|
+
},
|
|
102
|
+
hasSuggestions: true,
|
|
103
|
+
messages: {
|
|
104
|
+
preferTsExtrasAssertNever: "Prefer `assertNever` from `ts-extras` over a manual `const _: never` exhaustiveness assertion.",
|
|
105
|
+
suggestTsExtrasAssertNever: "Replace this manual exhaustiveness check with `assertNever(...)` from `ts-extras`.",
|
|
106
|
+
},
|
|
107
|
+
schema: [],
|
|
108
|
+
type: "suggestion",
|
|
109
|
+
},
|
|
110
|
+
name: "prefer-ts-extras-assert-never",
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Default export for the `prefer-ts-extras-assert-never` rule module.
|
|
114
|
+
*/
|
|
115
|
+
export default preferTsExtrasAssertNeverRule;
|
|
116
|
+
//# sourceMappingURL=prefer-ts-extras-assert-never.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-ts-extras-assert-never.js","sourceRoot":"","sources":["../../src/rules/prefer-ts-extras-assert-never.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACH,wCAAwC,EACxC,qCAAqC,EACrC,2BAA2B,GAC9B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EACH,qBAAqB,EACrB,wBAAwB,GAC3B,MAAM,gCAAgC,CAAC;AACxC,OAAO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.js";
|
|
2
|
+
/**
|
|
3
|
+
* ESLint rule definition for `prefer-ts-extras-is-property-defined`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
7
|
+
*/
|
|
8
|
+
declare const preferTsExtrasIsPropertyDefinedRule: ReturnType<typeof createTypedRule>;
|
|
9
|
+
/**
|
|
10
|
+
* Default export for the `prefer-ts-extras-is-property-defined` rule module.
|
|
11
|
+
*/
|
|
12
|
+
export default preferTsExtrasIsPropertyDefinedRule;
|
|
13
|
+
//# sourceMappingURL=prefer-ts-extras-is-property-defined.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-ts-extras-is-property-defined.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-ts-extras-is-property-defined.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,eAAe,EAElB,MAAM,4BAA4B,CAAC;AAwIpC;;;;;GAKG;AACH,QAAA,MAAM,mCAAmC,EAAE,UAAU,CAAC,OAAO,eAAe,CA0EtE,CAAC;AAEP;;GAEG;AACH,eAAe,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { getSingleParameterExpressionArrowFilterCallback } from "../_internal/filter-callback.js";
|
|
2
|
+
import { collectDirectNamedValueImportsFromSource, createSafeValueNodeTextReplacementFix, } from "../_internal/imported-value-symbols.js";
|
|
3
|
+
import { TS_EXTRAS_MODULE_SOURCE } from "../_internal/module-source.js";
|
|
4
|
+
import { reportWithOptionalFix } from "../_internal/rule-reporting.js";
|
|
5
|
+
import { createTypedRule, isGlobalUndefinedIdentifier, } from "../_internal/typed-rule.js";
|
|
6
|
+
/**
|
|
7
|
+
* Extract the property name from a `typeof param.prop !== "undefined"` (or
|
|
8
|
+
* reversed) check, returning `null` when the shape does not match.
|
|
9
|
+
*
|
|
10
|
+
* @param typeofSide - Expected `typeof` unary expression side.
|
|
11
|
+
* @param stringSide - Expected `"undefined"` string literal side.
|
|
12
|
+
* @param operator - Binary expression operator.
|
|
13
|
+
* @param paramName - Expected parameter identifier name.
|
|
14
|
+
*
|
|
15
|
+
* @returns Property name when matched; otherwise `null`.
|
|
16
|
+
*/
|
|
17
|
+
const extractTypeofPropertyDefinedCheck = (typeofSide, stringSide, operator, paramName) => {
|
|
18
|
+
// Typeof checks are always strict
|
|
19
|
+
if (operator !== "!==") {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (typeofSide.type !== "UnaryExpression" ||
|
|
23
|
+
typeofSide.operator !== "typeof") {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const { argument } = typeofSide;
|
|
27
|
+
if (argument.type !== "MemberExpression" ||
|
|
28
|
+
argument.computed ||
|
|
29
|
+
argument.object.type !== "Identifier" ||
|
|
30
|
+
argument.object.name !== paramName ||
|
|
31
|
+
argument.property.type !== "Identifier") {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (stringSide.type !== "Literal" || stringSide.value !== "undefined") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return argument.property.name;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Determine whether an arrow-callback body is a supported property-undefined
|
|
41
|
+
* guard and, when matched, return the accessed property name.
|
|
42
|
+
*
|
|
43
|
+
* Recognized patterns:
|
|
44
|
+
*
|
|
45
|
+
* - `param.prop !== undefined`
|
|
46
|
+
* - `undefined !== param.prop`
|
|
47
|
+
* - `param.prop != undefined`
|
|
48
|
+
* - `undefined != param.prop`
|
|
49
|
+
* - `typeof param.prop !== "undefined"`
|
|
50
|
+
* - `"undefined" !== typeof param.prop`
|
|
51
|
+
*
|
|
52
|
+
* @param context - Active rule context for global-binding checks.
|
|
53
|
+
* @param body - Callback body expression to inspect.
|
|
54
|
+
* @param paramName - Callback parameter identifier name.
|
|
55
|
+
*
|
|
56
|
+
* @returns Property name when the body is a supported guard; otherwise `null`.
|
|
57
|
+
*/
|
|
58
|
+
const extractPropertyDefinedGuardBody = (context, body, paramName) => {
|
|
59
|
+
if (body.type !== "BinaryExpression") {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const { left, operator, right } = body;
|
|
63
|
+
if (operator !== "!==" && operator !== "!=") {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
// Typeof form: `typeof param.prop !== "undefined"` or reversed
|
|
67
|
+
const typeofLeftResult = extractTypeofPropertyDefinedCheck(left, right, operator, paramName);
|
|
68
|
+
if (typeofLeftResult !== null) {
|
|
69
|
+
return typeofLeftResult;
|
|
70
|
+
}
|
|
71
|
+
const typeofRightResult = extractTypeofPropertyDefinedCheck(right, left, operator, paramName);
|
|
72
|
+
if (typeofRightResult !== null) {
|
|
73
|
+
return typeofRightResult;
|
|
74
|
+
}
|
|
75
|
+
// Standard binary: `param.prop !== undefined` or `undefined !== param.prop`
|
|
76
|
+
if (left.type === "MemberExpression" &&
|
|
77
|
+
!left.computed &&
|
|
78
|
+
left.object.type === "Identifier" &&
|
|
79
|
+
left.object.name === paramName &&
|
|
80
|
+
left.property.type === "Identifier" &&
|
|
81
|
+
isGlobalUndefinedIdentifier(context, right)) {
|
|
82
|
+
return left.property.name;
|
|
83
|
+
}
|
|
84
|
+
if (right.type === "MemberExpression" &&
|
|
85
|
+
!right.computed &&
|
|
86
|
+
right.object.type === "Identifier" &&
|
|
87
|
+
right.object.name === paramName &&
|
|
88
|
+
right.property.type === "Identifier" &&
|
|
89
|
+
isGlobalUndefinedIdentifier(context, left)) {
|
|
90
|
+
return right.property.name;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* ESLint rule definition for `prefer-ts-extras-is-property-defined`.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
99
|
+
*/
|
|
100
|
+
const preferTsExtrasIsPropertyDefinedRule = createTypedRule({
|
|
101
|
+
create(context) {
|
|
102
|
+
const tsExtrasImports = collectDirectNamedValueImportsFromSource(context.sourceCode, TS_EXTRAS_MODULE_SOURCE);
|
|
103
|
+
return {
|
|
104
|
+
'CallExpression[callee.type="MemberExpression"][callee.property.type="Identifier"][callee.property.name="filter"]'(node) {
|
|
105
|
+
const callbackMatch = getSingleParameterExpressionArrowFilterCallback(node);
|
|
106
|
+
if (!callbackMatch) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const { callback, parameter } = callbackMatch;
|
|
110
|
+
const propName = extractPropertyDefinedGuardBody(context, callback.body, parameter.name);
|
|
111
|
+
if (propName === null) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
reportWithOptionalFix({
|
|
115
|
+
context,
|
|
116
|
+
fix: createSafeValueNodeTextReplacementFix({
|
|
117
|
+
context,
|
|
118
|
+
importedName: "isPropertyDefined",
|
|
119
|
+
imports: tsExtrasImports,
|
|
120
|
+
replacementTextFactory: (localName) => `${localName}(${JSON.stringify(propName)})`,
|
|
121
|
+
reportFixIntent: "autofix",
|
|
122
|
+
sourceModuleName: TS_EXTRAS_MODULE_SOURCE,
|
|
123
|
+
targetNode: callback,
|
|
124
|
+
}),
|
|
125
|
+
messageId: "preferTsExtrasIsPropertyDefined",
|
|
126
|
+
node: callback,
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
meta: {
|
|
132
|
+
deprecated: false,
|
|
133
|
+
docs: {
|
|
134
|
+
description: "require ts-extras isPropertyDefined in Array.filter callbacks instead of inline property-undefined checks.",
|
|
135
|
+
frozen: false,
|
|
136
|
+
recommended: true,
|
|
137
|
+
requiresTypeChecking: false,
|
|
138
|
+
typefestConfigs: [
|
|
139
|
+
"typefest.configs.minimal",
|
|
140
|
+
"typefest.configs.recommended",
|
|
141
|
+
"typefest.configs.strict",
|
|
142
|
+
"typefest.configs.all",
|
|
143
|
+
"typefest.configs.ts-extras/type-guards",
|
|
144
|
+
],
|
|
145
|
+
url: "https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-ts-extras-is-property-defined",
|
|
146
|
+
},
|
|
147
|
+
fixable: "code",
|
|
148
|
+
messages: {
|
|
149
|
+
preferTsExtrasIsPropertyDefined: "Prefer `isPropertyDefined` from `ts-extras` over an inline property-undefined filter callback.",
|
|
150
|
+
},
|
|
151
|
+
schema: [],
|
|
152
|
+
type: "suggestion",
|
|
153
|
+
},
|
|
154
|
+
name: "prefer-ts-extras-is-property-defined",
|
|
155
|
+
});
|
|
156
|
+
/**
|
|
157
|
+
* Default export for the `prefer-ts-extras-is-property-defined` rule module.
|
|
158
|
+
*/
|
|
159
|
+
export default preferTsExtrasIsPropertyDefinedRule;
|
|
160
|
+
//# sourceMappingURL=prefer-ts-extras-is-property-defined.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-ts-extras-is-property-defined.js","sourceRoot":"","sources":["../../src/rules/prefer-ts-extras-is-property-defined.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,+CAA+C,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EACH,wCAAwC,EACxC,qCAAqC,GACxC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACH,eAAe,EACf,2BAA2B,GAC9B,MAAM,4BAA4B,CAAC;AAOpC;;;;;;;;;;GAUG;AACH,MAAM,iCAAiC,GAAG,CACtC,UAAyC,EACzC,UAAyC,EACzC,QAAgB,EAChB,SAAiB,EACJ,EAAE;IACf,kCAAkC;IAClC,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IACI,UAAU,CAAC,IAAI,KAAK,iBAAiB;QACrC,UAAU,CAAC,QAAQ,KAAK,QA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CAC5C,OAAO,EACP,QAAQ,CAAC,IAAI,EACb,SAAS,CAAC,IAAI,CACjB,CAAC;gBAEF,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;oBACpB,OAAO;gBACX,CAAC;gBAED,qBAAqB,CAAC;oBAClB,OAAO;oBACP,GAAG,EAAE,qCAAqC,CAAC;wBACvC,OAAO;wBACP,YAAY,EAAE,mBAAmB;wBACjC,OAAO,EAAE,eAAe;wBACxB,sBAAsB,EAAE,CAAC,SAAS,EAAE,EAAE,CAClC,GAAG,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG;wBAC/C,eAAe,EAAE,SAAS;wBAC1B,gBAAgB,EAAE,uBAAuB;wBACzC,UAAU,EAAE,QAAQ;qBACvB,CAAC;oBACF,SAAS,EAAE,iCAAiC;oBAC5C,IAAI,EAAE,QAAQ;iBACjB,CAAC,CAAC;YACP,CAAC;SACJ,CAAC;IACN,CAAC;IACD,IAAI,EAAE;QACF,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE;YACF,WAAW,EACP,4GAA4G;YAChH,MAAM,EAAE,KAAK;YACb,WAAW,EAAE,IAAI;YACjB,oBAAoB,EAAE,KAAK;YAC3B,eAAe,EAAE;gBACb,0BAA0B;gBAC1B,8BAA8B;gBAC9B,yBAAyB;gBACzB,sBAAsB;gBACtB,wCAAwC;aAC3C;YACD,GAAG,EAAE,qGAAqG;SAC7G;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACN,+BAA+B,EAC3B,gGAAgG;SACvG;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;KACrB;IACD,IAAI,EAAE,sCAAsC;CAC/C,CAAC,CAAC;AAEP;;GAEG;AACH,eAAe,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
2
|
+
/**
|
|
3
|
+
* ESLint rule definition for `prefer-ts-extras-is-property-present`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
7
|
+
*/
|
|
8
|
+
declare const preferTsExtrasIsPropertyPresentRule: ReturnType<typeof createTypedRule>;
|
|
9
|
+
/**
|
|
10
|
+
* Default export for the `prefer-ts-extras-is-property-present` rule module.
|
|
11
|
+
*/
|
|
12
|
+
export default preferTsExtrasIsPropertyPresentRule;
|
|
13
|
+
//# sourceMappingURL=prefer-ts-extras-is-property-present.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-ts-extras-is-property-present.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-ts-extras-is-property-present.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAwD7D;;;;;GAKG;AACH,QAAA,MAAM,mCAAmC,EAAE,UAAU,CAAC,OAAO,eAAe,CAyEtE,CAAC;AAEP;;GAEG;AACH,eAAe,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { getSingleParameterExpressionArrowFilterCallback } from "../_internal/filter-callback.js";
|
|
2
|
+
import { collectDirectNamedValueImportsFromSource, createSafeValueNodeTextReplacementFix, } from "../_internal/imported-value-symbols.js";
|
|
3
|
+
import { TS_EXTRAS_MODULE_SOURCE } from "../_internal/module-source.js";
|
|
4
|
+
import { reportWithOptionalFix } from "../_internal/rule-reporting.js";
|
|
5
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
6
|
+
/**
|
|
7
|
+
* Determine whether an arrow-callback body is a supported property-nullish
|
|
8
|
+
* guard and, when matched, return the accessed property name.
|
|
9
|
+
*
|
|
10
|
+
* Recognized patterns (loose equality against `null` catches both `null` and
|
|
11
|
+
* `undefined`):
|
|
12
|
+
*
|
|
13
|
+
* - `param.prop != null`
|
|
14
|
+
* - `null != param.prop`
|
|
15
|
+
*
|
|
16
|
+
* @param body - Callback body expression to inspect.
|
|
17
|
+
* @param paramName - Callback parameter identifier name.
|
|
18
|
+
*
|
|
19
|
+
* @returns Property name when the body is a supported guard; otherwise `null`.
|
|
20
|
+
*/
|
|
21
|
+
const extractPropertyPresentGuardBody = (body, paramName) => {
|
|
22
|
+
if (body.type !== "BinaryExpression" || body.operator !== "!=") {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const { left, right } = body;
|
|
26
|
+
// `param.prop != null`
|
|
27
|
+
if (left.type === "MemberExpression" &&
|
|
28
|
+
!left.computed &&
|
|
29
|
+
left.object.type === "Identifier" &&
|
|
30
|
+
left.object.name === paramName &&
|
|
31
|
+
left.property.type === "Identifier" &&
|
|
32
|
+
right.type === "Literal" &&
|
|
33
|
+
right.value === null) {
|
|
34
|
+
return left.property.name;
|
|
35
|
+
}
|
|
36
|
+
// `null != param.prop`
|
|
37
|
+
if (right.type === "MemberExpression" &&
|
|
38
|
+
!right.computed &&
|
|
39
|
+
right.object.type === "Identifier" &&
|
|
40
|
+
right.object.name === paramName &&
|
|
41
|
+
right.property.type === "Identifier" &&
|
|
42
|
+
left.type === "Literal" &&
|
|
43
|
+
left.value === null) {
|
|
44
|
+
return right.property.name;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* ESLint rule definition for `prefer-ts-extras-is-property-present`.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
53
|
+
*/
|
|
54
|
+
const preferTsExtrasIsPropertyPresentRule = createTypedRule({
|
|
55
|
+
create(context) {
|
|
56
|
+
const tsExtrasImports = collectDirectNamedValueImportsFromSource(context.sourceCode, TS_EXTRAS_MODULE_SOURCE);
|
|
57
|
+
return {
|
|
58
|
+
'CallExpression[callee.type="MemberExpression"][callee.property.type="Identifier"][callee.property.name="filter"]'(node) {
|
|
59
|
+
const callbackMatch = getSingleParameterExpressionArrowFilterCallback(node);
|
|
60
|
+
if (!callbackMatch) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { callback, parameter } = callbackMatch;
|
|
64
|
+
const propName = extractPropertyPresentGuardBody(callback.body, parameter.name);
|
|
65
|
+
if (propName === null) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
reportWithOptionalFix({
|
|
69
|
+
context,
|
|
70
|
+
fix: createSafeValueNodeTextReplacementFix({
|
|
71
|
+
context,
|
|
72
|
+
importedName: "isPropertyPresent",
|
|
73
|
+
imports: tsExtrasImports,
|
|
74
|
+
replacementTextFactory: (localName) => `${localName}(${JSON.stringify(propName)})`,
|
|
75
|
+
reportFixIntent: "autofix",
|
|
76
|
+
sourceModuleName: TS_EXTRAS_MODULE_SOURCE,
|
|
77
|
+
targetNode: callback,
|
|
78
|
+
}),
|
|
79
|
+
messageId: "preferTsExtrasIsPropertyPresent",
|
|
80
|
+
node: callback,
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
meta: {
|
|
86
|
+
deprecated: false,
|
|
87
|
+
docs: {
|
|
88
|
+
description: "require ts-extras isPropertyPresent in Array.filter callbacks instead of inline property-nullish checks.",
|
|
89
|
+
frozen: false,
|
|
90
|
+
recommended: true,
|
|
91
|
+
requiresTypeChecking: false,
|
|
92
|
+
typefestConfigs: [
|
|
93
|
+
"typefest.configs.minimal",
|
|
94
|
+
"typefest.configs.recommended",
|
|
95
|
+
"typefest.configs.strict",
|
|
96
|
+
"typefest.configs.all",
|
|
97
|
+
"typefest.configs.ts-extras/type-guards",
|
|
98
|
+
],
|
|
99
|
+
url: "https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-ts-extras-is-property-present",
|
|
100
|
+
},
|
|
101
|
+
fixable: "code",
|
|
102
|
+
messages: {
|
|
103
|
+
preferTsExtrasIsPropertyPresent: "Prefer `isPropertyPresent` from `ts-extras` over an inline property-nullish filter callback.",
|
|
104
|
+
},
|
|
105
|
+
schema: [],
|
|
106
|
+
type: "suggestion",
|
|
107
|
+
},
|
|
108
|
+
name: "prefer-ts-extras-is-property-present",
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Default export for the `prefer-ts-extras-is-property-present` rule module.
|
|
112
|
+
*/
|
|
113
|
+
export default preferTsExtrasIsPropertyPresentRule;
|
|
114
|
+
//# sourceMappingURL=prefer-ts-extras-is-property-present.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-ts-extras-is-property-present.js","sourceRoot":"","sources":["../../src/rules/prefer-ts-extras-is-property-present.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,+CAA+C,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EACH,wCAAwC,EACxC,qCAAqC,GACxC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;;;;;;;;;;GAcG;AACH,MAAM,+BAA+B,GAAG,CACpC,IAAmC,EACnC,SAAiB,EACJ,EAAE;IACf,IAAI,IAAI,CAAC,IAAI,KAAK,kBAAkB,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC7D,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAE7B,uBAAuB;IACvB,IACI,IAAI,CAAC,IAAI,KAAK,kBAAkB;QAChC,CAAC,IAAI,CAAC,QAAQ;QACd,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;QAC9B,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;QACnC,KAAK,CAAC,IAAI,KAAK,SAAS;QACx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AC,SAAS,EAAE,EAAE,CAClC,GAAG,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG;wBAC/C,eAAe,EAAE,SAAS;wBAC1B,gBAAgB,EAAE,uBAAuB;wBACzC,UAAU,EAAE,QAAQ;qBACvB,CAAC;oBACF,SAAS,EAAE,iCAAiC;oBAC5C,IAAI,EAAE,QAAQ;iBACjB,CAAC,CAAC;YACP,CAAC;SACJ,CAAC;IACN,CAAC;IACD,IAAI,EAAE;QACF,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE;YACF,WAAW,EACP,0GAA0G;YAC9G,MAAM,EAAE,KAAK;YACb,WAAW,EAAE,IAAI;YACjB,oBAAoB,EAAE,KAAK;YAC3B,eAAe,EAAE;gBACb,0BAA0B;gBAC1B,8BAA8B;gBAC9B,yBAAyB;gBACzB,sBAAsB;gBACtB,wCAAwC;aAC3C;YACD,GAAG,EAAE,qGAAqG;SAC7G;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACN,+BAA+B,EAC3B,8FAA8F;SACrG;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;KACrB;IACD,IAAI,EAAE,sCAAsC;CAC/C,CAAC,CAAC;AAEP;;GAEG;AACH,eAAe,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
2
|
+
/**
|
|
3
|
+
* ESLint rule definition for `prefer-type-fest-absolute`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
7
|
+
*/
|
|
8
|
+
declare const preferTypeFestAbsoluteRule: ReturnType<typeof createTypedRule>;
|
|
9
|
+
/**
|
|
10
|
+
* Default export for the `prefer-type-fest-absolute` rule module.
|
|
11
|
+
*/
|
|
12
|
+
export default preferTypeFestAbsoluteRule;
|
|
13
|
+
//# sourceMappingURL=prefer-type-fest-absolute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-type-fest-absolute.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-type-fest-absolute.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAU7D;;;;;GAKG;AACH,QAAA,MAAM,0BAA0B,EAAE,UAAU,CAAC,OAAO,eAAe,CA6D7D,CAAC;AAEP;;GAEG;AACH,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { setHas } from "ts-extras";
|
|
2
|
+
import { collectDirectNamedImportsFromSource, createSafeTypeReferenceReplacementFix, } from "../_internal/imported-type-aliases.js";
|
|
3
|
+
import { TYPE_FEST_MODULE_SOURCE } from "../_internal/module-source.js";
|
|
4
|
+
import { reportWithOptionalFix } from "../_internal/rule-reporting.js";
|
|
5
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
6
|
+
/**
|
|
7
|
+
* Common alias names used for numeric absolute-value type utilities.
|
|
8
|
+
*/
|
|
9
|
+
const ABSOLUTE_ALIAS_NAMES = new Set([
|
|
10
|
+
"Abs",
|
|
11
|
+
"AbsoluteValue",
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* ESLint rule definition for `prefer-type-fest-absolute`.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
18
|
+
*/
|
|
19
|
+
const preferTypeFestAbsoluteRule = createTypedRule({
|
|
20
|
+
create(context) {
|
|
21
|
+
const typeFestDirectImports = collectDirectNamedImportsFromSource(context.sourceCode, TYPE_FEST_MODULE_SOURCE);
|
|
22
|
+
return {
|
|
23
|
+
'TSTypeReference[typeName.type="Identifier"]'(node) {
|
|
24
|
+
if (node.typeName.type !== "Identifier" ||
|
|
25
|
+
!setHas(ABSOLUTE_ALIAS_NAMES, node.typeName.name)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const aliasReplacementFix = createSafeTypeReferenceReplacementFix(node, "Absolute", typeFestDirectImports);
|
|
29
|
+
reportWithOptionalFix({
|
|
30
|
+
context,
|
|
31
|
+
data: { aliasName: node.typeName.name },
|
|
32
|
+
fix: aliasReplacementFix,
|
|
33
|
+
messageId: "preferAbsolute",
|
|
34
|
+
node,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
meta: {
|
|
40
|
+
deprecated: false,
|
|
41
|
+
docs: {
|
|
42
|
+
description: "require TypeFest `Absolute` over common `Abs` or `AbsoluteValue` aliases.",
|
|
43
|
+
frozen: false,
|
|
44
|
+
recommended: true,
|
|
45
|
+
requiresTypeChecking: false,
|
|
46
|
+
typefestConfigs: [
|
|
47
|
+
"typefest.configs.recommended",
|
|
48
|
+
"typefest.configs.strict",
|
|
49
|
+
"typefest.configs.all",
|
|
50
|
+
"typefest.configs.type-fest/types",
|
|
51
|
+
],
|
|
52
|
+
url: "https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-absolute",
|
|
53
|
+
},
|
|
54
|
+
fixable: "code",
|
|
55
|
+
messages: {
|
|
56
|
+
preferAbsolute: "Prefer `Absolute` from type-fest over `{{aliasName}}`.",
|
|
57
|
+
},
|
|
58
|
+
schema: [],
|
|
59
|
+
type: "suggestion",
|
|
60
|
+
},
|
|
61
|
+
name: "prefer-type-fest-absolute",
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Default export for the `prefer-type-fest-absolute` rule module.
|
|
65
|
+
*/
|
|
66
|
+
export default preferTypeFestAbsoluteRule;
|
|
67
|
+
//# sourceMappingURL=prefer-type-fest-absolute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-type-fest-absolute.js","sourceRoot":"","sources":["../../src/rules/prefer-type-fest-absolute.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE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BAAyB;gBACzB,sBAAsB;gBACtB,kCAAkC;aACrC;YACD,GAAG,EAAE,0FAA0F;SAClG;QACD,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACN,cAAc,EACV,wDAAwD;SAC/D;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;KACrB;IACD,IAAI,EAAE,2BAA2B;CACpC,CAAC,CAAC;AAEP;;GAEG;AACH,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
2
|
+
/**
|
|
3
|
+
* ESLint rule definition for `prefer-type-fest-non-nullable-deep`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
7
|
+
*/
|
|
8
|
+
declare const preferTypeFestNonNullableDeepRule: ReturnType<typeof createTypedRule>;
|
|
9
|
+
/**
|
|
10
|
+
* Default export for the `prefer-type-fest-non-nullable-deep` rule module.
|
|
11
|
+
*/
|
|
12
|
+
export default preferTypeFestNonNullableDeepRule;
|
|
13
|
+
//# sourceMappingURL=prefer-type-fest-non-nullable-deep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-type-fest-non-nullable-deep.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-type-fest-non-nullable-deep.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;GAKG;AACH,QAAA,MAAM,iCAAiC,EAAE,UAAU,CAAC,OAAO,eAAe,CA4DpE,CAAC;AAEP;;GAEG;AACH,eAAe,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { collectDirectNamedImportsFromSource, createSafeTypeReferenceReplacementFix, } from "../_internal/imported-type-aliases.js";
|
|
2
|
+
import { TYPE_FEST_MODULE_SOURCE } from "../_internal/module-source.js";
|
|
3
|
+
import { reportWithOptionalFix } from "../_internal/rule-reporting.js";
|
|
4
|
+
import { createTypedRule } from "../_internal/typed-rule.js";
|
|
5
|
+
/**
|
|
6
|
+
* ESLint rule definition for `prefer-type-fest-non-nullable-deep`.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Defines metadata, diagnostics, and suggestions/fixes for this rule.
|
|
10
|
+
*/
|
|
11
|
+
const preferTypeFestNonNullableDeepRule = createTypedRule({
|
|
12
|
+
create(context) {
|
|
13
|
+
const typeFestDirectImports = collectDirectNamedImportsFromSource(context.sourceCode, TYPE_FEST_MODULE_SOURCE);
|
|
14
|
+
return {
|
|
15
|
+
'TSTypeReference[typeName.type="Identifier"]'(node) {
|
|
16
|
+
if (node.typeName.type !== "Identifier" ||
|
|
17
|
+
node.typeName.name !== "DeepNonNullable") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const aliasReplacementFix = createSafeTypeReferenceReplacementFix(node, "NonNullableDeep", typeFestDirectImports);
|
|
21
|
+
reportWithOptionalFix({
|
|
22
|
+
context,
|
|
23
|
+
fix: aliasReplacementFix,
|
|
24
|
+
messageId: "preferNonNullableDeep",
|
|
25
|
+
node,
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
meta: {
|
|
31
|
+
deprecated: false,
|
|
32
|
+
docs: {
|
|
33
|
+
description: "require TypeFest `NonNullableDeep` over `DeepNonNullable` aliases.",
|
|
34
|
+
frozen: false,
|
|
35
|
+
recommended: true,
|
|
36
|
+
requiresTypeChecking: false,
|
|
37
|
+
typefestConfigs: [
|
|
38
|
+
"typefest.configs.recommended",
|
|
39
|
+
"typefest.configs.strict",
|
|
40
|
+
"typefest.configs.all",
|
|
41
|
+
"typefest.configs.type-fest/types",
|
|
42
|
+
],
|
|
43
|
+
url: "https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-non-nullable-deep",
|
|
44
|
+
},
|
|
45
|
+
fixable: "code",
|
|
46
|
+
messages: {
|
|
47
|
+
preferNonNullableDeep: "Prefer `NonNullableDeep` from type-fest over `DeepNonNullable`.",
|
|
48
|
+
},
|
|
49
|
+
schema: [],
|
|
50
|
+
type: "suggestion",
|
|
51
|
+
},
|
|
52
|
+
name: "prefer-type-fest-non-nullable-deep",
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Default export for the `prefer-type-fest-non-nullable-deep` rule module.
|
|
56
|
+
*/
|
|
57
|
+
export default preferTypeFestNonNullableDeepRule;
|
|
58
|
+
//# sourceMappingURL=prefer-type-fest-non-nullable-deep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-type-fest-non-nullable-deep.js","sourceRoot":"","sources":["../../src/rules/prefer-type-fest-non-nullable-deep.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,mCAAmC,EACnC,qCAAqC,GACxC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,iCAAiC,GACnC,eAAe,CAAC;IACZ,MAAM,CAAC,OAAO;QACV,MAAM,qBAAqB,GAAG,mCAAmC,CAC7D,OAAO,CAAC,UAAU,EAClB,uBAAuB,CAC1B,CAAC;QAEF,OAAO;YACH,6CAA6C,CACzC,IAA8B;gBAE9B,IACI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;oBACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,iBAAiB,EAC1C,CAAC;oBACC,OAAO;gBACX,CAAC;gBAED,MAAM,mBAAmB,GACrB,qCAAqC,CACjC,IAAI,EACJ,iBAAiB,EACjB,qBAAqB,CACxB,CAAC;gBAEN,qBAAqB,CAAC;oBAClB,OAAO;oBACP,G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