@typescript-eslint/eslint-plugin 7.12.1-alpha.14 → 7.12.1-alpha.16
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.
|
@@ -18,7 +18,45 @@ exports.default = (0, util_1.createRule)({
|
|
|
18
18
|
},
|
|
19
19
|
defaultOptions: ['always'],
|
|
20
20
|
create(context, [mode]) {
|
|
21
|
-
|
|
21
|
+
// Make a custom context to adjust the the loc of reports where the base
|
|
22
|
+
// rule's behavior is a bit too aggressive with TS-specific syntax (namely,
|
|
23
|
+
// type annotations).
|
|
24
|
+
function getBaseContextOverride() {
|
|
25
|
+
const reportOverride = descriptor => {
|
|
26
|
+
if ('node' in descriptor && descriptor.loc == null) {
|
|
27
|
+
const { node, ...rest } = descriptor;
|
|
28
|
+
// We only want to special case the report loc when reporting on
|
|
29
|
+
// variables declarations that are not initialized. Declarations that
|
|
30
|
+
// _are_ initialized get reported by the base rule due to a setting to
|
|
31
|
+
// prohibit initializing variables entirely, in which case underlining
|
|
32
|
+
// the whole node including the type annotation and initializer is
|
|
33
|
+
// appropriate.
|
|
34
|
+
if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
|
|
35
|
+
node.init == null) {
|
|
36
|
+
context.report({
|
|
37
|
+
...rest,
|
|
38
|
+
loc: getReportLoc(node),
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
context.report(descriptor);
|
|
44
|
+
};
|
|
45
|
+
// `return { ...context, report: reportOverride }` isn't safe because the
|
|
46
|
+
// `context` object has some getters that need to be preserved.
|
|
47
|
+
//
|
|
48
|
+
// `return new Proxy(context, ...)` doesn't work because `context` has
|
|
49
|
+
// non-configurable properties that throw when constructing a Proxy.
|
|
50
|
+
//
|
|
51
|
+
// So, we'll just use Proxy on a dummy object and use the `get` trap to
|
|
52
|
+
// proxy `context`'s properties.
|
|
53
|
+
return new Proxy({}, {
|
|
54
|
+
get: (target, prop, receiver) => prop === 'report'
|
|
55
|
+
? reportOverride
|
|
56
|
+
: Reflect.get(context, prop, receiver),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const rules = baseRule.create(getBaseContextOverride());
|
|
22
60
|
return {
|
|
23
61
|
'VariableDeclaration:exit'(node) {
|
|
24
62
|
if (mode === 'always') {
|
|
@@ -45,4 +83,22 @@ exports.default = (0, util_1.createRule)({
|
|
|
45
83
|
}
|
|
46
84
|
},
|
|
47
85
|
});
|
|
86
|
+
/**
|
|
87
|
+
* When reporting an uninitialized variable declarator, get the loc excluding
|
|
88
|
+
* the type annotation.
|
|
89
|
+
*/
|
|
90
|
+
function getReportLoc(node) {
|
|
91
|
+
const start = structuredClone(node.loc.start);
|
|
92
|
+
const end = {
|
|
93
|
+
line: node.loc.start.line,
|
|
94
|
+
// `if (id.type === AST_NODE_TYPES.Identifier)` is a condition for
|
|
95
|
+
// reporting in the base rule (as opposed to things like destructuring
|
|
96
|
+
// assignment), so the type assertion should always be valid.
|
|
97
|
+
column: node.loc.start.column + node.id.name.length,
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
start,
|
|
101
|
+
end,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
48
104
|
//# sourceMappingURL=init-declarations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-declarations.js","sourceRoot":"","sources":["../../src/rules/init-declarations.ts"],"names":[],"mappings":";;AACA,oDAA0D;AAM1D,kCAAqC;AACrC,iEAA8D;AAE9D,MAAM,QAAQ,GAAG,IAAA,qCAAiB,EAAC,mBAAmB,CAAC,CAAC;AAKxD,kBAAe,IAAA,iBAAU,EAAsB;IAC7C,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,6DAA6D;YAC/D,eAAe,EAAE,IAAI;SACtB;QACD,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC,cAA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pD,QAAQ,CAAC,OAAO,EAChB,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC;gBAED,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;YAC7B,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAS,YAAY,CACnB,IAAiC;IAEjC,MAAM,KAAK,GAAsB,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjE,MAAM,GAAG,GAAsB;QAC7B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI;QACzB,kEAAkE;QAClE,sEAAsE;QACtE,6DAA6D;QAC7D,MAAM,EACJ,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAI,IAAI,CAAC,EAA0B,CAAC,IAAI,CAAC,MAAM;KACvE,CAAC;IAEF,OAAO;QACL,KAAK;QACL,GAAG;KACJ,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "7.12.1-alpha.
|
|
3
|
+
"version": "7.12.1-alpha.16",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@eslint-community/regexpp": "^4.10.0",
|
|
65
|
-
"@typescript-eslint/scope-manager": "7.12.1-alpha.
|
|
66
|
-
"@typescript-eslint/type-utils": "7.12.1-alpha.
|
|
67
|
-
"@typescript-eslint/utils": "7.12.1-alpha.
|
|
68
|
-
"@typescript-eslint/visitor-keys": "7.12.1-alpha.
|
|
65
|
+
"@typescript-eslint/scope-manager": "7.12.1-alpha.16",
|
|
66
|
+
"@typescript-eslint/type-utils": "7.12.1-alpha.16",
|
|
67
|
+
"@typescript-eslint/utils": "7.12.1-alpha.16",
|
|
68
|
+
"@typescript-eslint/visitor-keys": "7.12.1-alpha.16",
|
|
69
69
|
"graphemer": "^1.4.0",
|
|
70
70
|
"ignore": "^5.3.1",
|
|
71
71
|
"natural-compare": "^1.4.0",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@types/marked": "^5.0.2",
|
|
77
77
|
"@types/mdast": "^4.0.3",
|
|
78
78
|
"@types/natural-compare": "*",
|
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "7.12.1-alpha.
|
|
80
|
-
"@typescript-eslint/rule-tester": "7.12.1-alpha.
|
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "7.12.1-alpha.16",
|
|
80
|
+
"@typescript-eslint/rule-tester": "7.12.1-alpha.16",
|
|
81
81
|
"ajv": "^6.12.6",
|
|
82
82
|
"cross-env": "^7.0.3",
|
|
83
83
|
"cross-fetch": "*",
|