Skip to content

refactor(cli): defer default value applying#4045

Closed
ikatyang wants to merge 1 commit intoprettier:masterfrom
ikatyang:refactor/cli-defer-default-value-applying
Closed

refactor(cli): defer default value applying#4045
ikatyang wants to merge 1 commit intoprettier:masterfrom
ikatyang:refactor/cli-defer-default-value-applying

Conversation

@ikatyang
Copy link
Copy Markdown
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
Copy Markdown
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