0.0
No release in over 3 years
Rubocop rules for adopting `rubyfmt`
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 1.72.2
 Project Readme

rubocop-rubyfmt

rubyfmt-compliant Rubocop configuration.

Installation

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

bundle add rubocop-rubyfmt

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

gem install rubocop-rubyfmt

Usage

Add the plugin to your .rubocop.yml:

plugins:
  - rubocop-rubyfmt

Custom Lints

Rubyfmt/NoEndOfLineRubocopDisables

Rubocop allows two ways to disable lints for a certain expression. You can disable them at the end of a line, like so:

'foo' # rubocop:disable Some/Lint

Alternatively, you can wrap the whole expression with comments on multiple lines.

# rubocop:disable Some/Lint
'foo'
# rubocop:enable Some/Lint

rubyfmt only supports comments on their own line, and thus the latter is the only one that will work.

Rubyfmt/NoEndOfLineRubocopDisables is a custom lint that prevents usages of the end-of-line format, and it includes an autocorrect.

Tip

If you're adopting rubyfmt for the first time and want to codemod your rubocop disables, you can run only this cop with bundle exec rubocop --autocorrect --only Rubyfmt/NoEndOfLineRubocopDisables

Note that the autocorrect for this lint is best-effort and may require manual fixups. That said, it'll only move comments and should be safe, and RuboCop will notify you of any new failures.

Disabled Lints

All the disabled lints along with the rationale for disabling them is listed in config/default.yml.

The goal of these lints is not to prevent any violations, but to prevent lint violations specific to rubyfmt. Other lint violations may still occur after formatting: for example, a method body may get longer and cause a Metrics/MethodLength violation. Such violations are not covered by rubocop-rubyfmt.

Optional Lint Disables

There are also some matters of taste (especially in RuboCop's Style department) that rubyfmt doesn't automatically enforce but which may be modified by rubyfmt and cause failures. For example, rubyfmt does not currently enforce that multiline blocks must use do/end. For those who wish to leave formatting decisions entirely up to rubyfmt and not worry about them, there's a "full" config that more aggressively disables such lints, which you can include in your RuboCop config:

inherit_gem:
  rubocop-rubyfmt:
    - config/full.yml

You may also wish to instead read the file and pick-and-choose which ones to disable.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/reese/rubocop-rubyfmt.

License

The gem is available as open source under the terms of the MIT License.