@tsslint/config 1.5.2 → 1.5.4

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.
@@ -6,9 +6,11 @@ function create(cmdOption, reportsUnusedComments) {
6
6
  const mode = typeof cmdOption === 'string' ? 'singleLine' : 'multiLine';
7
7
  const [cmd, endCmd] = Array.isArray(cmdOption) ? cmdOption : [cmdOption, undefined];
8
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;
9
+ const withRuleId = '[ \\t]*(?<ruleId>\\w\\S*)?';
10
+ const header = '^\\s*';
11
+ const ending = '([ \\t]+[^\\r\\n]*)?$';
12
+ const reg = new RegExp(`${header}${cmd}${withRuleId}${ending}`);
13
+ const endReg = endCmd ? new RegExp(`${header}${endCmd}${withRuleId}${ending}`) : undefined;
12
14
  const completeReg1 = /^\s*\/\/(\s*)([\S]*)?$/;
13
15
  const completeReg2 = new RegExp(`//\\s*${cmd}(\\S*)?$`);
14
16
  return ({ typescript: ts, languageService }) => {
@@ -119,29 +121,36 @@ function create(cmdOption, reportsUnusedComments) {
119
121
  const startComment = commentText.match(reg);
120
122
  if (startComment?.index !== undefined) {
121
123
  const index = startComment.index + pos;
122
- const nextLine = sourceFile.getLineAndCharacterOfPosition(index).line + 1;
123
124
  const ruleId = startComment.groups?.ruleId;
124
125
  if (!comments.has(ruleId)) {
125
126
  comments.set(ruleId, []);
126
127
  }
127
128
  const disabledLines = comments.get(ruleId);
129
+ const line = sourceFile.getLineAndCharacterOfPosition(index).line;
130
+ let startLine = line;
131
+ if (mode === 'singleLine') {
132
+ const startWithComment = sourceFile.text.slice(sourceFile.getPositionOfLineAndCharacter(line, 0), index - 2).trim() === '';
133
+ if (startWithComment) {
134
+ startLine = line + 1; // If the comment is at the start of the line, the error is in the next line
135
+ }
136
+ }
128
137
  disabledLines.push({
129
138
  commentRange: [
130
139
  index - 2,
131
140
  index + startComment[0].length,
132
141
  ],
133
- nextLine,
142
+ startLine,
134
143
  });
135
144
  }
136
145
  else if (endReg) {
137
146
  const endComment = commentText.match(endReg);
138
147
  if (endComment?.index !== undefined) {
139
148
  const index = endComment.index + pos;
140
- const prevLine = sourceFile.getLineAndCharacterOfPosition(index).line - 1;
149
+ const prevLine = sourceFile.getLineAndCharacterOfPosition(index).line;
141
150
  const ruleId = endComment.groups?.ruleId;
142
151
  const disabledLines = comments.get(ruleId);
143
152
  if (disabledLines) {
144
- disabledLines[disabledLines.length - 1].lastLine = prevLine;
153
+ disabledLines[disabledLines.length - 1].endLine = prevLine;
145
154
  }
146
155
  }
147
156
  }
@@ -162,9 +171,9 @@ function create(cmdOption, reportsUnusedComments) {
162
171
  const states = comments.get(code);
163
172
  if (states) {
164
173
  if (mode === 'singleLine') {
165
- if (states.some(({ nextLine }) => nextLine === line)) {
174
+ if (states.some(comment => comment.startLine === line)) {
166
175
  for (const state of states) {
167
- if (state.nextLine === line) {
176
+ if (state.startLine === line) {
168
177
  state.used = true;
169
178
  break;
170
179
  }
@@ -173,9 +182,9 @@ function create(cmdOption, reportsUnusedComments) {
173
182
  }
174
183
  }
175
184
  else {
176
- if (states.some(({ nextLine, lastLine }) => line >= nextLine && line <= (lastLine ?? Number.MAX_VALUE))) {
185
+ if (states.some((comment => line >= comment.startLine && line <= (comment.endLine ?? Number.MAX_VALUE)))) {
177
186
  for (const state of states) {
178
- if (line >= state.nextLine && line <= (state.lastLine ?? Number.MAX_VALUE)) {
187
+ if (line >= state.startLine && line <= (state.endLine ?? Number.MAX_VALUE)) {
179
188
  state.used = true;
180
189
  break;
181
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/config",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
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.2",
15
+ "@tsslint/types": "1.5.4",
16
16
  "ts-api-utils": "^2.0.0"
17
17
  },
18
- "gitHead": "7d5ed919f5a6ac75b76319396ff2d43b5d9a8ad4"
18
+ "gitHead": "02cbc403c85b4224b5ccd732dc96f7a0991a6ae2"
19
19
  }