@blumintinc/eslint-plugin-blumint 1.20.92 → 1.20.93
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/lib/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
export declare const enforceDateTTime: TSESLint.RuleModule<"enforceDateTTime", [], TSESLint.RuleListener>;
|
|
@@ -27,6 +27,7 @@ exports.enforceDateTTime = void 0;
|
|
|
27
27
|
const utils_1 = require("@typescript-eslint/utils");
|
|
28
28
|
const ts = __importStar(require("typescript"));
|
|
29
29
|
const createRule_1 = require("../utils/createRule");
|
|
30
|
+
const importRemoval_1 = require("../utils/importRemoval");
|
|
30
31
|
exports.enforceDateTTime = (0, createRule_1.createRule)({
|
|
31
32
|
name: 'enforce-date-ttime',
|
|
32
33
|
meta: {
|
|
@@ -43,7 +44,8 @@ exports.enforceDateTTime = (0, createRule_1.createRule)({
|
|
|
43
44
|
},
|
|
44
45
|
defaultOptions: [],
|
|
45
46
|
create(context) {
|
|
46
|
-
const sourceCode = context
|
|
47
|
+
const sourceCode = context
|
|
48
|
+
.sourceCode ?? context.getSourceCode();
|
|
47
49
|
const parserServices = sourceCode?.parserServices ?? context.parserServices;
|
|
48
50
|
const checker = parserServices?.program?.getTypeChecker();
|
|
49
51
|
if (!parserServices || !checker) {
|
|
@@ -139,14 +141,46 @@ exports.enforceDateTTime = (0, createRule_1.createRule)({
|
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
else if (!isExactDate(tTimeArg)) {
|
|
142
|
-
// TTime is provided but is not exactly Date
|
|
144
|
+
// TTime is provided but is not exactly Date. Overwriting the argument
|
|
145
|
+
// deletes every name it mentions, so the rewrite and the unbinding of
|
|
146
|
+
// whatever it was the last reference to are one fix: applying either
|
|
147
|
+
// half alone leaves the file worse than applying neither, and since
|
|
148
|
+
// this rule's own report is resolved by the fix, nothing re-reports
|
|
149
|
+
// the debt an orphaned declaration becomes.
|
|
150
|
+
//
|
|
151
|
+
// Orphanhood is judged against this one argument's own range and the
|
|
152
|
+
// file as it stands, never against what the rest of the `--fix` run
|
|
153
|
+
// might also overwrite. A sibling argument naming the same alias may
|
|
154
|
+
// be `eslint-disable`d — which a rule cannot see, since suppression is
|
|
155
|
+
// applied to reports after they are emitted — so an edit assuming its
|
|
156
|
+
// sibling will also go unbinds an import the survivor still
|
|
157
|
+
// references, trading an unused import for a dangling type. Judging
|
|
158
|
+
// one edit at a time is suppression-safe by construction.
|
|
159
|
+
const importRanges = (0, importRemoval_1.planOrphanedImportRemoval)(sourceCode, [
|
|
160
|
+
tTimeArg.range,
|
|
161
|
+
]);
|
|
143
162
|
context.report({
|
|
144
163
|
node: tTimeArg,
|
|
145
164
|
messageId: 'enforceDateTTime',
|
|
146
165
|
data: { typeName },
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
166
|
+
// No plan means the argument holds the last reference to something
|
|
167
|
+
// the helper cannot rewrite — a locally declared alias, or the
|
|
168
|
+
// enclosing declaration's own type parameter — so the argument
|
|
169
|
+
// stays as written: the report without a fixer is the lesser
|
|
170
|
+
// damage. Deleting a declaration is a materially riskier edit than
|
|
171
|
+
// dropping an import specifier, and a type parameter left unread by
|
|
172
|
+
// its own body fails `no-unused-vars` and `noUnusedParameters`
|
|
173
|
+
// exactly as an orphaned alias does, on top of turning a
|
|
174
|
+
// pass-through generic into one whose argument no longer means
|
|
175
|
+
// anything.
|
|
176
|
+
...(importRanges
|
|
177
|
+
? {
|
|
178
|
+
fix: (fixer) => [
|
|
179
|
+
fixer.replaceText(tTimeArg, 'Date'),
|
|
180
|
+
...importRanges.map((range) => fixer.removeRange([range[0], range[1]])),
|
|
181
|
+
],
|
|
182
|
+
}
|
|
183
|
+
: {}),
|
|
150
184
|
});
|
|
151
185
|
}
|
|
152
186
|
},
|
|
@@ -29,6 +29,7 @@ const visitor_keys_1 = require("@typescript-eslint/visitor-keys");
|
|
|
29
29
|
const ts = __importStar(require("typescript"));
|
|
30
30
|
const ASTHelpers_1 = require("../utils/ASTHelpers");
|
|
31
31
|
const createRule_1 = require("../utils/createRule");
|
|
32
|
+
const importRemoval_1 = require("../utils/importRemoval");
|
|
32
33
|
/**
|
|
33
34
|
* Type string formatting flags chosen to keep comparisons stable and predictable.
|
|
34
35
|
* - NoTruncation avoids `...` elisions that can hide important differences.
|
|
@@ -143,10 +144,15 @@ function findTypeAnnotationStart(typeAnnotation, sourceCode) {
|
|
|
143
144
|
}
|
|
144
145
|
return removalStart;
|
|
145
146
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
/**
|
|
148
|
+
* The slice a fix deletes to drop `typeAnnotation`: the `:` and the whitespace
|
|
149
|
+
* separating it from the declared name go with the type.
|
|
150
|
+
*/
|
|
151
|
+
function annotationRemovalRange(typeAnnotation, sourceCode) {
|
|
152
|
+
return [
|
|
153
|
+
findTypeAnnotationStart(typeAnnotation, sourceCode),
|
|
154
|
+
typeAnnotation.range[1],
|
|
155
|
+
];
|
|
150
156
|
}
|
|
151
157
|
function typeText(type, checker) {
|
|
152
158
|
return checker.typeToString(type, undefined, typeFormatFlags());
|
|
@@ -338,15 +344,49 @@ exports.noRedundantAnnotationAssertion = (0, createRule_1.createRule)({
|
|
|
338
344
|
return {};
|
|
339
345
|
}
|
|
340
346
|
const checker = parserServices.program.getTypeChecker();
|
|
347
|
+
/**
|
|
348
|
+
* Reports the redundant annotation, taking with it any import it was the
|
|
349
|
+
* only consumer of. The two are one fix: applying either half alone leaves
|
|
350
|
+
* the file worse than applying neither — a stripped annotation with its
|
|
351
|
+
* import left behind fails `no-unused-vars`, and since this rule's own
|
|
352
|
+
* report is resolved by the fix, nothing re-reports the debt.
|
|
353
|
+
*
|
|
354
|
+
* Orphanhood is judged against this one annotation's own removal and the
|
|
355
|
+
* file as it stands, never against what the rest of the `--fix` run might
|
|
356
|
+
* also delete. A sibling annotation naming the same type may be
|
|
357
|
+
* `eslint-disable`d — which a rule cannot see, since suppression is applied
|
|
358
|
+
* to reports after they are emitted — so an edit that assumes its sibling
|
|
359
|
+
* will also go deletes an import the surviving annotation still references,
|
|
360
|
+
* trading an unused import for a dangling type. Judging one edit at a time
|
|
361
|
+
* is suppression-safe by construction: a suppressed report's fix never
|
|
362
|
+
* applies, so it can never have been depended on.
|
|
363
|
+
*
|
|
364
|
+
* A type the annotation names but the helper cannot rewrite — a local alias,
|
|
365
|
+
* an interface, a type parameter — declines the fix outright. Deleting a
|
|
366
|
+
* declaration is a materially riskier edit than dropping an import
|
|
367
|
+
* specifier, and the author is better placed to decide whether the type
|
|
368
|
+
* should go or be used elsewhere.
|
|
369
|
+
*/
|
|
341
370
|
function reportIfRedundant(annotation, assertion, reportNode, fixerTarget) {
|
|
342
371
|
const matchingType = haveMatchingTypes(annotation.typeAnnotation, assertion, checker, parserServices);
|
|
343
372
|
if (!matchingType)
|
|
344
373
|
return;
|
|
374
|
+
const removal = annotationRemovalRange(fixerTarget, sourceCode);
|
|
375
|
+
const importRanges = (0, importRemoval_1.planOrphanedImportRemoval)(sourceCode, [removal]);
|
|
345
376
|
context.report({
|
|
346
377
|
node: reportNode,
|
|
347
378
|
messageId: 'redundantAnnotationAndAssertion',
|
|
348
379
|
data: { type: matchingType },
|
|
349
|
-
|
|
380
|
+
// No plan means no binding can be unbound safely, so the annotation
|
|
381
|
+
// stays too: the report without a fixer is the lesser damage.
|
|
382
|
+
...(importRanges
|
|
383
|
+
? {
|
|
384
|
+
fix: (fixer) => [
|
|
385
|
+
fixer.removeRange([removal[0], removal[1]]),
|
|
386
|
+
...importRanges.map((range) => fixer.removeRange([range[0], range[1]])),
|
|
387
|
+
],
|
|
388
|
+
}
|
|
389
|
+
: {}),
|
|
350
390
|
});
|
|
351
391
|
}
|
|
352
392
|
return {
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "1.20.93",
|
|
4
|
+
"date": "2026-08-03T22:34:05.616Z",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"name": "enforce-date-ttime",
|
|
8
|
+
"changeType": "fix",
|
|
9
|
+
"issues": [
|
|
10
|
+
1667
|
|
11
|
+
],
|
|
12
|
+
"summary": "keep the alias it rewrites away (closes #1667)"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "no-redundant-annotation-assertion",
|
|
16
|
+
"changeType": "fix",
|
|
17
|
+
"issues": [
|
|
18
|
+
1666
|
|
19
|
+
],
|
|
20
|
+
"summary": "keep the type its annotation named (closes #1666)"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
2
24
|
{
|
|
3
25
|
"version": "1.20.92",
|
|
4
26
|
"date": "2026-08-03T19:30:56.799Z",
|