mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Report error if commanline only option is specified in tsconfig (#53397)
This commit is contained in:
1 parent
79a414bb5e
commit
8814f6da48
6 files changed
+63
-11
No files matched your search
@@ -3170,6 +3170,7 @@ function getExtendsConfigPathOrArray(
|
||||
basePath: string,
|
||||
configFileName: string | undefined,
|
||||
errors: Diagnostic[],
|
||||
propertyAssignment?: PropertyAssignment,
|
||||
valueExpression?: Expression,
|
||||
sourceFile?: JsonSourceFile,
|
||||
) {
|
||||
@@ -3200,12 +3201,12 @@ function getExtendsConfigPathOrArray(
|
||||
));
|
||||
}
|
||||
else {
|
||||
convertJsonOption(extendsOptionDeclaration.element, value, basePath, errors, (valueExpression as ArrayLiteralExpression | undefined)?.elements[index], sourceFile);
|
||||
convertJsonOption(extendsOptionDeclaration.element, value, basePath, errors, propertyAssignment, (valueExpression as ArrayLiteralExpression | undefined)?.elements[index], sourceFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
convertJsonOption(extendsOptionDeclaration, value, basePath, errors, valueExpression, sourceFile);
|
||||
convertJsonOption(extendsOptionDeclaration, value, basePath, errors, propertyAssignment, valueExpression, sourceFile);
|
||||
}
|
||||
return extendedConfigPath;
|
||||
}
|
||||
@@ -3248,7 +3249,7 @@ function parseOwnConfigOfJsonSourceFile(
|
||||
option: CommandLineOption | undefined,
|
||||
) {
|
||||
// Ensure value is verified except for extends which is handled in its own way for error reporting
|
||||
if (option && option !== extendsOptionDeclaration) value = convertJsonOption(option, value, basePath, errors, propertyAssignment.initializer, sourceFile);
|
||||
if (option && option !== extendsOptionDeclaration) value = convertJsonOption(option, value, basePath, errors, propertyAssignment, propertyAssignment.initializer, sourceFile);
|
||||
if (parentOption?.name) {
|
||||
if (option) {
|
||||
let currentOption;
|
||||
@@ -3275,7 +3276,7 @@ function parseOwnConfigOfJsonSourceFile(
|
||||
}
|
||||
else if (parentOption === rootOptions) {
|
||||
if (option === extendsOptionDeclaration) {
|
||||
extendedConfigPath = getExtendsConfigPathOrArray(value, host, basePath, configFileName, errors, propertyAssignment.initializer, sourceFile);
|
||||
extendedConfigPath = getExtendsConfigPathOrArray(value, host, basePath, configFileName, errors, propertyAssignment, propertyAssignment.initializer, sourceFile);
|
||||
}
|
||||
else if (!option) {
|
||||
if (keyText === "excludes") {
|
||||
@@ -3458,18 +3459,23 @@ export function convertJsonOption(
|
||||
value: any,
|
||||
basePath: string,
|
||||
errors: Diagnostic[],
|
||||
propertyAssignment?: PropertyAssignment,
|
||||
valueExpression?: Expression,
|
||||
sourceFile?: TsConfigSourceFile,
|
||||
): CompilerOptionsValue {
|
||||
if (opt.isCommandLineOnly) {
|
||||
errors.push(createDiagnosticForNodeInSourceFileOrCompilerDiagnostic(sourceFile, propertyAssignment?.name, Diagnostics.Option_0_can_only_be_specified_on_command_line, opt.name));
|
||||
return undefined;
|
||||
}
|
||||
if (isCompilerOptionsValue(opt, value)) {
|
||||
const optType = opt.type;
|
||||
if ((optType === "list") && isArray(value)) {
|
||||
return convertJsonOptionOfListType(opt, value, basePath, errors, valueExpression as ArrayLiteralExpression | undefined, sourceFile);
|
||||
return convertJsonOptionOfListType(opt, value, basePath, errors, propertyAssignment, valueExpression as ArrayLiteralExpression | undefined, sourceFile);
|
||||
}
|
||||
else if (optType === "listOrElement") {
|
||||
return isArray(value) ?
|
||||
convertJsonOptionOfListType(opt, value, basePath, errors, valueExpression as ArrayLiteralExpression | undefined, sourceFile) :
|
||||
convertJsonOption(opt.element, value, basePath, errors, valueExpression, sourceFile);
|
||||
convertJsonOptionOfListType(opt, value, basePath, errors, propertyAssignment, valueExpression as ArrayLiteralExpression | undefined, sourceFile) :
|
||||
convertJsonOption(opt.element, value, basePath, errors, propertyAssignment, valueExpression, sourceFile);
|
||||
}
|
||||
else if (!isString(opt.type)) {
|
||||
return convertJsonOptionOfCustomType(opt as CommandLineOptionOfCustomType, value as string, errors, valueExpression, sourceFile);
|
||||
@@ -3530,10 +3536,11 @@ function convertJsonOptionOfListType(
|
||||
values: readonly any[],
|
||||
basePath: string,
|
||||
errors: Diagnostic[],
|
||||
propertyAssignment: PropertyAssignment | undefined,
|
||||
valueExpression: ArrayLiteralExpression | undefined,
|
||||
sourceFile: TsConfigSourceFile | undefined,
|
||||
): any[] {
|
||||
return filter(map(values, (v, index) => convertJsonOption(option.element, v, basePath, errors, valueExpression?.elements[index], sourceFile)), v => option.listPreserveFalsyValues ? true : !!v);
|
||||
return filter(map(values, (v, index) => convertJsonOption(option.element, v, basePath, errors, propertyAssignment, valueExpression?.elements[index], sourceFile)), v => option.listPreserveFalsyValues ? true : !!v);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5270,6 +5270,10 @@
|
||||
"category": "Message",
|
||||
"code": 6265
|
||||
},
|
||||
"Option '{0}' can only be specified on command line.": {
|
||||
"category": "Error",
|
||||
"code": 6266
|
||||
},
|
||||
|
||||
"Directory '{0}' has no containing package.json scope. Imports will not resolve.": {
|
||||
"category": "Message",
|
||||
|
||||
@@ -342,6 +342,17 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
|
||||
allFileList: ["/apath/a.ts"],
|
||||
}]);
|
||||
|
||||
baselinedParsed("generates errors when commandline option is in tsconfig", () => [{
|
||||
jsonText: JSON.stringify({
|
||||
compilerOptions: {
|
||||
help: true,
|
||||
}
|
||||
}),
|
||||
configFileName: "/apath/tsconfig.json",
|
||||
basePath: "tests/cases/unittests",
|
||||
allFileList: ["/apath/a.ts"],
|
||||
}]);
|
||||
|
||||
function baselineWildcards(subScenario: string, scenario: () => { configFileName: string, jsonText: string, basePath: string }[]) {
|
||||
baselineParseConfig({
|
||||
scenario: "tsconfigParsing",
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
Fs::
|
||||
//// [/apath/a.ts]
|
||||
|
||||
|
||||
//// [/apath/tsconfig.json]
|
||||
{"compilerOptions":{"help":true}}
|
||||
|
||||
|
||||
configFileName:: /apath/tsconfig.json
|
||||
FileNames::
|
||||
/apath/a.ts
|
||||
Errors::
|
||||
[91merror[0m[90m TS6266: [0mOption 'help' can only be specified on command line.
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
Fs::
|
||||
//// [/apath/a.ts]
|
||||
|
||||
|
||||
//// [/apath/tsconfig.json]
|
||||
{"compilerOptions":{"help":true}}
|
||||
|
||||
|
||||
configFileName:: /apath/tsconfig.json
|
||||
FileNames::
|
||||
/apath/a.ts
|
||||
Errors::
|
||||
[96m/apath/tsconfig.json[0m:[93m1[0m:[93m21[0m - [91merror[0m[90m TS6266: [0mOption 'help' can only be specified on command line.
|
||||
|
||||
[7m1[0m {"compilerOptions":{"help":true}}
|
||||
[7m [0m [91m ~~~~~~[0m
|
||||
|
||||
@@ -47,7 +47,6 @@ Info 7 [00:00:14.000] Config: /tsconfig.json : {
|
||||
"out": "hunter2",
|
||||
"reactNamespace": "hunter2",
|
||||
"charset": "hunter2",
|
||||
"locale": "hunter2",
|
||||
"declarationDir": "/hunter2",
|
||||
"paths": {
|
||||
"*": [
|
||||
@@ -81,9 +80,9 @@ Info 16 [00:00:23.000] -----------------------------------------------
|
||||
Info 17 [00:00:24.000] event:
|
||||
{"seq":0,"type":"event","event":"projectLoadingFinish","body":{"projectName":"/tsconfig.json"}}
|
||||
Info 18 [00:00:25.000] event:
|
||||
{"seq":0,"type":"event","event":"telemetry","body":{"telemetryEventName":"projectInfo","payload":{"projectId":"aace87d7c1572ff43c6978074161b586788b4518c7a9d06c79c03e613b6ce5a3","fileStats":{"js":0,"jsSize":0,"jsx":0,"jsxSize":0,"ts":1,"tsSize":0,"tsx":0,"tsxSize":0,"dts":0,"dtsSize":0,"deferred":0,"deferredSize":0},"compilerOptions":{"project":"","outFile":"","outDir":"","rootDir":"","baseUrl":"","rootDirs":[""],"typeRoots":[""],"types":[""],"sourceRoot":"","mapRoot":"","jsxFactory":"","out":"","reactNamespace":"","charset":"","locale":"","declarationDir":"","paths":"","declaration":true,"lib":["es6","dom"]},"typeAcquisition":{"enable":false,"include":false,"exclude":false},"extends":false,"files":true,"include":false,"exclude":false,"compileOnSave":false,"configFileName":"tsconfig.json","projectType":"configured","languageServiceEnabled":true,"version":"FakeVersion"}}}
|
||||
{"seq":0,"type":"event","event":"telemetry","body":{"telemetryEventName":"projectInfo","payload":{"projectId":"aace87d7c1572ff43c6978074161b586788b4518c7a9d06c79c03e613b6ce5a3","fileStats":{"js":0,"jsSize":0,"jsx":0,"jsxSize":0,"ts":1,"tsSize":0,"tsx":0,"tsxSize":0,"dts":0,"dtsSize":0,"deferred":0,"deferredSize":0},"compilerOptions":{"project":"","outFile":"","outDir":"","rootDir":"","baseUrl":"","rootDirs":[""],"typeRoots":[""],"types":[""],"sourceRoot":"","mapRoot":"","jsxFactory":"","out":"","reactNamespace":"","charset":"","declarationDir":"","paths":"","declaration":true,"lib":["es6","dom"]},"typeAcquisition":{"enable":false,"include":false,"exclude":false},"extends":false,"files":true,"include":false,"exclude":false,"compileOnSave":false,"configFileName":"tsconfig.json","projectType":"configured","languageServiceEnabled":true,"version":"FakeVersion"}}}
|
||||
Info 19 [00:00:26.000] event:
|
||||
{"seq":0,"type":"event","event":"configFileDiag","body":{"triggerFile":"/a.ts","configFile":"/tsconfig.json","diagnostics":[{"text":"Cannot find type definition file for 'hunter2'.\n The file is in the program because:\n Entry point of type library 'hunter2' specified in compilerOptions","code":2688,"category":"error","relatedInformation":[{"span":{"start":{"line":1,"offset":172},"end":{"line":1,"offset":181},"file":"/tsconfig.json"},"message":"File is entry point of type library specified here.","category":"message","code":1419}]},{"text":"File '/a/lib/lib.dom.d.ts' not found.\n The file is in the program because:\n Library 'lib.dom.d.ts' specified in compilerOptions","code":6053,"category":"error"},{"text":"File '/a/lib/lib.es2015.d.ts' not found.\n The file is in the program because:\n Library 'lib.es2015.d.ts' specified in compilerOptions","code":6053,"category":"error"},{"text":"File '/a.ts' is not under 'rootDir' '/hunter2'. 'rootDir' is expected to contain all source files.\n The file is in the program because:\n Part of 'files' list in tsconfig.json","code":6059,"category":"error","relatedInformation":[{"span":{"start":{"line":1,"offset":497},"end":{"line":1,"offset":504},"file":"/tsconfig.json"},"message":"File is matched by 'files' list specified here.","category":"message","code":1410}]},{"start":{"line":1,"offset":34},"end":{"line":1,"offset":43},"text":"Option 'out' cannot be specified with option 'outFile'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":183},"end":{"line":1,"offset":195},"text":"Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.","code":5051,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":206},"end":{"line":1,"offset":215},"text":"Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'.","code":5069,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":226},"end":{"line":1,"offset":238},"text":"Option 'reactNamespace' cannot be specified with option 'jsxFactory'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":249},"end":{"line":1,"offset":254},"text":"Option 'declarationDir' cannot be specified with option 'out'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":249},"end":{"line":1,"offset":254},"text":"Option 'out' cannot be specified with option 'outFile'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":249},"end":{"line":1,"offset":254},"text":"Option 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '\"ignoreDeprecations\": \"5.0\"' to silence this error.\n Use 'outFile' instead.","code":5101,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":265},"end":{"line":1,"offset":281},"text":"Option 'reactNamespace' cannot be specified with option 'jsxFactory'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":292},"end":{"line":1,"offset":301},"text":"Option 'charset' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '\"ignoreDeprecations\": \"5.0\"' to silence this error.","code":5101,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":331},"end":{"line":1,"offset":347},"text":"Option 'declarationDir' cannot be specified with option 'out'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"text":"Cannot find global type 'Array'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Boolean'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Function'.","code":2318,"category":"error"},{"text":"Cannot find global type 'IArguments'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Number'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Object'.","code":2318,"category":"error"},{"text":"Cannot find global type 'RegExp'.","code":2318,"category":"error"},{"text":"Cannot find global type 'String'.","code":2318,"category":"error"},{"start":{"line":1,"offset":422},"end":{"line":1,"offset":431},"text":"Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'eLine truncated
|
||||
{"seq":0,"type":"event","event":"configFileDiag","body":{"triggerFile":"/a.ts","configFile":"/tsconfig.json","diagnostics":[{"text":"Cannot find type definition file for 'hunter2'.\n The file is in the program because:\n Entry point of type library 'hunter2' specified in compilerOptions","code":2688,"category":"error","relatedInformation":[{"span":{"start":{"line":1,"offset":172},"end":{"line":1,"offset":181},"file":"/tsconfig.json"},"message":"File is entry point of type library specified here.","category":"message","code":1419}]},{"text":"File '/a/lib/lib.dom.d.ts' not found.\n The file is in the program because:\n Library 'lib.dom.d.ts' specified in compilerOptions","code":6053,"category":"error"},{"text":"File '/a/lib/lib.es2015.d.ts' not found.\n The file is in the program because:\n Library 'lib.es2015.d.ts' specified in compilerOptions","code":6053,"category":"error"},{"text":"File '/a.ts' is not under 'rootDir' '/hunter2'. 'rootDir' is expected to contain all source files.\n The file is in the program because:\n Part of 'files' list in tsconfig.json","code":6059,"category":"error","relatedInformation":[{"span":{"start":{"line":1,"offset":497},"end":{"line":1,"offset":504},"file":"/tsconfig.json"},"message":"File is matched by 'files' list specified here.","category":"message","code":1410}]},{"start":{"line":1,"offset":34},"end":{"line":1,"offset":43},"text":"Option 'out' cannot be specified with option 'outFile'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":183},"end":{"line":1,"offset":195},"text":"Option 'sourceRoot can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.","code":5051,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":206},"end":{"line":1,"offset":215},"text":"Option 'mapRoot' cannot be specified without specifying option 'sourceMap' or option 'declarationMap'.","code":5069,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":226},"end":{"line":1,"offset":238},"text":"Option 'reactNamespace' cannot be specified with option 'jsxFactory'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":249},"end":{"line":1,"offset":254},"text":"Option 'declarationDir' cannot be specified with option 'out'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":249},"end":{"line":1,"offset":254},"text":"Option 'out' cannot be specified with option 'outFile'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":249},"end":{"line":1,"offset":254},"text":"Option 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '\"ignoreDeprecations\": \"5.0\"' to silence this error.\n Use 'outFile' instead.","code":5101,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":265},"end":{"line":1,"offset":281},"text":"Option 'reactNamespace' cannot be specified with option 'jsxFactory'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":292},"end":{"line":1,"offset":301},"text":"Option 'charset' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '\"ignoreDeprecations\": \"5.0\"' to silence this error.","code":5101,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":331},"end":{"line":1,"offset":347},"text":"Option 'declarationDir' cannot be specified with option 'out'.","code":5053,"category":"error","fileName":"/tsconfig.json"},{"text":"Cannot find global type 'Array'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Boolean'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Function'.","code":2318,"category":"error"},{"text":"Cannot find global type 'IArguments'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Number'.","code":2318,"category":"error"},{"text":"Cannot find global type 'Object'.","code":2318,"category":"error"},{"text":"Cannot find global type 'RegExp'.","code":2318,"category":"error"},{"text":"Cannot find global type 'String'.","code":2318,"category":"error"},{"start":{"line":1,"offset":312},"end":{"line":1,"offset":320},"text":"Option 'locale' can only be specified on command line.","code":6266,"category":"error","fileName":"/tsconfig.json"},{"start":{"line":1,"offset":422},"end":{"line":1,"offset":431},"text":"Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrayLine truncated
|
||||
Info 20 [00:00:27.000] Project '/tsconfig.json' (Configured)
|
||||
Info 20 [00:00:28.000] Files (1)
|
||||
|
||||
|
||||
Reference in new issue
Block a user