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

Get all shell scripts passing shellcheck #10795

Open
Ericson2314 opened this issue May 28, 2024 · 5 comments
Open

Get all shell scripts passing shellcheck #10795

Ericson2314 opened this issue May 28, 2024 · 5 comments
Labels
contributor-experience Developer experience for Nix contributors good first issue Quick win for first-time contributors idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome.

Comments

@Ericson2314
Copy link
Member

Since #10787, we are now running shellcheck on scripts.

Just like with C/C++ formatting, we are excluding almost all existing files by default. However, the reason for doing that is different than for formatting --- fixing shellcheck lint errors does not have the downside of causing merge conflicts churn, but does require manual edits. Thus we're skipping existing files not because it would be potentially bad to get them passing, but because it is more work than is appropriate for a single PR.

Scripts can one-by-one be made passing, which is a great issue to share between new contributors!

@Ericson2314 Ericson2314 added good first issue Quick win for first-time contributors contributor-experience Developer experience for Nix contributors labels May 28, 2024
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue May 28, 2024
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue May 28, 2024
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue May 28, 2024
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue May 28, 2024
Ericson2314 added a commit to obsidiansystems/nix that referenced this issue May 28, 2024
@fricklerhandwerk fricklerhandwerk added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label May 29, 2024
@SkamDart
Copy link
Contributor

SkamDart commented Jun 3, 2024

Is there a way to run individual tests?
I have a bash script that automates away the happy path where we can use shellcheck to auto-apply fixes.
Would be cool to run a n individual tests instead of running the full test suite n times.

#!/usr/bin/env bash

# this file was made by manually editing the list of the shcellcheck exluded files.
#
# Use some vim/emacs magic from the output of
#
# $ cat $_NIX_PRE_COMMIT_HOOKS_CONFIG | yq -y .repos[0].hooks[1].exclude
#
# e.g.
# tests/functional/gc.sh
# tests/functional/add.sh
# tests/functional/fmt.sh
FILES=$(cat /tmp/excluded-files.txt)
MAINT="./maintainers/flake-module.nix"

for file in $FILES
do
    shellcheck -f diff "$file" | git apply
    SC=$?

    # if shellcheck/git patch fails.... manually fix
    if [ $SC -ne 0 ]; then
        echo "$file failed to be formatted manual intervention required"
        nvim $file
    else
        # Remove the processed file from the list
        #
        # we need to escape the nested directories for our regex.
        escaped_file=$(echo "$file" | sed -e 's/[]\/$*.^[]/\\&/g')
        sed -i "/$escaped_file/d" $MAINT

        # Do git stuffs
        git add "$file" "$MAINT"
        git commit -m "housekeeping: shellcheck for $file"
    fi
done

@Ericson2314
Copy link
Member Author

@SkamDart Yes there is! See https://nixos.org/manual/nix/unstable/contributing/testing and ./mk/debug-test.sh tests/functional/${testName}.sh.

fzakaria added a commit to fzakaria/nix that referenced this issue Jul 15, 2024
Got shellcheck passing for misc/systemv/nix-daemon

Not sure how to test this since it's not running on my NixOS machine and
I see no references to it in the directory otherwise.

See NixOS#10795
bryanhonof added a commit to bryanhonof/nix that referenced this issue Aug 1, 2024
@bryanhonof
Copy link
Member

What should we do about scripts like the following?

#! @ENV_PROG@ nix-shell
#! nix-shell -I nixpkgs=shell.nix --no-substitute
#! nix-shell --pure -i bash -p foo bar
echo "$(foo) $(bar) $@"

I can't disable SC2230, or at least, I don't think I can.

@Ericson2314
Copy link
Member Author

@bryanhonof we might be able to put some disables in the precommit configuration as a workaround?

@Ericson2314
Copy link
Member Author

Per the discussion in #10857, on issue with shellcheck's --diff is is koalaman/shellcheck#2996, quotes appears in the middle of "words" rather than next to spaces, is a funky style.

In #10857 (comment) I through together this hackjob sed (not fully correct, just a heuristic!) that can help a big fixing.

sed -i -E -e 's/( "[^"]+)"([a-z/=#_1-9-]+)( |\)|$)/\1\2"\3/' tests/functional/**.sh

bryanhonof added a commit to bryanhonof/nix that referenced this issue Aug 14, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 19, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 19, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 20, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 20, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 25, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 26, 2024
bryanhonof added a commit to bryanhonof/nix that referenced this issue Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor-experience Developer experience for Nix contributors good first issue Quick win for first-time contributors idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome.
Projects
None yet
Development

No branches or pull requests

4 participants