015.Check syntax với rubocop.

Thach
Written by Thach on
015.Check syntax với rubocop.

Hướng dẫn dùng rubocop để check syntax

Config

Add gem file rubocop vào Gemfile và bundle

# Gemfile

group :development, :test do
  gem 'rubocop', require: false
  gem 'rubocop-checkstyle_formatter', require: false
  gem 'rubocop-rails'
end

Tạo một file .rubocop.yml

# .rubocop.yml - basic setup example
require:
  - rubocop-rails

AllCops:
  NewCops: enable
  TargetRubyVersion: 3.3.0
  Exclude:
    - vendor/bundle/**/*
    - '**/db/schema.rb'
    - '**/db/**/*'
    - 'config/**/*'
    - 'bin/*'
    - 'config.ru'
    - 'Rakefile'

Style/Documentation:
  Enabled: false

Style/ClassAndModuleChildren:
  Enabled: false

Rails/Output:
  Enabled: false

Style/EmptyMethod:
  Enabled: false

Bundler/OrderedGems:
  Enabled: false

Lint/UnusedMethodArgument:
  Enabled: false

Style/FrozenStringLiteralComment:
  Enabled: false

Cách dùng

# kiểm tra syntax toàn dự án
rubocop

# kiểm tra syntax và tự sửa những lỗi cơ bản
rubocop -A

# kiểm tra riêng một file
rubocop app/models/user.rb

Comments

comments powered by Disqus