Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
Add --ignoreConfig and dont allow specifying files on commandline without it if there is config file present#62477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5e5aaa9fb5c30aa9c97f36baf76745f24e29b4787b7541cc8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -614,20 +614,27 @@ function executeCommandLineWorker( | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| else if (commandLine.fileNames.length === 0) { | ||||||
| else if (!commandLine.options.ignoreConfig || commandLine.fileNames.length === 0) { | ||||||
| const searchPath = normalizePath(sys.getCurrentDirectory()); | ||||||
| configFileName = findConfigFile(searchPath, fileName => sys.fileExists(fileName)); | ||||||
| } | ||||||
| if (commandLine.fileNames.length === 0 && !configFileName) { | ||||||
| if (commandLine.options.showConfig) { | ||||||
| reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_current_directory_Colon_0, normalizePath(sys.getCurrentDirectory()))); | ||||||
| // if (!commandLine.options.ignoreConfig) { | ||||||
CopilotAI | ||||||
| // if (!commandLine.options.ignoreConfig) { | |
CopilotAINov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is unclear and grammatically incorrect. It should be "Error when files are specified on command line but tsconfig.json is present" to accurately describe what's happening.
| // Error to not specify config file | |
| // Error when files are specified on command line but tsconfig.json is present |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import * as ts from "../../_namespaces/ts.js"; | ||
| import { jsonToReadableText } from "../helpers.js"; | ||
| import { verifyTsc } from "../helpers/tsc.js"; | ||
| import { TestServerHost } from "../helpers/virtualFileSystemWithWatch.js"; | ||
| describe("unittests:: tsc:: ignoreConfig::", () => { | ||
| function sysWithoutConfig() { | ||
| return TestServerHost.createWatchedSystem({ | ||
| "/home/src/workspaces/project/src/a.ts": "export const a = 10;", | ||
| "/home/src/workspaces/project/src/b.ts": "export const b = 10;", | ||
| "/home/src/workspaces/project/c.ts": "export const c = 10;", | ||
| }); | ||
| } | ||
| function sysWithConfig() { | ||
| const sys = sysWithoutConfig(); | ||
| sys.writeFile( | ||
| "/home/src/workspaces/project/tsconfig.json", | ||
| jsonToReadableText({ | ||
| include: ["src"], | ||
| }), | ||
| ); | ||
| return sys; | ||
| } | ||
| function runScenario(subScenario: string, commandLineArgs: readonly string[]) { | ||
| verifyTsc({ | ||
| scenario: "ignoreConfig", | ||
| subScenario, | ||
| sys: sysWithConfig, | ||
| commandLineArgs, | ||
| }); | ||
| verifyTsc({ | ||
| scenario: "ignoreConfig", | ||
| subScenario: subScenario + " with --ignoreConfig", | ||
| sys: sysWithConfig, | ||
| commandLineArgs: commandLineArgs.concat("--ignoreConfig"), | ||
| }); | ||
| verifyTsc({ | ||
| scenario: "ignoreConfig", | ||
| subScenario: subScenario + " when config file absent", | ||
| sys: sysWithoutConfig, | ||
| commandLineArgs, | ||
| }); | ||
| verifyTsc({ | ||
| scenario: "ignoreConfig", | ||
| subScenario: subScenario + " when config file absent with --ignoreConfig", | ||
| sys: sysWithoutConfig, | ||
| commandLineArgs: commandLineArgs.concat("--ignoreConfig"), | ||
| }); | ||
| } | ||
| runScenario("without any options", ts.emptyArray); | ||
| runScenario("specifying files", ["src/a.ts"]); | ||
| runScenario("specifying project", ["-p", "."]); | ||
| runScenario("mixing project and files", ["-p", ".", "src/a.ts", "c.ts"]); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "ignoreConfig": true | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false | ||
| Input:: | ||
| //// [/home/src/workspaces/project/src/a.ts] | ||
| export const a = 10; | ||
| //// [/home/src/workspaces/project/src/b.ts] | ||
| export const b = 10; | ||
| //// [/home/src/workspaces/project/c.ts] | ||
| export const c = 10; | ||
| //// [/home/src/tslibs/TS/Lib/lib.d.ts] | ||
| interface Boolean {} | ||
| interface Function {} | ||
| interface CallableFunction {} | ||
| interface NewableFunction {} | ||
| interface IArguments {} | ||
| interface Number { toExponential: any; } | ||
| interface Object {} | ||
| interface RegExp {} | ||
| interface String { charAt: any; } | ||
| interface Array<T> { length: number; [n: number]: T; } | ||
| interface ReadonlyArray<T> {} | ||
| declare const console: { log(msg: any): void; }; | ||
| /home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts --ignoreConfig | ||
| Output:: | ||
| error TS5042: Option 'project' cannot be mixed with source files on a command line. | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false | ||
| Input:: | ||
| //// [/home/src/workspaces/project/src/a.ts] | ||
| export const a = 10; | ||
| //// [/home/src/workspaces/project/src/b.ts] | ||
| export const b = 10; | ||
| //// [/home/src/workspaces/project/c.ts] | ||
| export const c = 10; | ||
| //// [/home/src/tslibs/TS/Lib/lib.d.ts] | ||
| interface Boolean {} | ||
| interface Function {} | ||
| interface CallableFunction {} | ||
| interface NewableFunction {} | ||
| interface IArguments {} | ||
| interface Number { toExponential: any; } | ||
| interface Object {} | ||
| interface RegExp {} | ||
| interface String { charAt: any; } | ||
| interface Array<T> { length: number; [n: number]: T; } | ||
| interface ReadonlyArray<T> {} | ||
| declare const console: { log(msg: any): void; }; | ||
| /home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts | ||
| Output:: | ||
| error TS5042: Option 'project' cannot be mixed with source files on a command line. | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false | ||
| Input:: | ||
| //// [/home/src/workspaces/project/src/a.ts] | ||
| export const a = 10; | ||
| //// [/home/src/workspaces/project/src/b.ts] | ||
| export const b = 10; | ||
| //// [/home/src/workspaces/project/c.ts] | ||
| export const c = 10; | ||
| //// [/home/src/tslibs/TS/Lib/lib.d.ts] | ||
| interface Boolean {} | ||
| interface Function {} | ||
| interface CallableFunction {} | ||
| interface NewableFunction {} | ||
| interface IArguments {} | ||
| interface Number { toExponential: any; } | ||
| interface Object {} | ||
| interface RegExp {} | ||
| interface String { charAt: any; } | ||
| interface Array<T> { length: number; [n: number]: T; } | ||
| interface ReadonlyArray<T> {} | ||
| declare const console: { log(msg: any): void; }; | ||
| //// [/home/src/workspaces/project/tsconfig.json] | ||
| { | ||
| "include": [ | ||
| "src" | ||
| ] | ||
| } | ||
| /home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts --ignoreConfig | ||
| Output:: | ||
| error TS5042: Option 'project' cannot be mixed with source files on a command line. | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false | ||
| Input:: | ||
| //// [/home/src/workspaces/project/src/a.ts] | ||
| export const a = 10; | ||
| //// [/home/src/workspaces/project/src/b.ts] | ||
| export const b = 10; | ||
| //// [/home/src/workspaces/project/c.ts] | ||
| export const c = 10; | ||
| //// [/home/src/tslibs/TS/Lib/lib.d.ts] | ||
| interface Boolean {} | ||
| interface Function {} | ||
| interface CallableFunction {} | ||
| interface NewableFunction {} | ||
| interface IArguments {} | ||
| interface Number { toExponential: any; } | ||
| interface Object {} | ||
| interface RegExp {} | ||
| interface String { charAt: any; } | ||
| interface Array<T> { length: number; [n: number]: T; } | ||
| interface ReadonlyArray<T> {} | ||
| declare const console: { log(msg: any): void; }; | ||
| //// [/home/src/workspaces/project/tsconfig.json] | ||
| { | ||
| "include": [ | ||
| "src" | ||
| ] | ||
| } | ||
| /home/src/tslibs/TS/Lib/tsc.js -p . src/a.ts c.ts | ||
| Output:: | ||
| error TS5042: Option 'project' cannot be mixed with source files on a command line. | ||
| exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
CopilotAINov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The logic here is hard to follow. When
ignoreConfigis true ANDfileNames.length > 0, this condition is false andconfigFileNameremains undefined (desired). WhenignoreConfigis false OR no files specified, we search for config. Consider extracting this condition to a named boolean variable likeshouldSearchForConfigto improve readability.