rubocop-petal 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7943295b53d5afb66efeedd6b5801405d67f41ca3e87cbe80afe6310e8dfa65a
4
- data.tar.gz: 2ee305587c6e13494669395c45ce9e405d902ca3a05727f9fac28858af800c0e
3
+ metadata.gz: f457dc147b37b31a89fc5f511560442983a438b191e5723fe95d981f8cb32e91
4
+ data.tar.gz: 197112fd588a74778acc75c2d0da8238dcc4681c49636b5ed7a543728b0abe97
5
5
  SHA512:
6
- metadata.gz: db9b94e57d4ce9c6656488786e91c7a9f89d71b93e7ee816535610a2877b2e2a29ffbec578c2f97eec195b68e5d86e54d35a27208b23986a46956a2b034b5817
7
- data.tar.gz: 9bff7fea4ee7d6df84a93f6acac7518591fbe6a75dda9ba2b9fd8a894ce305c028076e1c7bd9e3bf5cf4b5ae03d82c01ca594df4218eda7b6ad12e1860c867b7
6
+ metadata.gz: a455e3b3db660c5fa02a148263582aee5e82ad561638d8094f2beff087c08eb0e8414e45f2eccd4f1bbaa7d8740e41317fb5421dea0a9e39a41fbc947cb65f49
7
+ data.tar.gz: f89c1da3350fccba89c879092bfb8734f2a903714017cf177e24183a3bb44864c86c90ab1648bb9a5cf8cf0f0347b7dc2f4bfdebb139a684ac9a45b7af5676a7
data/config/default.yml CHANGED
@@ -77,3 +77,14 @@ Rails/TableName:
77
77
  Chewy/ResetOnType:
78
78
  Description: 'Prevent using reset! methods on Chewy type class'
79
79
  Enabled: true
80
+
81
+ RSpec/JsonResponse:
82
+ Description: 'Prevent json_response in favor of response.parsed_body'
83
+ Enabled: true
84
+ SafeAutoCorrect: true
85
+ Include:
86
+ - spec/**/*
87
+
88
+ Performance/Snif:
89
+ Description: 'Prevent snif in favor of detect'
90
+ Enabled: true
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Performance
6
+ # Prevent using `snif`.
7
+ # Consider using `detect`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # period.equity_packs.snif(:code, 'ONCALL')
12
+ #
13
+ # # good
14
+ # period.equity_packs.detect { |equity_pack| equity_pack.code == 'ONCALL' }
15
+ class Snif < Base
16
+ MSG = 'Use `detect` instead.'
17
+
18
+ def_node_matcher :snif?, <<~PATTERN
19
+ (send _ :snif _ _)
20
+ PATTERN
21
+
22
+ def on_send(node)
23
+ return unless snif?(node)
24
+
25
+ add_offense(node)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Prevent using `json_response` in spec.
7
+ # Consider using `response.parsed_body`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # expect(json_response)
12
+ #
13
+ # # good
14
+ # expect(response.parsed_body)
15
+ #
16
+ class JsonResponse < Base
17
+ extend AutoCorrector
18
+
19
+ MSG = 'Use `response.parsed_body` instead.'
20
+
21
+ def_node_matcher :json_response?, <<~PATTERN
22
+ (send _ :json_response)
23
+ PATTERN
24
+
25
+ def on_send(node)
26
+ return unless json_response?(node)
27
+
28
+ add_offense(node) do |corrector|
29
+ corrector.replace(node, 'response.parsed_body')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -7,19 +7,21 @@ module RuboCop
7
7
  # The method will execute inline every perform_async called.
8
8
  # Must likely a spec want to test a specific worker and called it.
9
9
  # If you don't need to execute it, consider using `have_enqueued_sidekiq_job`
10
- # matcher.
10
+ # matcher. Or if you need to perform the jobs in queue for this worker, use
11
+ # `drain` method on the worker class.
11
12
  #
12
13
  # @example
13
14
  # # bad
14
- # Sidekiq::Testing.inline! do; end
15
+ # Sidekiq::Testing.inline! do
16
+ # OperationThatTriggerWorker.call(some_id)
17
+ # end
15
18
  #
16
19
  # # good
17
- # expect(MyWorker).to receive(:perform_async).with(some_id) do |id|
18
- # MyWorker.new.perform(id)
19
- # end
20
+ # OperationThatTriggerWorker.call(some_id)
21
+ # MyWorker.drain
20
22
  #
21
23
  class SidekiqInline < Base
22
- MSG = 'Stub `perform_async` and call inline worker with `new.perform`.'
24
+ MSG = 'Use `MyWorker.drain` method instead of `Sidekiq::Testing.inline!`.'
23
25
  RESTRICT_ON_SEND = [:inline!].freeze
24
26
 
25
27
  def_node_matcher :sidekiq_inline?, <<~PATTERN
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Petal
5
- VERSION = '0.7.0'
5
+ VERSION = '0.9.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-petal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Francis Bastien
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -49,20 +49,12 @@ email:
49
49
  - jfbastien@petalmd.com
50
50
  executables: []
51
51
  extensions: []
52
- extra_rdoc_files: []
52
+ extra_rdoc_files:
53
+ - LICENSE.txt
54
+ - README.md
53
55
  files:
54
- - ".github/workflows/build.yml"
55
- - ".gitignore"
56
- - ".rspec"
57
- - ".rubocop.yml"
58
- - CHANGELOG.md
59
- - Gemfile
60
- - Gemfile.lock
61
56
  - LICENSE.txt
62
57
  - README.md
63
- - Rakefile
64
- - bin/console
65
- - bin/setup
66
58
  - config/default.yml
67
59
  - lib/rubocop-petal.rb
68
60
  - lib/rubocop/cop/chewy/reset_on_type.rb
@@ -71,24 +63,27 @@ files:
71
63
  - lib/rubocop/cop/grape/unnecessary_namespace.rb
72
64
  - lib/rubocop/cop/migration/foreign_key_option.rb
73
65
  - lib/rubocop/cop/migration/schema_statements_methods.rb
66
+ - lib/rubocop/cop/performance/snif.rb
74
67
  - lib/rubocop/cop/petal_cops.rb
75
68
  - lib/rubocop/cop/rails/enum_prefix.rb
76
69
  - lib/rubocop/cop/rails/risky_activerecord_invocation.rb
77
70
  - lib/rubocop/cop/rails/table_name.rb
78
71
  - lib/rubocop/cop/rspec/authenticated_as.rb
79
72
  - lib/rubocop/cop/rspec/create_list_max.rb
73
+ - lib/rubocop/cop/rspec/json_response.rb
80
74
  - lib/rubocop/cop/rspec/sidekiq_inline.rb
81
75
  - lib/rubocop/cop/rspec/stub_products.rb
82
76
  - lib/rubocop/petal.rb
83
77
  - lib/rubocop/petal/inject.rb
84
78
  - lib/rubocop/petal/version.rb
85
- - rubocop-petal.gemspec
86
79
  homepage: https://github.com/petalmd/rubocop-petal
87
80
  licenses:
88
81
  - MIT
89
82
  metadata:
90
83
  homepage_uri: https://github.com/petalmd/rubocop-petal
84
+ changelog_uri: https://github.com/petalmd/rubocop-petal/blob/main/CHANGELOG.md
91
85
  source_code_uri: https://github.com/petalmd/rubocop-petal
86
+ bug_tracker_uri: https://github.com/petalmd/rubocop-petal/issues
92
87
  rubygems_mfa_required: 'true'
93
88
  post_install_message:
94
89
  rdoc_options: []
@@ -105,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
100
  - !ruby/object:Gem::Version
106
101
  version: '0'
107
102
  requirements: []
108
- rubygems_version: 3.0.3
103
+ rubygems_version: 3.2.3
109
104
  signing_key:
110
105
  specification_version: 4
111
106
  summary: Petal custom cops
@@ -1,18 +0,0 @@
1
- name: Build
2
- on:
3
- pull_request:
4
- push:
5
- branches:
6
- - main
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Ruby
13
- uses: ruby/setup-ruby@v1
14
- with:
15
- ruby-version: 2.6
16
- bundler-cache: true
17
- - name: Default task, RSpec and Rubocop
18
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /.idea/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,18 +0,0 @@
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
- Enabled: false
data/CHANGELOG.md DELETED
@@ -1,52 +0,0 @@
1
- # Changelog
2
-
3
- # main
4
-
5
- # v0.7.0
6
-
7
- * Support more cases for `Grape/UnnecessaryNamespace`. ([#26](https://github.com/petalmd/rubocop-petal/pull/26))
8
-
9
- # v0.6.0
10
-
11
- * Added cop `RSpec::SidekiqInline` ([#24](https://github.com/petalmd/rubocop-petal/pull/24))
12
- * Remove cop `Rails/ValidateUniquenessCase` ([#21](https://github.com/petalmd/rubocop-petal/pull/21))
13
-
14
- # v0.5.0
15
-
16
- * Added cop `Rails/ValidateUniquenessCase` ([#20](https://github.com/petalmd/rubocop-petal/pull/20))
17
-
18
- # v0.4.1
19
-
20
- * Fix typo default config SafeAutoCorrect RSpec/StubProducts ([#19](https://github.com/petalmd/rubocop-petal/pull/19))
21
-
22
- # v0.4.0
23
-
24
- * Added cop `RSpec/StubProducts` ([#18](https://github.com/petalmd/rubocop-petal/pull/18))
25
-
26
- # v0.3.1
27
-
28
- * Correct cop name `Migration/SchemaStatementsMethods` in config ([#17](https://github.com/petalmd/rubocop-petal/pull/17))
29
-
30
- # v0.3.0
31
-
32
- * Added cop `Added Migration/ForeignKeyOption` ([#11](https://github.com/petalmd/rubocop-petal/pull/11))
33
- * Added cop `Added Grape/PreferNamespace` ([#6](https://github.com/petalmd/rubocop-petal/pull/6))
34
- * Added cop `Added Migration/SchemaStatementsMethods` ([#14](https://github.com/petalmd/rubocop-petal/pull/14))
35
- * Remove cop `Added Migration/UseChangeTableBulk` ([#15](https://github.com/petalmd/rubocop-petal/pull/15))
36
- * Update cop `Grape/PreferNamespace` ([#16](https://github.com/petalmd/rubocop-petal/pull/16))
37
-
38
- # v0.2.1
39
-
40
- * Update lock dependencies `rubocop-rails` ([#9](https://github.com/petalmd/rubocop-petal/pull/9))
41
-
42
- # v0.2.0
43
-
44
- * Added cop `RSpec/AuthenticatedAs` ([#3](https://github.com/petalmd/rubocop-petal/pull/3))
45
- * Added cop `Grape/UnnecessaryNamespace` ([#2](https://github.com/petalmd/rubocop-petal/pull/2))
46
- * Added cop `RSpec/CreateListMax` ([#4](https://github.com/petalmd/rubocop-petal/pull/4))
47
- * Added Cop `Migration/UseChangeTableBulk` ([#7](https://github.com/petalmd/rubocop-petal/pull/7))
48
- * Added cop `Grape/HelpersIncludeModule` ([#1](https://github.com/petalmd/rubocop-petal/pull/1))
49
-
50
- # v0.1.0
51
-
52
- * First version
data/Gemfile DELETED
@@ -1,15 +0,0 @@
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 DELETED
@@ -1,78 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rubocop-petal (0.7.0)
5
- rubocop (>= 1.7.0, < 2.0)
6
- rubocop-rails (~> 2.10)
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 (3.0.0)
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.15.2)
55
- activesupport (>= 4.2.0)
56
- rack (>= 1.1)
57
- rubocop (>= 1.7.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/Rakefile DELETED
@@ -1,34 +0,0 @@
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 DELETED
@@ -1,15 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,36 +0,0 @@
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', '>= 1.7.0', '< 2.0'
35
- spec.add_dependency 'rubocop-rails', '~> 2.10'
36
- end