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

prettier:write complains about package.json when saved from Windows #21

Closed
3esmit opened this issue Feb 26, 2024 · 8 comments
Closed

prettier:write complains about package.json when saved from Windows #21

3esmit opened this issue Feb 26, 2024 · 8 comments
Assignees
Labels
type: bug Something isn't working

Comments

@3esmit
Copy link

3esmit commented Feb 26, 2024

I am using WSL with Ubuntu. My console is Linux, but my editor is Windows.

When I edit package.json, I can run normally everything here, 'pnpm lint' or whatever. However, when I send to repository, CI lint complains about package.json having style issues.

When we see the diff, nothing changes, besides the last line of the code that is changed in an invisible character.

To workaround this, I open the file in a console editor inside WSL, and than save it.

I think this is a bug or configuration on prettier itself, as it should not matter what EOL are used, as Windows is able to interpret Linux files, and Linux is able to interpret Windows file.

It shouldn't warn for Windows EOL, unless there is a good reason for that.

@3esmit
Copy link
Author

3esmit commented Feb 26, 2024

an workaround would be to add this to .gitattributes:

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text

# Declare files that will always have CRLF line endings on checkout.
*.json text eol=lf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary

@3esmit
Copy link
Author

3esmit commented Feb 26, 2024

0x-r4bbit added a commit that referenced this issue Feb 28, 2024
This is to ensure git will always converts to line feed endings.
This should help with #21
@0x-r4bbit
Copy link
Collaborator

@3esmit Here's a PR that enforces line feeds in the git repository: #26

Following the recommendations by prettier:

If you want to make sure that your entire git repository only contains Linux-style line endings in files covered by Prettier:

  1. Ensure Prettier’s endOfLine option is set to lf (this is a default value since v2.0.0)
  2. Configure a pre-commit hook that will run Prettier
  3. Configure Prettier to run in your CI pipeline using --check flag. If you use Travis > CI, set the autocrlf option to input in .travis.yml.
  4. Add * text=auto eol=lf to the repo’s .gitattributes file. You may need to ask Windows users to re-clone your repo after this change to ensure git has not converted LF to CRLF on checkout.

With this we're checking off 1), 3) and 4).

I'll look into setting up the commit hook next.

@0x-r4bbit
Copy link
Collaborator

So git hooks are client-side (local) only.
Before we start adding additional dependencies to get hooks for everyone, can you try any of these options here and see if they actually work for you:

https://prettier.io/docs/en/precommit

You might want to try this on top of #26 also

@0x-r4bbit 0x-r4bbit moved this from Todo to In Progress in Tasks - Smart Contracts Feb 28, 2024
@0x-r4bbit 0x-r4bbit added the type: bug Something isn't working label Feb 28, 2024
0x-r4bbit added a commit that referenced this issue Feb 29, 2024
This is to ensure git will always converts to line feed endings.
This should help with #21
@0x-r4bbit
Copy link
Collaborator

@3esmit how do we move forward here. Did you try any of the options?

@3esmit
Copy link
Author

3esmit commented Mar 19, 2024

I am not sure. I have tried some but didnt seemed to work. It's difficult to diagnose this.

@0x-r4bbit
Copy link
Collaborator

Did you try installing a pre-commit hook?

@0x-r4bbit
Copy link
Collaborator

Closing this due to inactivity

@github-project-automation github-project-automation bot moved this from In Progress to Done in Tasks - Smart Contracts Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
Development

No branches or pull requests

2 participants