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

chore: format all files #22

Merged
merged 3 commits into from
May 14, 2024
Merged

chore: format all files #22

merged 3 commits into from
May 14, 2024

Conversation

mdjermanovic
Copy link
Member

@mdjermanovic mdjermanovic commented May 13, 2024

This PR:

  • Checks in formatted versions of all files in the repo (I ran npm run fmt) so that unrelated formatting changes no longer appear in PRs.
  • Adds Verify Files CI job that checks if all files are lint-free (eslint) and properly formatted (prettier).
  • Adds a lint-staged task to format non-js files.

Question: I assumed we want to format all files that prettier knows to handle. Are there some files we'd like to ignore or format differently? I only ignored CHANGELOG.md files because those are autogenerated.

Comment on lines 21 to +25
"*.js": [
"eslint --fix",
"prettier --write"
]
],
"!(*.js)": "prettier --write --ignore-unknown"
Copy link
Member Author

Choose a reason for hiding this comment

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

Prettier runs on all files, but separate "*.js" and "!(*.js)" tasks are needed to make sure that eslint runs before prettier on .js files.

https://github.com/lint-staged/lint-staged?tab=readme-ov-file#task-concurrency

@mdjermanovic mdjermanovic marked this pull request as ready for review May 13, 2024 12:26
@@ -8,7 +8,8 @@
"build": "node scripts/build.js",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"fmt": "prettier --write ."
"fmt": "prettier --write .",
Copy link
Member

Choose a reason for hiding this comment

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

this should rather be fmt:fix and the check should be fmt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Formatting is currently not covered by our package-json-conventions.

@nzakas what do you think about script names?

Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest lets keep the script name to be format for analysing formatting problems. and format:fix for the write formatted changes. I can send a PR to add it to package conventions as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

format & format:fix would be aligned with lint & lint:fix, which looks good for consistency, but in the context of the word "format" it might be surprising that format only checks the format, so maybe format:check & format:fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this PR has a high potential of running into merge conflicts with any future PRs, what do you think about merging this now as-is, and continuing this discussion on a PR that updates package conventions? Then, we could get back to this repo and update the script names if needed.

Copy link
Member

Choose a reason for hiding this comment

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

Yea lets merge this PR and then pick this as a separate issue.

"somePlugin/rule-name": "error"
}
}
{
Copy link
Member

Choose a reason for hiding this comment

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

prettier uses tabs by default? Seems like too much space from the existing one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, tabs are default in Prettier. - wrong

This is only 1 tab, but GitHub by default renders tabs as 8 spaces so it looks huge.

Copy link
Member Author

Choose a reason for hiding this comment

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

GitHub by default renders tabs as 8 spaces

It's configurable:

https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-user-account-settings/managing-your-tab-size-rendering-preference

I've just changed my Tab size preference to 4 and this looks the same as before on my screen:

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, prettier's default indentation is 2 spaces. But we configured it in this project to use tabs:

useTabs: true,

@nzakas
Copy link
Member

nzakas commented May 13, 2024

Question: I assumed we want to format all files that prettier knows to handle. Are there some files we'd like to ignore or format differently?

I think just CHANGELOG.md we should leave alone. Otherwise, I'm 👍 to formatting everything. We can always adjust later if we don't like something.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Just leaving open until @harish-sethuraman's questions are answered.

Copy link
Member

@harish-sethuraman harish-sethuraman left a comment

Choose a reason for hiding this comment

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

LGTM

@aladdin-add aladdin-add merged commit d5a0496 into main May 14, 2024
13 checks passed
@aladdin-add aladdin-add deleted the format-repo branch May 14, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

4 participants