@tsslint/typescript-plugin 0.0.8 → 0.0.10

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 +41 -31
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -6,51 +6,61 @@ const init = (modules) => {
6
6
  const { typescript: ts } = modules;
7
7
  const pluginModule = {
8
8
  create(info) {
9
- if (!languageServiceDecorators.has(info.languageService)) {
9
+ if (!languageServiceDecorators.has(info.project)) {
10
10
  const tsconfig = info.project.projectKind === ts.server.ProjectKind.Configured
11
11
  ? info.project.getProjectName()
12
12
  : undefined;
13
13
  if (tsconfig) {
14
- languageServiceDecorators.set(info.languageService, decorateLanguageService(ts, tsconfig, info));
14
+ languageServiceDecorators.set(info.project, decorateLanguageService(ts, tsconfig, info));
15
15
  }
16
16
  }
17
- languageServiceDecorators.get(info.languageService)?.update(info.config);
17
+ languageServiceDecorators.get(info.project)?.update(info.config);
18
18
  return info.languageService;
19
19
  },
20
20
  };
21
21
  return pluginModule;
22
22
  };
23
23
  function decorateLanguageService(ts, tsconfig, info) {
24
- const { getCompilerOptionsDiagnostics, getSyntacticDiagnostics, getCodeFixesAtPosition, getCombinedCodeFix, } = info.languageService;
24
+ const { getSemanticDiagnostics, getCodeFixesAtPosition, getCombinedCodeFix, } = info.languageService;
25
25
  let configFile;
26
26
  let configFileBuildContext;
27
27
  let configFileDiagnostics = [];
28
28
  let config;
29
29
  let linter;
30
- info.languageService.getCompilerOptionsDiagnostics = () => {
31
- return getCompilerOptionsDiagnostics().concat(configFileDiagnostics);
32
- };
33
- info.languageService.getSyntacticDiagnostics = fileName => {
34
- let result = getSyntacticDiagnostics(fileName);
35
- if (!linter || !info.languageServiceHost.getScriptFileNames().includes(fileName)) {
30
+ info.languageService.getSemanticDiagnostics = fileName => {
31
+ let result = getSemanticDiagnostics(fileName);
32
+ if (!info.languageServiceHost.getScriptFileNames().includes(fileName)) {
36
33
  return result;
37
34
  }
38
- result = result.concat(linter.lint(fileName));
39
- if (config?.debug) {
40
- result.push({
41
- category: ts.DiagnosticCategory.Warning,
42
- source: 'tsslint',
43
- code: 'debug-info',
44
- messageText: JSON.stringify({
45
- rules: Object.keys(config?.rules ?? {}),
46
- plugins: config.plugins?.length,
47
- configFile,
48
- tsconfig,
49
- }, null, 2),
50
- file: info.languageService.getProgram().getSourceFile(fileName),
51
- start: 0,
52
- length: 0,
53
- });
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
+ })));
44
+ }
45
+ if (config?.debug) {
46
+ result.push({
47
+ category: ts.DiagnosticCategory.Warning,
48
+ source: 'tsl',
49
+ code: 'debug-info',
50
+ messageText: JSON.stringify({
51
+ rules: Object.keys(config?.rules ?? {}),
52
+ plugins: config.plugins?.length,
53
+ configFile,
54
+ tsconfig,
55
+ }, null, 2),
56
+ file: sourceFile,
57
+ start: 0,
58
+ length: 0,
59
+ });
60
+ }
61
+ }
62
+ if (linter) {
63
+ result = result.concat(linter.lint(fileName));
54
64
  }
55
65
  return result;
56
66
  };
@@ -61,7 +71,7 @@ function decorateLanguageService(ts, tsconfig, info) {
61
71
  ];
62
72
  };
63
73
  info.languageService.getCombinedCodeFix = (scope, fixId, formatOptions, preferences) => {
64
- if (fixId === 'tsslint' && linter) {
74
+ if (fixId === 'tsl' && linter) {
65
75
  const fixes = linter.getCodeFixes(scope.fileName, 0, Number.MAX_VALUE);
66
76
  const changes = (0, core_1.combineCodeFixes)(scope.fileName, fixes);
67
77
  return {
@@ -92,7 +102,7 @@ function decorateLanguageService(ts, tsconfig, info) {
92
102
  }
93
103
  }
94
104
  else {
95
- 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');
96
106
  }
97
107
  if (newConfigFile !== configFile) {
98
108
  configFile = newConfigFile;
@@ -115,7 +125,7 @@ function decorateLanguageService(ts, tsconfig, info) {
115
125
  }
116
126
  let configImportPath;
117
127
  try {
118
- configImportPath = require.resolve('@tsslint/config', { paths: [configFile] });
128
+ configImportPath = require.resolve('tsl', { paths: [configFile] });
119
129
  }
120
130
  catch (err) {
121
131
  configFileDiagnostics = [{
@@ -144,7 +154,7 @@ function decorateLanguageService(ts, tsconfig, info) {
144
154
  ].map(([error, category]) => {
145
155
  const diag = {
146
156
  category,
147
- source: 'tsslint',
157
+ source: 'tsl',
148
158
  code: 0,
149
159
  messageText: 'Failed to build config',
150
160
  file: jsonConfigFile,
@@ -170,7 +180,7 @@ function decorateLanguageService(ts, tsconfig, info) {
170
180
  linter = (0, core_1.createLinter)(projectContext, config, true);
171
181
  }
172
182
  info.project.refreshDiagnostics();
173
- });
183
+ }, true, ts.sys.createHash);
174
184
  }
175
185
  }
176
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/typescript-plugin",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
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.8"
15
+ "@tsslint/core": "0.0.10"
16
16
  },
17
17
  "devDependencies": {
18
- "@tsslint/config": "0.0.8"
18
+ "@tsslint/config": "0.0.10"
19
19
  },
20
- "gitHead": "6fc30164bf7d50722f3fdb565f178b13821be692"
20
+ "gitHead": "79b03c8ead69ee6e2e6fbb469012d378a7cf1d31"
21
21
  }