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

Don't look for a configuration file outside the project directory #8303

Open
thorn0 opened this issue May 13, 2020 · 11 comments · May be fixed by #15675
Open

Don't look for a configuration file outside the project directory #8303

thorn0 opened this issue May 13, 2020 · 11 comments · May be fixed by #15675
Labels
area:api Issues with Prettier's Application Programming Interface
Milestone

Comments

@thorn0
Copy link
Member

thorn0 commented May 13, 2020

When looking for the .editorconfig file, Prettier doesn't climb all the way up the file system. It finds the 'project (repository) root' and stops there. It would make sense to adjust the resolution of configuration files the same way.

  • Prettier should be configured on the project-level, its configuration should be part of the project.
  • It's encouraged to use Prettier with default settings, which means without a configuration file. It also means that if there is a configuration file in some parent directory, it can unexpectedly affect formatting.
  • It's inconsistent that .editorconfig and .prettierrc are resolved differently.

But this would be a breaking change.

Thoughts?

@thorn0 thorn0 added area:api Issues with Prettier's Application Programming Interface status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels May 13, 2020
@fisker
Copy link
Sponsor Member

fisker commented May 13, 2020

root = true

root: true

@thorn0
Copy link
Member Author

thorn0 commented May 14, 2020

@fisker Unlike ESLint and EditorConfig, Prettier's configuration file isn't hierarchical. Once it's found, the resolution process stops, so it's always "root" anyway. But I'm also talking about a use case when there is no configuration file at all. If the user wants to use all the defaults, they don't need a config file. Looks like the docs should recommend doing this for now:

@thorn0 thorn0 added this to the 3.0 milestone Feb 16, 2021
@QimatLuo
Copy link

git clone repo_with_prettier_configed
cd repo_with_prettier_configed
git submodule add repo_with_empty_prettier_config

In this case, the submodule folder with prettier empty config {} still not work, it get affected by parent config.
But if it's not a submodule, just a normal folder, then it works with empty config {} without get affect by parent config.

To me it's a bug.
Because the person who work with submodule will get different behavior even though the submodule setup correct itself.

@thorn0
Copy link
Member Author

thorn0 commented May 14, 2021

@QimatLuo Is your message about the current behavior of Prettier or about the logic proposed in this issue? If former, please provide more specific reproduce steps and a sample repo on GitHub. (I must notice though that Prettier doesn't have a notion of "parent config". Configs aren't hierarchical.)

@katsar0v

This comment was marked as off-topic.

@QimatLuo
Copy link

@QimatLuo Is your message about the current behavior of Prettier or about the logic proposed in this issue? If former, please provide more specific reproduce steps and a sample repo on GitHub. (I must notice though that Prettier doesn't have a notion of "parent config". Configs aren't hierarchical.)

Cannot replicate with newest prettier version.
I'm good now.

@fisker
Copy link
Sponsor Member

fisker commented Oct 20, 2022

Pass this

root: findProjectRoot(path.dirname(path.resolve(filePath))),
as stopDir option should fix this.

@fisker fisker modified the milestones: 3.0, 4.0 Feb 8, 2023
@fisker
Copy link
Sponsor Member

fisker commented Feb 8, 2023

I'm going to postpone this, can't get it done before v3 release.

@buckley310
Copy link

Related? #13538
The editorconfig spec actually says the search should proceed outside the project directory.

@fisker fisker removed the status:needs discussion Issues needing discussion and a decision to be made before action can be taken label Nov 17, 2023
@fisker
Copy link
Sponsor Member

fisker commented Nov 17, 2023

We'll accept this.

@fisker fisker linked a pull request Nov 18, 2023 that will close this issue
4 tasks
@pronebird
Copy link

Can anyone explain please, I have .editorconfig two levels above where I run prettier and it seems to be completely oblivious that there is ../../.editorconfig with root = true inside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues with Prettier's Application Programming Interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants