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

Support options in external plugins #3615

Closed
3 tasks done
azz opened this issue Dec 31, 2017 · 5 comments
Closed
3 tasks done

Support options in external plugins #3615

azz opened this issue Dec 31, 2017 · 5 comments
Assignees
Labels
area:api Issues with Prettier's Application Programming Interface area:cli Issues with Prettier's Command Line Interface locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@azz
Copy link
Member

azz commented Dec 31, 2017

#3433 moved the definition of options to our internal parsers but there's still a bit of work to support external plugins defining new options:

Use cases:

  • This should include the options contributed by plugins:

    prettier --plugin @prettier/plugin-python --help
  • CLI should work:

    prettier --plugin my-cool-prettier-plugin --my-custom-option
  • Remove unknown option warning for options contributed by external plugins.

    prettier.format('def foo(): pass', {
      parser: 'python',
      plugins: ['@prettier/plugin-python'],
      pythonVersion: '3.1.4'
    })
     Validation Warning:
    
     Unknown option "pythonVersion" with value "3.1.4" was found.
     This is probably a typing mistake. Fixing it will remove this message.
@azz azz added area:api Issues with Prettier's Application Programming Interface area:cli Issues with Prettier's Command Line Interface type:enhancement A potential new feature to be added, or an improvement to how we print something labels Dec 31, 2017
@azz azz mentioned this issue Dec 31, 2017
@taion
Copy link
Contributor

taion commented Dec 31, 2017

I don't believe #3433 did that. I believe it just exposed (via some code duplication) plugin options in getSupportInfo().

At the moment, all options other than the ones in cli/constant get dropped:

prettier/src/cli/util.js

Lines 628 to 642 in 6c0dd74

let option = constant.detailedOptionMap[key];
if (type === "api" && option === undefined) {
option = constant.apiDetailedOptionMap[key];
}
// unknown option
if (option === undefined) {
if (type === "api") {
consoleWarn(`Ignored unknown option: ${rawKey}`);
} else {
const optionName = rawValue === false ? `no-${rawKey}` : rawKey;
consoleWarn(`Ignored unknown option: --${optionName}`);
}
return;
}

In fact this happens before plugins are even loaded.

Unless I'm missing something, supporting per-plugin options would require a revamp of option parsing here. You'd need to first load plugins, then load their options, then parse the rest of the config.

@azz
Copy link
Member Author

azz commented Dec 31, 2017

It will just need to key into main/options.js's normalize. Shouldn't be too much work.

@taion
Copy link
Contributor

taion commented Dec 31, 2017

Yeah, something like that. There are a few different code paths here depending on which entry point you use. Also a bit harder for CLI stuff if relevant. Nothing too bad though.

Though it is worth thinking about how to configure e.g. trailing commas for Python. Something other than --trailing-comma would be most straightforward, but slightly messy.

@duailibe
Copy link
Member

duailibe commented Jan 1, 2018

@ikatyang has already planned a follow-up PR to deduplicate work with normalize. #3433 was just the start in that direction to unblock some other stuff (like #3573)

@ikatyang
Copy link
Member

ikatyang commented Jan 1, 2018

use supportOptions to generate CLI options (internal plugins) --> #3622

@ikatyang ikatyang self-assigned this Jan 18, 2018
@ikatyang ikatyang added the status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! label Jan 20, 2018
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 6, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:api Issues with Prettier's Application Programming Interface area:cli Issues with Prettier's Command Line Interface locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:has pr Issues with an accompanying pull request. These issues will probably be fixed soon! type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

No branches or pull requests

4 participants