prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

Require a prettier config when requireConfig is true

Open redoPop opened this issue 3 years ago • 19 comments

Fix for #2402. When requireConfig is true we cannot rely on the resolvedConfig value to indicate that a Prettier config was found: the resolved configuration may have been picked up from an .editorconfig file instead.

This issue was previously fixed in 8.1.0 but the fix seems to have been undone by subsequent changes.

  • [x] Run tests
  • [x] Update the CHANGELOG.md with a summary of your changes

redoPop avatar Sep 08 '22 03:09 redoPop

I don't think this is right. I need to test, but I think configPath is just the location but doesn't necessarily indicate that there is a config at that location.

ntotten avatar Sep 23 '22 14:09 ntotten

configPath is the resolution of prettier.resolveConfigFile given the current document path. That's null if no Prettier config file is found in the parent tree, coalesced to undefined in our code.

One thing to watch out for as you test: if you have a prettier config in your home dir or elsewhere in the parent tree then it'll get picked up by resolveConfigFile. That seems like the right behavior for this feature, but it's a potential red herring for testing.

redoPop avatar Sep 23 '22 19:09 redoPop

I'll merge this for v10 with prettier 3 as its a breaking change

ntotten avatar Apr 22 '23 13:04 ntotten

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

github-actions[bot] avatar Jun 22 '23 02:06 github-actions[bot]

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

Keep open for next major release.

redoPop avatar Jun 22 '23 09:06 redoPop

Actually, now that i think about this. Why can't you just set the config prettier.useEditorConfig to false? This will prevent the use of editorconfig as the config file and thus will require only a prettier config to be present.

ntotten avatar Jul 10 '23 17:07 ntotten

@orenklein gave a good example in #2402: they're working in a monorepo with a global .editorconfig. Some of the individual packages in the monorepo augment those rules with Prettier configs, while others rely entirely on EditorConfig.

My team has a similar use case: we have a boilerplate .editorconfig in every repo to set broad formatting rules, and .prettierrc as an additional layer of configuration for projects that use Prettier.

In both use cases, it's helpful that Prettier allows us to extend EditorConfig rules and establish a hierarchy with a single source of truth for configurations that apply across multiple globs.

A couple of other factors I can think of:

  • I work with projects from multiple teams, and it's useful to know that prettier-vscode will follow another team's Prettier config as best it can – including editorconfig: true – without requiring me to make additional configurations specific to that project.
  • It's caught a few of us by surprise that EditorConfig satisfies the requireConfig rule. That doesn't necessarily make it a bug, but I think the natural expectation is that prettier-vscode requires a Prettier config, not necessarily an EditorConfig.

redoPop avatar Jul 10 '23 19:07 redoPop

I think your points are valid, but from the history of this debate I think some people are going to want the current behavior. I don’t love extra complexity, but I wonder is we should evolve this config into maybe three values.

useEditorConfig: “never” | “fallback” | “always”

I am leaning toward not using editor config as a default with the require config, but i feel like we should allow for it.

the next challenge will be picking the names of these config in a way that makes sense. Open to suggestions.

ntotten avatar Jul 14 '23 03:07 ntotten

A suggestion for config naming: we could change the values for requireConfig instead of useEditorConfig. Something like this:

"requireConfig": "strict" | "inclusive" | "none"

  • strict = Files are formatted only if a Prettier configuration file is present
  • inclusive = Files are formatted if Prettier or EditorConfig configuration files are present
  • none = Formatting is always enabled (default)

We could then leave useEditorConfig as is and let people opt in to the new behavior explicitly while continuing to support people who've come to expect the current behavior.

redoPop avatar Jul 21 '23 21:07 redoPop

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

github-actions[bot] avatar Sep 20 '23 01:09 github-actions[bot]

Keep open.

redoPop avatar Sep 20 '23 13:09 redoPop

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

github-actions[bot] avatar Nov 20 '23 01:11 github-actions[bot]

Keep open.

redoPop avatar Nov 20 '23 03:11 redoPop

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

github-actions[bot] avatar Jan 22 '24 01:01 github-actions[bot]

Keep open.

redoPop avatar Jan 23 '24 03:01 redoPop

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

github-actions[bot] avatar Mar 25 '24 01:03 github-actions[bot]

@ntotten What's the next step here? Happy to try implementing either of the proposed config changes in this PR, but not sure which you'd prefer.

redoPop avatar Mar 25 '24 19:03 redoPop

This pull request has been labeled as stale due to inactivity. Reply to keep this pull request open.

github-actions[bot] avatar May 25 '24 01:05 github-actions[bot]

Keep open?

redoPop avatar May 25 '24 03:05 redoPop