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

Add type checking for global / command options #1144

Open
rpl opened this issue Dec 6, 2017 · 0 comments
Open

Add type checking for global / command options #1144

rpl opened this issue Dec 6, 2017 · 0 comments

Comments

@rpl
Copy link
Member

rpl commented Dec 6, 2017

Is this a feature request or a bug?

code quality improvement

What is the current behavior?

While working on the config file support in #1080, we have noticed that it would be possible (and helpful) to define the shape of the CLI options defined in src/program.js as JS object literals (which are currently using Object as their flow type, which is basically a "catch-all" which will match any object type).

What is the expected or desired behavior?

By declaring more detailed flow types for the program cli/config options, flow will be able to catch some additional classes of mistakes when we add new options or change the existent ones using the flow static analysis.

In particular the following are the lines in src/program.js which would need to switch to the new types:

commandOptions: Object = {}

setGlobalOptions(options: Object): Program {

We could probably start to only enforce the presence and type of the "type" attribute on every option object, e.g.

type OptionsType = 'boolean' | 'string' | 'number' | 'array';
 
type Option = {
  type: OptionsType,
  [key: string]: any,
}

An additional object related to the options that could use a more detailed type is the following:

options: Object;

Which is a map of the options by command name, and so it could be probably defined using the following flow type (or something similar to it):

type CommandsOptions = {
    [commandName: string]: Options,
}
@kumar303 kumar303 changed the title Type checking global and command options Add type checking for global and command options Mar 1, 2018
@kumar303 kumar303 changed the title Add type checking for global and command options Add type checking for global / command options Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant