@tsslint/typescript-plugin 0.0.7 → 0.0.9

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.
Files changed (2) hide show
  1. package/index.js +35 -15
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -21,27 +21,31 @@ const init = (modules) => {
21
21
  return pluginModule;
22
22
  };
23
23
  function decorateLanguageService(ts, tsconfig, info) {
24
- const getCompilerOptionsDiagnostics = info.languageService.getCompilerOptionsDiagnostics;
25
- const getSyntacticDiagnostics = info.languageService.getSyntacticDiagnostics;
26
- const getCodeFixesAtPosition = info.languageService.getCodeFixesAtPosition;
24
+ const { getSyntacticDiagnostics, getCodeFixesAtPosition, getCombinedCodeFix, } = info.languageService;
27
25
  let configFile;
28
26
  let configFileBuildContext;
29
27
  let configFileDiagnostics = [];
30
28
  let config;
31
29
  let linter;
32
- info.languageService.getCompilerOptionsDiagnostics = () => {
33
- return getCompilerOptionsDiagnostics().concat(configFileDiagnostics);
34
- };
35
30
  info.languageService.getSyntacticDiagnostics = fileName => {
36
31
  let result = getSyntacticDiagnostics(fileName);
37
- if (info.languageServiceHost.getScriptFileNames().includes(fileName)) {
38
- if (linter) {
39
- result = result.concat(linter.lint(fileName));
32
+ if (!info.languageServiceHost.getScriptFileNames().includes(fileName)) {
33
+ return result;
34
+ }
35
+ const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
36
+ if (sourceFile) {
37
+ if (configFileDiagnostics.length) {
38
+ result = result.concat(configFileDiagnostics.map(diagnostic => ({
39
+ ...diagnostic,
40
+ file: sourceFile,
41
+ start: 0,
42
+ length: 0,
43
+ })));
40
44
  }
41
45
  if (config?.debug) {
42
46
  result.push({
43
47
  category: ts.DiagnosticCategory.Warning,
44
- source: 'tsslint',
48
+ source: 'tsl',
45
49
  code: 'debug-info',
46
50
  messageText: JSON.stringify({
47
51
  rules: Object.keys(config?.rules ?? {}),
@@ -49,12 +53,15 @@ function decorateLanguageService(ts, tsconfig, info) {
49
53
  configFile,
50
54
  tsconfig,
51
55
  }, null, 2),
52
- file: info.languageService.getProgram().getSourceFile(fileName),
56
+ file: sourceFile,
53
57
  start: 0,
54
58
  length: 0,
55
59
  });
56
60
  }
57
61
  }
62
+ if (linter) {
63
+ result = result.concat(linter.lint(fileName));
64
+ }
58
65
  return result;
59
66
  };
60
67
  info.languageService.getCodeFixesAtPosition = (fileName, start, end, errorCodes, formatOptions, preferences) => {
@@ -63,6 +70,19 @@ function decorateLanguageService(ts, tsconfig, info) {
63
70
  ...linter?.getCodeFixes(fileName, start, end) ?? [],
64
71
  ];
65
72
  };
73
+ info.languageService.getCombinedCodeFix = (scope, fixId, formatOptions, preferences) => {
74
+ if (fixId === 'tsl' && linter) {
75
+ const fixes = linter.getCodeFixes(scope.fileName, 0, Number.MAX_VALUE);
76
+ const changes = (0, core_1.combineCodeFixes)(scope.fileName, fixes);
77
+ return {
78
+ changes: [{
79
+ fileName: scope.fileName,
80
+ textChanges: changes,
81
+ }],
82
+ };
83
+ }
84
+ return getCombinedCodeFix(scope, fixId, formatOptions, preferences);
85
+ };
66
86
  return { update };
67
87
  async function update(pluginConfig) {
68
88
  let configOptionSpan = { start: 0, length: 0 };
@@ -82,7 +102,7 @@ function decorateLanguageService(ts, tsconfig, info) {
82
102
  }
83
103
  }
84
104
  else {
85
- newConfigFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'tsslint.config.ts');
105
+ newConfigFile = ts.findConfigFile(path.dirname(tsconfig), ts.sys.fileExists, 'tsl.config.ts');
86
106
  }
87
107
  if (newConfigFile !== configFile) {
88
108
  configFile = newConfigFile;
@@ -105,7 +125,7 @@ function decorateLanguageService(ts, tsconfig, info) {
105
125
  }
106
126
  let configImportPath;
107
127
  try {
108
- configImportPath = require.resolve('@tsslint/config', { paths: [configFile] });
128
+ configImportPath = require.resolve('tsl', { paths: [configFile] });
109
129
  }
110
130
  catch (err) {
111
131
  configFileDiagnostics = [{
@@ -134,7 +154,7 @@ function decorateLanguageService(ts, tsconfig, info) {
134
154
  ].map(([error, category]) => {
135
155
  const diag = {
136
156
  category,
137
- source: 'tsslint',
157
+ source: 'tsl',
138
158
  code: 0,
139
159
  messageText: 'Failed to build config',
140
160
  file: jsonConfigFile,
@@ -160,7 +180,7 @@ function decorateLanguageService(ts, tsconfig, info) {
160
180
  linter = (0, core_1.createLinter)(projectContext, config, true);
161
181
  }
162
182
  info.project.refreshDiagnostics();
163
- });
183
+ }, true, ts.sys.createHash);
164
184
  }
165
185
  }
166
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/typescript-plugin",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,10 +12,10 @@
12
12
  "directory": "packages/typescript-plugin"
13
13
  },
14
14
  "dependencies": {
15
- "@tsslint/core": "0.0.7"
15
+ "@tsslint/core": "0.0.9"
16
16
  },
17
17
  "devDependencies": {
18
- "@tsslint/config": "0.0.7"
18
+ "@tsslint/config": "0.0.9"
19
19
  },
20
- "gitHead": "ed1086b1f11469e0a9d6a14199c7e027eb28b488"
20
+ "gitHead": "ee84b80bac5dab5fad732e4265e2164c6a0724a6"
21
21
  }