@tsslint/config 1.4.0 → 1.4.1
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/plugins/ignore.js +15 -8
- package/package.json +4 -3
- package/lib/ignore.d.ts +0 -2
- package/lib/ignore.js +0 -186
- package/lib/ignorePlugin.d.ts +0 -2
- package/lib/ignorePlugin.js +0 -186
package/lib/plugins/ignore.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = create;
|
|
4
|
-
|
|
4
|
+
const ts_api_utils_1 = require("ts-api-utils");
|
|
5
|
+
function create(cmd, reportsUnusedComments, reg = new RegExp(`//\\s*${cmd}\\b[ \\t]*(?<ruleId>\\S*)\\b`), completeReg1 = /^\s*\/\/(\s*)([\S]*)?$/, completeReg2 = new RegExp(`//\\s*${cmd}\\b[ \\t]*(\\S*)?$`)) {
|
|
5
6
|
return ({ typescript: ts, languageService }) => {
|
|
6
7
|
const reportedRulesOfFile = new Map();
|
|
7
8
|
const { getCompletionsAtPosition } = languageService;
|
|
@@ -103,25 +104,31 @@ function create(cmd, reportsUnusedComments, reg = new RegExp(`//\\s*${cmd}\\b[ \
|
|
|
103
104
|
}
|
|
104
105
|
const disabledLines = new Map();
|
|
105
106
|
const disabledLinesByRules = new Map();
|
|
106
|
-
|
|
107
|
-
const
|
|
107
|
+
(0, ts_api_utils_1.forEachComment)(sourceFile, (fullText, { pos, end }) => {
|
|
108
|
+
const commentText = fullText.substring(pos, end);
|
|
109
|
+
const comment = commentText.match(reg);
|
|
110
|
+
if (comment?.index === undefined) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const index = comment.index + pos;
|
|
114
|
+
const line = sourceFile.getLineAndCharacterOfPosition(index).line + 1;
|
|
108
115
|
const ruleId = comment.groups?.ruleId;
|
|
109
116
|
if (ruleId) {
|
|
110
117
|
if (!disabledLinesByRules.has(ruleId)) {
|
|
111
118
|
disabledLinesByRules.set(ruleId, new Map());
|
|
112
119
|
}
|
|
113
120
|
disabledLinesByRules.get(ruleId).set(line, {
|
|
114
|
-
start:
|
|
115
|
-
end:
|
|
121
|
+
start: index,
|
|
122
|
+
end: index + comment[0].length,
|
|
116
123
|
});
|
|
117
124
|
}
|
|
118
125
|
else {
|
|
119
126
|
disabledLines.set(line, {
|
|
120
|
-
start:
|
|
121
|
-
end:
|
|
127
|
+
start: index,
|
|
128
|
+
end: index + comment[0].length,
|
|
122
129
|
});
|
|
123
130
|
}
|
|
124
|
-
}
|
|
131
|
+
});
|
|
125
132
|
let reportedRules = reportedRulesOfFile.get(sourceFile.fileName);
|
|
126
133
|
if (!reportedRules) {
|
|
127
134
|
reportedRules = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/config",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"directory": "packages/config"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/types": "1.4.
|
|
15
|
+
"@tsslint/types": "1.4.1",
|
|
16
|
+
"ts-api-utils": "^2.0.0"
|
|
16
17
|
},
|
|
17
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "54f42ec9414029a356fa19a762260f03392563fa"
|
|
18
19
|
}
|
package/lib/ignore.d.ts
DELETED
package/lib/ignore.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create = create;
|
|
4
|
-
function create(cmd, reportsUnusedComments) {
|
|
5
|
-
return ({ typescript: ts, languageService }) => {
|
|
6
|
-
const reg = new RegExp(`//\\s*${cmd}\\b[ \\t]*(?<ruleId>\\S*)\\b`, 'g');
|
|
7
|
-
const completeReg1 = /^\s*\/\/(\s*)([\S]*)?$/;
|
|
8
|
-
const completeReg2 = new RegExp(`//\\s*${cmd}\\b[ \\t]*(\\S*)?$`);
|
|
9
|
-
const reportedRulesOfFile = new Map();
|
|
10
|
-
const { getCompletionsAtPosition } = languageService;
|
|
11
|
-
languageService.getCompletionsAtPosition = (fileName, position, ...rest) => {
|
|
12
|
-
let result = getCompletionsAtPosition(fileName, position, ...rest);
|
|
13
|
-
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
|
|
14
|
-
if (!sourceFile) {
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
const reportedRules = reportedRulesOfFile.get(fileName);
|
|
18
|
-
const line = sourceFile.getLineAndCharacterOfPosition(position).line;
|
|
19
|
-
const lineStart = sourceFile.getPositionOfLineAndCharacter(line, 0);
|
|
20
|
-
const prefix = sourceFile.text.slice(lineStart, position);
|
|
21
|
-
const matchCmd = completeReg1
|
|
22
|
-
? prefix.match(completeReg1)
|
|
23
|
-
: undefined;
|
|
24
|
-
if (matchCmd) {
|
|
25
|
-
const nextLineRules = reportedRules?.filter(([, reportedLine]) => reportedLine === line + 1) ?? [];
|
|
26
|
-
const item = {
|
|
27
|
-
name: cmd,
|
|
28
|
-
insertText: matchCmd[1].length ? cmd : ` ${cmd}`,
|
|
29
|
-
kind: ts.ScriptElementKind.keyword,
|
|
30
|
-
sortText: 'a',
|
|
31
|
-
replacementSpan: matchCmd[2]
|
|
32
|
-
? {
|
|
33
|
-
start: position - matchCmd[2].length,
|
|
34
|
-
length: matchCmd[2].length,
|
|
35
|
-
}
|
|
36
|
-
: undefined,
|
|
37
|
-
labelDetails: {
|
|
38
|
-
description: nextLineRules.length >= 2
|
|
39
|
-
? `Ignore ${nextLineRules.length} issues in next line`
|
|
40
|
-
: nextLineRules.length
|
|
41
|
-
? 'Ignore 1 issue in next line'
|
|
42
|
-
: undefined,
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
if (result) {
|
|
46
|
-
result.entries.push(item);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
result = {
|
|
50
|
-
isGlobalCompletion: false,
|
|
51
|
-
isMemberCompletion: false,
|
|
52
|
-
isNewIdentifierLocation: false,
|
|
53
|
-
entries: [item],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else if (reportedRules?.length) {
|
|
58
|
-
const matchRule = completeReg2
|
|
59
|
-
? prefix.match(completeReg2)
|
|
60
|
-
: undefined;
|
|
61
|
-
if (matchRule) {
|
|
62
|
-
const visited = new Set();
|
|
63
|
-
for (const [ruleId] of reportedRules) {
|
|
64
|
-
if (visited.has(ruleId)) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
visited.add(ruleId);
|
|
68
|
-
const reportedLines = reportedRules
|
|
69
|
-
.filter(([r]) => r === ruleId)
|
|
70
|
-
.map(([, l]) => l + 1);
|
|
71
|
-
const item = {
|
|
72
|
-
name: ruleId,
|
|
73
|
-
kind: ts.ScriptElementKind.keyword,
|
|
74
|
-
sortText: ruleId,
|
|
75
|
-
replacementSpan: matchRule[1]
|
|
76
|
-
? {
|
|
77
|
-
start: position - matchRule[1].length,
|
|
78
|
-
length: matchRule[1].length,
|
|
79
|
-
}
|
|
80
|
-
: undefined,
|
|
81
|
-
labelDetails: {
|
|
82
|
-
description: `Reported in line${reportedLines.length >= 2 ? 's' : ''} ${reportedLines.join(', ')}`,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
if (result) {
|
|
86
|
-
result.entries.push(item);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
result = {
|
|
90
|
-
isGlobalCompletion: false,
|
|
91
|
-
isMemberCompletion: false,
|
|
92
|
-
isNewIdentifierLocation: false,
|
|
93
|
-
entries: [item],
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
resolveDiagnostics(sourceFile, results) {
|
|
103
|
-
if (!reportsUnusedComments &&
|
|
104
|
-
!results.some(error => error.source === 'tsslint')) {
|
|
105
|
-
return results;
|
|
106
|
-
}
|
|
107
|
-
const disabledLines = new Map();
|
|
108
|
-
const disabledLinesByRules = new Map();
|
|
109
|
-
for (const comment of sourceFile.text.matchAll(reg)) {
|
|
110
|
-
const line = sourceFile.getLineAndCharacterOfPosition(comment.index).line + 1;
|
|
111
|
-
const ruleId = comment.groups?.ruleId;
|
|
112
|
-
if (ruleId) {
|
|
113
|
-
if (!disabledLinesByRules.has(ruleId)) {
|
|
114
|
-
disabledLinesByRules.set(ruleId, new Map());
|
|
115
|
-
}
|
|
116
|
-
disabledLinesByRules.get(ruleId).set(line, {
|
|
117
|
-
start: comment.index,
|
|
118
|
-
end: comment.index + comment[0].length,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
disabledLines.set(line, {
|
|
123
|
-
start: comment.index,
|
|
124
|
-
end: comment.index + comment[0].length,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
let reportedRules = reportedRulesOfFile.get(sourceFile.fileName);
|
|
129
|
-
if (!reportedRules) {
|
|
130
|
-
reportedRules = [];
|
|
131
|
-
reportedRulesOfFile.set(sourceFile.fileName, reportedRules);
|
|
132
|
-
}
|
|
133
|
-
reportedRules.length = 0;
|
|
134
|
-
results = results.filter(error => {
|
|
135
|
-
if (error.source !== 'tsslint') {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
const line = sourceFile.getLineAndCharacterOfPosition(error.start).line;
|
|
139
|
-
reportedRules.push([error.code, line]);
|
|
140
|
-
if (disabledLines.has(line)) {
|
|
141
|
-
disabledLines.get(line).used = true;
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
const disabledLinesByRule = disabledLinesByRules.get(error.code);
|
|
145
|
-
if (disabledLinesByRule?.has(line)) {
|
|
146
|
-
disabledLinesByRule.get(line).used = true;
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
-
});
|
|
151
|
-
if (reportsUnusedComments) {
|
|
152
|
-
for (const state of disabledLines.values()) {
|
|
153
|
-
if (!state.used) {
|
|
154
|
-
results.push({
|
|
155
|
-
file: sourceFile,
|
|
156
|
-
start: state.start,
|
|
157
|
-
length: state.end - state.start,
|
|
158
|
-
code: 'tsslint:unused-ignore-comment',
|
|
159
|
-
messageText: `Unused ${cmd} comment.`,
|
|
160
|
-
source: 'tsslint',
|
|
161
|
-
category: 1,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
for (const disabledLinesByRule of disabledLinesByRules.values()) {
|
|
166
|
-
for (const state of disabledLinesByRule.values()) {
|
|
167
|
-
if (!state.used) {
|
|
168
|
-
results.push({
|
|
169
|
-
file: sourceFile,
|
|
170
|
-
start: state.start,
|
|
171
|
-
length: state.end - state.start,
|
|
172
|
-
code: 'tsslint:unused-ignore-comment',
|
|
173
|
-
messageText: `Unused ${cmd} comment.`,
|
|
174
|
-
source: 'tsslint',
|
|
175
|
-
category: 1,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return results;
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
//# sourceMappingURL=ignore.js.map
|
package/lib/ignorePlugin.d.ts
DELETED
package/lib/ignorePlugin.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create = create;
|
|
4
|
-
function create(cmd, reportsUnusedComments) {
|
|
5
|
-
return ({ typescript: ts, languageService }) => {
|
|
6
|
-
const reg = new RegExp(`//\\s*${cmd}\\b[ \\t]*(?<ruleId>\\S*)\\b`, 'g');
|
|
7
|
-
const completeReg1 = /^\s*\/\/(\s*)([\S]*)?$/;
|
|
8
|
-
const completeReg2 = new RegExp(`//\\s*${cmd}\\b[ \\t]*(\\S*)?$`);
|
|
9
|
-
const reportedRulesOfFile = new Map();
|
|
10
|
-
const { getCompletionsAtPosition } = languageService;
|
|
11
|
-
languageService.getCompletionsAtPosition = (fileName, position, ...rest) => {
|
|
12
|
-
let result = getCompletionsAtPosition(fileName, position, ...rest);
|
|
13
|
-
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
|
|
14
|
-
if (!sourceFile) {
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
const reportedRules = reportedRulesOfFile.get(fileName);
|
|
18
|
-
const line = sourceFile.getLineAndCharacterOfPosition(position).line;
|
|
19
|
-
const lineStart = sourceFile.getPositionOfLineAndCharacter(line, 0);
|
|
20
|
-
const prefix = sourceFile.text.slice(lineStart, position);
|
|
21
|
-
const matchCmd = completeReg1
|
|
22
|
-
? prefix.match(completeReg1)
|
|
23
|
-
: undefined;
|
|
24
|
-
if (matchCmd) {
|
|
25
|
-
const nextLineRules = reportedRules?.filter(([, reportedLine]) => reportedLine === line + 1) ?? [];
|
|
26
|
-
const item = {
|
|
27
|
-
name: cmd,
|
|
28
|
-
insertText: matchCmd[1].length ? cmd : ` ${cmd}`,
|
|
29
|
-
kind: ts.ScriptElementKind.keyword,
|
|
30
|
-
sortText: 'a',
|
|
31
|
-
replacementSpan: matchCmd[2]
|
|
32
|
-
? {
|
|
33
|
-
start: position - matchCmd[2].length,
|
|
34
|
-
length: matchCmd[2].length,
|
|
35
|
-
}
|
|
36
|
-
: undefined,
|
|
37
|
-
labelDetails: {
|
|
38
|
-
description: nextLineRules.length >= 2
|
|
39
|
-
? `Ignore ${nextLineRules.length} issues in next line`
|
|
40
|
-
: nextLineRules.length
|
|
41
|
-
? 'Ignore 1 issue in next line'
|
|
42
|
-
: undefined,
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
if (result) {
|
|
46
|
-
result.entries.push(item);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
result = {
|
|
50
|
-
isGlobalCompletion: false,
|
|
51
|
-
isMemberCompletion: false,
|
|
52
|
-
isNewIdentifierLocation: false,
|
|
53
|
-
entries: [item],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else if (reportedRules?.length) {
|
|
58
|
-
const matchRule = completeReg2
|
|
59
|
-
? prefix.match(completeReg2)
|
|
60
|
-
: undefined;
|
|
61
|
-
if (matchRule) {
|
|
62
|
-
const visited = new Set();
|
|
63
|
-
for (const [ruleId] of reportedRules) {
|
|
64
|
-
if (visited.has(ruleId)) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
visited.add(ruleId);
|
|
68
|
-
const reportedLines = reportedRules
|
|
69
|
-
.filter(([r]) => r === ruleId)
|
|
70
|
-
.map(([, l]) => l + 1);
|
|
71
|
-
const item = {
|
|
72
|
-
name: ruleId,
|
|
73
|
-
kind: ts.ScriptElementKind.keyword,
|
|
74
|
-
sortText: ruleId,
|
|
75
|
-
replacementSpan: matchRule[1]
|
|
76
|
-
? {
|
|
77
|
-
start: position - matchRule[1].length,
|
|
78
|
-
length: matchRule[1].length,
|
|
79
|
-
}
|
|
80
|
-
: undefined,
|
|
81
|
-
labelDetails: {
|
|
82
|
-
description: `Reported in line${reportedLines.length >= 2 ? 's' : ''} ${reportedLines.join(', ')}`,
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
if (result) {
|
|
86
|
-
result.entries.push(item);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
result = {
|
|
90
|
-
isGlobalCompletion: false,
|
|
91
|
-
isMemberCompletion: false,
|
|
92
|
-
isNewIdentifierLocation: false,
|
|
93
|
-
entries: [item],
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
resolveDiagnostics(sourceFile, results) {
|
|
103
|
-
if (!reportsUnusedComments &&
|
|
104
|
-
!results.some(error => error.source === 'tsslint')) {
|
|
105
|
-
return results;
|
|
106
|
-
}
|
|
107
|
-
const disabledLines = new Map();
|
|
108
|
-
const disabledLinesByRules = new Map();
|
|
109
|
-
for (const comment of sourceFile.text.matchAll(reg)) {
|
|
110
|
-
const line = sourceFile.getLineAndCharacterOfPosition(comment.index).line + 1;
|
|
111
|
-
const ruleId = comment.groups?.ruleId;
|
|
112
|
-
if (ruleId) {
|
|
113
|
-
if (!disabledLinesByRules.has(ruleId)) {
|
|
114
|
-
disabledLinesByRules.set(ruleId, new Map());
|
|
115
|
-
}
|
|
116
|
-
disabledLinesByRules.get(ruleId).set(line, {
|
|
117
|
-
start: comment.index,
|
|
118
|
-
end: comment.index + comment[0].length,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
disabledLines.set(line, {
|
|
123
|
-
start: comment.index,
|
|
124
|
-
end: comment.index + comment[0].length,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
let reportedRules = reportedRulesOfFile.get(sourceFile.fileName);
|
|
129
|
-
if (!reportedRules) {
|
|
130
|
-
reportedRules = [];
|
|
131
|
-
reportedRulesOfFile.set(sourceFile.fileName, reportedRules);
|
|
132
|
-
}
|
|
133
|
-
reportedRules.length = 0;
|
|
134
|
-
results = results.filter(error => {
|
|
135
|
-
if (error.source !== 'tsslint') {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
const line = sourceFile.getLineAndCharacterOfPosition(error.start).line;
|
|
139
|
-
reportedRules.push([error.code, line]);
|
|
140
|
-
if (disabledLines.has(line)) {
|
|
141
|
-
disabledLines.get(line).used = true;
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
const disabledLinesByRule = disabledLinesByRules.get(error.code);
|
|
145
|
-
if (disabledLinesByRule?.has(line)) {
|
|
146
|
-
disabledLinesByRule.get(line).used = true;
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
-
});
|
|
151
|
-
if (reportsUnusedComments) {
|
|
152
|
-
for (const state of disabledLines.values()) {
|
|
153
|
-
if (!state.used) {
|
|
154
|
-
results.push({
|
|
155
|
-
file: sourceFile,
|
|
156
|
-
start: state.start,
|
|
157
|
-
length: state.end - state.start,
|
|
158
|
-
code: 'tsslint:unused-ignore-comment',
|
|
159
|
-
messageText: `Unused ${cmd} comment.`,
|
|
160
|
-
source: 'tsslint',
|
|
161
|
-
category: 1,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
for (const disabledLinesByRule of disabledLinesByRules.values()) {
|
|
166
|
-
for (const state of disabledLinesByRule.values()) {
|
|
167
|
-
if (!state.used) {
|
|
168
|
-
results.push({
|
|
169
|
-
file: sourceFile,
|
|
170
|
-
start: state.start,
|
|
171
|
-
length: state.end - state.start,
|
|
172
|
-
code: 'tsslint:unused-ignore-comment',
|
|
173
|
-
messageText: `Unused ${cmd} comment.`,
|
|
174
|
-
source: 'tsslint',
|
|
175
|
-
category: 1,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return results;
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
//# sourceMappingURL=ignorePlugin.js.map
|