eslint-config-typed 7.6.1 → 7.7.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/dist/plugins/total-functions/rules/no-hidden-type-assertions.d.mts.map +1 -1
- package/dist/plugins/total-functions/rules/no-hidden-type-assertions.mjs +53 -44
- package/dist/plugins/total-functions/rules/no-hidden-type-assertions.mjs.map +1 -1
- package/dist/plugins/ts-restrictions/rules/no-date-only-string-to-date.d.mts +50 -0
- package/dist/plugins/ts-restrictions/rules/no-date-only-string-to-date.d.mts.map +1 -0
- package/dist/plugins/ts-restrictions/rules/no-date-only-string-to-date.mjs +215 -0
- package/dist/plugins/ts-restrictions/rules/no-date-only-string-to-date.mjs.map +1 -0
- package/dist/plugins/ts-restrictions/rules/rules.d.mts +3 -0
- package/dist/plugins/ts-restrictions/rules/rules.d.mts.map +1 -1
- package/dist/plugins/ts-restrictions/rules/rules.mjs +2 -0
- package/dist/plugins/ts-restrictions/rules/rules.mjs.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.d.mts +8 -1
- package/dist/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.d.mts.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.mjs +70 -9
- package/dist/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.mjs.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/prefer-assert-is-false-over-expect-false.d.mts.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/prefer-assert-is-false-over-expect-false.mjs +6 -8
- package/dist/plugins/vitest-coding-style/rules/prefer-assert-is-false-over-expect-false.mjs.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/prefer-assert-is-true-over-expect-true.d.mts.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/prefer-assert-is-true-over-expect-true.mjs +6 -8
- package/dist/plugins/vitest-coding-style/rules/prefer-assert-is-true-over-expect-true.mjs.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/rules.d.mts +1 -1
- package/dist/plugins/vitest-coding-style/rules/vitest-binding.d.mts +9 -0
- package/dist/plugins/vitest-coding-style/rules/vitest-binding.d.mts.map +1 -1
- package/dist/plugins/vitest-coding-style/rules/vitest-binding.mjs +16 -0
- package/dist/plugins/vitest-coding-style/rules/vitest-binding.mjs.map +1 -1
- package/dist/rules/eslint-ts-restrictions-rules.d.mts +1 -0
- package/dist/rules/eslint-ts-restrictions-rules.d.mts.map +1 -1
- package/dist/rules/eslint-ts-restrictions-rules.mjs +1 -0
- package/dist/rules/eslint-ts-restrictions-rules.mjs.map +1 -1
- package/dist/types/rules/eslint-ts-restrictions-rules.d.mts +42 -0
- package/dist/types/rules/eslint-ts-restrictions-rules.d.mts.map +1 -1
- package/dist/types/rules/eslint-vitest-coding-style-rules.d.mts +1 -1
- package/package.json +8 -8
- package/src/plugins/total-functions/rules/no-hidden-type-assertions.mts +97 -101
- package/src/plugins/total-functions/rules/no-hidden-type-assertions.test.mts +180 -7
- package/src/plugins/ts-restrictions/rules/no-date-only-string-to-date.mts +305 -0
- package/src/plugins/ts-restrictions/rules/no-date-only-string-to-date.test.mts +254 -0
- package/src/plugins/ts-restrictions/rules/rules.mts +2 -0
- package/src/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.mts +109 -13
- package/src/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.test.mts +126 -0
- package/src/plugins/vitest-coding-style/rules/prefer-assert-is-false-over-expect-false.mts +6 -9
- package/src/plugins/vitest-coding-style/rules/prefer-assert-is-true-over-expect-true.mts +6 -9
- package/src/plugins/vitest-coding-style/rules/vitest-binding.mts +24 -0
- package/src/rules/eslint-ts-restrictions-rules.mts +1 -0
- package/src/types/rules/eslint-ts-restrictions-rules.mts +45 -0
- package/src/types/rules/eslint-vitest-coding-style-rules.mts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-hidden-type-assertions.d.mts","sourceRoot":"","sources":["../../../../src/plugins/total-functions/rules/no-hidden-type-assertions.mts"],"names":[],"mappings":"AAIA,OAAO,EAEL,WAAW,EAEZ,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"no-hidden-type-assertions.d.mts","sourceRoot":"","sources":["../../../../src/plugins/total-functions/rules/no-hidden-type-assertions.mts"],"names":[],"mappings":"AAIA,OAAO,EAEL,WAAW,EAEZ,MAAM,0BAA0B,CAAC;AAsBlC,oDAAoD;AAEpD,eAAO,MAAM,sBAAsB;;CA8QxB,CAAC"}
|
|
@@ -13,7 +13,7 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
13
13
|
description: 'Bans hidden type assertions.',
|
|
14
14
|
},
|
|
15
15
|
messages: {
|
|
16
|
-
errorStringGeneric: 'Do not use hidden type assertions.
|
|
16
|
+
errorStringGeneric: 'Do not use hidden type assertions. Set the type argument to `unknown` or `never` rather than to an arbitrary type, whether written or inferred from the context.',
|
|
17
17
|
},
|
|
18
18
|
schema: [],
|
|
19
19
|
defaultOptions: [],
|
|
@@ -26,6 +26,22 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
const checkerFrom58 = checker;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const writtenTypeArgumentOrDefault = (typeArguments, index, typeParameter) => {
|
|
35
|
+
const typeNode = typeArguments?.[index] ?? typeParameter.default;
|
|
36
|
+
return typeNode === undefined
|
|
37
|
+
? undefined
|
|
38
|
+
: checker.getTypeAtLocation(typeNode);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
29
45
|
|
|
30
46
|
|
|
31
47
|
|
|
@@ -45,47 +61,34 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
45
61
|
|
|
46
62
|
|
|
47
63
|
|
|
48
|
-
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const hiddenTypeParamsOf = (declaration) => {
|
|
49
68
|
const { typeParameters, type: returnType } = declaration;
|
|
50
69
|
if (returnType === undefined ||
|
|
51
70
|
typeParameters === undefined ||
|
|
52
71
|
typeParameters.length === 0) {
|
|
53
72
|
return undefined;
|
|
54
73
|
}
|
|
55
|
-
const
|
|
74
|
+
const hidden = typeParameters.flatMap((typeParameter, index) => {
|
|
56
75
|
const symbol = checker.getSymbolAtLocation(typeParameter.name);
|
|
57
76
|
return symbol !== undefined &&
|
|
58
|
-
referencesTypeParameter(returnType, symbol)
|
|
59
|
-
|
|
77
|
+
referencesTypeParameter(returnType, symbol) &&
|
|
78
|
+
!declaration.parameters.some((parameter) => parameter.type !== undefined &&
|
|
79
|
+
referencesTypeParameter(parameter.type, symbol))
|
|
80
|
+
? [{ typeParameter, index }]
|
|
60
81
|
: [];
|
|
61
82
|
});
|
|
62
|
-
return Arr.isNonEmpty(
|
|
83
|
+
return Arr.isNonEmpty(hidden) ? hidden : undefined;
|
|
63
84
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const returnTypeParamsAppearInValueParams = (declaration, typeParamsUsedInReturnType) => typeParamsUsedInReturnType.every(({ symbol }) => declaration.parameters.some((parameter) => parameter.type !== undefined &&
|
|
70
|
-
referencesTypeParameter(parameter.type, symbol)));
|
|
71
85
|
const mut_analysisCache = new WeakMap();
|
|
72
86
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
87
|
const analyzeSignature = (declaration) => {
|
|
79
88
|
if (mut_analysisCache.has(declaration)) {
|
|
80
89
|
return mut_analysisCache.get(declaration);
|
|
81
90
|
}
|
|
82
|
-
const
|
|
83
|
-
const analysis = typeParamsUsedInReturnType === undefined
|
|
84
|
-
? undefined
|
|
85
|
-
: {
|
|
86
|
-
typeParamsUsedInReturnType,
|
|
87
|
-
appearInValueParams: returnTypeParamsAppearInValueParams(declaration, typeParamsUsedInReturnType),
|
|
88
|
-
};
|
|
91
|
+
const analysis = hiddenTypeParamsOf(declaration);
|
|
89
92
|
mut_analysisCache.set(declaration, analysis);
|
|
90
93
|
return analysis;
|
|
91
94
|
};
|
|
@@ -99,8 +102,7 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
99
102
|
declaration.kind === SyntaxKind.JSDocSignature) {
|
|
100
103
|
return false;
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
return analysis !== undefined && !analysis.appearInValueParams;
|
|
105
|
+
return analyzeSignature(declaration) !== undefined;
|
|
104
106
|
});
|
|
105
107
|
|
|
106
108
|
|
|
@@ -112,6 +114,8 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
112
114
|
|
|
113
115
|
|
|
114
116
|
|
|
117
|
+
|
|
118
|
+
|
|
115
119
|
const isCallThroughCastOfHiddenTypeAssertion = (node, callSignature) => {
|
|
116
120
|
const layers = typeWrapperLayers(node.callee);
|
|
117
121
|
const castIndex = layers.findIndex((layer) => layer.type === AST_NODE_TYPES.TSAsExpression ||
|
|
@@ -119,8 +123,11 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
119
123
|
if (castIndex === -1) {
|
|
120
124
|
return false;
|
|
121
125
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
126
|
+
const predicate = checker.getTypePredicateOfSignature(callSignature);
|
|
127
|
+
const assertedType = predicate === undefined
|
|
128
|
+
? callSignature.getReturnType()
|
|
129
|
+
: predicate.type;
|
|
130
|
+
if (assertedType === undefined || isUnknownOrNever(assertedType)) {
|
|
124
131
|
return false;
|
|
125
132
|
}
|
|
126
133
|
return layers
|
|
@@ -156,22 +163,23 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
156
163
|
|
|
157
164
|
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
const resolvedTypeArguments = checkerFrom58.getTypeArgumentsForResolvedSignature?.(callSignature);
|
|
174
|
+
const assertsSomething = analysis.some(({ index, typeParameter }) => {
|
|
175
|
+
const resolved = resolvedTypeArguments?.[index];
|
|
176
|
+
if (resolved !== undefined && isUnknownOrNever(resolved)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const written = writtenTypeArgumentOrDefault(tsExpressionNode.typeArguments, index, typeParameter);
|
|
180
|
+
return written === undefined || !isUnknownOrNever(written);
|
|
170
181
|
});
|
|
171
|
-
if (
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (!analysis.appearInValueParams) {
|
|
182
|
+
if (assertsSomething) {
|
|
175
183
|
context.report({
|
|
176
184
|
node,
|
|
177
185
|
messageId: 'errorStringGeneric',
|
|
@@ -181,4 +189,5 @@ export const noHiddenTypeAssertions = createRule({
|
|
|
181
189
|
};
|
|
182
190
|
},
|
|
183
191
|
});
|
|
192
|
+
const isUnknownOrNever = (type) => isTypeUnknownType(type) || isTypeNeverType(type);
|
|
184
193
|
//# sourceMappingURL=no-hidden-type-assertions.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-hidden-type-assertions.mjs","sourceRoot":"","sources":["../../../../src/plugins/total-functions/rules/no-hidden-type-assertions.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,cAAc,EACd,WAAW,GAEZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"no-hidden-type-assertions.mjs","sourceRoot":"","sources":["../../../../src/plugins/total-functions/rules/no-hidden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EAAE,oBAAoB;qBACvB,CAAC,CAAC;gBACd,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACO,CAAC,CAAC;AASZ,MAAM,gBAAgB,GAAG,CAAC,IAAU,EAAW,EAAE,CAC/C,iBAAiB,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
type Options = readonly [
|
|
3
|
+
Readonly<{
|
|
4
|
+
functions?: readonly string[];
|
|
5
|
+
}>?
|
|
6
|
+
];
|
|
7
|
+
type MessageIds = 'dateOnlyString';
|
|
8
|
+
/**
|
|
9
|
+
* Disallow passing a date-only string to `new Date` or `Date.parse`.
|
|
10
|
+
*
|
|
11
|
+
* ## Why
|
|
12
|
+
*
|
|
13
|
+
* ECMAScript reads the ISO date-only forms — `YYYY`, `YYYY-MM` and
|
|
14
|
+
* `YYYY-MM-DD`, the year also as a sign and six digits — as midnight **UTC**,
|
|
15
|
+
* while the same string with a time (`YYYY-MM-DDTHH:mm`) is local time. Read
|
|
16
|
+
* back with the local getters (`getDate`, `getMonth`, …), the date-only form is
|
|
17
|
+
* therefore the day before wherever the offset is negative, and code or a test
|
|
18
|
+
* written east of UTC passes there and fails west of it. Build the date from
|
|
19
|
+
* its numbers, or write the time and zone (`T00:00:00Z`) when UTC is meant.
|
|
20
|
+
*
|
|
21
|
+
* Only the ISO forms are reported: `'2026/11/03'`, `'+2026-11-03'` or `'20261'`
|
|
22
|
+
* are not ISO, and V8 reads them as local time.
|
|
23
|
+
*
|
|
24
|
+
* ## What it sees
|
|
25
|
+
*
|
|
26
|
+
* The first argument is judged by its type: a string literal type that is a
|
|
27
|
+
* date alone, or a union, an intersection (a branded literal) or a type
|
|
28
|
+
* parameter's constraint with one. So a literal written at the call is seen,
|
|
29
|
+
* and so is a `const` holding one or a row of an `as const` table; a `string`
|
|
30
|
+
* is not, whatever it holds at run time. It is reported when any layer of its
|
|
31
|
+
* `as` / `satisfies` / `!` / `<T>` wrappers has such a type, since a widening
|
|
32
|
+
* cast does not change the string, and when a branch of a `?:`, `??` or `||`, or
|
|
33
|
+
* the right of `&&`, does, since `x ?? '2026-11-03'` is a `string` once `x` is.
|
|
34
|
+
*
|
|
35
|
+
* The callee is read through those wrappers and through `?.`, and a computed
|
|
36
|
+
* member with a static key (`Date['parse']`) is the same member. A `Date`
|
|
37
|
+
* declared in the file is not the global and is left alone. The constructor is
|
|
38
|
+
* matched by name, so `const D = Date` or a subclass of `Date` is not seen
|
|
39
|
+
* unless `functions` names it.
|
|
40
|
+
*
|
|
41
|
+
* ## Options
|
|
42
|
+
*
|
|
43
|
+
* `functions` names further callees, called or constructed, that hand their
|
|
44
|
+
* first argument to `new Date`, as a dotted path (`'DateUtils.from'`). They are
|
|
45
|
+
* matched by the names written at the call, so an import renamed at the call
|
|
46
|
+
* site is not seen.
|
|
47
|
+
*/
|
|
48
|
+
export declare const noDateOnlyStringToDate: TSESLint.RuleModule<MessageIds, Options>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=no-date-only-string-to-date.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-date-only-string-to-date.d.mts","sourceRoot":"","sources":["../../../../src/plugins/ts-restrictions/rules/no-date-only-string-to-date.mts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EAEd,MAAM,0BAA0B,CAAC;AAUlC,KAAK,OAAO,GAAG,SAAS;IACtB,QAAQ,CAAC;QACP,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KAC/B,CAAC,CAAC;CACJ,CAAC;AAEF,KAAK,UAAU,GAAG,gBAAgB,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CA4KhE,CAAC"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { AST_NODE_TYPES, ESLintUtils, } from '@typescript-eslint/utils';
|
|
2
|
+
import { createGetLayerTypes, isRuntimeBound, skipTypeWrappers, } from 'eslint-rule-forge';
|
|
3
|
+
import { Arr } from 'ts-data-forge';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export const noDateOnlyStringToDate = {
|
|
45
|
+
meta: {
|
|
46
|
+
type: 'problem',
|
|
47
|
+
docs: {
|
|
48
|
+
description: 'Disallow a date-only string (`YYYY-MM-DD`) read by `new Date` or `Date.parse`, which take it as midnight UTC rather than local midnight',
|
|
49
|
+
},
|
|
50
|
+
schema: [
|
|
51
|
+
{
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
functions: {
|
|
55
|
+
type: 'array',
|
|
56
|
+
items: { type: 'string' },
|
|
57
|
+
description: 'Further callees, called or constructed, as dotted paths such as `DateUtils.from`, that pass their first argument to `new Date`.',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
messages: {
|
|
64
|
+
dateOnlyString: 'A date-only string is midnight UTC to `{{callee}}`, the day before in local time west of UTC. Build the date from its numbers, or write the time and zone (`T00:00:00Z`) if UTC is meant.',
|
|
65
|
+
},
|
|
66
|
+
defaultOptions: [{}],
|
|
67
|
+
},
|
|
68
|
+
create: (context) => {
|
|
69
|
+
const functions = new Set(context.options[0]?.functions);
|
|
70
|
+
const services = ESLintUtils.getParserServices(context);
|
|
71
|
+
const checker = services.program.getTypeChecker();
|
|
72
|
+
const getLayerTypes = createGetLayerTypes(services);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const isDateOnlyType = (type) => {
|
|
80
|
+
if (type.isStringLiteral()) {
|
|
81
|
+
return dateOnlyPattern.test(type.value);
|
|
82
|
+
}
|
|
83
|
+
if (type.isUnionOrIntersection()) {
|
|
84
|
+
return type.types.some(isDateOnlyType);
|
|
85
|
+
}
|
|
86
|
+
const constraint = type.isTypeParameter()
|
|
87
|
+
? checker.getBaseConstraintOfType(type)
|
|
88
|
+
: undefined;
|
|
89
|
+
return constraint !== undefined && isDateOnlyType(constraint);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
const isGlobalDate = (callee) => {
|
|
96
|
+
const path = namePath(callee);
|
|
97
|
+
const root = path === 'Date'
|
|
98
|
+
? 'Date'
|
|
99
|
+
: path === 'globalThis.Date'
|
|
100
|
+
? 'globalThis'
|
|
101
|
+
: undefined;
|
|
102
|
+
return (root !== undefined &&
|
|
103
|
+
!isRuntimeBound(context.sourceCode, asNode(callee), root));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const checkedCallee = (callee, isNew) => {
|
|
107
|
+
if (isNew && isGlobalDate(callee)) {
|
|
108
|
+
return 'Date';
|
|
109
|
+
}
|
|
110
|
+
const unwrapped = skipTypeWrappers(callee);
|
|
111
|
+
|
|
112
|
+
const value = unwrapped.type === AST_NODE_TYPES.ChainExpression
|
|
113
|
+
? skipTypeWrappers(unwrapped.expression)
|
|
114
|
+
: unwrapped;
|
|
115
|
+
if (!isNew &&
|
|
116
|
+
value.type === AST_NODE_TYPES.MemberExpression &&
|
|
117
|
+
memberName(value) === 'parse' &&
|
|
118
|
+
isGlobalDate(value.object)) {
|
|
119
|
+
return 'Date.parse';
|
|
120
|
+
}
|
|
121
|
+
const path = namePath(value);
|
|
122
|
+
return path !== undefined && functions.has(path) ? path : undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
const isDateOnlyString = (node) => {
|
|
133
|
+
if (getLayerTypes(node).some(isDateOnlyType)) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
const value = skipTypeWrappers(node);
|
|
137
|
+
if (value.type === AST_NODE_TYPES.ConditionalExpression) {
|
|
138
|
+
return (isDateOnlyString(value.consequent) ||
|
|
139
|
+
isDateOnlyString(value.alternate));
|
|
140
|
+
}
|
|
141
|
+
return (value.type === AST_NODE_TYPES.LogicalExpression &&
|
|
142
|
+
((value.operator !== '&&' && isDateOnlyString(value.left)) ||
|
|
143
|
+
isDateOnlyString(value.right)));
|
|
144
|
+
};
|
|
145
|
+
const check = (node) => {
|
|
146
|
+
const callee = checkedCallee(node.callee, node.type === AST_NODE_TYPES.NewExpression);
|
|
147
|
+
const first = node.arguments[0];
|
|
148
|
+
if (callee === undefined ||
|
|
149
|
+
first === undefined ||
|
|
150
|
+
!isDateOnlyString(first)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
context.report({
|
|
154
|
+
node: asNode(first),
|
|
155
|
+
messageId: 'dateOnlyString',
|
|
156
|
+
data: { callee },
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
NewExpression: check,
|
|
161
|
+
CallExpression: check,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
const dateOnlyPattern = /^(?:\d{4}|[+-]\d{6})(?:|-\d{2}|-\d{2}-\d{2})$/u;
|
|
170
|
+
|
|
171
|
+
const staticString = (node) => {
|
|
172
|
+
const value = skipTypeWrappers(node);
|
|
173
|
+
if (value.type === AST_NODE_TYPES.Literal) {
|
|
174
|
+
return typeof value.value === 'string' ? value.value : undefined;
|
|
175
|
+
}
|
|
176
|
+
return value.type === AST_NODE_TYPES.TemplateLiteral &&
|
|
177
|
+
Arr.isEmpty(value.expressions)
|
|
178
|
+
? (value.quasis[0]?.value.cooked ?? undefined)
|
|
179
|
+
: undefined;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
const memberName = (node) => !node.computed && node.property.type === AST_NODE_TYPES.Identifier
|
|
185
|
+
? node.property.name
|
|
186
|
+
: node.computed
|
|
187
|
+
? staticString(node.property)
|
|
188
|
+
: undefined;
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
const namePath = (node) => {
|
|
195
|
+
const unwrapped = skipTypeWrappers(node);
|
|
196
|
+
|
|
197
|
+
const value = unwrapped.type === AST_NODE_TYPES.ChainExpression
|
|
198
|
+
? skipTypeWrappers(unwrapped.expression)
|
|
199
|
+
: unwrapped;
|
|
200
|
+
if (value.type === AST_NODE_TYPES.Identifier) {
|
|
201
|
+
return value.name;
|
|
202
|
+
}
|
|
203
|
+
if (value.type !== AST_NODE_TYPES.MemberExpression) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
const object = namePath(value.object);
|
|
207
|
+
const name = memberName(value);
|
|
208
|
+
return object === undefined || name === undefined
|
|
209
|
+
? undefined
|
|
210
|
+
: `${object}.${name}`;
|
|
211
|
+
};
|
|
212
|
+
const asNode = (node) =>
|
|
213
|
+
|
|
214
|
+
node;
|
|
215
|
+
//# sourceMappingURL=no-date-only-string-to-date.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-date-only-string-to-date.mjs","sourceRoot":"","sources":["../../../../src/plugins/ts-restrictions/rules/no-date-only-string-to-date.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAYpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,CAAC,MAAM,sBAAsB,GACjC;IACE,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,yIAAyI;SAC5I;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,SAAS,EAAE;wBACT,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,WAAW,EACT,iIAAiI;qBACpI;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,cAAc,EACZ,2LAA2L;SAC9L;QACD,cAAc,EAAE,CAAC,EAAE,CAAC;KACrB;IAED,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,SAAS,GAAwB,IAAI,GAAG,CAC5C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAC9B,CAAC;QAEF,MAAM,QAAQ,GAAG,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAExD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAElD,MAAM,aAAa,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAEpD;;;;WAIG;QACH,8HAA8H;QAC9H,MAAM,cA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ictionsRules: {
|
|
|
6
6
|
readonly 'explicit-collection-type-arguments': import("@typescript-eslint/utils/ts-eslint").RuleModule<"addInferredTypeArguments" | "missingTypeArguments", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
7
7
|
readonly 'function-order': import("@typescript-eslint/utils/ts-eslint").RuleModule<"calleeAfterCaller" | "exportedAfterHelper", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
8
8
|
readonly 'jsx-boolean-logical-operands': import("@typescript-eslint/utils/ts-eslint").RuleModule<"booleanOperands" | "nonBooleanLeft", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
|
+
readonly 'no-date-only-string-to-date': import("@typescript-eslint/utils/ts-eslint").RuleModule<"dateOnlyString", readonly [(Readonly<{
|
|
10
|
+
functions?: readonly string[];
|
|
11
|
+
}> | undefined)?], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
9
12
|
readonly 'no-detached-jsdoc': import("@typescript-eslint/utils/ts-eslint").RuleModule<"detachedJsdoc", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
10
13
|
readonly 'no-export-type-side-effects': import("@typescript-eslint/utils/ts-eslint").RuleModule<"importFromDeclaration" | "useTopLevelQualifier", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
11
14
|
readonly 'no-negated-comparison': import("@typescript-eslint/utils/ts-eslint").RuleModule<"invertComparison" | "negatedComparison" | "negatedComparisonMaybeNaN", readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.mts","sourceRoot":"","sources":["../../../../src/plugins/ts-restrictions/rules/rules.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.d.mts","sourceRoot":"","sources":["../../../../src/plugins/ts-restrictions/rules/rules.mts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBU,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { checkDestructuringCompleteness } from './check-destructuring-completene
|
|
|
2
2
|
import { explicitCollectionTypeArguments } from './explicit-collection-type-arguments.mjs';
|
|
3
3
|
import { functionOrder } from './function-order.mjs';
|
|
4
4
|
import { jsxBooleanLogicalOperands } from './jsx-boolean-logical-operands.mjs';
|
|
5
|
+
import { noDateOnlyStringToDate } from './no-date-only-string-to-date.mjs';
|
|
5
6
|
import { noDetachedJsdoc } from './no-detached-jsdoc.mjs';
|
|
6
7
|
import { noExportTypeSideEffects } from './no-export-type-side-effects.mjs';
|
|
7
8
|
import { noNegatedComparison } from './no-negated-comparison.mjs';
|
|
@@ -26,6 +27,7 @@ export const tsRestrictionsRules = {
|
|
|
26
27
|
'explicit-collection-type-arguments': explicitCollectionTypeArguments,
|
|
27
28
|
'function-order': functionOrder,
|
|
28
29
|
'jsx-boolean-logical-operands': jsxBooleanLogicalOperands,
|
|
30
|
+
'no-date-only-string-to-date': noDateOnlyStringToDate,
|
|
29
31
|
'no-detached-jsdoc': noDetachedJsdoc,
|
|
30
32
|
'no-export-type-side-effects': noExportTypeSideEffects,
|
|
31
33
|
'no-negated-comparison': noNegatedComparison,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.mjs","sourceRoot":"","sources":["../../../../src/plugins/ts-restrictions/rules/rules.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,m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AA4B,EAAE,sBAAsB;CACZ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type TSESLint } from '@typescript-eslint/utils';
|
|
2
|
-
type MessageIds = 'useAssert';
|
|
2
|
+
type MessageIds = 'useAssert' | 'useAssertMovingMessage';
|
|
3
3
|
/**
|
|
4
4
|
* The trade-off, measured in `assert-vs-expect-strict-equality.test.mts`:
|
|
5
5
|
*
|
|
@@ -22,6 +22,13 @@ type MessageIds = 'useAssert';
|
|
|
22
22
|
* and `<T>` (`expect(X)!.toStrictEqual(Y)`); `X` and `Y` keep theirs. `expect`
|
|
23
23
|
* is Vitest's only (`getVitestReceiver`), and the fix names Vitest's `assert`
|
|
24
24
|
* only (`createVitestAssertFixer`).
|
|
25
|
+
*
|
|
26
|
+
* `expect(X, message)` is reported too, and its message becomes the third
|
|
27
|
+
* argument, `assert.deepStrictEqual(X, Y, message)`. That moves its evaluation
|
|
28
|
+
* from before `Y` to after it, so the fix is written only when the order cannot
|
|
29
|
+
* matter: either side is a literal, or neither has a side effect
|
|
30
|
+
* (`mayHaveEffect`). Otherwise it is reported as `useAssertMovingMessage`, with
|
|
31
|
+
* no fix.
|
|
25
32
|
*/
|
|
26
33
|
export declare const noExpectToStrictEqualRule: TSESLint.RuleModule<MessageIds>;
|
|
27
34
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-expect-to-strict-equal.d.mts","sourceRoot":"","sources":["../../../../src/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.mts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"no-expect-to-strict-equal.d.mts","sourceRoot":"","sources":["../../../../src/plugins/vitest-coding-style/rules/no-expect-to-strict-equal.mts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EAEd,MAAM,0BAA0B,CAAC;AAUlC,KAAK,UAAU,GAAG,WAAW,GAAG,wBAAwB,CAAC;AAOzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,yBAAyB,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,CAgH5D,CAAC"}
|