Skip to content

Suggestion: herb-lint CLI should accept multiple file paths as arguments #803

Description

@maxjacobson

Hello again!

I'm interested in using herb-lint with lint-staged, but the herb-lint CLI interface makes this non-optimal.

Here's an example configuration I would like to use:

.lintstagedrc.json:

{
  "**/*.html.erb": "herb-lint"
}

With that configuration, when I author a commit, and I have staged changes to multiple files, lint-stage will run something like:

$ herb-lint app/views/foo.html.erb app/views/bar.html.erb app/views/baz.html.erb

lint-staged will pass all staged files that match the glob pattern as arguments to the CLI. This is useful, because I can stage just a few files and commit those (feeling confident that the linter has checked those files) even if I have other uncommitted changes that do have issues. Also, herb-lint should run faster when it only has to check changed files and not the entire repository.

herb-lint, however, does not accept multiple files as arguments like this, it only accepts one file at a time. When I do pass multiple files as arguments to herb-lint, the current behavior with 0.7.5 seems to be that it inspects the first file and silently ignores the rest.

Many other linter and formatter tools that I'm familiar with do accept multiple files as arguments, so they work very well with lint-staged. I'm thinking of tools like rubocop, eslint, prettier, erb lint. It would be great if herb-lint joined them.

Or, if you're not interested in changing the interface in this way, it might be a good idea for herb-lint to exit nonzero and print an error when the user passes multiple files as arguments, to give feedback that the command is not valid as written. That may be preferable to silently ignoring files.


There's a related benefit that would come with making this change. Right now, the CLI accepts a single file, a glob pattern, or a directory:

$ herb-lint --help
Usage: herb-lint [file|glob-pattern|directory] [options]

Arguments:
  file             Single file to lint
  glob-pattern     Files to lint (defaults to **/*.html.erb)
  directory        Directory to lint (automatically appends **/*.html.erb)

...

When I try to use a glob pattern, the behavior can be counterintuitive. Let's say I type this in my shell (I use fish, but I think the same behavior pertains in other shells):

$ herb-lint **/*.html.erb

Reading the above, I might (reasonably, if a bit naively1) expect this to run on multiple files. Instead, my shell performs shell expansion, and expands the glob to a list of many arguments, and herb-lint analyzes only the first file. It would be very nice if that Just Worked ™️ -- meaning, if herb-lint checked each of the files in the list.

Footnotes

  1. Of course, quoting the glob pattern works as designed:

    $ herb-lint "**/*.html.erb"
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeatureNew feature or requestlinter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions