rubocop-petal 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/.github/workflows/build.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +78 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +34 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/config/default.yml +21 -0
- data/lib/rubocop/cop/chewy/reset_on_type.rb +37 -0
- data/lib/rubocop/cop/petal_cops.rb +8 -0
- data/lib/rubocop/cop/rails/enum_prefix.rb +46 -0
- data/lib/rubocop/cop/rails/risky_activerecord_invocation.rb +70 -0
- data/lib/rubocop/cop/rails/table_name.rb +26 -0
- data/lib/rubocop/petal/inject.rb +20 -0
- data/lib/rubocop/petal/version.rb +7 -0
- data/lib/rubocop/petal.rb +15 -0
- data/lib/rubocop-petal.rb +11 -0
- data/rubocop-petal.gemspec +36 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19be17cd451b07bcec9a8d40b5b2f5b6ba1b8b6b1c41b72a6de2d09e2418a5aa
|
4
|
+
data.tar.gz: fae5baf51f4cc13bcb846cf7821c8747aeaf35ed171bed13c167e3697845f0a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e263be802e2969189d10679f9287ecc6d7653644040574e5ad3ffa3221be90cc5aee59c75689ae4ef6a8287b2d95040b4430413995cd0c4b5d4a8ecdcde4ecd3
|
7
|
+
data.tar.gz: 5f19e9ead08ad127feb9e9efb16bcd0eda62e3f5a79e859d77f5eec2e227ae98cb3bcfea43e5ad5db6d046fda3d7b4ade723f4d68a1f8222243f55c8f9c2aba6
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Build
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.6
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Default task, RSpec and Rubocop
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
NewCops: enable
|
6
|
+
TargetRubyVersion: 2.6
|
7
|
+
SuggestExtensions: false
|
8
|
+
|
9
|
+
Naming/FileName:
|
10
|
+
Exclude:
|
11
|
+
- lib/rubocop-petal.rb
|
12
|
+
|
13
|
+
Metrics/BlockLength:
|
14
|
+
Exclude:
|
15
|
+
- spec/**/*_spec.rb
|
16
|
+
|
17
|
+
RSpec/ExampleLength:
|
18
|
+
Max: 10
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in rubocop-petal.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
|
12
|
+
gem 'rubocop', '~> 1.0'
|
13
|
+
gem 'rubocop-rspec', require: false
|
14
|
+
|
15
|
+
gem 'activesupport', '~> 5.2.0'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubocop-petal (0.1.0)
|
5
|
+
rubocop
|
6
|
+
rubocop-rails
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.6)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.1.9)
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
i18n (1.8.11)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
minitest (5.15.0)
|
22
|
+
parallel (1.21.0)
|
23
|
+
parser (3.0.3.2)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
rack (2.2.3)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (13.0.6)
|
28
|
+
regexp_parser (2.2.0)
|
29
|
+
rexml (3.2.5)
|
30
|
+
rspec (3.10.0)
|
31
|
+
rspec-core (~> 3.10.0)
|
32
|
+
rspec-expectations (~> 3.10.0)
|
33
|
+
rspec-mocks (~> 3.10.0)
|
34
|
+
rspec-core (3.10.1)
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-expectations (3.10.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.10.0)
|
39
|
+
rspec-mocks (3.10.2)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-support (3.10.3)
|
43
|
+
rubocop (1.23.0)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 3.0.0.0)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
regexp_parser (>= 1.8, < 3.0)
|
48
|
+
rexml
|
49
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
50
|
+
ruby-progressbar (~> 1.7)
|
51
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
52
|
+
rubocop-ast (1.15.0)
|
53
|
+
parser (>= 3.0.1.1)
|
54
|
+
rubocop-rails (2.9.1)
|
55
|
+
activesupport (>= 4.2.0)
|
56
|
+
rack (>= 1.1)
|
57
|
+
rubocop (>= 0.90.0, < 2.0)
|
58
|
+
rubocop-rspec (2.6.0)
|
59
|
+
rubocop (~> 1.19)
|
60
|
+
ruby-progressbar (1.11.0)
|
61
|
+
thread_safe (0.3.6)
|
62
|
+
tzinfo (1.2.9)
|
63
|
+
thread_safe (~> 0.1)
|
64
|
+
unicode-display_width (2.1.0)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
activesupport (~> 5.2.0)
|
71
|
+
rake (~> 13.0)
|
72
|
+
rspec (~> 3.0)
|
73
|
+
rubocop (~> 1.0)
|
74
|
+
rubocop-petal!
|
75
|
+
rubocop-rspec
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jean-Francis Bastien
|
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,54 @@
|
|
1
|
+
# RuboCop::Petal
|
2
|
+
|
3
|
+
[![Build](https://github.com/petalmd/rubocop-petal/actions/workflows/build.yml/badge.svg)](https://github.com/petalmd/rubocop-petal/actions/workflows/build.yml)
|
4
|
+
|
5
|
+
Petal custom cops. List of cops can be find [here](https://github.com/petalmd/rubocop-petal/tree/main/lib/rubocop/cop).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rubocop-petal', require: false
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rubocop-petal
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
In your `.rubocop.yml` file, add `rubocop-petal`
|
26
|
+
|
27
|
+
```yaml
|
28
|
+
require:
|
29
|
+
- rubocop-rails
|
30
|
+
```
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
37
|
+
|
38
|
+
## Create new cop
|
39
|
+
|
40
|
+
```shell
|
41
|
+
bundle exec rake 'new_cop[Rails/MyNewCop]'
|
42
|
+
```
|
43
|
+
|
44
|
+
## Release
|
45
|
+
|
46
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/petalmd/rubocop-petal.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
task default: %i[spec rubocop]
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
14
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generate a new cop with a template'
|
18
|
+
task :new_cop, [:cop] do |_task, args|
|
19
|
+
require 'rubocop'
|
20
|
+
|
21
|
+
cop_name = args.fetch(:cop) do
|
22
|
+
warn 'usage: bundle exec rake new_cop[Department/Name]'
|
23
|
+
exit!
|
24
|
+
end
|
25
|
+
|
26
|
+
generator = RuboCop::Cop::Generator.new(cop_name)
|
27
|
+
|
28
|
+
generator.write_source
|
29
|
+
generator.write_spec
|
30
|
+
generator.inject_require(root_file_path: 'lib/rubocop/cop/petal_cops.rb')
|
31
|
+
generator.inject_config(config_file_path: 'config/default.yml')
|
32
|
+
|
33
|
+
puts generator.todo
|
34
|
+
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/petal'
|
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,21 @@
|
|
1
|
+
Rails/EnumPrefix:
|
2
|
+
Description: 'Set prefix options when using enums.'
|
3
|
+
Enabled: true
|
4
|
+
StyleGuide: https://github.com/rails/rails/issues/13389#issue-24527737
|
5
|
+
Include:
|
6
|
+
- app/models/**/*
|
7
|
+
|
8
|
+
Rails/RiskyActiverecordInvocation:
|
9
|
+
Description: 'Interpolation, use hash or parameterized syntax.'
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Rails/TableName:
|
13
|
+
Description: 'Prevent usage of table_name= to in favor of convention.'
|
14
|
+
Enabled: true
|
15
|
+
StyleGuide: "https://rails.rubystyle.guide/#keep-ar-defaults"
|
16
|
+
Include:
|
17
|
+
- app/models/**/*
|
18
|
+
|
19
|
+
Chewy/ResetOnType:
|
20
|
+
Description: 'Prevent using reset! methods on Chewy type class'
|
21
|
+
Enabled: true
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Chewy
|
6
|
+
# This cop prevent usage of table_name= to in favor of convention.
|
7
|
+
#
|
8
|
+
# # bad
|
9
|
+
# UsersIndex::User.reset!
|
10
|
+
#
|
11
|
+
# # good
|
12
|
+
# UsersIndex.reset!
|
13
|
+
class ResetOnType < Base
|
14
|
+
MSG = 'Using reset or reset! on the type instead of the index will put Elasticsearch in an unhealthy state'
|
15
|
+
|
16
|
+
def_node_matcher :reset_on_type?, <<~PATTERN
|
17
|
+
(const (const ... #index?) _)
|
18
|
+
PATTERN
|
19
|
+
|
20
|
+
def on_send(node)
|
21
|
+
receiver, method_name, *_args = *node
|
22
|
+
return unless %i[reset reset!].include? method_name
|
23
|
+
|
24
|
+
return unless reset_on_type?(receiver)
|
25
|
+
|
26
|
+
add_offense(node)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def index?(sym)
|
32
|
+
sym.to_s.end_with?('Index')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# Enforces the use of `_prefix` with any enum.
|
7
|
+
# Using a prefix helps prevent overriding of existing methods
|
8
|
+
# Example: enum some_enum: { open: 0, each: 1 }
|
9
|
+
#
|
10
|
+
# Will cause an error because of overlap with existing methods such as `open` and `each`
|
11
|
+
# For more information, see https://github.com/rails/rails/issues/13389#issue-24527737
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# enum my_enum: {some_value: 0, another: 1}
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# enum my_enum: {some_value: 0, another: 1}, _prefix: true
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# enum my_enum: {some_value: 0, another: 1}, _prefix: :my_prefix
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
# enum my_enum: {some_value: 0, another: 1}, _suffix: true
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# enum my_enum: {some_value: 0, another: 1}, _suffix: 'another_suffix'
|
27
|
+
class EnumPrefix < Base
|
28
|
+
MSG = 'Prefer using a `_prefix` or `_suffix` with `enum`.'
|
29
|
+
|
30
|
+
def_node_matcher :enum?, <<~PATTERN
|
31
|
+
(send nil? :enum (hash ...))
|
32
|
+
PATTERN
|
33
|
+
|
34
|
+
def_node_matcher :use_prefix_or_suffix?, <<~PATTERN
|
35
|
+
(send nil? :enum (hash <(pair (sym {:_prefix :_suffix}) {true str sym}) ...>))
|
36
|
+
PATTERN
|
37
|
+
|
38
|
+
def on_send(node)
|
39
|
+
return unless enum? node
|
40
|
+
|
41
|
+
add_offense(node) unless use_prefix_or_suffix? node
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# Disallow ActiveRecord calls that pass interpolated or added strings as an argument.
|
7
|
+
# https://github.com/airbnb/ruby/blob/12435e8136d2adf710de999bc0f6bef01215df2c/rubocop-airbnb/lib/rubocop/cop/airbnb/risky_activerecord_invocation.rb
|
8
|
+
class RiskyActiverecordInvocation < Cop
|
9
|
+
VULNERABLE_AR_METHODS = %i[
|
10
|
+
delete_all
|
11
|
+
destroy_all
|
12
|
+
exists?
|
13
|
+
execute
|
14
|
+
find_by_sql
|
15
|
+
group
|
16
|
+
having
|
17
|
+
insert
|
18
|
+
order
|
19
|
+
pluck
|
20
|
+
reorder
|
21
|
+
select
|
22
|
+
select_rows
|
23
|
+
select_values
|
24
|
+
select_all
|
25
|
+
update_all
|
26
|
+
where
|
27
|
+
].freeze
|
28
|
+
|
29
|
+
MSG = 'Passing a string computed by interpolation or addition to an ActiveRecord ' \
|
30
|
+
'method is likely to lead to SQL injection. Use hash or parameterized syntax. For ' \
|
31
|
+
'more information, see ' \
|
32
|
+
'http://guides.rubyonrails.org/security.html#sql-injection-countermeasures and ' \
|
33
|
+
'https://rails-sqli.org/rails3. If you have confirmed with Security that this is a ' \
|
34
|
+
'safe usage of this style, disable this alert with ' \
|
35
|
+
'`# rubocop:disable Rails/RiskyActiverecordInvocation`.'
|
36
|
+
|
37
|
+
PATTERN_SPEC_FILE = /^.*_spec\.rb$/.freeze
|
38
|
+
|
39
|
+
def on_send(node)
|
40
|
+
receiver, method_name, *args = *node
|
41
|
+
return if processed_source.buffer.name.match? PATTERN_SPEC_FILE
|
42
|
+
return if receiver.nil?
|
43
|
+
return unless vulnerable_ar_method?(method_name)
|
44
|
+
return if !includes_interpolation?(args) && !includes_sum?(args)
|
45
|
+
|
46
|
+
add_offense(node)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def vulnerable_ar_method?(method)
|
52
|
+
VULNERABLE_AR_METHODS.include?(method)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Return true if the first arg is a :dstr that has non-:str components
|
56
|
+
def includes_interpolation?(args)
|
57
|
+
!args.first.nil? &&
|
58
|
+
args.first.type == :dstr &&
|
59
|
+
args.first.each_child_node.any? { |child| child.type != :str }
|
60
|
+
end
|
61
|
+
|
62
|
+
def includes_sum?(args)
|
63
|
+
!args.first.nil? &&
|
64
|
+
args.first.type == :send &&
|
65
|
+
args.first.method_name == :+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rails
|
6
|
+
# This cop enforces the absence of explicit table name definitions.
|
7
|
+
#
|
8
|
+
# # bad
|
9
|
+
# self.table_name = 'some_table_name'
|
10
|
+
# self.table_name = :some_other_name
|
11
|
+
class TableName < Base
|
12
|
+
include ActiveRecordHelper
|
13
|
+
|
14
|
+
MSG = %(
|
15
|
+
Avoid using `self.table_name=` if at all possible. When ActiveRecord's defaults are used, it may be omitted.
|
16
|
+
If you are working on a new model, you should name the table and model to fit the defaults
|
17
|
+
If you absolutely must use it, disable the cop with `# rubocop:disable Rails/TableName`
|
18
|
+
)
|
19
|
+
|
20
|
+
def on_send(node)
|
21
|
+
add_offense(node) if find_set_table_name(node).to_a.any?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -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 Petal
|
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,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'petal/version'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Petal # rubocop:disable Style/Documentation
|
7
|
+
class Error < StandardError; end
|
8
|
+
# Your code goes here...
|
9
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
10
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
11
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
12
|
+
|
13
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/rubocop/petal/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rubocop-petal'
|
7
|
+
spec.version = RuboCop::Petal::VERSION
|
8
|
+
spec.authors = ['Jean-Francis Bastien']
|
9
|
+
spec.email = ['jfbastien@petalmd.com']
|
10
|
+
|
11
|
+
spec.summary = 'Petal custom cops'
|
12
|
+
spec.homepage = 'https://github.com/petalmd/rubocop-petal'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/petalmd/rubocop-petal'
|
18
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
# Uncomment to register a new dependency of your gem
|
29
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
30
|
+
|
31
|
+
# For more information and examples about making a new gem, checkout our
|
32
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
33
|
+
|
34
|
+
spec.add_runtime_dependency 'rubocop'
|
35
|
+
spec.add_dependency 'rubocop-rails'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-petal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jean-Francis Bastien
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-07 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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- jfbastien@petalmd.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".github/workflows/build.yml"
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".rubocop.yml"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- config/default.yml
|
60
|
+
- lib/rubocop-petal.rb
|
61
|
+
- lib/rubocop/cop/chewy/reset_on_type.rb
|
62
|
+
- lib/rubocop/cop/petal_cops.rb
|
63
|
+
- lib/rubocop/cop/rails/enum_prefix.rb
|
64
|
+
- lib/rubocop/cop/rails/risky_activerecord_invocation.rb
|
65
|
+
- lib/rubocop/cop/rails/table_name.rb
|
66
|
+
- lib/rubocop/petal.rb
|
67
|
+
- lib/rubocop/petal/inject.rb
|
68
|
+
- lib/rubocop/petal/version.rb
|
69
|
+
- rubocop-petal.gemspec
|
70
|
+
homepage: https://github.com/petalmd/rubocop-petal
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://github.com/petalmd/rubocop-petal
|
75
|
+
source_code_uri: https://github.com/petalmd/rubocop-petal
|
76
|
+
rubygems_mfa_required: 'true'
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.6'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.2.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Petal custom cops
|
96
|
+
test_files: []
|