Skip to content
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

Validate the options passed in are numbers instead of strings for our custom commandline options #58388

Merged
merged 3 commits into from
May 1, 2024

Conversation

sheetalkamat
Copy link
Member

cc: @RyanCavanaugh

There are only 7 options that need to be checked so i think should be ok to check that irrespective of setting some symbol or something on our parsed option and not verify it.

@@ -1550,6 +1551,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion } = createProgramOptions;
let { oldProgram } = createProgramOptions;
for (const option of commandLineOptionOfCustomType) {
if (hasProperty(options, option.name)) {
if (typeof options[option.name] === "string") throw new Error(`Found option: ${option.name} that is string and expected number/enum value.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof options[option.name] === "string") throw new Error(`Found option: ${option.name} that is string and expected number/enum value.`);
if (typeof options[option.name] === "string") {
throw new Error(`${option.name} is a string value; tsconfig JSON must be parsed with zzzz before passing to createProgram`);
}

Replace zzzz with whatever the right function is

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have so many ways thats why i didnt want to name the function name

@sheetalkamat sheetalkamat merged commit 7a38980 into main May 1, 2024
28 checks passed
@sheetalkamat sheetalkamat deleted the validateEnumOptions branch May 1, 2024 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants