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

Correct documentation on the editorconfig option. #15255

Open
mangelozzi opened this issue Aug 17, 2023 · 10 comments · May be fixed by #15984
Open

Correct documentation on the editorconfig option. #15255

mangelozzi opened this issue Aug 17, 2023 · 10 comments · May be fixed by #15984
Labels
help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! type:docs Issues about adding or improving documentation

Comments

@mangelozzi
Copy link

mangelozzi commented Aug 17, 2023

The issue is related to #6176

The documentation describes a editorconfig option, and trying to implement results in an error (tried both ways):

[warn] Ignored unknown option { editorconfig: true }.
[warn] Ignored unknown option { options: { editorconfig: true } }.

#6176 Says there is no editorconfig option, please update the documentation:
https://prettier.io/docs/en/configuration#editorconfig

If options.editorconfig is true and an .editorconfig file is in your project, Prettier will parse it and convert its properties to the corresponding Prettier configuration. This configuration will be overridden by .prettierrc, etc.

Having read more documentation, I think the documentation is refering to the API option: https://prettier.io/docs/en/api#prettierresolveconfigfilepath--options

Maybe the documentation should clarifying that it is a Node.js API configuration option object, and not a configuration file option, which is not an unreasonable conclusion in the given context of info about a config file

@arkinmodi
Copy link

editorconfig is also listed as an option in the JSON schema.

https://prettier.io/docs/en/configuration#configuration-schema
http://json.schemastore.org/prettierrc

        "editorconfig": {
          "description": "Whether parse the .editorconfig file in your project and convert its properties to the corresponding Prettier configuration. This configuration will be overridden by .prettierrc, etc.",
          "default": false,
          "type": "boolean"
        },

@mhagnumdw
Copy link

mhagnumdw commented Sep 5, 2023

Configuring Prettier with .editorconfig, I ran into the same problem. Reading the doc and checking the JSON schema, editorconfig=true should be a valid option. But when running npx prettier . --check get [warn] Ignored unknown option { editorconfig: true }.

version: "prettier": "3.0.3"

.prettierrc.yaml (I also tried with .prettierrc and .prettierrc.json)

editorconfig: true # problem!
printWidth: 100
singleQuote: true
trailingComma: "es5"
semi: true
arrowParens: "avoid"

vscode
image

Where am I going wrong?

edit: even without the editorconfig property defined, Prettier still seems to read the .editorconfig file, although it shouldn't since by JSON Schema the default value of the editorconfig property is false.

@sosukesuzuki sosukesuzuki added help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! type:docs Issues about adding or improving documentation labels Sep 16, 2023
@kingyue737
Copy link
Contributor

kingyue737 commented Nov 8, 2023

editorconfig in schema was added by me as I misunderstood the documentation SchemaStore/schemastore#2355. I've reopened a PR to remove it as a maintainer #6176 (comment) confirmed that this option only exists in function API, not CLI (CLI will always read the .editorconfig file if it exists). Sorry for bothering many other users😭😭😭.

@JoepKockelkorn
Copy link

Maybe we can mention in the docs (here) that the CLI always reads the .editorconfig file. I've been here multiple times already 😆.

@cavcrosby cavcrosby linked a pull request Jan 25, 2024 that will close this issue
4 tasks
@shantanu-bbai
Copy link

Maybe we can mention in the docs (here) that the CLI always reads the .editorconfig file. I've been here multiple times already 😆.

I don't think this is always true. Or at least, the cli is not respecting the use of tabs unless it's specified in the .prettierrc file.

@JoepKockelkorn
Copy link

@shantanu-bbai I don't experience the behaviour you describe. These are my config files and I reliably get tabs as the indentation character:

.prettierrc

{
	"singleQuote": true,
	"semi": false,
	"bracketSpacing": true,
	"bracketSameLine": false,
	"trailingComma": "all"
}

.editorconfig

root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80

[*.md]
max_line_length = off
trim_trailing_whitespace = false

Used version of prettier is 2.8.8.

@shantanu-bbai
Copy link

shantanu-bbai commented Feb 21, 2024

Hi @JoepKockelkorn, I'm fairly new to prettier and csharpier (we're just starting to use both) so its entirely possible I don't know what I'm doing. My initial plan was not to use the .prettierrc file at all (though I had planned on having an empty file in our git project just so new devs would realize that we're using prettier) and just use the .editorconfig for everything.

Here are the contents of my files:

.prettierrc (what I ended up having to populate instead of having an empty file - these configurations are picked up by the prettier commadline execution)

trailingComma: 'es5'
tabWidth: 4
semi: false
singleQuote: true
useTabs: true

.editorconfig

prettier configuration

[*]
charset = utf-8
insert_final_newline = true
end_of_line = lf
indent_style = tabs
indent_size = 4
max_line_length = 150
use_tabs = true

So maybe I should step back. I was looking through the project docs and I don't believe I've found a full set of possible configuration options listed (preferably both the editorconfig and prettierrc options since they aren't exactly the same). Most of the options I've found through stackoverflow threads.

Could you point me to an exhaustive set of options for prettier?

Also, can you tell me what has to go in prettierrc (i.e. cannot be configured via .editorconfig) if anything?

Lastly, can you tell me what I'm doing wrong with my configs (editorconfig specifically)?

We're using the most recent version of prettier:

npm info prettier version
3.2.5

@JoepKockelkorn
Copy link

@shantanu-bbai I will offer my help to you, but I have no experience with csharpier. Besides, it's unclear what you're trying to achieve. What are you using these tools for, what's your goal?

It's good to realise that editorconfig and prettier are both formatting tools but they slightly differ in scope and features. Editorconfig tries to bring a standardised formatting experience from the IDE perspective for nearly every file format. Without using an IDE (and plugin) to format your files, your .editorconfig settings won't do anything. It has no CLI to format files without using an IDE. You can find a list of supported settings here.

Prettier is similar, but different. It is much more opinionated, which means that there are some settings to tweak its behaviour, but some things just work as they do without a way to configure its behaviour. Also, it only works on certain file formats, not just every file. Prettier is pluggable though, so you can make it work for xml files using https://github.com/prettier/plugin-xml, but it doesn't work out of the box in contrast to editorconfig. Also, Prettier has extensions/plugins for your IDE to format files there, but it also has a CLI to format independent of your IDE. This opens possibilities to use it in CI to guarantee your files adhere to the configured prettier format using prettier . --check.

Some settings of Prettier overlap with editorconfig settings. Try searching for 'editorconfig' on the Prettier configuration page. For those, it's better to omit them from the Prettier configuration so Prettier will read them from the .editorconfig.

The documentation websites of both tools are pretty good, so any remaining questions you have will probably be answered by reading them:

@hallipr
Copy link

hallipr commented May 7, 2024

@shantanu-bbai, it looks like Prettier's options documentation lists the .editorconfig settings that will be imported.

printWidth

Setting max_line_length in an .editorconfig file will configure Prettier’s print width, unless overridden.

tabWidth

Setting indent_size or tab_width in an .editorconfig file will configure Prettier’s tab width, unless overridden.

useTabs

Setting indent_style in an .editorconfig file will configure Prettier’s tab usage, unless overridden.

Maintainers, is this an exhaustive list of settings read from .editorconfig?

@JoepKockelkorn
Copy link

You've missed end_of_line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! type:docs Issues about adding or improving documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants