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

refactor(cli): defer default value applying #4045

Conversation

ikatyang
Copy link
Member

Context: #3991 (comment)

Object.keys(defaults).forEach(k => {
if (rawOptions[k] == null) {
rawOptions[k] = defaults[k];
}
});

If add this line before L58:

console.info(Object.keys(rawOptions).filter(x => rawOptions[x] != null));

and a test case:

describe.only("test", () => {
  runPrettier("cli", ["--use-tabs"]).test({
    status: 0,
    input: ""
  });
});

We'll get:

  • before

    [ 'arrowParens', 'bracketSpacing', 'cursorOffset', 'insertPragma', 'jsxBracketSameLine', 'parser', 'plugins', 'printWidth', 'proseWrap', 'rangeEnd', 'rangeStart', 'requirePragma', 'semi', 'singleQuote', 'tabWidth', 'trailingComma', 'useTabs', 'astFormat', 'locEnd', 'locStart', 'printer' ]
    
  • after

    [ 'plugins', 'useTabs', 'astFormat', 'locEnd', 'locStart', 'printer' ]
    

Unnecessary cli default applying is removed, it's now handled in options.js.

Don't know how to test it in production mode so I didn't add test cases, I just test it manually.


cc @czosel

czosel added a commit to czosel/prettier that referenced this pull request Feb 26, 2018
@ikatyang
Copy link
Member Author

This PR is included in #3991.

@ikatyang ikatyang closed this Feb 27, 2018
@ikatyang ikatyang deleted the refactor/cli-defer-default-value-applying branch February 27, 2018 09:26
azz pushed a commit that referenced this pull request Feb 27, 2018
* refactor(cli): defer default value applying

* Allow plugins to override default options

* Move "defaultOptions" to top level of plugin

* Simplify implementation

* Attach plugin name

* Add pluginOptions to cli help

* Update snapshots

* Code review (immutable style)

* Add test for help output

* Use snapshot test, fix Object.assign

* Refactor to immutable style

* Add test case for automatic plugin resolution

* Add tests for applying and overriding default opts

* Remove "since" option

* Only set defaults for CLI args when no pluginDefaults are present

* Revert workaround, rebase to #4045

* Add basic documentation for `options` and `defaultOptions`
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant