Skip to content

Commit

Permalink
feat(lib): Add rubocop and reek
Browse files Browse the repository at this point in the history
Rubocop has an inheritance system to share rubocop config with a gem.
See: https://blog.percy.io/share-rubocop-rules-across-all-of-your-repos-f3281fbd71f8

Reek does not have identical system. We are waiting for: troessner/reek#1430

Code Climate can use config from a gem: https://codeclimate.com/changelog/582495c32c33066f1b00191d/
  • Loading branch information
papa-cool committed Oct 19, 2018
1 parent 1ada2e8 commit 0de6419
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 2 deletions.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# code_climate_config
Config for all style, linting, quality, and security static analysis tools
# code_climate_ruby

JobTeaser shared configuration for ruby style, linting, quality, and security static analysis tools.

## Installation

Add this line to your application's Gemfile:

```
group :test, :development do
gem 'code_climate_ruby', git: 'https://github.com/jobteaser/code_climate_ruby', branch: :master
end
```

Or, for a Ruby library, add this to your gemspec:

```
spec.add_development_dependency 'code_climate_ruby'
```

And then run:

```
$ bundle install
```

## Rubocop usage

Create a `.rubocop.yml` with the following directives:

```
inherit_gem:
percy-style:
- default.yml
```

Now, run:

```
$ bundle exec rubocop
```

You do not need to include rubocop directly in your application's dependencies. Code Climate Ruby will include a specific version of rubocop that is shared across all projects.
19 changes: 19 additions & 0 deletions code_climate_config.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Gem::Specification.new do |s|
s.name = 'code_climate_ruby'
s.version = '0.0.0'
s.authors = ['The jobteaser team']
s.email = "dev@jobteaser.com"
s.homepage = 'http://github.com/jobteaser/code_climate_ruby'
s.date = '2018-10-19'
s.summary = 'Share config for Code Climate'
s.description = "This gem contains all config file shared between our ruby projects for Code Climate"

s.files = %w(
lib/rubocop/default.yml
lib/reek/default.yml
)
s.require_paths = %w(lib)

s.add_development_dependency 'rubocop', '>= 0.59.2'
s.add_development_dependency 'reek', '>= 5.0.2'
end
146 changes: 146 additions & 0 deletions lib/reek/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
# https://github.com/troessner/reek/tree/v5.0.2/docs
# https://github.com/troessner/reek/blob/v5.0.2/docs/defaults.reek.yml
detectors:
# Depending on the case, it could be fine to have accessible state outside of the class.
Attribute:
enabled: false
exclude: []
BooleanParameter:
enabled: true
exclude: []
# Use class level instance variable instead of class variable
# when the value should not be shared with subclasses.
# When the value should be shared with subclasses or no subclasses exist,
# class variable is fine and easier to use and understand.
ClassVariable:
enabled: false
exclude: []
ControlParameter:
enabled: true
exclude: []
DataClump:
enabled: true
exclude: []
max_copies: 2
min_clump_size: 2
DuplicateMethodCall:
enabled: false
exclude: []
max_calls: 1
allow_calls: []
FeatureEnvy:
enabled: true
exclude: []
InstanceVariableAssumption:
enabled: false
exclude: []
# Already catch by rubocop.
IrresponsibleModule:
enabled: false
exclude: []
# Already catch by rubocop.
LongParameterList:
enabled: false
exclude: []
max_params: 3
overrides:
initialize:
max_params: 5
# Already catch by rubocop.
LongYieldList:
enabled: false
exclude: []
max_params: 3
ManualDispatch:
enabled: true
exclude: []
MissingSafeMethod:
enabled: true
exclude: []
ModuleInitialize:
enabled: true
exclude: []
NestedIterators:
enabled: true
exclude: []
max_allowed_nesting: 1
ignore_iterators:
- tap
# Too much use today and not only for SimulatedPolymorphism.
# We should start to always implement nil pattern before to enable this check.
NilCheck:
enabled: false
exclude: []
RepeatedConditional:
enabled: true
exclude: []
max_ifs: 2
SubclassedFromCoreClass:
enabled: true
exclude: []
# Already catch by rubocop.
TooManyConstants:
enabled: false
exclude: []
max_constants: 5
TooManyInstanceVariables:
enabled: false
exclude: []
max_instance_variables: 4
# Already catch by rubocop.
TooManyMethods:
enabled: false
exclude: []
max_methods: 15
# Already catch by rubocop.
TooManyStatements:
enabled: false
exclude:
- initialize
max_statements: 5
UncommunicativeMethodName:
enabled: true
exclude: []
reject:
- "/^[a-z]$/"
- "/[0-9]$/"
- "/[A-Z]/"
accept: []
UncommunicativeModuleName:
enabled: true
exclude: []
reject:
- "/^.$/"
- "/[0-9]$/"
accept:
- "/V[0-9]$/"
UncommunicativeParameterName:
enabled: true
exclude: []
reject:
- "/^.$/"
- "/[0-9]$/"
- "/[A-Z]/"
- "/^_/"
accept: []
UncommunicativeVariableName:
enabled: true
exclude: []
reject:
- "/^.$/"
- "/[0-9]$/"
- "/[A-Z]/"
accept:
- "/^_$/"
# Already catch by rubocop.
UnusedParameters:
enabled: false
exclude: []
UnusedPrivateMethod:
enabled: false
exclude: []
UtilityFunction:
enabled: true
exclude: []
public_methods_only: false
129 changes: 129 additions & 0 deletions lib/rubocop/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# List of all cops and their description/default values is available here:
# https://github.com/bbatsov/rubocop/blob/master/manual/cops.md

AllCops:
TargetRubyVersion: 2.3

# ==================================== Department Bundler ==========================================

Bundler/OrderedGems:
Enabled: false

# ===================================== Department Layout ==========================================

Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation

Layout/DotPosition:
EnforcedStyle: trailing

Layout/EmptyLinesAroundClassBody:
EnforcedStyle: empty_lines
SupportedStyles:
- empty_lines
- no_empty_lines

Layout/EmptyLinesAroundModuleBody:
EnforcedStyle: no_empty_lines
SupportedStyles:
- empty_lines
- no_empty_lines

Layout/EmptyLinesAroundBlockBody:
Description: "Keeps track of empty lines around block bodies."
Enabled: false

Layout/EmptyLines:
Description: "Don't use several empty lines in a row."
Enabled: true

Layout/EndOfLine:
Description: 'Use Unix-style line endings.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf'
Enabled: true

Layout/ExtraSpacing:
# When true, allows most uses of extra spacing if the intent is to align
# things with the previous or next line, not counting empty lines or comment
# lines.
AllowForAlignment: true

Layout/MultilineOperationIndentation:
EnforcedStyle: indented

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

# ==================================== Department Metrics ==========================================

Metrics/AbcSize:
Max: 15 # Default is 15

Metrics/ClassLength:
Max: 100 # Default is 100

Metrics/LineLength:
Max: 100 # Default is 80
Exclude:
- config/schedule.rb

Metrics/MethodLength:
Max: 10 # Default is 10

Metrics/ModuleLength:
Max: 100 # Default is 100

Metrics/ParameterLists:
Max: 5 # Default is 5

Metrics/BlockLength:
Exclude:
- spec/**/*.rb
- config/routes.rb
- config/initializers/secure_headers.rb

# ===================================== Department Style ===========================================

Style/Alias:
Description: 'Advise the use of alias_method over the alias keyword whenever possible.'
Enabled: true

Style/CollectionMethods:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

Style/GlobalVars:
Description: 'Do not introduce global variables.'
StyleGuide: '#instance-vars'
Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html'
AllowedVariables:
- $redis
- $redis_cache
- $redis_rollout
Enabled: true

Style/PercentLiteralDelimiters:
# Specify the default preferred delimiter for all types with the 'default' key
# Override individual delimiters (even with default specified) by specifying
# an individual key
PreferredDelimiters:
default: ()
'%i': '()'
'%I': '()'
'%r': '{}'
'%w': '()'
'%W': '()'

Style/SignalException:
Description: 'This cop checks for uses of fail and raise.'
EnforcedStyle: only_raise

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/WordArray:
Description: 'Use %w or %W for arrays of words.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w'
Enabled: false

0 comments on commit 0de6419

Please sign in to comment.