Skip to content

Commit

Permalink
chore: code adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 16, 2024
1 parent 7fae1d6 commit 11479d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
4 changes: 0 additions & 4 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ import glob = require('glob');
}
}
else {
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
if (!sourceFile) {
throw new Error(`No source file found for ${fileName}`);
}
const diagnostics = linter.lint(fileName);
for (const diagnostic of diagnostics) {
let output = ts.formatDiagnosticsWithColorAndContext([diagnostic], {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ export function createLinter(ctx: ProjectContext, config: Config, withStack: boo
try {
rule(rulesContext);
} catch (err) {
console.error(`An unexpected error occurred in rule "${id}" in file ${fileName}.`);
console.error(`An unexpected error occurred in rule "${id}" in file ${sourceFile.fileName}.`);
console.error(err);
}
}

for (const plugin of plugins) {
if (plugin.resolveDiagnostics) {
result = plugin.resolveDiagnostics(fileName, result);
result = plugin.resolveDiagnostics(sourceFile.fileName, result);
}
}

Expand Down
52 changes: 27 additions & 25 deletions packages/typescript-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,33 @@ function decorateLanguageService(
if (!info.languageServiceHost.getScriptFileNames().includes(fileName)) {
return result;
}
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
if (sourceFile) {
if (configFileDiagnostics.length) {
result = result.concat(configFileDiagnostics.map<ts.DiagnosticWithLocation>(diagnostic => ({
...diagnostic,
file: sourceFile,
start: 0,
length: 0,
})));
}
if (config?.debug) {
result.push({
category: ts.DiagnosticCategory.Suggestion,
source: 'tsslint',
code: 'debug-info' as any,
messageText: JSON.stringify({
rules: Object.keys(config?.rules ?? {}),
plugins: config.plugins?.length,
configFile,
tsconfig,
}, null, 2),
file: sourceFile,
start: 0,
length: 0,
});
if (configFileDiagnostics.length || config?.debug) {
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
if (sourceFile) {
if (configFileDiagnostics.length) {
result = result.concat(configFileDiagnostics.map<ts.DiagnosticWithLocation>(diagnostic => ({
...diagnostic,
file: sourceFile,
start: 0,
length: 0,
})));
}
if (config?.debug) {
result.push({
category: ts.DiagnosticCategory.Suggestion,
source: 'tsslint',
code: 'debug-info' as any,
messageText: JSON.stringify({
rules: Object.keys(config?.rules ?? {}),
plugins: config.plugins?.length,
configFile,
tsconfig,
}, null, 2),
file: sourceFile,
start: 0,
length: 0,
});
}
}
}
if (linter) {
Expand Down

0 comments on commit 11479d6

Please sign in to comment.