-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: enforce a consistent attributes wrapper style #89
Comments
Hmmm, I'm close... how can I set a different config option in my spec? I'm trying to test the different |
I think I got it! Within a let(:config) do
SlimLint::ConfigurationLoader.load_hash({
'linters' => {
'AttributesWrapper' => {
'enabled' => true,
'style' => 'round'
}
}
}).for_linter(described_class)
end |
@sds Is there any way, when matching with The tree for these two lines is identical as far as the parser is concerned: div foo="bar"
div(foo="bar") So inside an My 90% solution uses
And I haven't even got into what happens inside an embedded engine block like So ideally I'd only bother inspecting lines that actually contained an HTML element with attributes and go from there. But I can't see a way to get the whole line's content when matching with |
@cannikin it seems (from looking at the source code) that this is done with on [...] do |sexp|
line = document.source_lines[sexp.line() - 1] |
I solved my problems above by using an But I'm stuck on one last use case: attributes that span more than one line with line breaks. I can't figure out the best matcher to use to get back a sexp that can somehow tell me how many lines a statement is spanning. Any advice would be appreciated! |
I'd like to do exactly this. @cannikin did you ever get your linter working? Would you be willing to share what you have so far? |
@chevinbrown Mine is here, I don't think I ever got it to handle attribute spread over multiple lines though :( I've been in React-land for the past 6 months so I haven't used it in a while! https://github.com/cannikin/slim-lint/tree/attributes-wrapper |
@cannikin thanks! |
@cannikin FWIW, my solution was nearly identical to yours, but I just checked for either opening or closing style. If they don't match, another cop/parser will pick that up. |
@chevinbrown @cannikin Any progress on finishing this out? I'd love to start enforcing a consistent attributes style in my Slim code. |
@dkniffin I didn't get much further than this: https://github.com/cannikin/slim-lint/blob/attributes-wrapper/lib/slim_lint/linter/attributes_wrapper.rb |
Sorry, I haven't used this at all since my last post, I haven't been able to write slim in years! |
https://www.rubydoc.info/gems/slim/frames#Attributes_wrapper
Maybe with a config option like:
If I can figure out how the slim parser identifies these perhaps I can submit a PR soon. :)
The text was updated successfully, but these errors were encountered: