diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e942e3d..a6947af 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 @@ -43,8 +43,39 @@ jobs: name: Test run action runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: ./ with: path: test/testdata only_warn: 1 + + codespell: + name: Check for spelling errors + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + check_filenames: true + check_hidden: true + # When using this Action in other repos, the --skip option below can be removed + skip: ./.git,./codespell-problem-matcher/test,./test + + diagnose_bats: + name: Diagnose bats + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v2 + - run: pip3 --quiet --quiet install git+https://github.com/codespell-project/codespell.git + - run: | + export INPUT_CHECK_FILENAMES="" + export INPUT_CHECK_HIDDEN="" + export INPUT_EXCLUDE_FILE="" + export INPUT_SKIP="" + export INPUT_IGNORE_WORDS_FILE="./test/ignore-words-file.txt" + export INPUT_IGNORE_WORDS_LIST="" + export INPUT_PATH="./test/testdata" + export INPUT_ONLY_WARN="" + ./entrypoint.sh diff --git a/README.md b/README.md index f0de7e8..86ec47a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,55 @@ Any warnings or errors will be annotated in the Pull Request. ## Usage ``` -uses: peternewman/actions-codespell@master +uses: codespell-project/actions-codespell@master +``` + +### Parameter: check_filenames + +If set, check file names for spelling mistakes as well. + +This parameter is optional; by default `codespell` will only check the file contents. + +``` +uses: codespell-project/actions-codespell@master +with: + check_filenames: true +``` + +### Parameter: check_hidden + +If set, check hidden files (those starting with ".") for spelling mistakes as well. + +This parameter is optional; by default `codespell` will not check hidden files. + +``` +uses: codespell-project/actions-codespell@master +with: + check_hidden: true +``` + +### Parameter: exclude_file + +File with lines that should not be checked for spelling mistakes. + +This parameter is optional; by default `codespell` will check all lines. + +``` +uses: codespell-project/actions-codespell@master +with: + exclude_file: src/foo +``` + +### Parameter: skip + +Comma-separated list of files to skip (it accepts globs as well). + +This parameter is optional; by default `codespell` won't skip any files. + +``` +uses: codespell-project/actions-codespell@master +with: + skip: foo,bar ``` ### Parameter: path @@ -17,7 +65,7 @@ This can be useful if your project has code you don't want to spell check for so This parameter is optional; by default `codespell` will run on your whole repository. ``` -uses: peternewman/actions-codespell@master +uses: codespell-project/actions-codespell@master with: path: src ``` @@ -31,7 +79,7 @@ All errors and warnings are annotated in Pull Requests, but it will act like eve This parameter is optional; setting this to any value will enable it. ``` -uses: peternewman/actions-codespell@master +uses: codespell-project/actions-codespell@master with: only_warn: 1 ``` diff --git a/action.yml b/action.yml index e65adf0..e900b00 100644 --- a/action.yml +++ b/action.yml @@ -4,27 +4,39 @@ description: 'Codespell with annotations for Pull Request' inputs: check_filenames: description: 'If set, check file names as well' - requred: false + required: false default: '' check_hidden: description: 'If set, check hidden files (those starting with ".") as well' - requred: false + required: false default: '' exclude_file: - description: 'FILE with lines that should not be changed' - requred: false + description: 'File with lines that should not be checked for spelling mistakes' + required: false default: '' skip: description: 'Comma-separated list of files to skip (it accepts globs as well)' - requred: false + required: false + default: './.git' + builtin: + description: 'Comma-separated list of builtin dictionaries to include' + required: false + default: '' + ignore_words_file: + description: 'File with a list of words to be ignored' + required: false + default: '' + ignore_words_list: + description: 'Comma-separated list of words to be ignored' + required: false default: '' path: description: 'Path to run codespell in' - requred: false + required: false default: '' only_warn: description: 'If set, only warn, never error' - requred: false + required: false default: '' runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index 53182e3..1afc65c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -28,6 +28,18 @@ echo "Skipping '${INPUT_SKIP}'" if [ "x${INPUT_SKIP}" != "x" ]; then command_args="${command_args} --skip ${INPUT_SKIP}" fi +echo "Builtin dictionaries '${INPUT_BUILTIN}'" +if [ "x${INPUT_BUILTIN}" != "x" ]; then + command_args="${command_args} --builtin ${INPUT_BUILTIN}" +fi +echo "Ignore words file '${INPUT_IGNORE_WORDS_FILE}'" +if [ "x${INPUT_IGNORE_WORDS_FILE}" != "x" ]; then + command_args="${command_args} --ignore-words ${INPUT_IGNORE_WORDS_FILE}" +fi +echo "Ignore words list '${INPUT_IGNORE_WORDS_LIST}'" +if [ "x${INPUT_IGNORE_WORDS_LIST}" != "x" ]; then + command_args="${command_args} --ignore-words-list ${INPUT_IGNORE_WORDS_LIST}" +fi echo "Resulting CLI options ${command_args}" exec 5>&1 res=`{ { codespell ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; } 4>&1` diff --git a/test/ignore-words-file.txt b/test/ignore-words-file.txt new file mode 100644 index 0000000..3eda6e1 --- /dev/null +++ b/test/ignore-words-file.txt @@ -0,0 +1 @@ +abandonned diff --git a/test/test.bats b/test/test.bats index 4abad9c..3023406 100644 --- a/test/test.bats +++ b/test/test.bats @@ -7,6 +7,8 @@ ROOT_MISSPELLING_COUNT=5 FILENAME_MISSPELLING_COUNT=1 HIDDEN_MISSPELLING_COUNT=1 EXCLUDED_MISSPELLING_COUNT=1 +BUILTIN_NAMES_MISSPELLING_COUNT=1 +IGNORE_WORDS_MISSPELLING_COUNT=6 SUBFOLDER_MISSPELLING_COUNT=1 # From all files called example.txt EXAMPLE_MISSPELLING_COUNT=5 @@ -20,6 +22,9 @@ function setup() { export INPUT_CHECK_HIDDEN="" export INPUT_EXCLUDE_FILE="" export INPUT_SKIP="" + export INPUT_BUILTIN="" + export INPUT_IGNORE_WORDS_FILE="" + export INPUT_IGNORE_WORDS_LIST="" export INPUT_PATH="./test/testdata" export INPUT_ONLY_WARN="" } @@ -75,6 +80,27 @@ function setup() { [ $status -eq $expectedExitStatus ] } +@test "Use an additional builtin dictionary" { + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + BUILTIN_NAMES_MISSPELLING_COUNT)) + INPUT_BUILTIN="clear,rare,names" + run "./entrypoint.sh" + [ $status -eq $expectedExitStatus ] +} + +@test "Use an ignore words file" { + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT)) + INPUT_IGNORE_WORDS_FILE="./test/ignore-words-file.txt" + run "./entrypoint.sh" + [ $status -eq $expectedExitStatus ] +} + +@test "Use an ignore words list" { + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT)) + INPUT_IGNORE_WORDS_LIST="abandonned" + run "./entrypoint.sh" + [ $status -eq $expectedExitStatus ] +} + @test "Custom path" { expectedExitStatus=$((SUBFOLDER_MISSPELLING_COUNT)) INPUT_PATH="./test/testdata/subfolder" diff --git a/test/testdata/example:2.txt b/test/testdata/example:2.txt index 50a0985..d5f415f 100644 --- a/test/testdata/example:2.txt +++ b/test/testdata/example:2.txt @@ -1 +1 @@ -It's ackward when you make a spelling mistake. +It's ackward when you make a spelling mistake. My name is Tim.