0.01
The project is in a healthy, maintained state
RuboCop plugin for ERB template.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 1.72, >= 1.72.1
 Project Readme

rubocop-erb

test

RuboCop plugin for ERB template.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add rubocop-erb

If bundler is not being used to manage dependencies, install the gem by executing:

gem install rubocop-erb

Usage

Require rubocop-erb in your RuboCop config.

# .rubocop.yml
plugins:
  - rubocop-erb

Note

The plugin system is supported in RuboCop 1.72+. In earlier versions, use require instead of plugins.

Now you can use RuboCop also for ERB templates.

$ bundle exec rubocop spec/fixtures/dummy.erb
Inspecting 1 file
C

Offenses:

spec/fixtures/dummy.erb:1:4: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
<% "a" %>
   ^^^
spec/fixtures/dummy.erb:4:9: C: [Correctable] Style/ZeroLengthPredicate: Use !empty? instead of size > 0.
<% a if array.size > 0 %>
        ^^^^^^^^^^^^^^
spec/fixtures/dummy.erb:5:4: C: [Correctable] Style/NegatedIf: Favor unless over if for negative conditions.
<% a if !b %>
   ^^^^^^^
spec/fixtures/dummy.erb:7:7: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
<% if "a" %>
      ^^^

1 file inspected, 4 offenses detected, 4 offenses autocorrectable

Workaround

As a known issue, there seems to be a problem with .rubocop_todo.yml overriding config/default.yml provided by rubocop-erb, so we recommend adding a workaround to your .rubocop.yml as shown below:

inherit_from: .rubocop_todo.yml

inherit_mode:
  merge:
    - Exclude

See #15 for more details.

Related projects