haml-lint icon indicating copy to clipboard operation
haml-lint copied to clipboard

RuboCop HashSyntax rule breaks HAML

Open mockdeep opened this issue 3 years ago • 5 comments
trafficstars

I'm not sure if this issue is reporting the same thing, but the Ruby 3.1 hash shorthand does not appear to be valid syntax for HAML attributes, but haml-lint reports violations based on the RuboCop linter. We can add an exception for our views, but not sure if this should be handled on the haml-lint side of things. Is there a way not to run the linter on HAML attribute keys/values?

mockdeep avatar Sep 17 '22 18:09 mockdeep

If I'm understanding your question correctly, you can indeed use the technique in the issue referenced to use a custom RuboCop configuration that disables that specific RuboCop linter.

Very open to a pull request that makes this easier, e.g. some extension to the ignored_cops option that allows you to specify which files each cop is enabled for, but I would say at that point perhaps a HAML-Lint specific RuboCop config file (that inherits from your main .rubocop.yml and sets the appropriate overrides for HAML files) is likely the way to go.

sds avatar Sep 20 '22 18:09 sds

@sds thanks, we'll try that out. One thing I'm noticing is that if we pass a custom config the performance is significantly slower:

$ HAML_LINT_RUBOCOP_CONF=.rubocop-haml-lint.yml bundle exec rake haml_lint
585 files inspected, 0 lints detected
Done in 35.67s.

vs:

$ bundle exec rake haml_lint
585 files inspected, 0 lints detected
Done in 17.49s.

mockdeep avatar Sep 21 '22 23:09 mockdeep

I'm not sure why that would be the case. All we're doing when you specify HAML_LINT_RUBOCOP_CONF is passing the --config flag to RuboCop itself:

https://github.com/sds/haml-lint/blob/4f23cc37740ddb1f6bd1eabb4724546d77102a5b/lib/haml_lint/linter/rubocop.rb#L104

sds avatar Sep 22 '22 00:09 sds

I opened an issue on RuboCop about it. It looks like it's re-loading the configuration every time for some reason.

Way off topic now, but would it be possible to add a configuration to .haml-lint.yml for this? Environment variables are tricky because some projects may not have a custom RuboCop configuration.

mockdeep avatar Sep 22 '22 01:09 mockdeep

I was having the same problem and fixed it by adding this to rubocop config:

Style/HashSyntax:
  Enabled: true
  Include:
    - "[a-z]*/**/*"

Would have loved to be able to do Exclude: "*.haml.rb" (or any kind of meaningful Exclude, really) but for some reason that didn't work.

I know the latest version of haml_lint allows separate rubocop config file, but ALE doesn't seem to support that yet and this seems easier than maintaining a separate config just for this one rule.

jacobtbz avatar Oct 10 '22 18:10 jacobtbz

Closing question as answered. Happy to accept a PR if anyone is interested in making this easier.

sds avatar Jan 28 '23 20:01 sds