rubocop-doctolib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +44 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/config/default.yml +24 -0
- data/lib/rubocop-doctolib.rb +11 -0
- data/lib/rubocop/cop/doctolib/no_asymmetrical_pundit_after_actions.rb +112 -0
- data/lib/rubocop/cop/doctolib/no_unsafe_background_migration.rb +45 -0
- data/lib/rubocop/cop/doctolib/one_operation_per_migration.rb +88 -0
- data/lib/rubocop/cop/doctolib_cops.rb +4 -0
- data/lib/rubocop/doctolib.rb +18 -0
- data/lib/rubocop/doctolib/inject.rb +20 -0
- data/lib/rubocop/doctolib/version.rb +7 -0
- data/rubocop-doctolib.gemspec +38 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '08d2ed1d22b78320860a941291ab123cc4f4cf06aaf4cbabe9c6dbc12900d6f7'
|
4
|
+
data.tar.gz: 9a9be592b7cb991ff3c0500415adb85dd1137e8095e27749894eb8a5f6e8f368
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0b7d7de54233e87e2a83c6916645ca580d98e0111052cf29a6ca9b8c9359c5580826f14eed54e67f1bb9f87dacef87d98252da4f3db28a0bcd945a8f1d3851d
|
7
|
+
data.tar.gz: 4b56ad077d6d3304d512ae62b47f04040262f8ba0fa66b3722efdb1cf52834d10145a2b7981d552ccfd6fd9d949e7ca0344aaf6b6cc080ff212c93c4dd5fedab
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.1
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubocop-doctolib (0.1.0)
|
5
|
+
rubocop
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
minitest (5.14.4)
|
13
|
+
parallel (1.20.1)
|
14
|
+
parser (3.0.2.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rake (13.0.6)
|
18
|
+
regexp_parser (2.1.1)
|
19
|
+
rexml (3.2.5)
|
20
|
+
rspec (3.10.0)
|
21
|
+
rspec-core (~> 3.10.0)
|
22
|
+
rspec-expectations (~> 3.10.0)
|
23
|
+
rspec-mocks (~> 3.10.0)
|
24
|
+
rspec-core (3.10.1)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-expectations (3.10.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-mocks (3.10.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-support (3.10.2)
|
33
|
+
rubocop (1.18.3)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.0.0.0)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.8.0)
|
43
|
+
parser (>= 3.0.1.1)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
unicode-display_width (2.0.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
x86_64-linux
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
minitest (~> 5.0)
|
52
|
+
rake (~> 13.0)
|
53
|
+
rspec
|
54
|
+
rubocop (~> 1.7)
|
55
|
+
rubocop-doctolib!
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.2.15
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Victor Schubert
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Rubocop::Doctolib
|
2
|
+
|
3
|
+
rubocop-doctolib is a RuboCop extension containing various cops used and
|
4
|
+
produced at Doctolib. Many of them are useful only in the context of a Ruby on
|
5
|
+
Rails application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rubocop-doctolib', require: false
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rubocop-doctolib
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
30
|
+
`bundle exec rake test` and `bundle exec rake spec` to run the tests. You can
|
31
|
+
also run `bin/console` for an interactive prompt that will allow you to
|
32
|
+
experiment.
|
33
|
+
|
34
|
+
To add a new cop, run `bundle exec rake 'new_cop[Doctolib/NewCopName]'` and
|
35
|
+
implement the cop and its tests.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
38
|
+
release a new version, update the version number in `version.rb`, and then run
|
39
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
40
|
+
git commits and the created tag, and push the `.gem` file to
|
41
|
+
[rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at
|
46
|
+
https://github.com/doctolib/rubocop-doctolib.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT
|
51
|
+
License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
17
|
+
|
18
|
+
require 'rspec/core/rake_task'
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
21
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Generate a new cop with a template'
|
25
|
+
task :new_cop, [:cop] do |_task, args|
|
26
|
+
require 'rubocop'
|
27
|
+
|
28
|
+
cop_name = args.fetch(:cop) do
|
29
|
+
warn 'usage: bundle exec rake new_cop[Department/Name]'
|
30
|
+
exit!
|
31
|
+
end
|
32
|
+
|
33
|
+
github_user = `git config github.user`.chop
|
34
|
+
github_user = 'your_id' if github_user.empty?
|
35
|
+
|
36
|
+
generator = RuboCop::Cop::Generator.new(cop_name, github_user)
|
37
|
+
|
38
|
+
generator.write_source
|
39
|
+
generator.write_spec
|
40
|
+
generator.inject_require(root_file_path: 'lib/rubocop/cop/doctolib_cops.rb')
|
41
|
+
generator.inject_config(config_file_path: 'config/default.yml')
|
42
|
+
|
43
|
+
puts generator.todo
|
44
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rubocop/doctolib"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config/default.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Doctolib/NoAsymmetricalPunditAfterActions:
|
2
|
+
Description: >
|
3
|
+
Flag pairs of `after_action :verify_authorized` and `after_action
|
4
|
+
:verify_policy_scoped` which potentially let some actions covered by
|
5
|
+
neither filter.
|
6
|
+
Enabled: true
|
7
|
+
VersionAdded: 0.1.0
|
8
|
+
|
9
|
+
Doctolib/NoUnsafeBackgroundMigration:
|
10
|
+
Description: Flag migrations which alter the “shape” of the schema.
|
11
|
+
Enabled: true
|
12
|
+
VersionAdded: 0.1.0
|
13
|
+
Include:
|
14
|
+
- db/migrate-background/**/*.rb
|
15
|
+
|
16
|
+
Doctolib/OneOperationPerMigration:
|
17
|
+
Description: >
|
18
|
+
Flag ActiveRecord database migrations which contain more than one
|
19
|
+
operation.
|
20
|
+
Enabled: true
|
21
|
+
VersionAdded: 0.1.0
|
22
|
+
Include:
|
23
|
+
- db/migrate/**/*.rb
|
24
|
+
- db/migrate-background/**/*.rb
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
require_relative 'rubocop/doctolib'
|
6
|
+
require_relative 'rubocop/doctolib/version'
|
7
|
+
require_relative 'rubocop/doctolib/inject'
|
8
|
+
|
9
|
+
RuboCop::Doctolib::Inject.defaults!
|
10
|
+
|
11
|
+
require_relative 'rubocop/cop/doctolib_cops'
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Doctolib
|
6
|
+
KEYS = %i[only except].freeze
|
7
|
+
|
8
|
+
Verify =
|
9
|
+
Struct.new(:node) do
|
10
|
+
def arguments
|
11
|
+
node.arguments[1...]
|
12
|
+
end
|
13
|
+
|
14
|
+
def covers_all?
|
15
|
+
arguments.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def mode
|
19
|
+
only_or_except_kwarg&.key&.value
|
20
|
+
end
|
21
|
+
|
22
|
+
def actions
|
23
|
+
actions = only_or_except_kwarg&.value
|
24
|
+
return if actions.nil?
|
25
|
+
normalize actions
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def only_or_except_kwarg
|
31
|
+
hash = arguments.last
|
32
|
+
return unless hash.type == :hash
|
33
|
+
hash.pairs.find { |argument| KEYS.include? argument.key.value }
|
34
|
+
end
|
35
|
+
|
36
|
+
def normalize(value)
|
37
|
+
case value.type
|
38
|
+
when :sym
|
39
|
+
Set[value.value]
|
40
|
+
when :array
|
41
|
+
return unless value.values.all? { |value| value.type == :sym }
|
42
|
+
Set.new value.values.map(&:value)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Prevent uses of the `verify_authorized` and `verify_policy_scoped`
|
48
|
+
# after-action filters from Pundit, which potentially let some actions
|
49
|
+
# covered by neither after-action filter.
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
#
|
53
|
+
# # bad
|
54
|
+
# after_action :verify_policy_scoped, only: :show
|
55
|
+
# after_action :verify_authorized, only: :index
|
56
|
+
#
|
57
|
+
# # bad
|
58
|
+
# after_action :verify_policy_scoped, only: :show
|
59
|
+
# after_action :verify_authorized, except: :index
|
60
|
+
#
|
61
|
+
# # good
|
62
|
+
# after_action :verify_policy_scoped, only: :show
|
63
|
+
# after_action :verify_authorized, except: :show
|
64
|
+
#
|
65
|
+
# # good
|
66
|
+
# after_action :verify_policy_scoped, only: :show
|
67
|
+
# after_action :verify_authorized
|
68
|
+
#
|
69
|
+
class NoAsymmetricalPunditAfterActions < Base
|
70
|
+
def_node_matcher :verified_class?, <<~MATCHER
|
71
|
+
(class _ _
|
72
|
+
(begin <
|
73
|
+
$(send nil? :after_action (sym :verify_policy_scoped) ...)
|
74
|
+
$(send nil? :after_action (sym :verify_authorized) ...)
|
75
|
+
...>))
|
76
|
+
MATCHER
|
77
|
+
|
78
|
+
MSG = <<~MESSAGE.chomp.gsub("\n", ' ')
|
79
|
+
Some actions may not be covered by either of `:verify_policy_scoped` or `:verify_authorized`.
|
80
|
+
Prefer setting these with complementary `except` and `only` parameters.
|
81
|
+
MESSAGE
|
82
|
+
|
83
|
+
def on_class(node)
|
84
|
+
verified_class?(node) do |policy_scoped, authorized|
|
85
|
+
policy_scoped = Verify.new policy_scoped
|
86
|
+
authorized = Verify.new authorized
|
87
|
+
return if policy_scoped.covers_all?
|
88
|
+
return if authorized.covers_all?
|
89
|
+
return if only_superset_of_except? policy_scoped, authorized
|
90
|
+
return if disjoint_excepts? policy_scoped, authorized
|
91
|
+
add_offense policy_scoped.node
|
92
|
+
add_offense authorized.node
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def only_superset_of_except?(policy_scoped, authorized)
|
99
|
+
if policy_scoped.mode != authorized.mode
|
100
|
+
only, except = policy_scoped.mode == :only ? [policy_scoped, authorized] : [authorized, policy_scoped]
|
101
|
+
return true if only.actions >= except.actions
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def disjoint_excepts?(policy_scoped, authorized)
|
106
|
+
policy_scoped.mode == :except && authorized.mode == :except &&
|
107
|
+
policy_scoped.actions.disjoint?(authorized.actions)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Doctolib
|
6
|
+
# Flag migrations which alter the “shape” of the schema.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# add_column :foos, :bar, :text
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# add_index :foos, :bar
|
15
|
+
#
|
16
|
+
class NoUnsafeBackgroundMigration < RuboCop::Cop::Cop
|
17
|
+
MSG = 'Only use background migrations for index creation, column deletion or table deletion.'
|
18
|
+
|
19
|
+
def_node_matcher(:unsafe_operation_method?, <<~PATTERN)
|
20
|
+
{
|
21
|
+
:create_join_table
|
22
|
+
:create_table
|
23
|
+
:add_column
|
24
|
+
:add_reference
|
25
|
+
:add_timestamps
|
26
|
+
:change_column
|
27
|
+
:change_column_default
|
28
|
+
:change_column_null
|
29
|
+
:change_table
|
30
|
+
:rename_column
|
31
|
+
:rename_table
|
32
|
+
}
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def_node_matcher(:unsafe_operation?, <<~PATTERN)
|
36
|
+
(send nil? #unsafe_operation_method? ...)
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
add_offense(node) if unsafe_operation?(node)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Doctolib
|
6
|
+
# Flag ActiveRecord database migrations which contain more than one
|
7
|
+
# operation.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# def change
|
13
|
+
# add_column :foos, :bar, :text
|
14
|
+
# add_column :foos, :qux, :text
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# def change
|
19
|
+
# add_column :foos, :bar, :text
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class OneOperationPerMigration < RuboCop::Cop::Cop
|
23
|
+
MSG = 'Use only one operation per migration.'
|
24
|
+
|
25
|
+
# From: https://api.rubyonrails.org/classes/ActiveRecord/Migration.html
|
26
|
+
def_node_matcher(:migration_symbol?, <<~PATTERN)
|
27
|
+
{
|
28
|
+
:create_join_table
|
29
|
+
:create_table
|
30
|
+
:add_column
|
31
|
+
:add_foreign_key
|
32
|
+
:add_index
|
33
|
+
:add_reference
|
34
|
+
:add_timestamps
|
35
|
+
:change_column
|
36
|
+
:change_column_default
|
37
|
+
:change_column_null
|
38
|
+
:change_table
|
39
|
+
:rename_column
|
40
|
+
:rename_index
|
41
|
+
:rename_table
|
42
|
+
:drop_table
|
43
|
+
:drop_join_table
|
44
|
+
:remove_column
|
45
|
+
:remove_columns
|
46
|
+
:remove_foreign_key
|
47
|
+
:remove_index
|
48
|
+
:remove_reference
|
49
|
+
:remove_timestamps
|
50
|
+
:execute
|
51
|
+
}
|
52
|
+
PATTERN
|
53
|
+
|
54
|
+
# Descendent of migration class calls migration symbol
|
55
|
+
def_node_matcher(:migration_operation?, <<~PATTERN)
|
56
|
+
{
|
57
|
+
(send nil? #migration_symbol? ...)
|
58
|
+
}
|
59
|
+
PATTERN
|
60
|
+
|
61
|
+
def on_def(node)
|
62
|
+
migration_count = 0
|
63
|
+
each_child_recursive(node) do |child|
|
64
|
+
next unless migration_operation?(child)
|
65
|
+
|
66
|
+
migration_count += 1
|
67
|
+
add_offense(node) if migration_count > 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def each_child_recursive(node)
|
74
|
+
children_stack = [node] # Initialize stack with root node.
|
75
|
+
until children_stack.empty?
|
76
|
+
# Iterate until all leaves have been found.
|
77
|
+
child = children_stack.pop # Select one child from the stack.
|
78
|
+
|
79
|
+
# Add all the next children to the stack if this node-type can have children.
|
80
|
+
children_stack.push(*child.children) if child.respond_to?(:children)
|
81
|
+
|
82
|
+
yield(child)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
5
|
+
require_relative "doctolib/version"
|
6
|
+
|
7
|
+
module RuboCop
|
8
|
+
module Doctolib
|
9
|
+
class Error < StandardError; end
|
10
|
+
# Your code goes here...
|
11
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
12
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
13
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
14
|
+
|
15
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
+
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
|
+
module RuboCop
|
6
|
+
module Doctolib
|
7
|
+
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
+
# bit of our configuration.
|
9
|
+
module Inject
|
10
|
+
def self.defaults!
|
11
|
+
path = CONFIG_DEFAULT.to_s
|
12
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
13
|
+
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
15
|
+
config = ConfigLoader.merge_with_default(config, path)
|
16
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rubocop/doctolib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rubocop-doctolib"
|
7
|
+
spec.version = RuboCop::Doctolib::VERSION
|
8
|
+
spec.authors = ["Doctolib GmbH"]
|
9
|
+
spec.email = ["foss@doctolib.com"]
|
10
|
+
|
11
|
+
spec.summary = "Doctolib’s custom cops"
|
12
|
+
spec.description = "A set of RuboCop cops produced and used at Doctolib."
|
13
|
+
spec.homepage = "https://github.com/doctolib/rubocop-doctolib"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, checkout our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
|
36
|
+
spec.add_runtime_dependency 'rubocop'
|
37
|
+
end
|
38
|
+
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-doctolib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Doctolib GmbH
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A set of RuboCop cops produced and used at Doctolib.
|
28
|
+
email:
|
29
|
+
- foss@doctolib.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".ruby-version"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- config/default.yml
|
47
|
+
- lib/rubocop-doctolib.rb
|
48
|
+
- lib/rubocop/cop/doctolib/no_asymmetrical_pundit_after_actions.rb
|
49
|
+
- lib/rubocop/cop/doctolib/no_unsafe_background_migration.rb
|
50
|
+
- lib/rubocop/cop/doctolib/one_operation_per_migration.rb
|
51
|
+
- lib/rubocop/cop/doctolib_cops.rb
|
52
|
+
- lib/rubocop/doctolib.rb
|
53
|
+
- lib/rubocop/doctolib/inject.rb
|
54
|
+
- lib/rubocop/doctolib/version.rb
|
55
|
+
- rubocop-doctolib.gemspec
|
56
|
+
homepage: https://github.com/doctolib/rubocop-doctolib
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
homepage_uri: https://github.com/doctolib/rubocop-doctolib
|
61
|
+
source_code_uri: https://github.com/doctolib/rubocop-doctolib
|
62
|
+
changelog_uri: https://github.com/doctolib/rubocop-doctolib
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.4.0
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubygems_version: 3.2.15
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Doctolib’s custom cops
|
82
|
+
test_files: []
|