Shopify / erb-lint

Lint your ERB or HTML files
MIT License
593 stars 114 forks source link

Unrelated error is thrown in the event of a syntax error #304

Closed dmabuada closed 1 year ago

dmabuada commented 1 year ago

Excerpt of an erb-lint yml file:

glob: "**/*{.html,*}[!.atom,!.text,!.js,!.svg].erb"
linters:
  FinalNewline:
    enabled: false
  SpaceAroundErbTag:
    enabled: false
  RightTrim:
    enabled: false
  AllowedScriptType:
    enabled: true
    allowed_types:
      - 'application/ld+json'
      - 'application/json'
      - 'text/javascript'
      - 'text/html'....

Now if I remove one of the hyphens in allowed_types:

glob: "**/*{.html,*}[!.atom,!.text,!.js,!.svg].erb"
linters:
  FinalNewline:
    enabled: false
  SpaceAroundErbTag:
    enabled: false
  RightTrim:
    enabled: false
  AllowedScriptType:
    enabled: true
    allowed_types:
      'application/ld+json'
      - 'application/json'
      - 'text/javascript'
      - 'text/html'....

And then run autocorrect on a file, it raises a NoMethodError:

@dmabuada ➜ /workspaces/github $ bin/erblint --enable-linters rubocop --autocorrect app/views/index.erb

NoMethodError: undefined method `merge!' for nil:NilClass
/workspaces/github/vendor/gems/3.2.0/ruby/3.2.0/gems/erb_lint-0.3.0/lib/erb_lint/cli.rb:224:in `ensure in load_config'
/workspaces/github/vendor/gems/3.2.0/ruby/3.2.0/gems/erb_lint-0.3.0/lib/erb_lint/cli.rb:224:in `load_config'
/workspaces/github/vendor/gems/3.2.0/ruby/3.2.0/gems/erb_lint-0.3.0/lib/erb_lint/cli.rb:40:in `run'
/workspaces/github/vendor/gems/3.2.0/ruby/3.2.0/gems/erb_lint-0.3.0/exe/erblint:9:in `<main>'
/workspaces/github/vendor/gems/3.2.0/ruby/3.2.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
/workspaces/github/vendor/gems/3.2.0/ruby/3.2.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
bin/erblint:8:in `<main>'

It should probably be raising a SyntaxError instead.