Support Configuration Overrides for the experimental cli.
I've been trying out the new experimental CLI, and it is indeed seeming to be a lot faster.
Something I've noticed is that it appears there's no current support for Configuration Overrides. I suspect it just hasn't been added yet, which is fine, but as I couldn't see an existing issue for it, I thought I'd file one for helping with tracking.
STR
- Set up a repo with a
.prettierrc.jssuch as the one below:
module.exports = {
arrowParens: "avoid",
endOfLine: "lf",
printWidth: 80,
tabWidth: 2,
trailingComma: "es5",
overrides: [
{
files: "*.css",
options: {
parser: "css",
// Using a larger printWidth to avoid wrapping selectors.
printWidth: 160,
},
},
],
};
- Run the formatter
Expected Results
The CSS files are formatted correctly, with line width 160.
Actual Results
The CSS files are formatted with line width 80.
Can you try
module.exports = {
arrowParens: "avoid",
endOfLine: "lf",
printWidth: 80,
tabWidth: 2,
trailingComma: "es5",
overrides: [
{
- files: "*.css",
+ files: "**/*.css",
options: {
parser: "css",
// Using a larger printWidth to avoid wrapping selectors.
printWidth: 160,
},
},
],
};
I think it should work.
@43081j I thought this was fixed? Related PR https://github.com/prettier/prettier-cli/pull/34
Using files: "**/*.css", does work. Thank you.
I have the same issue, my overrides are not working. Here's my config file:
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"proseWrap": "preserve",
"endOfLine": "auto",
"singleAttributePerLine": true,
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
"importOrder": [
"",
"<BUILTIN_MODULES>",
"",
"<THIRD_PARTY_MODULES>",
"",
"^[.]"
],
"importOrderParserPlugins": ["typescript", "jsx", "decorators-legacy"],
"importOrderTypeScriptVersion": "5.8.0",
"overrides": [
{
"files": ["**/*.scss", "**/*.css"],
"options": {
"printWidth": 120
}
}
]
}
With the experimental cli, my css files are formated with a 80 printWidth
@fisker I think we have a TODO left about prefixing globs with **/ automatically unless they start with ./, assuming that's what the old CLI does, that hasn't been implemented yet. That said @Abreuvoir's config doesn't seem to be affected by that problem, so there might be another bug 🤔 I'll try to reproduce it once I get back home.
Sorry for going a bit off-topic, but I also had an issue with the @ianvs/prettier-plugin-sort-imports plugin's importOrder mentioned in @Abreuvoir's config, so there may be a compatibility issue between the new CLI and that plugin (it seemed like the importOrder property wasn't read correctly, or possibly at all, with the new CLI).
@Mathias-S Interestingly, thanks, I'll have a look 👍
@Mathias-S @fabiospampinato It doesn't seem related to @ianvs/prettier-plugin-sort-imports at all. For me, even with experimental CLI turned off, and with an option like singleQuote: false it still doesn't pick up on the overrides. Even a glob for all files still doesn't seem to match anything: - files: '**/*'
Are you using Prettier 3.6.0? That's the version that was working for me with files: "**/*.css",.
it seemed like the
importOrderproperty wasn't read correctly, or possibly at all, with the new CLI
This should probably be its own issue. overrides currently only pass on normalized configuration directives, no plugin options: https://github.com/prettier/prettier-cli/blob/4b1a66a1b8d7091ba53a37b4762b7863eaf09585/src/utils.ts#L659-L660
This is in contrast to the top-level configuration object which keeps everything (therefore also unknown plugin options) and only normalizes known directives: https://github.com/prettier/prettier-cli/blob/4b1a66a1b8d7091ba53a37b4762b7863eaf09585/src/config_prettier.ts#L94 https://github.com/prettier/prettier-cli/blob/4b1a66a1b8d7091ba53a37b4762b7863eaf09585/src/utils.ts#L640-L643
On 3.6.0, with config:
{
"arrowParens": "avoid",
"endOfLine": "lf",
"trailingComma": "all",
"printWidth": 120,
"singleQuote": true,
"tabWidth": 4,
"useTabs": true,
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
},
{
"files": "**/*.md",
"options": { "tabWidth": 2 }
}
]
}
Using --experimental-cli doesn't honor the markdown tabWidth.
I originally had "files": "*.md", and it didn't work, so I tried "files": "**/*.md", and don't see any difference
A shot in the dark, but could be Windows paths be the common denominator? In contrast to the cases where adding **/ to the glob has fixed the issue.
EDIT: Can't reproduce the issue of **/-prefix not working on windows…
No, I have the issue in a Linux Docker container. I see the same issue as @eamodio, where even standard Prettier options are not being respected.
does one of you experiencing exactly @eamodio's problem have a repo where it can be reproduced?
I can no longer reproduce this with https://github.com/prettier/prettier/releases/tag/3.6.1.
Though if I don't use "files": "**/*.md", over "files": "*.md", the behavior is different than prior prettier -- "files": "*.md", only matches .md files in the root folder, where as before it would be all .md files.
3.6.1 did not change anything for me
@43081j Here you go: https://github.com/oprypkhantc/prettier-reproduction/tree/master
It's in Docker, but you can clearly see that 3.5.x versions do respect useTabs and tabWidth options I've overwritten, and 3.6.x does not.
Thanks @oprypkhantc! This issue seems to be related to --config-path. When removing that directive from the docker run commands, the options are getting picked up.
If --config-path is used, the path matching against the overwrites is never performed.
getPrettierConfigResolved(), which handles the matching against overwrites, is never called when an explicit config file has been passed via --config-path: https://github.com/prettier/prettier-cli/blob/4b1a66a1b8d7091ba53a37b4762b7863eaf09585/src/index.ts#L133
Using Prettier 3.6.2 with the new cli flag I have to change my overwrites like this:
overrides: [
{
files:
- 'src/app/regionen/[regionSlug]/_components/SidebarInspector/TagsTable/translations/*.const.ts',
+ '**/translations/*.const.ts',
options: {
printWidth: 1000,
},
},
],
This overrides config works differently for me (versus the classic CLI):
overrides: [
{
files: ['**/tsconfig.json', '**/tsconfig.*.json'],
options: {
parser: 'jsonc',
},
},
],
The root tsconfig.json respects the parser: jsonc, but scripts/tsconfig.json file in my repo does not respect the overrides.
files: ['tsconfig.json', 'tsconfig.*.json']
doesn't work either
I just reported a similar issue on https://github.com/prettier/prettier/discussions/17818. I believe the reproduction I put in place could help into the investigation.
I tried to debug it, but so far I have not found my way through a fix, so I prefer asking to knowledgeable persons.
@dubzzz is your specific issue that plugin options in overrides are not honoured?
Please check if https://github.com/prettier/prettier-cli/pull/73 fixes your issue.
@tryone144 It works perfectly well 👍