mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Report error if commanline only option is specified in tsconfig (#53397)
This commit is contained in:
parent
79a414bb5e
commit
8814f6da48
@ -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",
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user