Skip to content

Add prettier.parser setting#3974

Open
br3ndonland wants to merge 1 commit intoprettier:mainfrom
br3ndonland:parser
Open

Add prettier.parser setting#3974
br3ndonland wants to merge 1 commit intoprettier:mainfrom
br3ndonland:parser

Conversation

@br3ndonland
Copy link

Description

The Prettier CLI has a --parser option for manually specifying the parser if needed, but the Prettier VSCode extension does not have a corresponding setting for specifying a parser in the VSCode settings.json. It is also not able to use custom language modes that have been set in VSCode (i.e., if a YAML file has been set as a helm-template).

A parser setting would also be helpful for "untrusted" VSCode workspaces (workspaces running in "Restricted Mode"). Starting with version 12.4.0 (#3972), untrusted workspaces now no longer load Prettier configuration files. However, they can still load settings.json, so Prettier settings can be added to settings.json for those workspaces.

This PR will add a prettier.parser setting.

The setting can be used in conjunction with language-specific settings to override the parser for specific VSCode languages. For example, to format Git commits and tags as Markdown, which can be useful for changelogs and docs:

{
  "[git-commit]": {
    "prettier.parser": "markdown",
    "prettier.printWidth": 72,
    "prettier.proseWrap": "always"
  }
}

Alternatively, setting prettier.parser: "vscode" will derive the parser from the active VSCode language mode.

Tests will be updated for the new setting and behavior. There are some small updates to config file parsing needed to properly respect the .do-not-use-prettier-vscode-root marker files.

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/Build changes

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project (npm run lint passes)
  • I have run npm run prettier to format my code
  • I have added/updated tests that prove my fix or feature works
  • All new and existing tests pass (npm test)
  • I have updated the CHANGELOG.md with a summary of my changes

The Prettier CLI has a `--parser` option for manually specifying the
parser if needed, but the Prettier VSCode extension does not have a
corresponding setting for specifying a parser in the VSCode
`settings.json`. It also is not able to use custom language modes that
have been set in VSCode (i.e., if a YAML file has been set as a
`helm-template`).

A parser setting would also be helpful for "untrusted" VSCode workspaces
(workspaces running in "Restricted Mode"). Starting with version 12.4.0,
untrusted workspaces now no longer load Prettier configuration files.
However, they can still load `settings.json`, so Prettier settings can
be added to `settings.json` for those workspaces.

This PR will add a `prettier.parser` setting.

The setting can be used in conjunction with language-specific settings
to override the parser for specific VSCode languages.

Alternatively, setting `prettier.parser: "vscode"` will derive the
parser from the active VSCode language mode.

Tests will be updated for the new setting and behavior. There are some
small updates to config file parsing needed to properly respect the
`.do-not-use-prettier-vscode-root` marker files.

Signed-off-by: Brendon Smith <bws@bws.bio>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to use VSCode language instead of prettier resolved language

1 participant