Skip to content

Commit

Permalink
add rubocop as a superset of standard
Browse files Browse the repository at this point in the history
this adds rails, rspec, and other rules in addition to the standardrb ones
  • Loading branch information
indirect committed Jan 13, 2022
1 parent 73bd254 commit 1c98ade
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 14 deletions.
34 changes: 34 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# .rubocop.yml
inherit_mode:
merge:
- Exclude

require:
- rubocop-performance
- standard/cop/block_single_line_braces
- ./lib/cops/lint/env.rb

inherit_gem:
standard: config/base.yml

inherit_from:
- .rubocop_rails.yml
- .rubocop_rspec.yml
- .rubocop_strict.yml

AllCops:
NewCops: disable

Lint/Env:
Enabled: true
Include:
- "**/*.rb"
Exclude:
- "**/config/environments/**/*"
- "**/config/application.rb"
- "**/config/environment.rb"
- "**/config/puma.rb"
- "**/config/boot.rb"
- "**/spec/*_helper.rb"
- "**/spec/**/support/**/*"
- "lib/generators/**/*"
255 changes: 255 additions & 0 deletions .rubocop_rails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
# Based on removed standard configuration:
# https://github.com/testdouble/standard/commit/94d133f477a5694084ac974d5ee01e8a66ce777e#diff-65478e10d5b2ef41c7293a110c0e6b7c

require:
- rubocop-rails

Rails/ActionFilter:
Enabled: true
EnforcedStyle: action
Include:
- app/controllers/**/*.rb

Rails/ActiveRecordAliases:
Enabled: true

Rails/ActiveSupportAliases:
Enabled: true

Rails/ApplicationJob:
Enabled: true

Rails/ApplicationRecord:
Enabled: true

Rails/AssertNot:
Enabled: true
Include:
- '**/test/**/*'

Rails/Blank:
Enabled: true
# Convert usages of `nil? || empty?` to `blank?`
NilOrEmpty: true
# Convert usages of `!present?` to `blank?`
NotPresent: true
# Convert usages of `unless present?` to `if blank?`
UnlessPresent: true

Rails/BulkChangeTable:
Enabled: true
Database: null
Include:
- db/migrate/*.rb

Rails/CreateTableWithTimestamps:
Enabled: true
Include:
- db/migrate/*.rb

Rails/Date:
Enabled: true
EnforcedStyle: flexible

Rails/Delegate:
Enabled: true
EnforceForPrefixed: true

Rails/DelegateAllowBlank:
Enabled: true

Rails/DynamicFindBy:
Enabled: true
Whitelist:
- find_by_sql

Rails/EnumUniqueness:
Enabled: true
Include:
- app/models/**/*.rb

Rails/EnvironmentComparison:
Enabled: true

Rails/Exit:
Enabled: true
Include:
- app/**/*.rb
- config/**/*.rb
- lib/**/*.rb
Exclude:
- lib/**/*.rake

Rails/FilePath:
Enabled: true
EnforcedStyle: arguments

Rails/FindBy:
Enabled: true
Include:
- app/models/**/*.rb

Rails/FindEach:
Enabled: true
Include:
- app/models/**/*.rb

Rails/HasAndBelongsToMany:
Enabled: true
Include:
- app/models/**/*.rb

Rails/HttpPositionalArguments:
Enabled: true
Include:
- 'spec/**/*'
- 'test/**/*'

Rails/HttpStatus:
Enabled: true
EnforcedStyle: symbolic

Rails/InverseOf:
Enabled: true
Include:
- app/models/**/*.rb

Rails/LexicallyScopedActionFilter:
Enabled: true
Safe: false
Include:
- app/controllers/**/*.rb

Rails/NotNullColumn:
Enabled: true
Include:
- db/migrate/*.rb

Rails/Output:
Enabled: true
Include:
- app/**/*.rb
- config/**/*.rb
- db/**/*.rb
- lib/**/*.rb

Rails/OutputSafety:
Enabled: true

Rails/PluralizationGrammar:
Enabled: true

Rails/Presence:
Enabled: true

Rails/Present:
Enabled: true
NotNilAndNotEmpty: true
NotBlank: true
UnlessBlank: true

Rails/ReadWriteAttribute:
Enabled: true
Include:
- app/models/**/*.rb

Rails/RedundantReceiverInWithOptions:
Enabled: true

Rails/RefuteMethods:
Enabled: true
Include:
- '**/test/**/*'

Rails/RelativeDateConstant:
Enabled: true
AutoCorrect: false

Rails/RequestReferer:
Enabled: true
EnforcedStyle: referer

Rails/ReversibleMigration:
Enabled: true
Include:
- db/migrate/*.rb

Rails/SafeNavigation:
Enabled: true
ConvertTry: false

Rails/ScopeArgs:
Enabled: true
Include:
- app/models/**/*.rb

Rails/TimeZone:
Enabled: true
EnforcedStyle: flexible

Rails/UniqBeforePluck:
Enabled: true
EnforcedStyle: conservative
AutoCorrect: false

Rails/Validation:
Enabled: true
Include:
- app/models/**/*.rb

Rails/ActiveRecordCallbacksOrder: # new in 2.7
Enabled: false
Rails/AddColumnIndex: # new in 2.11
Enabled: false
Rails/AfterCommitOverride: # new in 2.8
Enabled: false
Rails/AttributeDefaultBlockValue: # new in 2.9
Enabled: false
Rails/CompactBlank: # new in 2.13
Enabled: false
Rails/DurationArithmetic: # new in 2.13
Enabled: false
Rails/EagerEvaluationLogMessage: # new in 2.11
Enabled: false
Rails/ExpandedDateRange: # new in 2.11
Enabled: false
Rails/FindById: # new in 2.7
Enabled: false
Rails/I18nLocaleAssignment: # new in 2.11
Enabled: false
Rails/Inquiry: # new in 2.7
Enabled: false
Rails/MailerName: # new in 2.7
Enabled: false
Rails/MatchRoute: # new in 2.7
Enabled: false
Rails/NegateInclude: # new in 2.7
Enabled: false
Rails/Pluck: # new in 2.7
Enabled: false
Rails/PluckInWhere: # new in 2.7
Enabled: false
Rails/RedundantPresenceValidationOnBelongsTo: # new in 2.13
Enabled: false
Rails/RedundantTravelBack: # new in 2.12
Enabled: false
Rails/RenderInline: # new in 2.7
Enabled: false
Rails/RenderPlainText: # new in 2.7
Enabled: false
Rails/RootJoinChain: # new in 2.13
Enabled: false
Rails/ShortI18n: # new in 2.7
Enabled: false
Rails/SquishedSQLHeredocs: # new in 2.8
Enabled: false
Rails/TimeZoneAssignment: # new in 2.10
Enabled: false
Rails/UnusedIgnoredColumns: # new in 2.11
Enabled: false
Rails/WhereEquals: # new in 2.9
Enabled: false
Rails/WhereExists: # new in 2.7
Enabled: false
Rails/WhereNot: # new in 2.8
Enabled: false
55 changes: 55 additions & 0 deletions .rubocop_rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require:
- rubocop-rspec

# Disable all cops by default,
# only enable those defined explcitly in this configuration file
RSpec:
Enabled: false

RSpec/Focus:
Enabled: true

RSpec/EmptyExampleGroup:
Enabled: true

RSpec/EmptyLineAfterExampleGroup:
Enabled: true

RSpec/EmptyLineAfterFinalLet:
Enabled: true

RSpec/EmptyLineAfterHook:
Enabled: true

RSpec/EmptyLineAfterSubject:
Enabled: true

RSpec/HookArgument:
Enabled: true

RSpec/HooksBeforeExamples:
Enabled: true

RSpec/ImplicitExpect:
Enabled: true

RSpec/IteratedExpectation:
Enabled: true

RSpec/LetBeforeExamples:
Enabled: true

RSpec/MissingExampleGroupArgument:
Enabled: true

RSpec/ReceiveCounts:
Enabled: true

RSpec/Capybara/CurrentPathExpectation:
Enabled: true

RSpec/FactoryBot/AttributeDefinedStatically:
Enabled: true

RSpec/FactoryBot/CreateList:
Enabled: true
19 changes: 19 additions & 0 deletions .rubocop_strict.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Lint/Debugger: # don't leave binding.pry
Enabled: true
Exclude: []

RSpec/Focus: # run ALL tests on CI
Enabled: true
Exclude: []

Rails/Output: # Don't leave puts-debugging
Enabled: true
Exclude: []

Rails/FindEach: # each could severely affect the performance, use find_each
Enabled: true
Exclude: []

Rails/UniqBeforePluck: # uniq.pluck and not pluck.uniq
Enabled: true
Exclude: []
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ ruby "3.1.0"
gem "rails", "~> 7.0"

group :development, :test do
gem "debug", "~> 1.4", platforms: %i[ mri mingw x64_mingw ]
gem "debug", "~> 1.4", platforms: %i[mri mingw x64_mingw]
end

group :development do
gem "bundler-audit", "~> 0.9.0"
gem "guard-rspec", "~> 4.7"
gem "guard-rubocop", "~> 1.5"
gem "guard-shell", "~> 0.7.2"
gem "guard-standardrb", "~> 0.2.2"
gem "hotwire-livereload", "~> 1.0"
gem "rubocop-gemfile", "~> 0.1.0.beta3"
gem "rubocop-rails", "~> 2.13"
gem "rubocop-rspec", "~> 2.7"
gem "standard", "~> 1.6"
gem "web-console", "~> 4.2"
end
Expand Down
Loading

0 comments on commit 1c98ade

Please sign in to comment.