Skip to content

Handle no files being passed #817

Description

@iTrooz

The hook currently forces files to be passed to it (

- --files # this needs to be the last argument so that the paths are passed correctly.
), but this fail when the hook is configured to always run and there are no files staged. In this case, you get:

TypeError: files.flatMap is not a function
    at mergeFiles (file:///home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/cspell/dist/esm/application-Ck3Auwvx.js:3159:27)
    at new LintRequest (file:///home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/cspell/dist/esm/application-Ck3Auwvx.js:3141:16)
    at lint (file:///home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/cspell/dist/esm/application-Ck3Auwvx.js:3377:17)
    at Command.action (file:///home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/cspell/dist/esm/app.js:371:23)
    at Command.listener [as _actionHandler] (/home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/commander/lib/command.js:568:17)
    at /home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/commander/lib/command.js:1604:14
    at Command._chainOrCall (/home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/commander/lib/command.js:1488:12)
    at Command._parseCommand (/home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/commander/lib/command.js:1603:27)
    at /home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/commander/lib/command.js:1367:27
    at Command._chainOrCall (/home/itrooz/.cache/pre-commit/repovjx7nk1h/node_env-system/lib/node_modules/cspell-cli/node_modules/commander/lib/command.js:1488:12)

For anyone having the issue, I fixed it by overriding args:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/streetsidesoftware/cspell-cli
    rev: v10.0.1
    hooks:
      - id: cspell
        always_run: true
        pass_filenames: false
        args:
          - --no-must-find-files
          - --no-progress
          - --no-summary
          - --gitignore
          - .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions