prettier
prettier copied to clipboard
--range-{start,end} is ignored for --config-precedence=prefer-file
Environments:
- Prettier Version: 2.3.0
- Running Prettier via: CLI
- Runtime: v16
- Operating System: Linux, macOS
- Prettier plugins (if any):
Steps to reproduce:
- Create file
file.js
import { a } from 'a' ;
import {b, c } from 'b-c';
- Create file
.prettierrc.js
module.exports = {}
- Run
cat file.js | prettier --stdin-filepath file.js --config-precedence=file-override --range-start 9 --range-end 10
import { a } from "a";
import {b, c } from 'b-c';
- Run
cat file.js | prettier --stdin-filepath file.js --config-precedence=prefer-file --range-start 9 --range-end 10
import { a } from "a";
import { b, c } from "b-c";
Expected behavior:
Both output should be the same.
Actual behavior:
--config-precedence=prefer-file ignores --range-start and --range-end flags.
I can't reproduce this. Please provide complete steps to reproduce, including the contents of the two files.
@thorn0, sorry I wrote the command wrong previously. Updated the issue with examples.
Isn't this expected behavior though?
From https://prettier.io/docs/en/cli.html#--config-precedence:
prefer-file If a config file is found will evaluate it and ignore other CLI options. If no config file is found, CLI options will evaluate as normal.
--range-{start,end} should be treated differently. I can't imagine anybody putting those two options in config file (that would make prettier only format a specific region of every files).
I'm not familiar with the prefer-file use case, so I can't comment on it. Why doesn't file-override work for you?
I'm not familiar with the prefer-file use case
It's used for editor integrations. Integrations runs prettier like this:
cat file.js | prettier --stdin-filepath file.js --print-width=120 --config-precedence=prefer-file
with the expectations:
- Prettier will find config file by using it's logic.
- If config file is found Prettier will use it and ignore the CLI flags (e.g.
--print-widthwill be ignored). - If config file is not found Prettier will use the CLI flags (e.g.
--print-widthwill be used)
Why doesn't
file-overridework for you?
Like I said, it's used by editor integrations. The intention is to ignore cli flags if config file is found (i.e. when you're inside a project with prettierrc file).
- using
file-overridewill give precedence to config file (but also apply the cli flags for the missing options in config file) - using
cli-overridewill give precedence to cli flags (but also apply config file for the missing cli flags)
So prefer-file ensures that,
- If a config file is present, only follow it. So the project's styling preference will be respected.
- If a config file is not present use the cli flags. Since the project doesn't have any styling preference (no prettierrc config), respect the user's choice.
I hope that makes sense. Let me know if you have any additional questions.
Thanks for the explanation. The change you proposed makes sense.