@tsslint/config 2.0.0 → 2.0.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.
@@ -4,15 +4,15 @@ exports.create = create;
4
4
  function create(mode = 'semantic') {
5
5
  const modes = Array.isArray(mode) ? mode : [mode];
6
6
  return ({ languageService }) => ({
7
- resolveDiagnostics(sourceFile, diagnostics) {
7
+ resolveDiagnostics(file, diagnostics) {
8
8
  const program = languageService.getProgram();
9
9
  for (const mode of modes) {
10
10
  const diags = mode === 'syntactic'
11
- ? program.getSyntacticDiagnostics(sourceFile)
11
+ ? program.getSyntacticDiagnostics(file)
12
12
  : mode === 'semantic'
13
- ? program.getSemanticDiagnostics(sourceFile)
13
+ ? program.getSemanticDiagnostics(file)
14
14
  : mode === 'declaration'
15
- ? program.getDeclarationDiagnostics(sourceFile)
15
+ ? program.getDeclarationDiagnostics(file)
16
16
  : [];
17
17
  for (const diag of diags) {
18
18
  diag.start ??= 0;
@@ -107,14 +107,14 @@ function create(cmdOption, reportsUnusedComments) {
107
107
  return result;
108
108
  };
109
109
  return {
110
- resolveDiagnostics(sourceFile, results) {
110
+ resolveDiagnostics(file, results) {
111
111
  if (!reportsUnusedComments &&
112
112
  !results.some(error => error.source === 'tsslint')) {
113
113
  return results;
114
114
  }
115
115
  const comments = new Map();
116
116
  const logs = [];
117
- (0, ts_api_utils_1.forEachComment)(sourceFile, (fullText, { pos, end }) => {
117
+ (0, ts_api_utils_1.forEachComment)(file, (fullText, { pos, end }) => {
118
118
  pos += 2; // Trim the // or /* characters
119
119
  const commentText = fullText.substring(pos, end);
120
120
  logs.push(commentText);
@@ -126,10 +126,10 @@ function create(cmdOption, reportsUnusedComments) {
126
126
  comments.set(ruleId, []);
127
127
  }
128
128
  const disabledLines = comments.get(ruleId);
129
- const line = sourceFile.getLineAndCharacterOfPosition(index).line;
129
+ const line = file.getLineAndCharacterOfPosition(index).line;
130
130
  let startLine = line;
131
131
  if (mode === 'singleLine') {
132
- const startWithComment = sourceFile.text.slice(sourceFile.getPositionOfLineAndCharacter(line, 0), index - 2).trim() === '';
132
+ const startWithComment = file.text.slice(file.getPositionOfLineAndCharacter(line, 0), index - 2).trim() === '';
133
133
  if (startWithComment) {
134
134
  startLine = line + 1; // If the comment is at the start of the line, the error is in the next line
135
135
  }
@@ -146,7 +146,7 @@ function create(cmdOption, reportsUnusedComments) {
146
146
  const endComment = commentText.match(endReg);
147
147
  if (endComment?.index !== undefined) {
148
148
  const index = endComment.index + pos;
149
- const prevLine = sourceFile.getLineAndCharacterOfPosition(index).line;
149
+ const prevLine = file.getLineAndCharacterOfPosition(index).line;
150
150
  const ruleId = endComment.groups?.ruleId;
151
151
  const disabledLines = comments.get(ruleId);
152
152
  if (disabledLines) {
@@ -155,17 +155,17 @@ function create(cmdOption, reportsUnusedComments) {
155
155
  }
156
156
  }
157
157
  });
158
- let reportedRules = reportedRulesOfFile.get(sourceFile.fileName);
158
+ let reportedRules = reportedRulesOfFile.get(file.fileName);
159
159
  if (!reportedRules) {
160
160
  reportedRules = [];
161
- reportedRulesOfFile.set(sourceFile.fileName, reportedRules);
161
+ reportedRulesOfFile.set(file.fileName, reportedRules);
162
162
  }
163
163
  reportedRules.length = 0;
164
164
  results = results.filter(error => {
165
165
  if (error.source !== 'tsslint') {
166
166
  return true;
167
167
  }
168
- const line = sourceFile.getLineAndCharacterOfPosition(error.start).line;
168
+ const line = file.getLineAndCharacterOfPosition(error.start).line;
169
169
  reportedRules.push([error.code, line]);
170
170
  for (const code of [undefined, error.code]) {
171
171
  const states = comments.get(code);
@@ -196,7 +196,7 @@ function create(cmdOption, reportsUnusedComments) {
196
196
  for (const state of comment.values()) {
197
197
  if (!state.used) {
198
198
  results.push({
199
- file: sourceFile,
199
+ file: file,
200
200
  start: state.commentRange[0],
201
201
  length: state.commentRange[1] - state.commentRange[0],
202
202
  code: 'tsslint:unused-ignore-comment',
@@ -210,23 +210,23 @@ function create(cmdOption, reportsUnusedComments) {
210
210
  }
211
211
  return results;
212
212
  },
213
- resolveCodeFixes(sourceFile, diagnostic, codeFixes) {
213
+ resolveCodeFixes(file, diagnostic, codeFixes) {
214
214
  if (diagnostic.source !== 'tsslint' || diagnostic.start === undefined) {
215
215
  return codeFixes;
216
216
  }
217
- const line = sourceFile.getLineAndCharacterOfPosition(diagnostic.start).line;
217
+ const line = file.getLineAndCharacterOfPosition(diagnostic.start).line;
218
218
  codeFixes.push({
219
219
  fixName: cmd,
220
220
  description: `Ignore with ${cmdText}`,
221
221
  changes: [
222
222
  {
223
- fileName: sourceFile.fileName,
223
+ fileName: file.fileName,
224
224
  textChanges: [{
225
225
  newText: reg.test(`${cmdText}${diagnostic.code}`)
226
226
  ? `// ${cmdText}${diagnostic.code}\n`
227
227
  : `// ${cmdText} ${diagnostic.code}\n`,
228
228
  span: {
229
- start: sourceFile.getPositionOfLineAndCharacter(line, 0),
229
+ start: file.getPositionOfLineAndCharacter(line, 0),
230
230
  length: 0,
231
231
  },
232
232
  }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/config",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
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": "2.0.0",
15
+ "@tsslint/types": "2.0.1",
16
16
  "ts-api-utils": "^2.0.0"
17
17
  },
18
- "gitHead": "ae93f5a423f55be0af23e4b088bf589dbc215ef6"
18
+ "gitHead": "175c1f2840d38e50f8042542feb317acc7049f91"
19
19
  }