Skip to content

Commit

Permalink
misc: Add rubocop and simplecov (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet authored Mar 25, 2022
1 parent f59d169 commit d08ab85
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
.env
.byebug_history

# Ignore credential keys
/config/credentials/staging.key

/config/credentials/development.key

/config/credentials/test.key

# Ignore Simplecov coverage status
/coverage/*
296 changes: 296 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
require:
- rubocop-rspec
- rubocop-performance
- rubocop-rails
- rubocop-thread_safety

AllCops:
DisplayStyleGuide: true
Exclude:
- 'bin/**/*'
- 'db/schema.rb'

Layout/BlockAlignment:
Description: 'Align block ends correctly.'
Enabled: true
# The value `start_of_block` means that the `end` should be aligned with line
# where the `do` keyword appears.
EnforcedStyleAlignWith: start_of_block

Layout/ClassStructure:
Description: 'Enforces a configured order of definitions within a class body.'
Enabled: true
Categories:
module_inclusion:
- include
- prepend
- extend
ExpectedOrder:
- module_inclusion
- constants
- public_class_methods
- initializer
- public_methods
- protected_methods
- private_methods

Layout/EndAlignment:
Description: 'Align ends correctly.'
Enabled: true
# The value `variable` means that in assignments, `end` should be aligned
# with the start of the variable on the left hand side of `=`. In all other
EnforcedStyleAlignWith: variable

Layout/FirstArrayElementLineBreak:
Description: 'Checks for a line break before the first element in a multi-line array.'
Enabled: true

Layout/FirstHashElementLineBreak:
Description: 'Checks for a line break before the first element in a multi-line hash.'
Enabled: true

Layout/FirstMethodArgumentLineBreak:
Description: 'Checks for a line break before the first argument in a multi-line method call.'
Enabled: true

Layout/FirstMethodParameterLineBreak:
Description: 'Checks for a line break before the first parameter in a multi-line method parameter definition.'
Enabled: true

Layout/FirstArgumentIndentation:
Description: 'Checks the indentation of the first argument in a method call.'
Enabled: true
# The first parameter should always be indented one level relative to the
# parent that is receiving the parameter
EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
Description: 'Checks the indentation of the first element in an array literal.'
Enabled: true
# The value `consistent` means that the indentation of the first element shall
# always be relative to the first position of the line where the opening
# bracket is.
EnforcedStyle: consistent

Layout/FirstHashElementIndentation:
Description: 'Checks the indentation of the first key in a hash literal.'
Enabled: true
# The value `consistent` means that the indentation of the first key shall
# always be relative to the first position of the line where the opening
# brace is.
EnforcedStyle: consistent

Layout/LineLength:
Description: 'Limit lines to 120 characters.'
Enabled: true
Max: 120

Layout/MultilineArrayLineBreaks:
Description: 'Checks that each item in a multi-line array literal starts on a separate line.'
Enabled: true

Layout/MultilineAssignmentLayout:
Description: 'Check for a newline after the assignment operator in multi-line assignments.'
Enabled: true
# Ensures that the assignment operator and the rhs are on the same line for
# the set of supported types.
EnforcedStyle: same_line

Layout/MultilineHashKeyLineBreaks:
Description: 'Checks that each item in a multi-line hash literal starts on a separate line.'
Enabled: true

Layout/MultilineMethodArgumentLineBreaks:
Description: 'Checks that each argument in a multi-line method call starts on a separate line.'
Enabled: true

Layout/MultilineMethodCallIndentation:
Description: 'Checks indentation of method calls with the dot operator that span more than one line.'
Enabled: true
EnforcedStyle: indented

Lint/AmbiguousBlockAssociation:
Description: 'Checks for ambiguous block association with method when param passed without parentheses.'
Enabled: true
Exclude:
- 'spec/**/*'

Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Naming/PredicateName:
Enabled: false

Performance/CaseWhenSplat:
Enabled: true

Rails/InverseOf:
Description: 'Checks for associations where the inverse cannot be determined automatically.'
Enabled: false

Rails/HttpStatus:
Description: 'Enforces use of symbolic or numeric value to describe HTTP status.'
Enabled: false

Rails/HasManyOrHasOneDependent:
Description: 'Forces a "dependent" options for has_one and has_many rails relations.'
Enabled: false

RSpec/ExampleLength:
Description: 'Checks for long examples.'
Enabled: false

RSpec/MultipleExpectations:
Description: 'Checks if examples contain too many expect calls.'
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

RSpec/NestedGroups:
Enabled: false

Style/BlockDelimiters:
Description: >-
Avoid using {...} for multi-line blocks (multiline chaining is always ugly).
Prefer {...} over do...end for single-line blocks.
Enabled: true
EnforcedStyle: line_count_based
IgnoredMethods:
- lambda
- proc
- it
- expect
- change

Style/CommentAnnotation:
Description: 'Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE, INFO).'
Enabled: true
Keywords:
- TODO
- FIXME
- OPTIMIZE
- HACK
- REVIEW
- NOTE
- INFO

Style/Documentation:
Enabled: false

Style/MethodCallWithArgsParentheses:
Description: 'Use parentheses for method calls with arguments.'
Enabled: true
IgnoreMacros: true
IgnoredMethods:
- require_relative
- require
- load
- raise
- desc
- yield
- puts
AllowParenthesesInMultilineCall: false
AllowParenthesesInChaining: false
AllowParenthesesInCamelCaseMethod: false
EnforcedStyle: require_parentheses
Exclude:
- 'lib/tasks/**/*'
- 'db/**/*'
- 'spec/**/*'
- 'config.ru'
- 'Gemfile'
- '**/rspec/**/*.rb'

Style/NestedParenthesizedCalls:
Description: >-
Parenthesize method calls which are nested inside the
argument list of another parenthesized method call.
Enabled: true
AllowedMethods: []

Style/OneLineConditional:
Description: 'Favor the ternary operator(?:) over if/then/else/end constructs.'
Enabled: false

Style/Send:
Description: >-
Prefer `Object#__send__` or `Object#public_send` to `send`,
as `send` may overlap with existing methods.
Enabled: true

Style/SymbolArray:
Description: 'Use %i or %I for arrays of symbols.'
Enabled: false

Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: '#no-trailing-params-comma'
Enabled: true
VersionAdded: '0.36'
# If `comma`, the cop requires a comma after the last argument, but only for
# parenthesized method calls where each argument is on its own line.
# If `consistent_comma`, the cop requires a comma after the last argument,
# for all parenthesized method calls with arguments.
EnforcedStyleForMultiline: comma
SupportedStylesForMultiline:
- comma
- consistent_comma
- no_comma

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/TernaryParentheses:
Description: 'Checks for use of parentheses around ternary conditions.'
Enabled: true
EnforcedStyle: require_parentheses_when_complex

Style/GlobalVars:
Description: 'Do not introduce global variables.'
StyleGuide: '#instance-vars'
Reference: 'https://www.zenspider.com/ruby/quickref.html'
Enabled: true
VersionAdded: '0.13'
# Built-in global variables are allowed by default.
AllowedVariables: ['$segment_client', '$json_web_token']

Style/ClassAndModuleChildren:
Exclude:
- 'test/**/*'

Lint/RaiseException:
Enabled: false

Lint/StructNewOverride:
Enabled: false

Style/HashEachMethods:
Enabled: false

Style/HashTransformKeys:
Enabled: false

Style/HashTransformValues:
Enabled: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ group :development, :test do
gem 'factory_bot_rails'
gem 'faker'
gem 'rspec-rails'
gem 'simplecov', require: false
end

group :development, :staging do
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ GEM
reline (>= 0.2.7)
diff-lcs (1.5.0)
digest (3.1.0)
docile (1.4.0)
dotenv (2.7.6)
erubi (1.10.0)
execjs (2.8.1)
Expand Down Expand Up @@ -213,6 +214,12 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -256,6 +263,7 @@ DEPENDENCIES
rails (~> 7.0.2)
rspec-rails
sass-rails
simplecov
tzinfo-data
uglifier

Expand Down
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
require 'simplecov'
SimpleCov.start
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
Expand Down

0 comments on commit d08ab85

Please sign in to comment.