Closed LeEnno closed 8 months ago
How does haml look up the configuration?
Don't know, but it seems like it delegates the heavy lifting for the rubocop gem.
Sorry, misunderstood your question. I thought since itβs an issue with rubocop you were interested in where that is coming from.
So yeah, haml-lint expects a haml-lint.yml (which works fine) but also integrates with rubocop (which does not work for me).
It loads the configuration based on the directory haml-lint is being run from, ascending until a configuration file is found.
This is just me guessing, again, but maybe this bit from the linters documentation helps:
You can also explicitly set which RuboCop configuration to use via the HAML_LINT_RUBOCOP_CONF environment variable. This is intended to be used by external tools which run the linter on files in temporary directories separate from the directory where the HAML template originally resided (and thus where the normal .rubocop.yml would be picked up).
Maybe haml-lint does not executed in the correct context, so it doesn't find path/to/projetc/.rubocop.yml.
If there's anything I can do to help investigating this let me know.
π Yeah that's it probably. See also https://github.com/dense-analysis/ale/blob/2b785688ead505dcbc1007374d3dca9914aa247a/ale_linters/haml/hamllint.vim#L10-L33
So, it looks up a .haml-lint.yml
based on the working dir (as per the doc cited), but the rubocop.yml
must be set explicitly because it is looked up by looking at the filepath we pass in which is a temp file. π€· funky
The work-around or test is to set it in the SL settings.
"linters":
"haml-lint":
"env": {
"HAML_LINT_RUBOCOP_CONF": "${folder}/.rubocop.yml"
}
If that works a PR can be made to automate this.
Unfortunately this does not work. Not with ${folder}/.rubocop.yml
and also not with the absolute path :(
Where you're standing here? Do you feel comfortable and can recreate what SublimeLinter does on the command line. Basically given the info when you set debug to true. T.i. can you make it fail on the command line?
I'm not Ruby developer so I would need a simple repo with basic instructions to fully dig into it. For example I can't write haml and a valid ruboconfig. π€«
Ok, I try my best to give a reproducible test case.
First You need to have ruby and also rubygems installed. Afterwards you need to run gem install haml_lint
to install haml-lint
executable.
As for the actual source files you need kaste.haml
und rubocop.yml
.
Contents of kaste.haml
:
- some_var = 123456
%p
= some_var
Contents of rubocop.yml
:
AllCops:
NewCops: enable
Style/NumericLiterals:
Enabled: false
If you run haml-lint kaste.haml
you should get 1 file inspected, 0 lints detected as output
. No lint offenses.
To recreate what the plugin does, the haml-file needs to be copied elsewhere. So if you run ...
cp kaste.haml /some/where/else/kaste.haml
haml-lint /some/where/else/kaste.haml
... you should get a lint offense along the lines of:
/some/where/else/kaste.haml:1 [W] RuboCop: Style/NumericLiterals: Use underscores(_) as thousands separator and separate every 3 digits with them.
Possible fixes:
HAML_LINT_RUBOCOP_CONF
, i.e. HAML_LINT_RUBOCOP_CONF="/path/to/project/.rubocop.yml" haml-lint /some/where/else/kaste.haml
I did not consider the environment dance with rvm
because it's not necessary in this case.
Hope this helps. If I can assist any further, let me know.
Okay, setting env
works for me.
"hamllint": {
"env": {
"HAML_LINT_RUBOCOP_CONF": "${folder}\\.rubocop.yml"
},
},
Note that hamllint
, in my previous post I spelled it haml-lint
.
A bit ridiculous because that exact config was in the last version of this plugin. Removal 5bfe0fb
(#10)
That totally explains why it used to work for our team. Fun fact: now we have
haml_lint
,haml-lint
andhamllint
π±What is the best way to go from here? Documenting this (probably not too rare) use case? Will gladly create a PR. Reverting parts of the mentioned commit? Or do you plan to give this plugin a proper rewrite to fix all those other weird issues (tempfile, executable
and use_bundle_exec
settings not being implemented)?
We should set the env variable if possible. But if it throws if there is no such file we shouldn't take the same kinda static approach t.i. just assuming it is in the root folder.
Executable can be fixed by removing the ruby -S from cmd which is really a mistake.
I consider renaming this plugin to haml-lint although that's breaking (everyone has to change its settings) but hamllint is so confusing, and the double l in the middle is ugly.
The other stuff must be implemented in SL core.
Isn't this solved now that we use stdin? We don't use the indirection ruby -S
anymore so that seems solved too.
I don't need the manual config anymore, indeed. Thx π
I have an example haml file:
My
rubocop.yml
says:When
cd
ing to/path/to/project
and runninghaml-lint test.haml
I get1 file inspected, 0 lints detected
. Works.Sublime Console tells me the following:
So haml-lint in Sublime ignores my settings in
rubocop.yml
.SublimeLinter.sublime-settings
does not have any settings regarding haml-lint.I'm using
Unfortunately I can't say for how long this has been the case.
Any ideas? Happy to help debugging.