Skip to main content

Esplint like pre-commit logic to ruby

Standardrb gem check​

This gem is a spiritual port of StandardJS and aims to save you (and others!) time in the same three ways:

  • No configuration. The easiest way to enforce consistent style in your project. Just drop it in.
  • Automatically format code. Just run standardrb --fix and say goodbye to messy or inconsistent code.
  • Catch style issues & programmer errors early. Save precious code review time by eliminating back-and-forth between reviewer & contributor.

Purpose​

The purpose of this program is to keep the ruby codebase clean, according to community accepted Ruby-code standard.

How it works​

When you commit files from app folder in the Powr project the hook will run all the logic contained in the .husky hidden directory. It takes indexed files from git and compares the amount of errors with the ones corresponding in errors.json file. If the number of errors for a indexed file greater than in errors.json it will cause an error and will not let you proceed, until you reduce the amount of errors.

Video demostration of it working​

https://www.loom.com/share/aa32a9838ea24d8792d8c72f1e47c6ba

Important details​

File errors.json is crucial for this program to work. After each successful commit, it will be automatically added to index and MUST be commited, so other developers can accept your codebase fixes (reduced errors amount). If you need to refresh errors count (the errors.json file) you can run npm run calculate_ruby_errors (please take a look at package.json scripts section)

Installation​

Install rubocop and standardrb gems from Gemfile

bundle install

Update husky npm package

npm install

For RubyMine, VSCode please also install Rubocop extension

RubyMine Rubocop installation https://www.jetbrains.com/help/ruby/rubocop.html