Coding Style with RuboCop

Importance of Consistent Coding Styles

Coding styles are controlled by RuboCop which performs a number of style related checks on the code. The code may run fine and pass tests while not being style compliant, but compliance with the configured style makes code easier to read and maintain. The continuous integration (CI) service for Hyrax and many other Samvera gems is configured to fail if RuboCop detects errors. It is recommneded that you configure CI to fail for RuboCop errors in your Samvera based apps.

What is RuboCop

RuboCop is a Ruby static code analyzer. The validations that RuboCop makes are configurable.

Recommended Configuration

The recommended configuration of RuboCop for the Samvera community can be included in your app by installing the Bixby gem. You can see the default configuration setup by Bixby in these three files: bixby_default.yml, bixby_rails_enabled.yml, bixby_rspec_enabled.yml.

You can include the default bixby RuboCop configuration by adding the following to the top of your app’s .rubocop.yml file.

inherit_gem: bixby: bixby_default.yml

Customizing the Configuration

You can override any configuration provided by Bixby in your app’s .rubycop.yml file. See the List of Cops and Configuration documentation in the References list below. Also, see the Bixby gem files listed above to see examples in use.

References:

Running RuboCop

Validate all files:

rubocop

Validate a specific file:

rubocop path/to/your/file

Autocorrect problems

If RuboCop finds style violations, you can ask it to try automatically fixing them.