rubocop-petal 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7943295b53d5afb66efeedd6b5801405d67f41ca3e87cbe80afe6310e8dfa65a
4
- data.tar.gz: 2ee305587c6e13494669395c45ce9e405d902ca3a05727f9fac28858af800c0e
3
+ metadata.gz: 424a55f53bbcb88794cf8a0122a376217db95d890fc789d0288a76434cdcb023
4
+ data.tar.gz: 838d1178021d47035f10b7fb139e3fb50955b823ec4f94f80bad0f504d042017
5
5
  SHA512:
6
- metadata.gz: db9b94e57d4ce9c6656488786e91c7a9f89d71b93e7ee816535610a2877b2e2a29ffbec578c2f97eec195b68e5d86e54d35a27208b23986a46956a2b034b5817
7
- data.tar.gz: 9bff7fea4ee7d6df84a93f6acac7518591fbe6a75dda9ba2b9fd8a894ce305c028076e1c7bd9e3bf5cf4b5ae03d82c01ca594df4218eda7b6ad12e1860c867b7
6
+ metadata.gz: d1d19b3bb4c94b070a0acb1d06442541aa333ef8a2170a4d2074ab828051909811d90c8e37ad4d10b5f76ba7fde2ba493bb2f1dcbbc9f5e5e2e930561be23412
7
+ data.tar.gz: a188cc40b0da58690ef31c33698ba33c6043e0d0a52d474b4ee07be5049991357373c97666b5c42996be7efedb56a8e540a4bbbd9d81ac8761bf6144c121ae73
data/config/default.yml CHANGED
@@ -77,3 +77,21 @@ Rails/TableName:
77
77
  Chewy/ResetOnType:
78
78
  Description: 'Prevent using reset! methods on Chewy type class'
79
79
  Enabled: true
80
+
81
+ RSpec/JsonParseResponseBody:
82
+ Description: 'Prevent JSON.parse(response.body) in favor of response.parsed_body'
83
+ Enabled: true
84
+ SafeAutoCorrect: true
85
+ Include:
86
+ - spec/**/*
87
+
88
+ RSpec/JsonResponse:
89
+ Description: 'Prevent json_response in favor of response.parsed_body'
90
+ Enabled: true
91
+ SafeAutoCorrect: true
92
+ Include:
93
+ - spec/**/*
94
+
95
+ Performance/Snif:
96
+ Description: 'Prevent snif in favor of detect'
97
+ 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.parse(response.body)` in spec.
7
+ # Consider using `response.parsed_body`.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # JSON.parse(response.body) do; end
12
+ #
13
+ # # good
14
+ # response.parsed_body
15
+ #
16
+ class JsonParseResponseBody < Base
17
+ extend AutoCorrector
18
+
19
+ MSG = 'Use `response.parsed_body` instead.'
20
+
21
+ def_node_matcher :json_parse_response_body?, <<~PATTERN
22
+ (send (const _ :JSON) :parse (send (send _ :response) :body))
23
+ PATTERN
24
+
25
+ def on_send(node)
26
+ return unless json_parse_response_body?(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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Petal
5
- VERSION = '0.7.0'
5
+ VERSION = '0.8.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.8.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-02-21 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,28 @@ 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_parse_response_body.rb
74
+ - lib/rubocop/cop/rspec/json_response.rb
80
75
  - lib/rubocop/cop/rspec/sidekiq_inline.rb
81
76
  - lib/rubocop/cop/rspec/stub_products.rb
82
77
  - lib/rubocop/petal.rb
83
78
  - lib/rubocop/petal/inject.rb
84
79
  - lib/rubocop/petal/version.rb
85
- - rubocop-petal.gemspec
86
80
  homepage: https://github.com/petalmd/rubocop-petal
87
81
  licenses:
88
82
  - MIT
89
83
  metadata:
90
84
  homepage_uri: https://github.com/petalmd/rubocop-petal
85
+ changelog_uri: https://github.com/petalmd/rubocop-petal/blob/main/CHANGELOG.md
91
86
  source_code_uri: https://github.com/petalmd/rubocop-petal
87
+ bug_tracker_uri: https://github.com/petalmd/rubocop-petal/issues
92
88
  rubygems_mfa_required: 'true'
93
89
  post_install_message:
94
90
  rdoc_options: []
@@ -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