Skip to content

Format comparisons, functions, and redirections to be consistent#1201

Merged
spacewander merged 3 commits intotj:mainfrom
hyperupcall:hyperupcall-style
Jun 6, 2025
Merged

Format comparisons, functions, and redirections to be consistent#1201
spacewander merged 3 commits intotj:mainfrom
hyperupcall:hyperupcall-style

Conversation

@hyperupcall
Copy link
Copy Markdown
Collaborator

@hyperupcall hyperupcall commented Mar 24, 2025

It can be difficult reading through scripts here with every file seemingly having a different convention (for argument parsing, help menu, function delarations, etc.). This cleans up some of that with a little checkstyle.py script I made for asdf-vm a while back (it has autofix). It catches some things that ShellCheck doesn't, or autofixes things that ShellCheck doesn't.

One thing I would like to do, is add a chekstyle.py here, so we can easily enforce those style issues (and possibly other automatically fixable things) for new PRs. Is there interest in that?

Copy link
Copy Markdown
Collaborator

@spacewander spacewander left a comment

Choose a reason for hiding this comment

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

Could we put this check in the CI?

Copy link
Copy Markdown

@ferdnyc ferdnyc left a comment

Choose a reason for hiding this comment

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

This seems like a helpful bit of cleanup, @hyperupcall -- I agree with @spacewander, it would be good to have those checks in the CI as well.

Comment thread bin/git-bulk

# add another workspace to global git config
function addworkspace {
addworkspace() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There's still some inconsistency allowed here because when your script adds parentheses, it adds them without a space after the function name...

Comment thread bin/git-bulk

# guarded execution of a git command in one specific repository
function guardedExecution () {
guardedExecution () {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But if they're already present, it will leave the format however it was previously...

Comment thread bin/git-clear
FORCE=0

function _usage() {
_usage() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Which means the results have all of:

# Definitions without a space, because they
# were changed from
function fname { ... }
# to
fname() { }

# Definitions without a space, because they were
# changed from
function fname() { ... }
# to
fname() { ... }

# Definitions with a space, because they were
# changed from
function fname () { ... }
# to
fname () { ... }

(And that's just in the ones the script modified.) Would it be better to decide on a particular style and apply it consistently?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The checkstyle.py script doesn't add rules that are supported by other tools. For example, shfmt supports automatically fixing that whitespace inconsistency.

I would rather add a proper tool like shfmt instead of tweaking the regular expressions to support different forms of whitespace.

@hyperupcall
Copy link
Copy Markdown
Collaborator Author

Script added to CI!.

@hyperupcall hyperupcall requested a review from spacewander June 4, 2025 12:56
@spacewander spacewander merged commit 3ddc315 into tj:main Jun 6, 2025
6 checks passed
@spacewander
Copy link
Copy Markdown
Collaborator

@hyperupcall
Merged. Thanks!

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