@typescript-eslint/eslint-plugin 6.1.1-alpha.7 → 6.1.1-alpha.8
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.
|
@@ -1,52 +1,162 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// adapted from https://github.com/eslint/eslint/blob/5bdaae205c3a0089ea338b382df59e21d5b06436/lib/rules/utils/ast-utils.js#L1668-L1787
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.getFunctionHeadLoc = void 0;
|
|
4
5
|
const utils_1 = require("@typescript-eslint/utils");
|
|
6
|
+
const astUtils_1 = require("./astUtils");
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
* Gets the `(` token of the given function node.
|
|
9
|
+
* @param node The function node to get.
|
|
10
|
+
* @param sourceCode The source code object to get tokens.
|
|
11
|
+
* @returns `(` token.
|
|
12
|
+
*/
|
|
13
|
+
function getOpeningParenOfParams(node, sourceCode) {
|
|
14
|
+
// If the node is an arrow function and doesn't have parens, this returns the identifier of the first param.
|
|
15
|
+
if (node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression &&
|
|
16
|
+
node.params.length === 1) {
|
|
17
|
+
const argToken = utils_1.ESLintUtils.nullThrows(sourceCode.getFirstToken(node.params[0]), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('parameter', 'arrow function'));
|
|
18
|
+
const maybeParenToken = sourceCode.getTokenBefore(argToken);
|
|
19
|
+
return maybeParenToken && (0, astUtils_1.isOpeningParenToken)(maybeParenToken)
|
|
20
|
+
? maybeParenToken
|
|
21
|
+
: argToken;
|
|
22
|
+
}
|
|
23
|
+
// Otherwise, returns paren.
|
|
24
|
+
return node.id != null
|
|
25
|
+
? utils_1.ESLintUtils.nullThrows(sourceCode.getTokenAfter(node.id, astUtils_1.isOpeningParenToken), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('id', 'function'))
|
|
26
|
+
: utils_1.ESLintUtils.nullThrows(sourceCode.getFirstToken(node, astUtils_1.isOpeningParenToken), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('opening parenthesis', 'function'));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Gets the location of the given function node for reporting.
|
|
17
30
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
31
|
+
* - `function foo() {}`
|
|
32
|
+
* ^^^^^^^^^^^^
|
|
33
|
+
* - `(function foo() {})`
|
|
34
|
+
* ^^^^^^^^^^^^
|
|
35
|
+
* - `(function() {})`
|
|
36
|
+
* ^^^^^^^^
|
|
37
|
+
* - `function* foo() {}`
|
|
38
|
+
* ^^^^^^^^^^^^^
|
|
39
|
+
* - `(function* foo() {})`
|
|
40
|
+
* ^^^^^^^^^^^^^
|
|
41
|
+
* - `(function*() {})`
|
|
42
|
+
* ^^^^^^^^^
|
|
43
|
+
* - `() => {}`
|
|
44
|
+
* ^^
|
|
45
|
+
* - `async () => {}`
|
|
46
|
+
* ^^
|
|
47
|
+
* - `({ foo: function foo() {} })`
|
|
48
|
+
* ^^^^^^^^^^^^^^^^^
|
|
49
|
+
* - `({ foo: function() {} })`
|
|
50
|
+
* ^^^^^^^^^^^^^
|
|
51
|
+
* - `({ ['foo']: function() {} })`
|
|
52
|
+
* ^^^^^^^^^^^^^^^^^
|
|
53
|
+
* - `({ [foo]: function() {} })`
|
|
54
|
+
* ^^^^^^^^^^^^^^^
|
|
55
|
+
* - `({ foo() {} })`
|
|
56
|
+
* ^^^
|
|
57
|
+
* - `({ foo: function* foo() {} })`
|
|
58
|
+
* ^^^^^^^^^^^^^^^^^^
|
|
59
|
+
* - `({ foo: function*() {} })`
|
|
60
|
+
* ^^^^^^^^^^^^^^
|
|
61
|
+
* - `({ ['foo']: function*() {} })`
|
|
62
|
+
* ^^^^^^^^^^^^^^^^^^
|
|
63
|
+
* - `({ [foo]: function*() {} })`
|
|
64
|
+
* ^^^^^^^^^^^^^^^^
|
|
65
|
+
* - `({ *foo() {} })`
|
|
66
|
+
* ^^^^
|
|
67
|
+
* - `({ foo: async function foo() {} })`
|
|
68
|
+
* ^^^^^^^^^^^^^^^^^^^^^^^
|
|
69
|
+
* - `({ foo: async function() {} })`
|
|
70
|
+
* ^^^^^^^^^^^^^^^^^^^
|
|
71
|
+
* - `({ ['foo']: async function() {} })`
|
|
72
|
+
* ^^^^^^^^^^^^^^^^^^^^^^^
|
|
73
|
+
* - `({ [foo]: async function() {} })`
|
|
74
|
+
* ^^^^^^^^^^^^^^^^^^^^^
|
|
75
|
+
* - `({ async foo() {} })`
|
|
76
|
+
* ^^^^^^^^^
|
|
77
|
+
* - `({ get foo() {} })`
|
|
78
|
+
* ^^^^^^^
|
|
79
|
+
* - `({ set foo(a) {} })`
|
|
80
|
+
* ^^^^^^^
|
|
81
|
+
* - `class A { constructor() {} }`
|
|
82
|
+
* ^^^^^^^^^^^
|
|
83
|
+
* - `class A { foo() {} }`
|
|
84
|
+
* ^^^
|
|
85
|
+
* - `class A { *foo() {} }`
|
|
86
|
+
* ^^^^
|
|
87
|
+
* - `class A { async foo() {} }`
|
|
88
|
+
* ^^^^^^^^^
|
|
89
|
+
* - `class A { ['foo']() {} }`
|
|
90
|
+
* ^^^^^^^
|
|
91
|
+
* - `class A { *['foo']() {} }`
|
|
92
|
+
* ^^^^^^^^
|
|
93
|
+
* - `class A { async ['foo']() {} }`
|
|
94
|
+
* ^^^^^^^^^^^^^
|
|
95
|
+
* - `class A { [foo]() {} }`
|
|
96
|
+
* ^^^^^
|
|
97
|
+
* - `class A { *[foo]() {} }`
|
|
98
|
+
* ^^^^^^
|
|
99
|
+
* - `class A { async [foo]() {} }`
|
|
100
|
+
* ^^^^^^^^^^^
|
|
101
|
+
* - `class A { get foo() {} }`
|
|
102
|
+
* ^^^^^^^
|
|
103
|
+
* - `class A { set foo(a) {} }`
|
|
104
|
+
* ^^^^^^^
|
|
105
|
+
* - `class A { static foo() {} }`
|
|
106
|
+
* ^^^^^^^^^^
|
|
107
|
+
* - `class A { static *foo() {} }`
|
|
108
|
+
* ^^^^^^^^^^^
|
|
109
|
+
* - `class A { static async foo() {} }`
|
|
110
|
+
* ^^^^^^^^^^^^^^^^
|
|
111
|
+
* - `class A { static get foo() {} }`
|
|
112
|
+
* ^^^^^^^^^^^^^^
|
|
113
|
+
* - `class A { static set foo(a) {} }`
|
|
114
|
+
* ^^^^^^^^^^^^^^
|
|
115
|
+
* - `class A { foo = function() {} }`
|
|
116
|
+
* ^^^^^^^^^^^^^^
|
|
117
|
+
* - `class A { static foo = function() {} }`
|
|
118
|
+
* ^^^^^^^^^^^^^^^^^^^^^
|
|
119
|
+
* - `class A { foo = (a, b) => {} }`
|
|
120
|
+
* ^^^^^^
|
|
121
|
+
* @param node The function node to get.
|
|
122
|
+
* @param sourceCode The source code object to get tokens.
|
|
123
|
+
* @returns The location of the function node for reporting.
|
|
21
124
|
*/
|
|
22
125
|
function getFunctionHeadLoc(node, sourceCode) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
126
|
+
const parent = node.parent;
|
|
127
|
+
let start = null;
|
|
128
|
+
let end = null;
|
|
129
|
+
if (parent.type === utils_1.AST_NODE_TYPES.MethodDefinition ||
|
|
130
|
+
parent.type === utils_1.AST_NODE_TYPES.PropertyDefinition) {
|
|
131
|
+
// the decorator's range is included within the member
|
|
132
|
+
// however it's usually irrelevant to the member itself - so we don't want
|
|
133
|
+
// to highlight it ever.
|
|
134
|
+
if (parent.decorators.length > 0) {
|
|
135
|
+
const lastDecorator = parent.decorators[parent.decorators.length - 1];
|
|
136
|
+
const firstTokenAfterDecorator = utils_1.ESLintUtils.nullThrows(sourceCode.getTokenAfter(lastDecorator), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('modifier or member name', 'class member'));
|
|
137
|
+
start = firstTokenAfterDecorator.loc.start;
|
|
31
138
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return node.parent.loc.start;
|
|
139
|
+
else {
|
|
140
|
+
start = parent.loc.start;
|
|
35
141
|
}
|
|
36
|
-
|
|
37
|
-
return node.loc.start;
|
|
142
|
+
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
|
38
143
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
144
|
+
else if (parent.type === utils_1.AST_NODE_TYPES.Property) {
|
|
145
|
+
start = parent.loc.start;
|
|
146
|
+
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
|
147
|
+
}
|
|
148
|
+
else if (node.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
149
|
+
const arrowToken = utils_1.ESLintUtils.nullThrows(sourceCode.getTokenBefore(node.body, astUtils_1.isArrowToken), utils_1.ESLintUtils.NullThrowsReasons.MissingToken('arrow token', 'arrow function'));
|
|
150
|
+
start = arrowToken.loc.start;
|
|
151
|
+
end = arrowToken.loc.end;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
start = node.loc.start;
|
|
155
|
+
end = getOpeningParenOfParams(node, sourceCode).loc.start;
|
|
46
156
|
}
|
|
47
157
|
return {
|
|
48
|
-
start:
|
|
49
|
-
end:
|
|
158
|
+
start: Object.assign({}, start),
|
|
159
|
+
end: Object.assign({}, end),
|
|
50
160
|
};
|
|
51
161
|
}
|
|
52
162
|
exports.getFunctionHeadLoc = getFunctionHeadLoc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFunctionHeadLoc.js","sourceRoot":"","sources":["../../src/util/getFunctionHeadLoc.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getFunctionHeadLoc.js","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IAAI,CAAC,IAAI,EAAE,uBAAY,CAAC,EAClD,mBAAW,CAAC,iBAAiB,CAAC,YAAY,CACxC,aAAa,EACb,gBAAgB,CACjB,CACF,CAAC;QAEF,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;QAC7B,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;KAC1B;SAAM;QACL,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QACvB,GAAG,GAAG,uBAAuB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;KAC3D;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC;QAC/B,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC;KAC5B,CAAC;AACJ,CAAC;AApDD,gDAoDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "6.1.1-alpha.
|
|
3
|
+
"version": "6.1.1-alpha.8+f81314731",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@eslint-community/regexpp": "^4.5.1",
|
|
60
|
-
"@typescript-eslint/scope-manager": "6.1.1-alpha.
|
|
61
|
-
"@typescript-eslint/type-utils": "6.1.1-alpha.
|
|
62
|
-
"@typescript-eslint/utils": "6.1.1-alpha.
|
|
63
|
-
"@typescript-eslint/visitor-keys": "6.1.1-alpha.
|
|
60
|
+
"@typescript-eslint/scope-manager": "6.1.1-alpha.8+f81314731",
|
|
61
|
+
"@typescript-eslint/type-utils": "6.1.1-alpha.8+f81314731",
|
|
62
|
+
"@typescript-eslint/utils": "6.1.1-alpha.8+f81314731",
|
|
63
|
+
"@typescript-eslint/visitor-keys": "6.1.1-alpha.8+f81314731",
|
|
64
64
|
"debug": "^4.3.4",
|
|
65
65
|
"graphemer": "^1.4.0",
|
|
66
66
|
"ignore": "^5.2.4",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/natural-compare": "*",
|
|
76
76
|
"@types/prettier": "*",
|
|
77
77
|
"@typescript-eslint/rule-schema-to-typescript-types": "6.1.0",
|
|
78
|
-
"@typescript-eslint/rule-tester": "6.1.1-alpha.
|
|
78
|
+
"@typescript-eslint/rule-tester": "6.1.1-alpha.8+f81314731",
|
|
79
79
|
"ajv": "^6.12.6",
|
|
80
80
|
"chalk": "^5.3.0",
|
|
81
81
|
"cross-fetch": "*",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"type": "opencollective",
|
|
101
101
|
"url": "https://opencollective.com/typescript-eslint"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "f81314731cccb779423e2580a805eff3efff8564"
|
|
104
104
|
}
|