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

Include e2e folder in shfmt editorconfig for 2 spaces indenting #1937

Merged
merged 7 commits into from
Apr 23, 2024

Conversation

zph
Copy link
Contributor

@zph zph commented Apr 22, 2024

Right now e2e differs from other *.sh formatting in that e2e is autoformatted w/ tabs rather than spaces.

It looks like an error and I'll see if this change to editorconfig correctly includes the e2e folder.

I segregated the bulk formatting changes to separate commit, but it's many lines of change. The other approach can be gradually unifying the formatting as individual new PRs come in or an area is refactored.

zph added 2 commits April 22, 2024 12:47
Without this, shfmt has a different format for *.sh vs e2e/test_* files
which are also shell scripts.
@zph
Copy link
Contributor Author

zph commented Apr 22, 2024

Strange. Maybe shfmt on CI is different than local or how we run shfmt isn't respecting the editorconfig.

@jdx
Copy link
Owner

jdx commented Apr 22, 2024

would it be simpler to use shfmt's default style maybe?

.editorconfig Outdated
@@ -2,7 +2,7 @@
indent_style = space
indent_size = 2

[{*.sh,.mise/tasks/**/*}]
[{*.sh,.mise/tasks/**/*,e2e/*}]
Copy link
Owner

Choose a reason for hiding this comment

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

this isn't ideal since it's missing test_* files in subdirectories. I think this is another good argument for sticking with shfmt's native behavior so we don't need to define this in editorconfig necessarily

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it was a function of shellcheck and shfmt usage in 7285064.

They were constraining the files considered for formatting and how it will include subdirectories.

@@ -2,7 +2,7 @@
indent_style = space
indent_size = 2

[{*.sh,.mise/tasks/**/*}]
[{*.sh,.mise/tasks/**/*,e2e/**/*}]
Copy link
Owner

Choose a reason for hiding this comment

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

This may still be a problem since I think this is globbing files which are not scripts. There are some other files in this directory. I'm not certain though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I think it behaves is:

  • editorconfig tells shfmt what to consider in scope aside from other instructions
  • in mise run lint and lint-fix, it's explicitly stated what to format and fed to shfmt, so shfmt restricts itself to those files, which didn't include the subdirectories

I have a commit later to address it.

Copy link
Owner

Choose a reason for hiding this comment

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

one thing I seem to have to relearn every few years is that file extensions are pretty much always a good idea :)

@zph
Copy link
Contributor Author

zph commented Apr 22, 2024

would it be simpler to use shfmt's default style maybe?

We could but I've seen shfmt default be less common than Google's shell styleguide in the bash ecosystem. shfmt has an example of the Google shell style guide in their own documentation: https://github.com/mvdan/sh/blob/master/cmd/shfmt/shfmt.1.scd#examples and I prefer it because the behavior more closely matches what's commonly used in many other languages (2x spaces = an indent level).

If editorconfig doesn't do it, explicitly putting the Google flags for the two places shfmt is run would ensure it's consistent in the codebase.

from shfmt docs:

shfmt -i 2 -ci -bn

I wanted to offer this change b/c it's currently an inconsistent mix of spaces and tabs. I think the uniformity is most important (tabs or spaces) followed by choosing which.

Also, this is a minor nit :) that I wanted to offer for my own simplicity in the project. I'm ok w/ it being closed too as working in a way that's acceptable.

@zph
Copy link
Contributor Author

zph commented Apr 22, 2024

🤔 I don't think CI is respecting .editorconfig.

@jdx
Copy link
Owner

jdx commented Apr 23, 2024

admittedly I have a weird mix of CI tools that might be conflicting a bit here—specifically megalinter and the lint mise task. I think megalinter does respect editorconfig but my custom CI logic may not be.

@zph
Copy link
Contributor Author

zph commented Apr 23, 2024

@jdx That's what I just came back to fill in as a comment :)

mise run lint and lint-fix override more explicitly what should be formatted and I think it invalidates editorconfig.

@jdx
Copy link
Owner

jdx commented Apr 23, 2024

oh looks like you got it all working? is this good to merge?

@zph
Copy link
Contributor Author

zph commented Apr 23, 2024

@jdx Yes, I took another look through and it's ✅ ready to merge.

Thanks for talking through it.

@jdx jdx merged commit 75810a2 into jdx:main Apr 23, 2024
7 checks passed
@zph zph deleted the include-e2e-in-shfmt-editorconfig branch April 23, 2024 00:17
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.

None yet

2 participants