Data-Liberation-Front / csvlint.rb

The gem behind http://csvlint.io
MIT License
286 stars 87 forks source link

Pre-commit passes a list of files to lint but csvlint can only accept one #288

Open jamesmelville-gds opened 9 months ago

jamesmelville-gds commented 9 months ago

Expected Behaviour

When running csvlint in a pre-commit hook pre-commit will pass a list of files to it as seperate args. csvlint should take the list and generate a response for all. cfn-lint has an example of this support https://github.com/aws-cloudformation/cfn-lint#basic-usage

Current Behaviour (for problems)

csvlint errors:

ERROR: "csvlint validate" was called with arguments ["file1.csv", "file2.csv"] Usage: "csvlint myfile.csv OR csvlint http://example.com/myfile.csv"

Steps to Reproduce (for problems)

Use a pre-commit config like:

---
default_language_version:
  ruby: 2.7.8
repos:
- repo: https://github.com/Data-Liberation-Front/csvlint.rb
  rev: v1.3.0
  hooks:
    - id: csvlint
      name: lint files/*.csv
      files: 'file.*\.csv'
      pass_filenames: true

against files like:

file1.csv
file2.csv
file3.csv

Current workaround is to use xargs to run csvlint against each file:

    - id: csvlint
      name: lint files/*.csv
      files: 'file.*\.csv'
      entry: bash -xc 'echo "$@" | xargs -n 1 -I filename csvlint filename --schema=schema/csv' --
huwd commented 6 months ago

Had a look at the usage, we sure this is expected behavior we'd want here @jamesmelville-gds?

Seems like the expected usage here is one linting pass per CSV. I imagine it'd be easy to get CSV lint to parse an array of inputs here and go through them in batch...

but then wondering if that breaks the model, are linting responses now to be grouped around an offending file, or clumped into "you've got these problems in that lump". 🤔

Not sure what @Floppy thinks, but perhaps us using bash-fu to enumerate all our CSVs and lint each separately is OK?