From 0f05b9129b9b4b99b0f2600cf8515638d8eb4cdb Mon Sep 17 00:00:00 2001 From: Jim Herring Date: Thu, 13 Apr 2023 05:58:47 -0400 Subject: [PATCH] initial commit --- README.md | 36 ++++++++++++++++++++++++++++++ config/rubocop-rails.yml | 11 ++++++++++ config/rubocop-vanilla.yml | 24 ++++++++++++++++++++ config/rubocop/layout.yml | 11 ++++++++++ config/rubocop/lint.yml | 17 ++++++++++++++ config/rubocop/metrics.yml | 28 ++++++++++++++++++++++++ config/rubocop/rails.yml | 20 +++++++++++++++++ config/rubocop/rspec.yml | 24 ++++++++++++++++++++ config/rubocop/style.yml | 45 ++++++++++++++++++++++++++++++++++++++ namely_ruby_whiff.gemspec | 14 ++++++++++++ 10 files changed, 230 insertions(+) create mode 100644 README.md create mode 100644 config/rubocop-rails.yml create mode 100644 config/rubocop-vanilla.yml create mode 100644 config/rubocop/layout.yml create mode 100644 config/rubocop/lint.yml create mode 100644 config/rubocop/metrics.yml create mode 100644 config/rubocop/rails.yml create mode 100644 config/rubocop/rspec.yml create mode 100644 config/rubocop/style.yml create mode 100644 namely_ruby_whiff.gemspec diff --git a/README.md b/README.md new file mode 100644 index 0000000..960c289 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Namely Ruby Whiff + +Namely Ruby Whiff is a Ruby gem that contains common Rubocop configurations to use in your Ruby projects. New tools will be added over time, the next being ruby critic. + +## Installation + +To install Namely Ruby Whiff, simply add it to your Gemfile: + +```ruby +gem 'namely-ruby-whiff' +``` + +And then run `bundle install`. + +Next, replace your project's `.rubocop.yml` file with the following, followed by any rules or configurations you want to add or override: + +```yaml +inherit_gem: + namely_ruby_whiff: config/rubocop-rails.yml +``` + +For non-Rails projects, use the following file path instead: `config/rubocop-vanilla.yml`. + +## Usage + +Once you've installed the gem, you can run Rubocop with the following command to make sure it's finding the configs from the gem: + +```bash +bundle exec rubocop +``` + +The gem also includes `rubocop-changes` a tool to apply Rubocop to only the files that have changes in your branch. + +```bash +bundle exec rubocop-changes +``` diff --git a/config/rubocop-rails.yml b/config/rubocop-rails.yml new file mode 100644 index 0000000..5d5a098 --- /dev/null +++ b/config/rubocop-rails.yml @@ -0,0 +1,11 @@ +require: + - rubocop-rails + +inherit_from: + - rubocop-vanilla.yml + - rubocop/rails.yml + +AllCops: + Exclude: + - 'db/**/*' + TargetRubyVersion: 2.6 diff --git a/config/rubocop-vanilla.yml b/config/rubocop-vanilla.yml new file mode 100644 index 0000000..d902e8f --- /dev/null +++ b/config/rubocop-vanilla.yml @@ -0,0 +1,24 @@ +require: + - rubocop-rspec + - rubocop-performance + +inherit_from: + - rubocop/layout.yml + - rubocop/lint.yml + - rubocop/metrics.yml + - rubocop/rspec.yml + - rubocop/style.yml + +AllCops: + Exclude: + - 'bin/**/*' + - 'gen/**/*' + - 'protorepo/**/*' + # rubocop checks .ruby-version for version + # TargetRubyVersion: 2.6 + +Naming/MethodParameterName: + AllowedNames: ['id', 'ms', 'to'] + +Performance/OpenStruct: + Enabled: true diff --git a/config/rubocop/layout.yml b/config/rubocop/layout.yml new file mode 100644 index 0000000..b9d3fb9 --- /dev/null +++ b/config/rubocop/layout.yml @@ -0,0 +1,11 @@ +Layout/FirstHashElementLineBreak: + Enabled: true + +Layout/FirstMethodArgumentLineBreak: + Enabled: true + +Layout/MultilineAssignmentLayout: + Enabled: true + +Layout/LineLength: + Max: 120 diff --git a/config/rubocop/lint.yml b/config/rubocop/lint.yml new file mode 100644 index 0000000..c58291a --- /dev/null +++ b/config/rubocop/lint.yml @@ -0,0 +1,17 @@ +Lint: + Severity: refactor + +Lint/NumberConversion: + Enabled: true + +Lint/ShadowedException: + Enabled: false + +Lint/RescueException: + Exclude: + - 'app/lib/koala/evaluator.rb' + - 'app/services/net_suite/gl_org_units_service.rb' + +Lint/UnifiedInteger: + Exclude: + - 'app/models/type_for_field.rb' diff --git a/config/rubocop/metrics.yml b/config/rubocop/metrics.yml new file mode 100644 index 0000000..06feeb9 --- /dev/null +++ b/config/rubocop/metrics.yml @@ -0,0 +1,28 @@ +Metrics/AbcSize: + Max: 100 + +Metrics/BlockLength: + Max: 40 + Exclude: + - 'config/routes.rb' + - 'spec/factories.rb' + - 'spec/**/*_spec.rb' + - 'app/workers/net_suite_export_job.rb' + +Metrics/ClassLength: + Max: 300 + +Metrics/CyclomaticComplexity: + Max: 15 + +Metrics/MethodLength: + Max: 60 + +Metrics/ModuleLength: + Max: 300 + +Metrics/PerceivedComplexity: + Max: 15 + +Metrics/ParameterLists: + Max: 8 diff --git a/config/rubocop/rails.yml b/config/rubocop/rails.yml new file mode 100644 index 0000000..c3298e4 --- /dev/null +++ b/config/rubocop/rails.yml @@ -0,0 +1,20 @@ +Rails: + Enabled: true + +Rails/ActiveRecordAliases: + Enabled: false + +Rails/ActiveRecordOverride: + Enabled: false + +Rails/HasManyOrHasOneDependent: + Enabled: false + +Rails/InverseOf: + Enabled: false + +Rails/SaveBang: + Enabled: false + +Rails/SkipsModelValidations: + Enabled: false diff --git a/config/rubocop/rspec.yml b/config/rubocop/rspec.yml new file mode 100644 index 0000000..123e259 --- /dev/null +++ b/config/rubocop/rspec.yml @@ -0,0 +1,24 @@ +RSpec/AnyInstance: + Enabled: false + +RSpec/ExampleLength: + Max: 45 + +RSpec/MessageChain: + Enabled: false + +RSpec/MessageSpies: + Enabled: false + +RSpec/MultipleExpectations: + Max: 13 + +RSpec/NestedGroups: + Max: 5 + +RSpec/LetSetup: + Exclude: + - 'spec/mailers/gl_sync_mailer_spec.rb' + +RSpec/NamedSubject: + Enabled: false diff --git a/config/rubocop/style.yml b/config/rubocop/style.yml new file mode 100644 index 0000000..3447108 --- /dev/null +++ b/config/rubocop/style.yml @@ -0,0 +1,45 @@ +Style/ClassAndModuleChildren: + Enabled: false + +Style/ClassVars: + Exclude: + - 'app/lib/koala/evaluator.rb' + +Style/DateTime: + Enabled: true + Exclude: + - 'app/workers/sync_job.rb' + +Style/Documentation: + Enabled: false + +Style/EachWithObject: + Exclude: + - 'app/models/namely_importer.rb' + +Style/FrozenStringLiteralComment: + Exclude: + - 'app/lib/koala/evaluator.rb' + - 'spec/features/**/*_spec.rb' + +Style/GuardClause: + MinBodyLength: 4 + +Style/MethodCalledOnDoEndBlock: + Enabled: false + +Style/MethodMissingSuper: + Enabled: false + +Style/MissingRespondToMissing: + Enabled: false + +Style/MultilineMethodSignature: + Enabled: true + +Style/MutableConstant: + Exclude: + - 'app/models/net_suite/constants.rb' + +Style/Send: + Enabled: true diff --git a/namely_ruby_whiff.gemspec b/namely_ruby_whiff.gemspec new file mode 100644 index 0000000..5960c46 --- /dev/null +++ b/namely_ruby_whiff.gemspec @@ -0,0 +1,14 @@ +Gem::Specification.new do |spec| + spec.name = 'namely_ruby_whiff' + spec.version = '0.0.2' + spec.summary = 'A set of configurations to support high quality Ruby code.' + spec.authors = ['jim.herring@namely.com'] + spec.files = [] + spec.required_ruby_version = '>= 2.5.0' + + spec.add_dependency 'rubocop', '>= 0.72' + spec.add_dependency 'rubocop-changes' + spec.add_dependency 'rubocop-performance' + spec.add_dependency 'rubocop-rails' + spec.add_dependency 'rubocop-rspec' +end