@tsslint/config 1.5.0 → 1.5.2
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.d.ts +1 -1
- package/lib/plugins/ignore.js +75 -51
- package/package.json +3 -3
package/lib/plugins/ignore.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Plugin } from '@tsslint/types';
|
|
2
|
-
export declare function create(
|
|
2
|
+
export declare function create(cmdOption: string | [string, string], reportsUnusedComments: boolean): Plugin;
|
package/lib/plugins/ignore.js
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
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(
|
|
5
|
+
function create(cmdOption, reportsUnusedComments) {
|
|
6
|
+
const mode = typeof cmdOption === 'string' ? 'singleLine' : 'multiLine';
|
|
7
|
+
const [cmd, endCmd] = Array.isArray(cmdOption) ? cmdOption : [cmdOption, undefined];
|
|
8
|
+
const cmdText = cmd.replace(/\?/g, '');
|
|
9
|
+
const withRuleId = '(\\b[ \\t]*|[ \\t]+)(?<ruleId>\\S*\\b)?';
|
|
10
|
+
const reg = new RegExp(`\\s*${cmd}${withRuleId}`);
|
|
11
|
+
const endReg = endCmd ? new RegExp(`\\s*${endCmd}${withRuleId}`) : undefined;
|
|
12
|
+
const completeReg1 = /^\s*\/\/(\s*)([\S]*)?$/;
|
|
13
|
+
const completeReg2 = new RegExp(`//\\s*${cmd}(\\S*)?$`);
|
|
6
14
|
return ({ typescript: ts, languageService }) => {
|
|
7
15
|
const reportedRulesOfFile = new Map();
|
|
8
16
|
const { getCompletionsAtPosition } = languageService;
|
|
@@ -22,8 +30,8 @@ function create(cmd, reportsUnusedComments, reg = new RegExp(`//\\s*${cmd}\\b[ \
|
|
|
22
30
|
if (matchCmd) {
|
|
23
31
|
const nextLineRules = reportedRules?.filter(([, reportedLine]) => reportedLine === line + 1) ?? [];
|
|
24
32
|
const item = {
|
|
25
|
-
name:
|
|
26
|
-
insertText: matchCmd[1].length ?
|
|
33
|
+
name: cmdText,
|
|
34
|
+
insertText: matchCmd[1].length ? cmdText : ` ${cmdText}`,
|
|
27
35
|
kind: ts.ScriptElementKind.keyword,
|
|
28
36
|
sortText: 'a',
|
|
29
37
|
replacementSpan: matchCmd[2]
|
|
@@ -102,31 +110,40 @@ function create(cmd, reportsUnusedComments, reg = new RegExp(`//\\s*${cmd}\\b[ \
|
|
|
102
110
|
!results.some(error => error.source === 'tsslint')) {
|
|
103
111
|
return results;
|
|
104
112
|
}
|
|
105
|
-
const
|
|
106
|
-
const
|
|
113
|
+
const comments = new Map();
|
|
114
|
+
const logs = [];
|
|
107
115
|
(0, ts_api_utils_1.forEachComment)(sourceFile, (fullText, { pos, end }) => {
|
|
116
|
+
pos += 2; // Trim the // or /* characters
|
|
108
117
|
const commentText = fullText.substring(pos, end);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (!disabledLinesByRules.has(ruleId)) {
|
|
118
|
-
disabledLinesByRules.set(ruleId, new Map());
|
|
118
|
+
logs.push(commentText);
|
|
119
|
+
const startComment = commentText.match(reg);
|
|
120
|
+
if (startComment?.index !== undefined) {
|
|
121
|
+
const index = startComment.index + pos;
|
|
122
|
+
const nextLine = sourceFile.getLineAndCharacterOfPosition(index).line + 1;
|
|
123
|
+
const ruleId = startComment.groups?.ruleId;
|
|
124
|
+
if (!comments.has(ruleId)) {
|
|
125
|
+
comments.set(ruleId, []);
|
|
119
126
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
const disabledLines = comments.get(ruleId);
|
|
128
|
+
disabledLines.push({
|
|
129
|
+
commentRange: [
|
|
130
|
+
index - 2,
|
|
131
|
+
index + startComment[0].length,
|
|
132
|
+
],
|
|
133
|
+
nextLine,
|
|
123
134
|
});
|
|
124
135
|
}
|
|
125
|
-
else {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
136
|
+
else if (endReg) {
|
|
137
|
+
const endComment = commentText.match(endReg);
|
|
138
|
+
if (endComment?.index !== undefined) {
|
|
139
|
+
const index = endComment.index + pos;
|
|
140
|
+
const prevLine = sourceFile.getLineAndCharacterOfPosition(index).line - 1;
|
|
141
|
+
const ruleId = endComment.groups?.ruleId;
|
|
142
|
+
const disabledLines = comments.get(ruleId);
|
|
143
|
+
if (disabledLines) {
|
|
144
|
+
disabledLines[disabledLines.length - 1].lastLine = prevLine;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
130
147
|
}
|
|
131
148
|
});
|
|
132
149
|
let reportedRules = reportedRulesOfFile.get(sourceFile.fileName);
|
|
@@ -141,40 +158,45 @@ function create(cmd, reportsUnusedComments, reg = new RegExp(`//\\s*${cmd}\\b[ \
|
|
|
141
158
|
}
|
|
142
159
|
const line = sourceFile.getLineAndCharacterOfPosition(error.start).line;
|
|
143
160
|
reportedRules.push([error.code, line]);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
for (const code of [undefined, error.code]) {
|
|
162
|
+
const states = comments.get(code);
|
|
163
|
+
if (states) {
|
|
164
|
+
if (mode === 'singleLine') {
|
|
165
|
+
if (states.some(({ nextLine }) => nextLine === line)) {
|
|
166
|
+
for (const state of states) {
|
|
167
|
+
if (state.nextLine === line) {
|
|
168
|
+
state.used = true;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (states.some(({ nextLine, lastLine }) => line >= nextLine && line <= (lastLine ?? Number.MAX_VALUE))) {
|
|
177
|
+
for (const state of states) {
|
|
178
|
+
if (line >= state.nextLine && line <= (state.lastLine ?? Number.MAX_VALUE)) {
|
|
179
|
+
state.used = true;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
152
187
|
}
|
|
153
188
|
return true;
|
|
154
189
|
});
|
|
155
190
|
if (reportsUnusedComments) {
|
|
156
|
-
for (const
|
|
157
|
-
|
|
158
|
-
results.push({
|
|
159
|
-
file: sourceFile,
|
|
160
|
-
start: state.start,
|
|
161
|
-
length: state.end - state.start,
|
|
162
|
-
code: 'tsslint:unused-ignore-comment',
|
|
163
|
-
messageText: `Unused ${cmd} comment.`,
|
|
164
|
-
source: 'tsslint',
|
|
165
|
-
category: 1,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
for (const disabledLinesByRule of disabledLinesByRules.values()) {
|
|
170
|
-
for (const state of disabledLinesByRule.values()) {
|
|
191
|
+
for (const comment of comments.values()) {
|
|
192
|
+
for (const state of comment.values()) {
|
|
171
193
|
if (!state.used) {
|
|
172
194
|
results.push({
|
|
173
195
|
file: sourceFile,
|
|
174
|
-
start: state.
|
|
175
|
-
length: state.
|
|
196
|
+
start: state.commentRange[0],
|
|
197
|
+
length: state.commentRange[1] - state.commentRange[0],
|
|
176
198
|
code: 'tsslint:unused-ignore-comment',
|
|
177
|
-
messageText: `Unused
|
|
199
|
+
messageText: `Unused comment.`,
|
|
178
200
|
source: 'tsslint',
|
|
179
201
|
category: 1,
|
|
180
202
|
});
|
|
@@ -191,12 +213,14 @@ function create(cmd, reportsUnusedComments, reg = new RegExp(`//\\s*${cmd}\\b[ \
|
|
|
191
213
|
const line = sourceFile.getLineAndCharacterOfPosition(diagnostic.start).line;
|
|
192
214
|
codeFixes.push({
|
|
193
215
|
fixName: cmd,
|
|
194
|
-
description: `Ignore with ${
|
|
216
|
+
description: `Ignore with ${cmdText}`,
|
|
195
217
|
changes: [
|
|
196
218
|
{
|
|
197
219
|
fileName: sourceFile.fileName,
|
|
198
220
|
textChanges: [{
|
|
199
|
-
newText:
|
|
221
|
+
newText: reg.test(`${cmdText}${diagnostic.code}`)
|
|
222
|
+
? `// ${cmdText}${diagnostic.code}\n`
|
|
223
|
+
: `// ${cmdText} ${diagnostic.code}\n`,
|
|
200
224
|
span: {
|
|
201
225
|
start: sourceFile.getPositionOfLineAndCharacter(line, 0),
|
|
202
226
|
length: 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/config",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"directory": "packages/config"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/types": "1.5.
|
|
15
|
+
"@tsslint/types": "1.5.2",
|
|
16
16
|
"ts-api-utils": "^2.0.0"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "7d5ed919f5a6ac75b76319396ff2d43b5d9a8ad4"
|
|
19
19
|
}
|