RuboCop – commands

Installing Rubocop and Overcommit

Install gems

$ gem install rubocop $ gem install overcommit

sets up githooks

$ overcommit –install

Sign changes to overcommit.yml

$ overcommit –sign

Run Rubocop against project

Displays Filename, line and description of error

$ rubocop

Rubocop Output

Symbol Description

. No issues

C Convention

E Error

F Fatal error

W Warning

Output offense name and count

$ rubocop –format offenses

Show cop definition

$ rubocop –show-cop Style/ZeroLengthPredicate

List all cops with description, key/values and link to style guide

$ rubocop –show-cops

Output offense name and count

$ rubocop –format offenses

Run a specific cop against project

$ rubocop –only Style/StringLiterals

Check a specific file with all cops

$ rubocop ./app/models/app_namespace/api/v1/saved_calendar.rb

Check a specific file with all cops

$ rubocop ./app/models/app_namespace/api/v1/saved_calendar.rb –only Style/StringLiterals

Check a specific file output errors as json

$ rubocop –format json app/models/app_namespace/api/v1/project.rb

Auto-correct with a specific cop

$ rubocop –auto-correct –only RedundantParentheses

Output offenses w formatted suggestion,

url to additional comments / example

$ rubocop –display-style-guide

Displays Filename, line and description of error

With url to documentation for this cop

$ rubocop –display-style-guide –display-cop-names

Show code correctness

$ rubocop –lint

List Files

$ rubocop –list-target-files

In the instance of a Merge, it may be required to Skip RuboCop

$ SKIP=RuboCop git commit -am “Merge”

Generate todo list / Turn off all cops

$ rubocop –auto-gen-config

Use Postgres to check for missing foreign keys – psql

select Distinct column_name, t1.tablename FROM information_schema.columns, (select * from pg_tables where schemaname='public' AND tablename = 'products') t1 WHERE table_name = 'projects' and column_name like '%_id' and column_name not in (

(SELECT
(SELECT a.attname FROM pg_attribute a WHERE a.attrelid = m.oid AND a.attnum = o.conkey[1] AND a.attisdropped = false) AS source_column
FROM
pg_constraint o LEFT JOIN pg_class c ON c.oid = o.conrelid
LEFT JOIN pg_class f ON f.oid = o.confrelid LEFT JOIN pg_class m ON m.oid = o.conrelid
WHERE
o.contype = 'f' AND o.conrelid IN (SELECT oid FROM pg_class c WHERE c.relkind = 'r') AND m.relname = 'products'))

postgres doesn’t start after restart. postmaster.pid may be blocking startup.

psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432”?

$ rm /usr/local/var/postgres/postmaster.pid

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Note: the path to postgres may be different.