Skip to content

Detect instance variables in all templates? #240

Open
@emilong

Description

@emilong

PartialInstanceVariable is great for partials, but I'd like to forbid instance variables in all templates.

The PartialInstanceVariable linter implementation has this guard to restrict it to partials:

https://github.com/Shopify/erb-lint/blob/c30fa2783d5a028b9c67795ab20f4d6b19280b9e/lib/erb_lint/linters/partial_instance_variable.rb#L11

So a linter simply without this restriction would work for my case.

The only thing between me and a PR is how to structure the configuration. Some options I came up with:

  1. Create a new InstanceVariable linter that works for all templates and document the fact that if you enable this and PartialInstanceVariable, you may get double warnings
  2. Create a new NonPartialInstanceVariable linter that only works on non-partials to avoid double linting if someone has both enabled
  3. Add configuration to PartialInstanceVariable of the sort all_templates: true to make it work for all templates
  4. Deprecate PartialInstanceVariable and create a InstanceVariable linter with a partials_only: true configuration

I'm inclined toward option 1 for simplicity, but I'm very open to whatever so I can add this linter 😄

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