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

Set "endOfLine" to auto in prettier config #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

allejo
Copy link

@allejo allejo commented Apr 21, 2023

Prettier by default uses LF but when working on a cross-platform repo where we let git handle the CRLF <> LF conversions for us. This default behavior causes Prettier and Git to start battling with each other and causes lint checks to fail. By setting it to auto, Prettier will respect the line endings that exist on the file and not change them.

@b-kelly
Copy link
Collaborator

b-kelly commented Apr 21, 2023

I'm not sure if I want to set this in the Prettier config or not. For reference, when running checks in GH actions / via package.json, we set that value explicitly. See Stacks-Editor as an example:

{
  "scripts": {
    "lint:prettier": "prettier --check . --end-of-line auto",
  }
}

@allejo
Copy link
Author

allejo commented Apr 21, 2023

If you set --end-of-line in the command line, would that take precedent over the loaded configuration file? If so, then wouldn't that allow users to opt-in to some line ending behavior whenever it's run? Git will always be the last operation (e.g. you make a commit) to handle CRLF <> LF conversions.

@b-kelly
Copy link
Collaborator

b-kelly commented Apr 21, 2023

Prettier will set any command line options over existing config settings (which are in turn set over any default setting). What the given command does is force prettier to use endOfLine: auto whenever someone runs npm run lint:prettier. This all happens only during the command's execution, so you can generally ignore any other environmental factors (such as what git or your OS has decided what your line endings should be). Something to note is that as-written, prettier is only checking, not modifying.

@allejo
Copy link
Author

allejo commented Apr 21, 2023

Right, the script above is only checking and not modifying any files. I haven't tried yet, but do IDEs support pulling in a configuration from a package? Like, what if your IDE is configured to do a "prettier on save" function, would it modify the line ends to LF and then cause Git to see that as the file being changed?

Copy link
Contributor

@giamir giamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-kelly I believe we could consider endOfLine: "auto" a sensible default for our Stack Overflow repositories which would make it a good candidate for this package. What about merging this PR and cut a release?

allejo added a commit to allejo/js-utils-monorepo that referenced this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants