reviewdog / action-shellcheck

Run shellcheck with reviewdog
https://github.com/marketplace?type=actions&query=reviewdog
MIT License
101 stars 20 forks source link

pattern / exclude is too granular #2

Closed lsgunth closed 2 years ago

lsgunth commented 4 years ago

Many shell scripts have no '.sh' suffix and but if we omit the pattern, this action checks all files in the repo except those excluded. This isn't terribly useful.

It would be nice if the files could be filtered by their shebang somehow.

lsgunth commented 4 years ago

Something like this might work in place of the find command:

grep -rIzl '^#![[:blank:]]*/bin/.*sh' . --exclude-dir=.git

Maybe only if the pattern is '*'?

fbartels commented 4 years ago

I am using the following for quite a while already (I think it was suggested in the shellcheck readme):

        grep -rIl '^#![[:blank:]]*/bin/\(bash\|sh\|zsh\)' \
        --exclude-dir=.git --exclude=*.sw? \
        | xargs shellcheck -x

I would be looking into integrating this into the current entrypoint script. the question is if @haya14busa would be willing to part with the find command.

haya14busa commented 4 years ago

Sounds good. We can add a flag for this.

ashleyvega commented 4 years ago

fwiw, here's the scriptlet I've been using to get a list of shell scripts.

(
  # find sh files
  find . \
    -name .git -prune -o \
    -name vendor -prune -o \
    -name '*.sh' -print
  # find executable files beginning with a "!#"
  find . \
    -name .git -prune -o \
    -name vendor -prune -o \
    "(" \
      -type f -and \
      -perm -100 \
    ")" -print0 \
  | xargs -0r grep -lE '^#!/bin/(ba)?sh'
) | sort -u | xargs shellcheck --shellcheck-options...

As you see, it finds:

(Note: I realise the grep doesn't spot #!/usr/bin/env bash.)

grische commented 2 years ago

@lsgunth you can use the new feature by setting check_all_files_with_shebangs to true.

name: reviewdog
on: [pull_request]
jobs:
  shellcheck:
    name: runner / shellcheck
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: shellcheck
        uses: reviewdog/action-shellcheck@v1
        with:
          check_all_files_with_shebangs: "true"