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

endOfLine changed from auto to LF in v2.0.0 doesn't take effect #1327

Open
snebjorn opened this issue Apr 15, 2020 · 17 comments
Open

endOfLine changed from auto to LF in v2.0.0 doesn't take effect #1327

snebjorn opened this issue Apr 15, 2020 · 17 comments
Labels
bug help-wanted Not something we plan on doing, but we will take a pull request.

Comments

@snebjorn
Copy link

Summary

Line endings was changed from auto to LF in prettier v2.0.0. However this doesn't change CRLF files to LF when formatting.

Github Repository to Reproduce Issue

Any CRLF file prettier supports will do

Steps To Reproduce:

Use prettier v2 default config

  1. Open a CRLF file (ie .ts) that is otherwise correctly formatted
  2. Observe that vscode doesn't report line ending errors
  3. Open command pallet and run "Format document with..." select "prettier"
  4. Observe that line endings are still CRLF and prettier still doesn't report errors

Expected result

Prettier should report line ending errors.
Prettier should change line endings to LF on format.

Actual result

Line endings are still CRLF after formatting.

Additional information

VS Code Version: 1.44.1

Prettier Extension Version: 4.4.0

OS and version: Windows 1909

.prettierrc

{
  "singleQuote": true,
  "printWidth": 200
}

.editorconfig

# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false

Prettier Log Output

["INFO" - 02.27.47] Formatting ~\Repos\akita\libs\akita\src\lib\updateEntities.ts
["INFO" - 02.27.47] Using ignore file (if present) at ~\Repos\akita\.prettierignore
["INFO" - 02.27.47] Loaded module 'prettier@2.0.4' from '~\Repos\akita\node_modules\prettier\index.js'
["INFO" - 02.27.47] File Info:
{
  "ignored": false,
  "inferredParser": "typescript"
}
["INFO" - 02.27.47] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 02.27.47] Prettier Options:
{
  "filepath": "~\\Repos\\akita\\libs\\akita\\src\\lib\\updateEntities.ts",
  "parser": "typescript",
  "useTabs": false,
  "tabWidth": 2,
  "singleQuote": true,
  "printWidth": 200
}
["INFO" - 02.27.47] Formatting completed in 26.475699ms.
@ntotten
Copy link
Member

ntotten commented Apr 15, 2020

Can you provide a github repo I can use to duplicate this? Everything in the log output is correct (the output config only shows overridden info so the endOfLine is set to default).

@snebjorn
Copy link
Author

snebjorn commented Apr 15, 2020

Sure https://github.com/datorama/akita
But line ending on checkout depend on your git settings and that one have

# .gitattributes
* text=auto

Still prettier should complain about every line in every file as I'm running on Windows

I discovered this when I added https://github.com/prettier/eslint-plugin-prettier to the eslint rules. Because it went absolutely nuts and complained about every line in every file :)

@ntotten
Copy link
Member

ntotten commented Apr 16, 2020

Can you tell me if you run prettier from the CLI does it fix the line endings correctly?

@snebjorn
Copy link
Author

Yep.

checking format

❯ yarn prettier --check .\libs\akita\src\lib\updateEntities.ts
yarn run v1.22.0
$ ~\Repos\akita\node_modules\.bin\prettier --check .\libs\akita\src\lib\updateEntities.ts
Checking formatting...
libs\akita\src\lib\updateEntities.ts
Code style issues found in the above file(s). Forgot to run Prettier?
error Command failed with exit code 1.

formatting

❯ yarn prettier --write .\libs\akita\src\lib\updateEntities.ts
yarn run v1.22.0
$ ~\Repos\akita\node_modules\.bin\prettier --write .\libs\akita\src\lib\updateEntities.ts
libs\akita\src\lib\updateEntities.ts 169ms
Done in 0.47s.

after running prettier --write VSCode now shows image

@snebjorn
Copy link
Author

@ntotten are you not able to reproduce this? Can I assist any further?

@ntotten ntotten added the uncomfirmed Possible bugs that haven't been confirmed label May 10, 2020
@zxjinghang
Copy link

Same here. While editorconfig vscode plugin takes effect.

@ScriptPup
Copy link

Same here with vscode as well

@vasilii-kovalev
Copy link

vasilii-kovalev commented Oct 30, 2020

It seems that even "endOfLine": "lf" doesn't work in VS Code automatically (without running Prettier via CLI).

@thorn0
Copy link
Member

thorn0 commented Dec 9, 2020

It might make sense to check the implementation of the EditorConfig extension to use the same way to override VS Code's newline settings.

@xulonc
Copy link

xulonc commented Apr 15, 2021

I have the same problem,VS code Prettier not work,but Prettier CLI work correctly 😐

@xulonc
Copy link

xulonc commented Apr 15, 2021

add .editorconfig file can work
image

@Dannymx
Copy link

Dannymx commented Jul 12, 2022

This is still a problem, on vscode my settings are to have the end line as lf, my .prettier.json also has lf but still inserts crlf

@taras-budzyn
Copy link

This is still a problem, on vscode my settings are to have the end line as lf, my .prettier.json also has lf but still inserts crlf

i was playing with it, but end up with using
git config --global core.autocrlf input
it covers what i actually need :)

@ntotten ntotten added bug help-wanted Not something we plan on doing, but we will take a pull request. and removed uncomfirmed Possible bugs that haven't been confirmed labels Aug 20, 2022
@mazyvan
Copy link

mazyvan commented Sep 13, 2023

I'm having the same issue. CLI works, vscode format with prettier doesn't

@uiii
Copy link

uiii commented Feb 9, 2024

I have this problem too, as it doesn't convert EOLs on "Format document" command. Any updates on this?

@sebastiangug
Copy link

still doesn't work, it's been over 4 years now, lol.

@Codex-
Copy link

Codex- commented Jun 13, 2024

Encountered this today, was very incredibly confusing to track down a case where locally running prettier updated line endings as expected but a colleagues result in no change, was due to a global git config autocrlf being set.

Would be good if there was some output or suppressible warning if the endOfLine setting was set and not being respected due to this, or having an option to opt out of that behaviour.

While the issue is here under the plugin, the execution via cli resulted in the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted Not something we plan on doing, but we will take a pull request.