Shopify / erb-lint

Lint your ERB or HTML files
MIT License
592 stars 113 forks source link

Suggestion: add a "todo" task to generate a todo file (like rubocop-todo) #238

Open BigBigDoudou opened 2 years ago

BigBigDoudou commented 2 years ago

Hi, firstly thanks for this gem which is very nice to use.

I've implemented it on a project and add it to the CI. I want to prevent more bad syntax to be added in the views, but I need time to correct legacy errors. Therefore, I need to generate an excluding list, just like the rubocop-todo system.

Actually I've already done a task in my project, and it (almost) works fine. Therefore I was wondering about adding it directly in the gem. Would that be useful for anyone? Should I open a PR?

How does it works?

You start with a .erb-lint.default.yml file containing the config you want to apply. For example:

EnableDefaultLinters: true
linters:
  ErbSafety:
    enabled: true
    exclude:
      - "**/app/path/to/foo" # should always be excluded
  DeprecatedClasses:
    enabled: true

Then you run the task erb_lint:generate_todo. It copies .erb-lint.default.yml into a .erb-lint.yml file (and eventually erase the previous one). All linters run (juste like with the CLI command) and all errors are added in exclusions, so at the end the .erb-lint.yml file looks like:

EnableDefaultLinters: true
linters:
  ErbSafety:
    enabled: true
    exclude:
      - "**/app/path/to/foo" # from default config
      - "**/app/path/to/bar" # spotted by linter
  DeprecatedClasses:
    enabled: true
  SpaceAroundErbTag:
    enabled: true
    exclude:
      - "**/app/path/to/foo" # spotted by linter

There is a special system for the rubocop linter. All errors are added in a .erb-lint-rubocop-todo.yml file which is then inherited in the config, so the .erb-lint.yml file looks like:

EnableDefaultLinters: true
linters:
  Rubocop:
    enabled: true
    rubocop_config:
      inherit_from:
      - ".rubocop.yml"
      - ".erb-lint-rubocop-todo.yml"
  ErbSafety:
    enabled: true
    exclude:
      - "**/app/path/to/foo"
      - "**/app/path/to/bar"
  DeprecatedClasses:
    enabled: true
  SpaceAroundErbTag:
    enabled: true
    exclude:
      - "**/app/path/to/foo"

Ideally, I would add an option to the CLI command, for example erblint --auto-gen-config so it works just like rubocop-todo.

SampsonCrowley commented 1 year ago

Is there no option here?

b-loyola commented 8 months ago

Hey @BigBigDoudou this seems like it could be really useful, would you be willing to share what you had implemented in your project to auto generate the config?