Rubocop for Rails and Rspec

Public
Rubocop rules
Icons/chart bar
Used 44 times
Created by
d dpaluy

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/X6ks2b"
Template Source

Review the code before running this template on your machine.

gem_group :tools do
  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', require: false
  gem 'rubocop-rspec', require: false
end

run 'bundle'

rubocop = <<~YAML
require:
  - rubocop-rails
  - rubocop-performance
  - rubocop-rspec

AllCops:
  NewCops: enable
  Exclude:
    - 'Guardfile'
    - 'db/**/*'
    - 'config/**/*'
    - 'spec/support/*.rb'
    - 'spec/*.rb'
    - 'node_modules/**/*'
    - 'bin/**/*/'
    - 'vendor/**/*'
    - 'lib/tasks/**/*'
    - 'lib/extensions/**/*'

Lint/MissingSuper:
  Exclude:
    - 'app/frontend/**/*.rb'

Metrics/BlockLength:
  Exclude:
    - 'spec/**/*_spec.rb'

RSpec/ImplicitExpect:
  Enabled: false

RSpec/ImplicitSubject:
  Enabled: false

RSpec/NamedSubject:
  Enabled: false

RSpec/ContextWording:
  Enabled: false

RSpec/LeakyConstantDeclaration:
  Enabled: false

Style/Documentation:
  Enabled: false

Style/FrozenStringLiteralComment:
  Enabled: false

Style/StringLiterals:
  Enabled: false

Style/ClassAndModuleChildren:
  Enabled: false
YAML

if yes?('Do you want to run the auto-generate configuration?')
  run "rubocop --auto-gen-config"
else
   create_file '.rubocop.yml', rubocop
end

github_rubocop = <<~YAML
name: Rubocop

on:
  pull_request:
  push:
    branches:
      - master
    tags:
      - v*
      
jobs:
  run-linters:
    runs-on: ubuntu-latest
    steps:
    - name: Git checkout
      uses: actions/checkout@v2

    - name: Set up ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.0.2

    - name: Gems Cache
      id: gem-cache
      uses: actions/cache@v2
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-gem-
    - name: Install dependencies
      run: bundle install --jobs 4 --retry 3

    - name: Run linters
      uses: wearerequired/lint-action@v1
      with:
        github_token: ${{ secrets.github_token }}
        rubocop: true
        rubocop_command_prefix: bundle exec
        rubocop_args: -c ./.rubocop.yml
YAML

if yes?('Do you want to add github actions configuration?')
  run 'mkdir .github & mkdir .github/workflows'
  create_file '.github/workflows/rubocop.yml', github_rubocop
end
Comments

Sign up or Login to leave a comment.