Personal web site, powered by Jekyll.
sds / slim-lint Goto Github PK
View Code? Open in Web Editor NEWConfigurable tool for analyzing Slim templates
License: Other
Configurable tool for analyzing Slim templates
License: Other
Personal web site, powered by Jekyll.
I started getting this error in my application and I am concerned it is related to ruby 2.3.0
-->> slim-lint /Users/chrishough/Studio/Code-Consulting/bilingualhire/app/**/*.slim --config=.slimlint.yml
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.x-compliant syntax, but you are running 2.3.0.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Hi,
This commit: rubocop/rubocop@54166bf
breaks default configuration for space related cops
Example of failure: https://travis-ci.org/diowa/icare/builds/235950888#L625
I'm going to submit a PR
It would be nice to show a message after executing slim-lint to know what was inspected, as currently if there are no offences nothing is shown and it is easy to think that something went wrong.
A message similar to the once used by Rubocop would work here as well:
80 files inspected, no offenses detected
rake -T 1 ↵ ✹ ✭ [12:06:31]
rake aborted!
NameError: uninitialized constant SlimLint::APP_NAME
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/slim_lint-0.5.0/lib/slim_lint/rake_task.rb:115:in `default_description'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/slim_lint-0.5.0/lib/slim_lint/rake_task.rb:70:in `define'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/slim_lint-0.5.0/lib/slim_lint/rake_task.rb:63:in `initialize'
/Users/justin/clients/madrone/investor-dashboard/lib/tasks/linters.rake:21:in `new'
/Users/justin/clients/madrone/investor-dashboard/lib/tasks/linters.rake:21:in `<top (required)>'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/engine.rb:658:in `block in run_tasks_blocks'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/engine.rb:658:in `each'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/engine.rb:658:in `run_tasks_blocks'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/application.rb:438:in `run_tasks_blocks'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/engine.rb:453:in `load_tasks'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/railtie.rb:194:in `public_send'
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/railties-4.2.0/lib/rails/railtie.rb:194:in `method_missing'
/Users/justin/clients/madrone/investor-dashboard/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
But I see the constant defined. Seems like some order that the modules are loaded or not loaded is causing this issue.
Any ideas? @sds?
I noticed inconsistency when my colleagues, who are used to Haml, transision to Slim:
Notice the space before the =
sign:
/ Good
div = 'This is what the official slim documentation uses consistently'
/ Bad
div= 'This works, but it should probably not be encouraged.'
/ Not affected
a href="This is still fine though, because it is an attribute"
I also noticed that my syntax highlighter (TextMate) doesn't properly recognize the non-spacing version:
Would this cop be something worth implementing?
(I tried twice to bugfix some rubocop internals and failed miserably somewhere in the AST 😂, so I cannot promise a PR, but I will try if you think this cop makes sense :)
Getting this error after gem updates.
warning: found = in conditional, should be ==
from this structure
- if @presenter.form_adv
- if @presenter.peer_group
#employee-composition.row
- if @presenter.form_adv.has_employees?
.col-sm-12.col-md-6.col-print-12
#employee_composition_vs_peers.chart-container.chart-resizeable data-max-height=700
.col-sm-12.col-md-6.col-print-12
#employee_vs_assets.chart-container.chart-resizeable data-max-height=700
I'd like a linter that checks for verbatim text that has leading whitespace. I had a go at creating this linter and came up with the following:
module SlimLint
# Searches for verbatim text with leading whitespace
class Linter::LeadingWhitespace < Linter
include LinterRegistry
on [:slim, :text, :verbatim] do |sexp|
_, _, _, content = sexp
next unless content[/\A\s+/] # This line is obviously wrong
report_lint(sexp, 'Line contains leading whitespace')
end
end
end
With this simple test:
context 'when line contains leading spaces' do
let(:slim) { "' Text with unecessary whitespace" }
it { should report_lint line: 1 }
end
content
ends up being:
[<#Atom :multi>, [<#Atom :slim>, <#Atom :interpolate>, <#Atom " Text with unecessary whitespace">]]
I'm not sure what the best way to match on this and extract the text so that it can be checked for leading whitespace.
Are you able to point me in the right direction?
Not sure it could be implemented but it will be great to have a cop to catch things like this
= post.author.posts.count
Any thought?
This gem has a runtime dependency on the gem Astrolabe which is used in the file ruby_parser.rb#L1.
Previously this dependency was brought in through Rubocop, but as of Rubocop-0.36.0 this is no longer the case. Adding it as a runtime dependency should fix this issue (or lock the version of Rubocop to 0.35.1).
The error caused by this missing dependency is LoadError: cannot load such file -- astrolabe/builder
It's weird why ControlStatementSpacing
linter keeps raising Please add a space before and after the =
even I didn't see any isse.
div layout="column" layout-gt-sm=="row" ng-show="search_meta.total_pages | valPresent"
.app-bg-color.md-primary.search-result flex=true
| Search Results ({{ search_meta.total_count }} {{ search_meta.total_count > 1 ? 'documents' : 'document' }})
.pagination.app-pagination[flex=true
layout="row"
layout-align="center center"
layout-align-gt-sm="end center"
ng-show="search_meta.total_pages > 1"]
md-button.app-color-hover.app-primary[ng-href="{{ searchURL({page: 1}) }}"
ng-disabled="search_meta.current_page == 1"
aria-label=online_t(:first_page, scope: %i(document actions search))]
md-icon.md-dark first_page
md-tooltip md-direction="bottom" = online_t(:first_page, scope: %i(document actions search))
md-button.app-color-hover.app-primary[ng-href="{{ searchURL({page: search_meta.prev_page}) }}"
ng-disabled="search_meta.prev_page == null"
aria-label=online_t(:prev_page, scope: %i(document actions search))]
md-icon.md-dark keyboard_arrow_left
md-button.app-primary[ng-repeat="page in searchNavPages(search_meta, search_meta.current_page)"
ng-href="{{ searchURL({page: page}) }}"
ng-class="{'app-bg-color': search_meta.current_page == page, \
'app-color-hover': search_meta.current_page != page}"
ng-bind="page"]
md-button.app-color-hover.app-primary[ng-href="{{ searchURL({page: search_meta.next_page}) }}"
ng-disabled="search_meta.next_page == null"
aria-label=online_t(:next_page, scope: %i(document actions search))]
md-icon.md-dark keyboard_arrow_right
md-tooltip md-direction="bottom" = online_t(:next_page, scope: %i(document actions search))
md-button.app-color-hover.app-primary[ng-href="{{ searchURL({page: search_meta.total_pages}) }}"
ng-disabled="search_meta.current_page == search_meta.total_pages"
aria-label=online_t(:last_page, scope: %i(document actions search))]
md-icon.md-dark last_page
md-tooltip md-direction="bottom" = online_t(:last_page, scope: %i(document actions search))
WARNINGS:
app/views/online/templates/_search_pagination.html.slim:26 [W] ControlStatementSpacing: Please add a space before and after the `=`
app/views/online/templates/_search_pagination.html.slim:31 [W] ControlStatementSpacing: Please add a space before and after the `=`
Dependencies:
slim_lint (0.17.0)
rake (>= 10, < 13)
rubocop (>= 0.50.0)
slim (>= 3.0, < 5.0)
sysexits (~> 1.1)
I've take the liberty of creating an atom linter plugin for your excellent tool, as I noticed one did not yet exist. The repo is https://github.com/mattaschmann/linter-slim-lint if you think it's worth adding to the applicable section in your readme.
I created a new rails app using https://github.com/RailsApps/rails-composer
I added overcommit and slim-lint.
I'm getting an error message "(Using Ruby 2.3 parser; configure using TargetRubyVersion
parameter, under AllCops
)" with TargetRubyVersion
already specified in .rubocop.rb.
This only occurs when I run slim-lint against a list of all slim files.
$ slim-lint **/*.slim
(Using Ruby 2.3 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
It does not occur when run against a specific directory:
$ slim-lint app/views/layouts/*.slim
Given a slim template with the following contents:
ruby:
->() { derp}
Running bin/rake slim_lint
fails:
./app/views/courses/dj/_dj.slim:2 [W] RuboCop: Space missing inside }.
rake aborted!
slim-lint failed with exit code 65
Hi!
Here is my config:
linters:
LineLength:
max: 100
exclude:
- app/views/site/abouts/terms_and_conditions.html.slim
It ignores the file in 0.15.0 but not in 0.15.1. Also all paths for warnings are shown expanded instead of relative to project root. Seems like ef9a07f caused this issue.
Loving this. Would be great we could disable linters via source to have nice granular control as in scss-lint.
e.g. // slim-lint:disable LineLength
New slim lint does not see final new line for some reasons.
It shows messages "Use 2 (not 0) spaces for indentation." that remain unchanged with any indentation changes.
Example:
.row
.columns
h2 = title("Forgot your password?")
.row
.medium-5.columns
= simple_form_for resource,
as: resource_name,
url: password_path(resource_name),
html: { method: :post } do |f|
.form-inputs
= f.input :email, required: true
.form-actions
= f.button :submit, "Send me reset password instructions"
.medium-5.medium-offset-1.columns.end
= render "admins/shared/links"
No matter how I move params from line 8, it says "Use one level of indentation for parameters following the first line of a multi-line method call."
Now that ControlStatementSpacing
is a default linter, and following #85, I have several warnings raising about usage of output operator with leading/trailing when I use it inline with a tag
p
' This
b => product.name # Lint warning
' product is astonishing
I could jump a line to get rid of the linter warning, but I like keep my slim file with few lines possible
p
' This
b
=> product.name # No Lint warning
' product is astonishing
Actually I wonder if it's a officially supported use-case as I cannot find any example of using slim syntax this way in the official documentation
https://www.rubydoc.info/gems/slim/frames#Output__
Output with trailing white space =>. Same as the single equals sign (=), except that it adds a trailing white space.
Output with leading white space =<. Same as the single equals sign (=), except that it adds a leading white space.
I don't know if slim-lint is about to consider having linters options like we can find in Rubocop for instance. It might be a good case here to specify wether "inline" output usage should be tolerated or enforced to a newline (without having any clue on about to propose a PR for that yet, sorry).
Is there a way for me to run slim-lint and have all hash-rocket syntax occurances be automatically turned into Ruby 1.9 hash syntax? I expect something like: rubocop --only HashSyntax --auto-correct
. Thank you 😄
I've been trying to integrate slim-lint with rubocop and overcommit this morning, and have yet to be able to have it successfully run either rubocop is run, or when a commit is made. The instructions given in README are somewhat sparse. What I've tried so far:
.overcommit.yml
:SlimLint:
enabled: true
on_warn: fail # Treat all warnings as failures
.rubocop.yml
:SlimLint:
enabled: true
require: slim_lint
to rubocop.yml
What is the current mechanism for integrating slim-lint with rubocop?
If I have this code for example:
- if condition?
a[target='_blank' href='#'] = name
- else
= name
Slim would now report this error two times:
[W] RuboCop: Style/IdenticalConditionalBranches: Move `name` out of the conditional.
Here is the logic behind it' s report.
But unfortunately in this case it is not possible to move name
out of the condition, because either the name of the link would be equal to name
or something on above the condition (for example a p
tag).
I am aware that I could've used the rails link_to
method and the problem wouldn't have appeared. The usage of the a
tag here is just to demonstrate my point.
I expect slim to recognise when the element used, in both the if
and the else
block, is called in void context or assigned to something.
Hi,
I'm using slim-lint and rubocop.
This code:
= select_tag :c,
data: {\
a: 'b'}
gives me that warning:
index.html.slim:3 [W] RuboCop: Style/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
To be honest I'm not sure what could wrong with my code. Any ideas?
In my template, I want to use the relatively new safe navigation operator like this:
= @some_object&.name
Since the object might be nil, so I use the safe navigation operator to prevent errors. However, rubocop errors on that line with Rubocop: Lint/Syntax: unexpected token error
, making Atom warn me on normally valid syntax.
I'm not sure if it is because of Rubocop or slim_lint, but normally Rubocop doesn't crash on the &
, so that's why I'm listing it here
app/views/layouts/application/_ancient_browser_check.html.slim:2 [W] LineLength: Line is too long. [260/120]
Here's the file
/ noinspection LineLength
/![if lt IE 7] <p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p
What do you recommend?
rubocop 0.34.1
bundle | ggrep -E '(rubo|slim_lint)'
Using rubocop 0.34.1
Using slim_lint 0.6.1
bundle exec slim-lint app/views
echo $? #=> 0
rubocop 0.35.1
bundle | ggrep -E '(rubo|slim_lint)'
Using rubocop 0.35.1
Using slim_lint 0.6.1
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-t4fjq4.
To see the complete backtrace run rubocop -d.
1 error occurred:
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-t4fjq4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.35.1 (using Parser 2.2.3.0, running on ruby 2.2.3 x86_64-darwin14)
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-1jekafi.
To see the complete backtrace run rubocop -d.
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-1jekafi.
To see the complete backtrace run rubocop -d.
2 errors occurred:
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-1jekafi.
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-1jekafi.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.35.1 (using Parser 2.2.3.0, running on ruby 2.2.3 x86_64-darwin14)
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-1hzi2bk.
To see the complete backtrace run rubocop -d.
1 error occurred:
An error occurred while Style/AlignParameters cop was inspecting /Users/jared/redacted/app/views/redacted.slim.slim_lint.tmp20160106-48574-1hzi2bk.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.35.1 (using Parser 2.2.3.0, running on ruby 2.2.3 x86_64-darwin14)
echo $? #=> 0
It says "To see the complete backtrace run rubocop -d." but if I did that it would just run rubocop, not slim-lint. Please let me know how I can help provide more information.
Following line in a slim template
select{id= 'select_this', name= 'sure_name', data= {placeholder: t('view.some_data')}}
would cause the following error on render
ActionView::Template::Error (Multiple , attributes specified):
However, linter is quiet about that.
Is slim-lint capable of catching such errors?
Hi,
I've noticed that slim-lint is creating a .rb file in the same folder of the file to inspect (which causes git clients to continuously see new files).
Is there any chance of doing this in memory or using stdoutput or at worst in a temporary dir like application's /tmp?
Thanks
I opened flycheck/flycheck#1102 because I noticed that Flycheck+Slim-lint was not respecting the .rubycop.yml
in my projects main folder. This stems from flycheck copying the file to be linted to a temp folder. I suspect it would also not respect the .slim-lint.yml
but that is easily fixed by passing the path to it with --config
.
I read through the code and found there is a way to pass the path of the rubocop config through an environment variable, but I am told that flycheck does not support this currently. There are a couple of different solutions to this as I see it:
I wanted to open an issue first to start a conversation instead of just dropping a PR. What would be preferred from the slim-lint side? I am happy to take a stab at a PR, just wanted to get some insight first.
Slim-lint display wrong line number for errors when ruby code is written in multiple lines. If ruby code break down into multiple line then slim-lint should count this as multiple line not one line.
Here is a screenshot:
Screenshot
Redundant div is in line 19 but error displaying in line 15.
It is currently possible to include invalid linter names in the config file. If an invalid name is included, an error should be thrown rather than silently ignoring it. (As seen here #31)
It shows warning if ==
used in slim, for example:
title == content_for?(:title) ? yield(:title) : 'Untitled'
I use SublimeLinter-slim-lint plugin for Sublime Text. Example of my Example.slim file:
| Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
In Status Bar I saw message:
LineLength: Line is too long [448/80]
I have 2 questions:
I have tried:
C:\WINDOWS\system32>slim-lint --show-linters
Available linters:
+ CommentControlStatement
+ ConsecutiveControlStatements
+ EmptyControlStatement
+ LineLength
+ RedundantDiv
+ RuboCop
+ TagCase
+ TrailingWhitespace
C:\WINDOWS\system32>slim-lint -x LineLength
C:\WINDOWS\system32>slim-lint --show-linters
Available linters:
+ CommentControlStatement
+ ConsecutiveControlStatements
+ EmptyControlStatement
+ LineLength
+ RedundantDiv
+ RuboCop
+ TagCase
+ TrailingWhitespace
The class is not disabled.
I read #12. Whether correctly I understood, what time can't disconnect separate linters at the moment?
Thanks.
https://www.rubydoc.info/gems/slim/frames#Attributes_wrapper
Maybe with a config option like:
AttributesWrapper:
enabled: true
style: none|any|curly|round|square
If I can figure out how the slim parser identifies these perhaps I can submit a PR soon. :)
Could you give me a hint on why the following does not work?
I still get [W] LineLength: Line is too long. [461/120]
/ rubocop:disable Metrics/LineLength
iframe [class="embed-responsive-item"
src="https://www.productreview.com.au/w/reviews/280683.html?_sf_ignore_cache=1&api_version=2&referer=http%3A%2F%2Fwww.carnextdoor.com.au%2Fcar-next-door-reviews%2F&url=https://www.productreview.com.au/w/reviews/&css_override=false&min_review_rating=0&min_avg_rating=0&order=best&num_reviews=3&width=800&height=290&preview=true&xdm_e=http%3A%2F%2Fwww.carnextdoor.com.au&xdm_c=default1590&xdm_p=1"
name="easyXDM_default1590_provider" id="easyXDM_default1590_provider"]
/ rubocop:enable Metrics/LineLength
I need to implement a linter that checks if there is any hard coded text (instead of i18n translations or method calls in general) for a project. So I wondered whether this project is a good place for this linter to live.
Here are some examples:
.foo
| This is bad
.foo
= t('.this_is_good')
.foo
= this_is_also_ok(42)
Run slim-lint on index.html.slim
with cyrillic symbols at CI server and got:
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.3-compliant syntax, but you are running 2.2.0.
invalid byte sequence in US-ASCII
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/document.rb:41:in `split'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/document.rb:41:in `process_source'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/document.rb:32:in `initialize'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/runner.rb:52:in `new'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/runner.rb:52:in `collect_lints'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/runner.rb:21:in `block in run'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/runner.rb:20:in `map'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/runner.rb:20:in `run'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/cli.rb:82:in `scan_for_lints'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/cli.rb:51:in `act_on_options'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/lib/slim_lint/cli.rb:23:in `run'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/gems/slim_lint-0.5.0/bin/slim-lint:6:in `<top (required)>'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/bin/slim-lint:23:in `load'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/bin/slim-lint:23:in `<main>'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
/home/gitlab_ci_runner/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'
Report this bug at https://github.com/sds/slim-lint/issues
slim-lint v0.8.0 with rubocop v 0.41.1 reports that html_safe in slim is unsafe. Is this true?
app/views/events/show.html.slim:65 [W] RuboCop: Rails/OutputSafety: Tagging a string as html safe may be a security risk, \
prefer `safe_join` or other Rails tag helpers instead
This blog
https://makandracards.com/makandra/2579-everything-you-know-about-html_safe-is-wrong
says that html_safe in views is safe.
Hi!
I've found that block argument which is used as attribute value generates warning, like this:
- 2.times do |x|
div attr=x
Can this be fixed?
This would make it much easier to integrate with Jenkins.
Rubocop for example has a plugin to do this: https://github.com/eitoball/rubocop-checkstyle_formatter
The format itself is pretty simple. For example:
<?xml version='1.0'?>
<checkstyle>
<file name='Gemfile'/>
<file name='config.ru'>
<error line='37' column='27' severity='info' message='Avoid using `{...}` for multi-line blocks.' source='com.puppycrawl.tools.checkstyle.Style/BlockDelimiters'/>
<error line='39' column='20' severity='info' message='Redundant curly braces around a hash parameter.' source='com.puppycrawl.tools.checkstyle.Style/BracesAroundHashParameters'/>
</file>
slim-lint app/views
app/views/devise/confirmations/new.html.slim:3 [W] RuboCop: Lint/UnderscorePrefixedVariableName: Do not use prefix `_` for a variable that is used.
I don't see any _
variable
h2
| Resend confirmation instructions
= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f|
= f.error_notification
= f.full_error :confirmation_token
.form-inputs
= f.input :email, required: true, autofocus: true
.form-actions
= f.button :submit, "Resend confirmation instructions"
= render "devise/shared/links"
Hi,
is there a way to generate a todo file like rubocops .rubocop_todo.yml?
I'm having too many linting errors right now and it would be nice if i could deal with old issues later™️.
This is a simple recreation of the issue I bumped into with a form_for
helper in rails. I'm using capture so that it's distilled down to the essence of the issue:
- url = 'https://google.com'
= capture do
a href=url = 'Google'
Running slim-lint on this gives me:
test.html.slim:2 [W] RuboCop: Useless assignment to variable - `url`.
app/views/admin/users/index.html.slim:1 [W] RuboCop: Naming/FileName: The name of this source file (`index.html.slim.slim_lint.tmp20170917-92660-1io5a15.rb`) should use snake_case.
Workaround:
linters:
RuboCop:
enabled: true
# These cops are incredibly noisy since the Ruby we extract from Slim
# templates isn't well-formatted, so we ignore them.
# WARNING: If you define this list in your own .slim-lint.yml file, you'll
# be overriding the list defined here.
ignored_cops:
- Layout/AlignArray
- Layout/AlignHash
- Layout/AlignParameters
- Layout/FirstParameterIndentation
- Layout/IndentArray
- Layout/IndentationConsistency
- Layout/IndentationWidth
- Layout/MultilineArrayBraceLayout
- Layout/MultilineAssignmentLayout
- Layout/MultilineHashBraceLayout
- Layout/MultilineMethodCallBraceLayout
- Layout/MultilineMethodCallIndentation
- Layout/MultilineMethodDefinitionBraceLayout
- Layout/MultilineOperationIndentation
- Layout/TrailingBlankLines
- Layout/TrailingWhitespace
- Lint/BlockAlignment
- Lint/EndAlignment
- Lint/Void
- Metrics/BlockLength
- Metrics/BlockNesting
- Metrics/LineLength
- Naming/FileName
- Style/FrozenStringLiteralComment
- Style/IfUnlessModifier
- Style/Next
- Style/WhileUntilModifier
I would rather replace dashes with underscore in temporary files for a better fix and leave that linter enabled
Any way to avoid directories like lib/templates/slim/scaffold?
Note, this does not happen with the rake task.
I ran this like
slim-lint app/**/*.slim
./lib/templates/slim/scaffold/_form.html.slim:1 [W] RuboCop: Syntax: unexpected `@'
Here's the file:
= simple_form_for(@<%= singular_table_name %>) do |f|
= f.error_notification
.form-inputs
<%- attributes.each do |attribute| -%>
= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
<%- end -%>
.form-actions
= f.button :submit
BTW -- LOOKS AWESOME!
I also tried with RuboCop 0.37.0 and MRI Ruby 2.2.3 but got the same error. Let me know if you need any more information.
> bundle exec rake slim_lint --trace
** Invoke slim_lint (first_time)
** Execute slim_lint
no block given
/Users/me/.rvm/gems/ruby-2.2.4@my_app/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/me/.rvm/gems/ruby-2.2.4@my_app/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/me/.rvm/gems/ruby-2.2.4@my_app/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Report this bug at https://github.com/sds/slim-lint/issues
To help fix this issue, please include:
- The above stack trace
- Slim-Lint version: 0.7.0
- RuboCop version: 0.36.0
- Ruby version: 2.2.4
rake aborted!
slim-lint failed with exit code 70
/Users/me/.rvm/gems/ruby-2.2.4@my_app/gems/slim_lint-0.7.0/lib/slim_lint/rake_task.rb:91:in `run_cli'
/Users/me/.rvm/gems/ruby-2.2.4@my_app/gems/slim_lint-0.7.0/lib/slim_lint/rake_task.rb:78:in `block in define'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/me/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/me/.rvm/rubies/ruby-2.2.4/bin/rake:33:in `<main>'
Tasks: TOP => slim_lint
Slim-lint 0.11-0.13 are broken for RuboCop 0.50.0 or newer. This should be documented somewhere.
In general it may be a good practise to have s.add_dependency 'rubocop', '~> 0.50.0'
and s.add_dependency 'rubocop', '>= 0.50.0'
if a Rubocop update may break a slim-lint in the slim_lint.gemspec.
Hi, what do you think about ignoring the above cop by default? It is noisy for slim templates and it doesn't report the proper number of lines
e.g.:
.table-responsive
table.table.table-striped
tbody
- elements.each do |element|
tr
td= link_to element
- if element.editable?
td.btn-toolbar
= link_to edit_element_path(itinerary), class: 'btn btn-xs btn-default' do
span.fa.fa-pencil<> aria-hidden='true'
= t('.edit')
= link_to element_path(itinerary), method: :delete, data: { confirm: t('.confirm') }, class: 'btn btn-xs btn-danger' do
span.fa.fa-trash<> aria-hidden='true'
= t('.destroy')
- else
td= t('.read_only')
Output:
_table.html.slim:4 [W] RuboCop: Block has too many lines. [28/25]
Current workaround:
linters:
RuboCop:
ignored_cops:
- Lint/BlockAlignment
- Lint/EndAlignment
- Lint/Void
- Metrics/BlockLength # TODO: https://github.com/sds/slim-lint/issues/49
- Metrics/LineLength
- Style/AlignHash
- Style/AlignParameters
- Style/BlockNesting
- Style/FileName
- Style/FirstParameterIndentation
- Style/FrozenStringLiteralComment
- Style/IfUnlessModifier
- Style/IndentationConsistency
- Style/IndentationWidth
- Style/MultilineArrayBraceLayout
- Style/MultilineAssignmentLayout
- Style/MultilineHashBraceLayout
- Style/MultilineMethodCallBraceLayout
- Style/MultilineMethodDefinitionBraceLayout
- Style/MultilineMethodCallIndentation
- Style/MultilineOperationIndentation
- Style/Next
- Style/TrailingBlankLines
- Style/TrailingWhitespace
- Style/WhileUntilModifier
The rake task should allow arbitrary CLI arguments. This feature is implemented for rubocop and scss-lint, and as far as I can tell it's necessary for specifying a formatter when running slim-lint via the rake task.
scss-lint implementation: sds/scss-lint@e2a96cb
rubocop implementation: https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/rake_task.rb#L57
My project has a .slim-lint.yml
in the root of the project containing the following:
exclude:
- 'lib/templates/slim/**/*'
When run via overcommit, the exclusion is not honored:
$ overcommit -r
Analyze with slim-lint.....................................[SlimLint] FAILED
Unexpected output: unable to determine line number or type of error/warning for output:
(Using Ruby 2.4 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
/Users/mbrictson/Code/my-rails-app/lib/templates/slim/scaffold/_form.html.slim:6 [W] RuboCop: Lint/Syntax: unexpected token tIDENTIFIER
From what I can tell, this is because overcommit calls the slim-lint command with a list of absolute paths. These absolute paths don't match when compared to the relative exclude
pattern.
My current workaround is to prepend a glob wildcard like this:
exclude:
# Leading "**" is needed for compatibility with overcommit
- '**/lib/templates/slim/**/*'
However I think a better solution would be for slim-lint to resolve relative paths as relative to the location of the .slim-lint.yml
file. This would be consistent with RuboCop's behavior: rubocop/rubocop#892
I'm not sure what's causing this yet, but I just wanted to report this with an example to reproduce so that maybe you or I can figure out what is happening here and fix it.
I'm experiencing an issue where slim-lint reports Rubocop errors on the wrong line instead of the line that actually caused the errors. The possible cause seems to be the presence of other linter errors (long line errors, mostly) on the same line; removing some of those long lines moves the phantom error around and in some cases fixes the issue. Here's an example file that displays the issue:
- provide :title, 'Title'
- provide :viewport, 'desktop'
= render 'partials/sidebar'
- action_bar do
div.action-bar-label
= fa_icon('spinner', class: 'fa-spin')
| Loading...
#content-container
h1 Heading
.instructions-and-upload-form
.instructions
p
| Some instruction text.
A very long line consisting of some more instructions, which goes over the slim-lint maximum line length.
More instruction text.
- if @some_variable > 0
p
| A very long line consisting of some more instructions, which goes over the slim-lint maximum line length.
A very long line consisting of some more instructions, which goes over the slim-lint maximum line length. #{link_to "link_text", some_rails_path_helper(@model1, @model2)}.
A very long line consisting of some more instructions, which goes over the slim-lint maximum line length. <strong>Do something</strong>.
.upload-form
= form_for @attachment, role: 'form', url: some_rails_path_helper_that_makes_this_line_too_long(@model1, @model2) do |f|
= f.labeled_file_upload :file, "Select", "Files", multiple: true, data: { prompt: "Select file(s)" }
= f.submit "Upload files(s)", id: "submit", class: ['btn', 'btn-primary']
= react_component('MyReactApp',
arg1: @arg1, arg2: @arg2, arg3: @arg3, arg4: @arg4)
And here's the output:
broken_lints.slim:7 [W] RedundantDiv: `div` is redundant when class attribute shortcut is present
broken_lints.slim:18 [W] LineLength: Line is too long. [115/80]
broken_lints.slim:22 [W] LineLength: Line is too long. [117/80]
broken_lints.slim:23 [W] LineLength: Line is too long. [183/80]
broken_lints.slim:24 [W] LineLength: Line is too long. [148/80]
broken_lints.slim:26 [W] LineLength: Line is too long. [126/80]
broken_lints.slim:26 [W] RuboCop: Prefer single-quoted strings when you don't need string interpolation or special symbols.
broken_lints.slim:27 [W] LineLength: Line is too long. [108/80]
broken_lints.slim:28 [W] LineLength: Line is too long. [81/80]
broken_lints.slim:31 [W] RuboCop: Prefer single-quoted strings when you don't need string interpolation or special symbols.
broken_lints.slim:31 [W] RuboCop: Prefer single-quoted strings when you don't need string interpolation or special symbols.
broken_lints.slim:31 [W] RuboCop: Prefer single-quoted strings when you don't need string interpolation or special symbols.
broken_lints.slim:32 [W] RuboCop: Prefer single-quoted strings when you don't need string interpolation or special symbols.
broken_lints.slim:32 [W] RuboCop: Prefer single-quoted strings when you don't need string interpolation or special symbols.
As you can see, the double-quoted strings lints are on the wrong line, since line 31 doesn't have any double quoted strings, and there is no line 32.
Again, if I have time, I might look into this myself, but I just thought I should report the bug so that you're aware of it. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.