Skip to content

Commit b140473

Browse files
dummdidummcor
andauthored
(fix) don't diagnose node_module files (#1104)
node_modules are considered read-only and unchangeable, so they should not be diagnosed. Make an exception for src/node_modules as this is a Sapper convention #1056, #1100 Co-authored-by: cor <[email protected]>
1 parent 127fda5 commit b140473

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

packages/language-server/src/plugins/typescript/features/DiagnosticsProvider.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ export class DiagnosticsProviderImpl implements DiagnosticsProvider {
1515
document: Document,
1616
cancellationToken?: CancellationToken
1717
): Promise<Diagnostic[]> {
18+
if (
19+
(document.getFilePath()?.includes('/node_modules/') ||
20+
document.getFilePath()?.includes('\\node_modules\\')) &&
21+
// Sapper convention: Put stuff inside node_modules below src
22+
!(
23+
document.getFilePath()?.includes('/src/node_modules/') ||
24+
document.getFilePath()?.includes('\\src\\node_modules\\')
25+
)
26+
) {
27+
// Don't return diagnostics for files inside node_modules. These are considered read-only (cannot be changed)
28+
// and in case of svelte-check they would pollute/skew the output
29+
return [];
30+
}
31+
1832
const { lang, tsDoc } = await this.getLSAndTSDoc(document);
1933

2034
if (

packages/language-server/src/plugins/typescript/module-loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export function createSvelteModuleLoader(
146146

147147
const resolvedSvelteModule: ts.ResolvedModuleFull = {
148148
extension: getExtensionFromScriptKind(snapshot && snapshot.scriptKind),
149-
resolvedFileName
149+
resolvedFileName,
150+
isExternalLibraryImport: svelteResolvedModule.isExternalLibraryImport
150151
};
151152
return resolvedSvelteModule;
152153
}

packages/language-server/test/plugins/typescript/module-loader.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ describe('createSvelteModuleLoader', () => {
114114
assert.deepStrictEqual(result, [
115115
<ts.ResolvedModuleFull>{
116116
extension: ts.Extension.Jsx,
117-
resolvedFileName: 'filename.svelte'
117+
resolvedFileName: 'filename.svelte',
118+
isExternalLibraryImport: undefined
118119
}
119120
]);
120121
assert.deepStrictEqual(lastCall(resolveStub).args, [
@@ -141,7 +142,8 @@ describe('createSvelteModuleLoader', () => {
141142
assert.deepStrictEqual(result, [
142143
<ts.ResolvedModuleFull>{
143144
extension: ts.Extension.Jsx,
144-
resolvedFileName: 'filename.svelte'
145+
resolvedFileName: 'filename.svelte',
146+
isExternalLibraryImport: undefined
145147
}
146148
]);
147149
assert.deepStrictEqual(lastCall(resolveStub).args, [

packages/svelte-check/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Usage:
5656
| `--output <human\|human-verbose\|machine>` |
5757
| `--watch` | Will not exit after one pass but keep watching files for changes and rerun diagnostics |
5858
| `--tsconfig <path>` | Pass a path to a tsconfig or jsconfig file. The path can be relative to the workspace path or absolute. Doing this means that only files matched by the files/include/exclude pattern of the config file are diagnosed. It also means that errors from TypeScript and JavaScript files are reported. |
59-
| `--ignore <path1,path2>` | Files/folders to ignore - relative to workspace root, comma-separated, inside quotes. Example: `--ignore "dist,build"`. When used in conjunction with `--tsconfig`, this will only have effect on the files watched, not on the files that are diagnosed, which is then determined by the `tsconfig.json` |
59+
| `--ignore <path1,path2>` | Files/folders to ignore - relative to workspace root, comma-separated, inside quotes. Example: `--ignore "dist,build"`. When used in conjunction with `--tsconfig`, this will only have effect on the files watched, not on the files that are diagnosed, which is then determined by the `tsconfig.json` |
6060
| `--fail-on-warnings` | Will also exit with error code when there are warnings |
6161
| `--fail-on-hints` | Will also exit with error code when there are hints |
6262
| `--compiler-warnings <code1:error\|ignore,code2:error\|ignore>` | A list of Svelte compiler warning codes. Each entry defines whether that warning should be ignored or treated as an error. Warnings are comma-separated, between warning code and error level is a colon; all inside quotes. Example: `--compiler-warnings "css-unused-selector:ignore,unused-export-let:error"` |

0 commit comments

Comments
 (0)