├── Rakefile ├── .rubocop-performance.yml ├── .github └── PULL_REQUEST_TEMPLATE.md ├── Gemfile ├── .gitignore ├── .rubocop-rspec.yml ├── exe └── rubocop-autofix ├── .rubocop-rails.yml ├── LICENSE.txt ├── .rubocop.yml ├── rubocop-bitcrowd.gemspec ├── README.md └── CHANGELOG.md /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | -------------------------------------------------------------------------------- /.rubocop-performance.yml: -------------------------------------------------------------------------------- 1 | require: rubocop-performance 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in rubocop-bitcrowd.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | /*.gem 11 | -------------------------------------------------------------------------------- /.rubocop-rspec.yml: -------------------------------------------------------------------------------- 1 | require: rubocop-rspec 2 | 3 | RSpec/MessageSpies: 4 | Enabled: false 5 | 6 | RSpec/MultipleExpectations: 7 | Enabled: false 8 | 9 | RSpec/NestedGroups: 10 | Max: 4 11 | 12 | RSpec/ExampleLength: 13 | Exclude: 14 | - 'spec/features/**/*' 15 | Max: 7 16 | 17 | RSpec/BeEql: 18 | Enabled: false 19 | -------------------------------------------------------------------------------- /exe/rubocop-autofix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'yaml' 3 | 4 | rubocop_todo = '.rubocop_todo.yml' 5 | if File.exist?(rubocop_todo) 6 | rubocop_yaml = YAML.load_file(rubocop_todo) 7 | rubocop_yaml.keys.each do |key| 8 | puts "Running autofix for #{key}" 9 | `rubocop --only '#{key}' -a` 10 | `git commit -am 'Run rubocop autofix for #{key}'` 11 | end 12 | else 13 | puts 'Please create a .rubocop_todo.yml with `rubocop --auto-gen-config` first.' 14 | end 15 | -------------------------------------------------------------------------------- /.rubocop-rails.yml: -------------------------------------------------------------------------------- 1 | require: rubocop-rails 2 | 3 | Rails/ActionFilter: 4 | Enabled: true 5 | 6 | Rails/Date: 7 | Enabled: true 8 | 9 | Rails/Delegate: 10 | Enabled: true 11 | 12 | Rails/FindBy: 13 | Enabled: true 14 | 15 | Rails/FindEach: 16 | Enabled: true 17 | 18 | Rails/HasAndBelongsToMany: 19 | Enabled: true 20 | 21 | Rails/Output: 22 | Enabled: true 23 | 24 | Rails/PluralizationGrammar: 25 | Enabled: true 26 | 27 | Rails/HttpPositionalArguments: 28 | Enabled: true 29 | 30 | Rails/ReadWriteAttribute: 31 | Enabled: true 32 | 33 | Rails/ScopeArgs: 34 | Enabled: true 35 | 36 | Rails/SkipsModelValidations: 37 | Enabled: false 38 | 39 | Rails/TimeZone: 40 | Enabled: true 41 | 42 | Rails/UnknownEnv: 43 | Environments: 44 | - development 45 | - test 46 | - staging 47 | - production 48 | 49 | Rails/Validation: 50 | Enabled: true 51 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Andreas Knöpfle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | # Additional exclude patterns for files that should not be analyzed. 3 | # These extend the default RuboCop exclude patterns: 4 | # https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml 5 | Exclude: 6 | - 'script/**/*' 7 | - 'db/schema.rb' 8 | - 'tmp/**/*' 9 | - 'storage/**/*' 10 | - 'log/**/*' 11 | DisplayStyleGuide: true 12 | 13 | Style/Documentation: 14 | Enabled: false 15 | 16 | Lint/UselessAccessModifier: 17 | Enabled: true 18 | 19 | Style/AndOr: 20 | Enabled: true 21 | 22 | Style/BlockDelimiters: 23 | EnforcedStyle: braces_for_chaining 24 | 25 | Style/ClassAndModuleChildren: 26 | EnforcedStyle: nested 27 | 28 | Style/CollectionMethods: 29 | Enabled: true 30 | 31 | Style/MethodCalledOnDoEndBlock: 32 | Enabled: true 33 | 34 | Style/FrozenStringLiteralComment: 35 | EnforcedStyle: always 36 | 37 | Style/MutableConstant: 38 | Enabled: true 39 | 40 | Metrics/MethodLength: 41 | Enabled: true 42 | 43 | Metrics/BlockLength: 44 | Enabled: true 45 | IgnoredMethods: ['describe', 'context', 'define', 'factory', 'namespace'] 46 | 47 | Metrics/AbcSize: 48 | Enabled: true 49 | 50 | Layout/LineLength: 51 | Enabled: true 52 | Max: 120 53 | 54 | Layout/SpaceInsideArrayLiteralBrackets: 55 | Enabled: true 56 | AutoCorrect: true 57 | 58 | Layout/SpaceInsideReferenceBrackets: 59 | Enabled: true 60 | AutoCorrect: true 61 | -------------------------------------------------------------------------------- /rubocop-bitcrowd.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |spec| 2 | spec.name = 'rubocop-bitcrowd' 3 | spec.version = '2.3.0' 4 | spec.authors = ['bitcrowd'] 5 | spec.email = ['info@bitcrowd.net'] 6 | 7 | spec.summary = 'The bitcrowd rubocop.yml as a gem.' 8 | spec.description = 'Use this as a quick start to get rubocop with the '\ 9 | 'settings we use at bitcrowd into your project' 10 | spec.homepage = 'https://github.com/bitcrowd/rubocop-bitcrowd' 11 | spec.license = 'MIT' 12 | 13 | spec.post_install_message = <<~HEREDOC 14 | 15 | Starting with this version of rubocop-bitcrowd, we are following RuboCop's 16 | modularization into separate gems and splitting up our configuration into: 17 | - .rubocop.yml 18 | - .rubocop-rails.yml 19 | - .rubocop-rspec.yml 20 | - .rubocop-performance.yml 21 | 22 | If you want to include the `rails`, `rspec` or `performance` cops, add the 23 | respective gems to your Gemfile: 24 | 25 | gem 'rubocop-rails', require: false 26 | gem 'rubocop-rspec', require: false 27 | gem 'rubocop-performance', require: false 28 | 29 | Add include the bitcrowd specific configuration in your .rubocop.yml 30 | 31 | inherit_gem: 32 | rubocop-bitcrowd: 33 | - .rubocop.yml 34 | - .rubocop-rspec.yml 35 | - .rubocop-rails.yml 36 | - .rubocop-performance.yml 37 | 38 | Cheers! 39 | Your friends at bitcrowd 40 | 41 | HEREDOC 42 | 43 | spec.files = `git ls-files -z`.split("\x0").reject do |f| 44 | f.match(%r{^(test|spec|features)/}) 45 | end 46 | spec.bindir = 'exe' 47 | spec.executables = 'rubocop-autofix' 48 | 49 | spec.metadata = { 50 | 'changelog_uri' => 'https://github.com/bitcrowd/rubocop-bitcrowd/blob/main/CHANGELOG.md' 51 | } 52 | 53 | spec.add_runtime_dependency 'rubocop', '>= 1.5.0' 54 | 55 | spec.add_development_dependency 'bundler', '>= 2.1.0' 56 | spec.add_development_dependency 'rake', '~> 12.3.3' 57 | end 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rubocop-bitcrowd 🚓 2 | 3 | [![Gem Version](https://badge.fury.io/rb/rubocop-bitcrowd.svg)](https://badge.fury.io/rb/rubocop-bitcrowd) 4 | 5 | The bitcrowd rubocop.yml as a gem. 6 | 7 | ## Installation 8 | 9 | Add this lines to your application's Gemfile: 10 | 11 | ```ruby 12 | gem 'rubocop-bitcrowd', require: false 13 | ``` 14 | 15 | And then execute: 16 | 17 | $ bundle 18 | 19 | ## Usage 20 | 21 | To use the configuration in your project create a `.rubocop.yml` with: 22 | 23 | ```yml 24 | inherit_gem: 25 | rubocop-bitcrowd: .rubocop.yml 26 | 27 | # Note: skip this if you want to override the default AllCops:Include and AllCops:Exclude list 28 | inherit_mode: 29 | merge: 30 | - Include 31 | - Exclude 32 | ``` 33 | 34 | ### Using other rubocop gems 35 | 36 | There are also config files for the other `rubocop` gems: 37 | * [rubocop-rails](https://github.com/rubocop-hq/rubocop-rails) 38 | * [rubocop-rspec](https://github.com/rubocop-hq/rubocop-rspec) 39 | * [rubocop-performance](https://github.com/rubocop-hq/rubocop-performance) 40 | 41 | To use any of them, add the respective gem to your Gemfile: 42 | 43 | ```ruby 44 | gem 'rubocop-rails', require: false 45 | gem 'rubocop-rspec', require: false 46 | gem 'rubocop-performance', require: false 47 | ``` 48 | 49 | Then include the bitcrowd config in your `.rubocop.yml`: 50 | 51 | ```yml 52 | inherit_gem: 53 | rubocop-bitcrowd: 54 | - .rubocop.yml 55 | - .rubocop-rspec.yml 56 | - .rubocop-rails.yml 57 | - .rubocop-performance.yml 58 | 59 | # Note: skip this if you want to override the default AllCops:Include and AllCops:Exclude list 60 | inherit_mode: 61 | merge: 62 | - Include 63 | - Exclude 64 | ``` 65 | 66 | ## Autofixing issues 67 | 68 | At bitcrowd we discovered it to be a very good practice to put each automatically fixable Cop into a single commit when initially adding rubocop into a bigger project. 69 | 70 | This gem provides a simple script, that can help you with this task: 71 | 72 | 1. Create your rubocop configuration (either with the instructions above or your own) 73 | 2. Create a rubocop_todo.yml with: `rubocop --auto-gen-config` 74 | 3. Make sure you have a clean state in git, since the script will make commits for you (you may want to commit your rubocop_todo.yml) 75 | 4. Run the script (may take a while, when you want to continue working on your project meanwhile run this in a separate checkout): `rubocop-autofix` 76 | 5. Review all commits made by the script and run your tests. You can now drop certain commits of cops you don't want. Often it may make some sense to run the script again with changed settings, since rebasing 100+ commits is no fun. 77 | 78 | ## Development 79 | 80 | Any contributions are welcome. If you attempt to change the behavior of this gem it might be wise to open an issue first to discuss the change. Otherwise feel free to open a PR. 81 | 82 | Every PR should have a change in the [CHANGELOG](./CHANGELOG.md) file (within the [`main` section](./CHANGELOG.md#main)) briefly outlining the attempted changes. 83 | 84 | ### Release a new version 85 | 86 | To release a new version, follow these steps: 87 | 88 | 1. update the [CHANGELOG](./CHANGELOG.md) to reflect the new release and prepare a new [`main` section](./CHANGELOG.md#main) 89 | 2. update the version in `rubocop-bitcrowd.gemspec` according to [semver](https://semver.org/) 90 | 3. commit that change 91 | 4. run `rake release` 92 | 93 | ## License 94 | 95 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 96 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog rubocop-bitcrowd 2 | 3 | Presented in reverse chronological order. Document adheres to [keepachangelog.com](https://keepachangelog.com/en/1.0.0/), though our sections are called "Deprecations", "Potentially breaking changes", "New features", and "Fixes". 4 | 5 | ## Unreleased 6 | 7 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.3.0...HEAD 8 | 9 | ## `2.3.0` (2022-02-21) 10 | 11 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.2.0...v2.3.0 12 | 13 | ### Fixes 14 | 15 | * [#42](https://github.com/bitcrowd/rubocop-bitcrowd/pull/42) Fix deprecation warning by renaming `ExcludedMethods` to `IgnoredMethods` and lock the Rubocop version to `>= 1.5.0`. 16 | See rubocop/rubocop#9098 and https://github.com/rubocop/rubocop/blob/1e55b1aa5e4c5eaeccad5d61f08b7930ed6bc341/relnotes/v1.5.0.md 17 | * [#43](https://github.com/bitcrowd/rubocop-bitcrowd/pull/43) Update documentation mentioning the `master` branch, to use `main` instead 18 | 19 | ## `2.2.0` (2020-03-26) 20 | 21 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.1.3...v2.2.0 22 | 23 | With this version update, `rubocop-bitcrowd` adapts to RuboCop's new modularized architecture of having separate gems for different cop targets (Rails, Rspec, Performance). 24 | 25 | `rubocop-bitcrowd` includes separate configuration files for each RuboCop gem. To continue using the previous configuration including rules for Rspec and Rails, add the respective gems to your Gemfile: 26 | 27 | ```ruby 28 | gem 'rubocop-rails', require: false 29 | gem 'rubocop-rspec', require: false 30 | ``` 31 | 32 | And update the configuration in your `.rubocop.yml` to include the bitcrowd rules: 33 | 34 | ```yml 35 | inherit_gem: 36 | rubocop-bitcrowd: 37 | - .rubocop.yml 38 | - .rubocop-rspec.yml 39 | - .rubocop-rails.yml 40 | ``` 41 | 42 | As a new addition, `rubocop-bitcrowd` now also includes rules for the `rubocop-performance` gem. To use them, add the gem to your Gemfile: 43 | 44 | ```ruby 45 | gem 'rubocop-performance', require: false 46 | ``` 47 | 48 | Then include the bitcrowd config in your `.rubocop.yml`: 49 | 50 | ```yml 51 | inherit_gem: 52 | rubocop-bitcrowd: 53 | - .rubocop.yml 54 | - .rubocop-rspec.yml 55 | - .rubocop-rails.yml 56 | - .rubocop-performance.yml 57 | ``` 58 | 59 | ### Potentially breaking changes 60 | 61 | * [#34](https://github.com/bitcrowd/rubocop-bitcrowd/pull/34) Extract `rails` cops into separate configuration based on [rubocop-rails](https://github.com/rubocop-hq/rubocop-rails), following the modularization of `rubocop` itself. 62 | 63 | ### New features 64 | 65 | * [#32](https://github.com/bitcrowd/rubocop-bitcrowd/pull/32) add possibility to include [rubocop-performance](https://github.com/rubocop-hq/rubocop-performance) cops. 66 | 67 | ## `2.1.3` (2020-03-26) 68 | 69 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.1.2...v2.1.3 70 | 71 | This releases silences some deprecation warnings and locks down the minimal `rubocop` version `rubocop-bitcrowd` depends on. 72 | 73 | ### Fixes 74 | 75 | * [#31](https://github.com/bitcrowd/rubocop-bitcrowd/pull/31) Fix deprecation warning by moving `LineLength` cop from `Metrics` to `Layout` and lock the Rubocop version to `>= 0.78.0` and `< 0.79`. 76 | * [#31](https://github.com/bitcrowd/rubocop-bitcrowd/pull/31) Lock down the minimal `rubocop` version we depend on. Similar to [rubocop-rspec](https://github.com/rubocop-hq/rubocop-rspec) we're only setting the lower boundary now. 77 | 78 | ## `2.1.2` (2019-12-17) 79 | 80 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.1.1...v2.1.2 81 | 82 | ### Fixes 83 | 84 | * Remove rubocop version lock to 0.57.x 85 | 86 | ## `2.1.1` (2019-12-17) 87 | 88 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.1.0...v2.1.1 89 | 90 | ### Fixes 91 | 92 | * Add compartment to `Documentation` cop 93 | 94 | ## `2.1.0` (2019-11-29) 95 | 96 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v2.0.0...v2.1.0 97 | 98 | ### New features 99 | 100 | * Exclude `namespace` method from `Metrics/BlockLength` to support longer namespace definitions in rake tasks. 101 | 102 | ## `2.0.0` (2019-02-06) 103 | 104 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v1.3.0...v2.0.0 105 | 106 | This release changes our approach on excluding certain file paths and directories from being inspected by the linter. Instead of fully overriding RuboCop's default `AllCops:Exclude` list (which used to be necessary up until `rubocop` v0.57.0), `rubocop-bitcrowd` now only provides some extra patterns as an extension to the default list. 107 | 108 | We in addition to the default directories, e.g. want to exclude `log`, `tmp` and `storage` in Rails projects. 109 | 110 | In order to keep excluding both, the bitcrowd patterns and the RuboCop's default ones, add this to your `.rubocop.yml` file: 111 | 112 | ```yml 113 | inherit_mode: 114 | merge: 115 | - Exclude 116 | ``` 117 | 118 | ### Potentially breaking changes 119 | 120 | * require a rubocop version >= 0.57.0 121 | * remove directories rubocop already excludes by default from the `AllCops:Exclude` list 122 | * keeping the existing list now requires to add an `inherit_mode` section into their `.rubocop.yml`: 123 | 124 | ```yml 125 | # This will merge the default exclude list with the one from rubocop-bitcrowd 126 | inherit_mode: 127 | merge: 128 | - Exclude 129 | ``` 130 | 131 | ### Fixes 132 | 133 | * Also exclude the `tmp`, `log` and `storage` directories from being inspected. 134 | Working on a Rails application, especially the `tmp` directory fills up over time and slows down linting the project enormously. Same goes for the `storage` directory: here rubocop also has to dig through deeply nested folder structures. 135 | Note: rubocop's "default" configuration also ignores the `tmp` directory. 136 | 137 | ## `1.3.0` (2018-10-22) 138 | 139 | This release is a maintenance release. Most notably it let's us be compatile with rubocop versions >= 0.56 again. For a full list of changes, see the link or summary below. 140 | 141 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v1.2.1...v1.3.0 142 | 143 | ### New features 144 | 145 | * added `staging` to the list of known environments 146 | * enforce frozen_string_literal comment 147 | 148 | ### Fixes 149 | 150 | * between rubocop version 0.55 and 0.56 we stopped processing most files because we overwrote `AllCops/Include`. 151 | This is fixed, but requires a rubocop version of 0.56 or higher. 152 | * we have a more detailed changelog which is conform with our changelog-style of other projects 153 | 154 | ## `1.2.1` (2018-03-22) 155 | 156 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v1.2.0...v1.2.1 157 | 158 | ### Potentially breaking changes 159 | 160 | * exclude spec/features from the `RSpec/ExampleLength` cop 161 | 162 | ### Fixes 163 | 164 | * ignore `node_modules` and `vendor/bundle` from being inspected 165 | 166 | ## `1.2.0` (2018-02-07) 167 | 168 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v1.1.2...v1.2.0 169 | 170 | ### Fixes 171 | 172 | * The cop `Layout/SpaceInsideBrackets` was deprecated and split into two sub-cops: 173 | * `Layout/SpaceInsideArrayLiteralBrackets` 174 | * and `Layout/SpaceInsideReferenceBrackets` 175 | 176 | ## `1.1.2` (2017-10-23) 177 | 178 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v1.1.1...v1.1.2 179 | 180 | ### Potentially breaking changes 181 | 182 | * Changed to nested module style see: https://github.com/bitcrowd/rubocop-bitcrowd/pull/4 183 | 184 | ## `1.1.1` (2017-09-21) 185 | 186 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/v1.1.0...v1.1.1 187 | 188 | ### Fixes 189 | 190 | * exclude db/schema.rb from being evaluated 191 | * the cop `Style/SpaceInsideBrackets` was renamed to `Layout/SpaceInsideBrackets` 192 | 193 | ## `1.1.0` (2017-09-21) 194 | 195 | https://github.com/bitcrowd/rubocop-bitcrowd/compare/695fb551bcd1e17a12f80e34c9bbcb842cee35ea...v1.1.1 196 | 197 | * First official release 198 | --------------------------------------------------------------------------------