Skip to content

Commit b49dbfd

Browse files
bradzacherJamesHenry
authored andcommitted
docs(typescript-estree): document that duplicate filenames are unsupported (typescript-eslint#957)
1 parent b99e831 commit b49dbfd

File tree

4 files changed

+69
-21
lines changed

4 files changed

+69
-21
lines changed

.vscode/launch.json

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@
1818
"sourceMaps": true,
1919
"console": "integratedTerminal",
2020
"internalConsoleOptions": "neverOpen"
21+
},
22+
{
23+
"type": "node",
24+
"request": "launch",
25+
"name": "Run currently opened typescript-estree test",
26+
"cwd": "${workspaceFolder}/packages/typescript-estree/",
27+
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
28+
"args": [
29+
"--runInBand",
30+
"${relativeFile}"
31+
],
32+
"sourceMaps": true,
33+
"console": "integratedTerminal",
34+
"internalConsoleOptions": "neverOpen"
2135
}
2236
]
2337
}

packages/parser/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ The following additional configuration options are available by specifying them
6666
];
6767
```
6868

69-
- Note that if you use project references, TypeScript will not automatically use project references to resolve files. This means that you will have to add each referenced tsconfig to the `project` field either separately, or via a glob.
69+
- If you use project references, TypeScript will not automatically use project references to resolve files. This means that you will have to add each referenced tsconfig to the `project` field either separately, or via a glob.
70+
71+
- TypeScript will ignore files with duplicate filenames in the same folder (for example, `src/file.ts` and `src/file.js`). TypeScript purposely ignore all but one of the files, only keeping the one file with the highest priority extension (the extension priority order (from highest to lowest) is `.ts`, `.tsx`, `.d.ts`, `.js`, `.jsx`). For more info see #955.
7072

7173
- Note that if this setting is specified and `createDefaultProgram` is not, you must only lint files that are included in the projects as defined by the provided `tsconfig.json` files. If your existing configuration does not include all of the files you would like to lint, you can create a separate `tsconfig.eslint.json` as follows:
7274

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// These types are internal to TS.
2+
// They have been trimmed down to only include the relevant bits
3+
// We use some special internal TS apis to help us do our parsing flexibly
4+
5+
import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports
6+
7+
// https://github.com/microsoft/TypeScript/blob/b84e65db4ea5c39dbaa2ccd6594efe4653318251/src/compiler/watchUtilities.ts#L6-L18
8+
interface DirectoryStructureHost {
9+
readDirectory?(
10+
path: string,
11+
extensions?: ReadonlyArray<string>,
12+
exclude?: ReadonlyArray<string>,
13+
include?: ReadonlyArray<string>,
14+
depth?: number,
15+
): string[];
16+
}
17+
18+
// https://github.com/microsoft/TypeScript/blob/b84e65db4ea5c39dbaa2ccd6594efe4653318251/src/compiler/watchUtilities.ts#L25-L35
19+
interface CachedDirectoryStructureHost extends DirectoryStructureHost {
20+
readDirectory(
21+
path: string,
22+
extensions?: ReadonlyArray<string>,
23+
exclude?: ReadonlyArray<string>,
24+
include?: ReadonlyArray<string>,
25+
depth?: number,
26+
): string[];
27+
}
28+
29+
// https://github.com/microsoft/TypeScript/blob/5d36aab06f12b0a3ba6197eb14e98204ec0195fb/src/compiler/watch.ts#L548-L554
30+
interface WatchCompilerHostOfConfigFile<T extends ts.BuilderProgram>
31+
extends ts.WatchCompilerHostOfConfigFile<T> {
32+
onCachedDirectoryStructureHostCreate(
33+
host: CachedDirectoryStructureHost,
34+
): void;
35+
}
36+
37+
export { WatchCompilerHostOfConfigFile };

packages/typescript-estree/src/tsconfig-parser.ts

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
22
import * as ts from 'typescript'; // leave this as * as ts so people using util package don't need syntheticDefaultImports
33
import { Extra } from './parser-options';
4+
import { WatchCompilerHostOfConfigFile } from './WatchCompilerHostOfConfigFile';
45

56
//------------------------------------------------------------------------------
67
// Environment calculation
@@ -13,6 +14,8 @@ export const defaultCompilerOptions: ts.CompilerOptions = {
1314
allowNonTsExtensions: true,
1415
allowJs: true,
1516
checkJs: true,
17+
noEmit: true,
18+
// extendedDiagnostics: true,
1619
};
1720

1821
/**
@@ -115,7 +118,7 @@ export function calculateProjectParserOptions(
115118
ts.createSemanticDiagnosticsBuilderProgram,
116119
diagnosticReporter,
117120
/*reportWatchStatus*/ () => {},
118-
);
121+
) as WatchCompilerHostOfConfigFile<ts.SemanticDiagnosticsBuilderProgram>;
119122

120123
// ensure readFile reads the code being linted instead of the copy on disk
121124
const oldReadFile = watchCompilerHost.readFile;
@@ -144,8 +147,7 @@ export function calculateProjectParserOptions(
144147
};
145148

146149
// register callbacks to trigger program updates without using fileWatchers
147-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
148-
watchCompilerHost.watchFile = (fileName, callback) => {
150+
watchCompilerHost.watchFile = (fileName, callback): ts.FileWatcher => {
149151
const normalizedFileName = path.normalize(fileName);
150152
watchCallbackTrackingMap.set(normalizedFileName, callback);
151153
return {
@@ -156,26 +158,20 @@ export function calculateProjectParserOptions(
156158
};
157159

158160
// ensure fileWatchers aren't created for directories
159-
watchCompilerHost.watchDirectory = (): typeof noopFileWatcher =>
160-
noopFileWatcher;
161+
watchCompilerHost.watchDirectory = (): ts.FileWatcher => noopFileWatcher;
161162

162-
// we're using internal typescript APIs which aren't on the types
163-
/* eslint-disable @typescript-eslint/no-explicit-any */
164163
// allow files with custom extensions to be included in program (uses internal ts api)
165-
const oldOnDirectoryStructureHostCreate = (watchCompilerHost as any)
166-
.onCachedDirectoryStructureHostCreate;
167-
(watchCompilerHost as any).onCachedDirectoryStructureHostCreate = (
168-
host: any,
169-
): void => {
164+
const oldOnDirectoryStructureHostCreate =
165+
watchCompilerHost.onCachedDirectoryStructureHostCreate;
166+
watchCompilerHost.onCachedDirectoryStructureHostCreate = (host): void => {
170167
const oldReadDirectory = host.readDirectory;
171-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
172168
host.readDirectory = (
173-
path: string,
174-
extensions?: readonly string[],
175-
exclude?: readonly string[],
176-
include?: readonly string[],
177-
depth?: number,
178-
) =>
169+
path,
170+
extensions,
171+
exclude,
172+
include,
173+
depth,
174+
): string[] =>
179175
oldReadDirectory(
180176
path,
181177
!extensions
@@ -187,7 +183,6 @@ export function calculateProjectParserOptions(
187183
);
188184
oldOnDirectoryStructureHostCreate(host);
189185
};
190-
/* eslint-enable @typescript-eslint/no-explicit-any */
191186

192187
// create program
193188
const programWatch = ts.createWatchProgram(watchCompilerHost);

0 commit comments

Comments
 (0)