0.0
The project is in a healthy, maintained state
Deterministic RuboCop cops for canonical Ruby form
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.75.0, < 2.0
 Project Readme

rubocop-canon

Deterministic RuboCop cops that reduce Ruby code to canonical form. Given any input, there is exactly one correct output.

Cops

Cop What it does
Canon/KeywordShorthand foo(bar: bar) becomes foo(bar:)
Canon/SortHash {b: 1, a: 2} becomes {a: 2, b: 1}
Canon/SortKeywords method(z: 1, a: 2) becomes method(a: 2, z: 1)
Canon/SortMethodArguments attr_reader :z, :a becomes attr_reader :a, :z
Canon/SortMethodDefinition def foo(z:, a:) becomes def foo(a:, z:)

Installation

Add to your Gemfile:

gem 'rubocop-canon', require: false

Add to your .rubocop.yml:

plugins:
  - rubocop-canon

Configuration

Canon/SortHash and the three sort cops accept:

Canon/SortHash:
  ShorthandsFirst: true     # shorthand pairs sort before expanded
  ExcludeMethods:           # skip hashes inside these methods
    - enum

Canon/SortKeywords:
  ShorthandsFirst: true
  Methods:                  # only check these methods (required)
    - attribute
    - belongs_to

Canon/SortMethodArguments:
  Methods:                  # only check these methods (required)
    - attr_reader
    - delegate

Canon/SortKeywords and Canon/SortMethodArguments are disabled by default. They require a Methods list to function.

License

MIT