Skip to content

Loading Custom Linters is broken #164

Closed
@brendo

Description

@brendo

It appears the loading custom linters from CLI doesn't work correctly. Following the README instructions is met with:

$ bundle exec erblint --enable-linters custom_linter --lint-all
custom_linter: not a valid linter name (rubocop, rubocop_text, parser_errors, space_around_erb_tag, space_in_html_tag, extra_newline, right_trim, erb_safety, trailing_whitespace, closing_erb_tag_indent, space_indentation, hard_coded_string, no_javascript_tag_helper, allowed_script_type, self_closing_tag, final_newline, deprecated_classes)

Taking a dive into this, it appears that options are loaded and validated before the custom linters are loaded.

https://github.com/Shopify/erb-lint/blob/90702271d5811cc9a677c69e2ae4f332ca53d248/lib/erb_lint/cli.rb#L35-L37

Here the args are validated against known_linter_names:

https://github.com/Shopify/erb-lint/blob/90702271d5811cc9a677c69e2ae4f332ca53d248/lib/erb_lint/cli.rb#L269-L277

known_linter_names expects that all the linters have already been loaded:

https://github.com/Shopify/erb-lint/blob/90702271d5811cc9a677c69e2ae4f332ca53d248/lib/erb_lint/cli.rb#L213-L217

But in the LinterRegistry we can see that custom linters are only explicitly loaded when load_custom_linters is called:

https://github.com/Shopify/erb-lint/blob/90702271d5811cc9a677c69e2ae4f332ca53d248/lib/erb_lint/linter_registry.rb#L20-L23

load_custom_linters is only called when the Runner is initialised, but that happens some 30 lines after the options have been validated:

https://github.com/Shopify/erb-lint/blob/90702271d5811cc9a677c69e2ae4f332ca53d248/lib/erb_lint/cli.rb#L58

Changing the known_linter_names to be the following appears to fix the issue:

def known_linter_names
  @known_linter_names ||= begin
    ERBLint::LinterRegistry.load_custom_linters
    ERBLint::LinterRegistry.linters
      .map(&:simple_name)
      .map(&:underscore)
  end
end

(Note that Custom Linters still don't work at this point as the README is out of date #123)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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