rubocop-grape 0.4.2 → 0.5.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: 590df7af3dec0374453d4f8ba4282b6d2981492c4e25d0ea537dd9e7b1de8eca
4
- data.tar.gz: d52f772ffb08ba797df64f30298362ce04872477b36544614430e7dd157540d4
3
+ metadata.gz: 8c25d3c6a6082d6b275b0e1d9b42ea3e563d268b093ee71f14d778286759e675
4
+ data.tar.gz: 379dc3a6046ce4365fbf5547e969bb121e98d44fb5020f5bcddafc444b116214
5
5
  SHA512:
6
- metadata.gz: 32c44eac0eee98cee4c97de9e3ff829c7f7d65ef532ee5066985804cc430aff642c93402712240023b430a5a02578806f9a2864e1550147dbc6e9a12e56dbf0c
7
- data.tar.gz: 6692df01c1c324431ba0625d5f2042447afb7b882977dd36fa3f556a9bf448f79cf5e9884240a66f9af1263d04b31e70ec8a1fd212975b6e0758816e9d899b29
6
+ metadata.gz: 5de198f343ab30657b1441c0ee038a4685d79435e0f0f6cd13e6c4d946e57e282ecf37f6614a5048bbdae0e4d4a5bf5a24842240bcf121e7e79f52defd0fb09b
7
+ data.tar.gz: 0fc7c0b5e700e381d9e9d8c2d2895f468bc1c3f2f593d4ccec09400e6e8c068d1b335c5093c8763fe1d64ec22e23a91b4f052ae3fdd0c5a20e7748124554c967
data/README.md CHANGED
@@ -26,13 +26,13 @@ ways to do this:
26
26
  Put this into your `.rubocop.yml`.
27
27
 
28
28
  ```yaml
29
- require: rubocop-grape
29
+ plugins: rubocop-grape
30
30
  ```
31
31
 
32
32
  Alternatively, use the following array notation when specifying multiple extensions.
33
33
 
34
34
  ```yaml
35
- require:
35
+ plugins:
36
36
  - rubocop-other-extension
37
37
  - rubocop-grape
38
38
  ```
@@ -40,6 +40,9 @@ require:
40
40
  Now you can run `rubocop` and it will automatically load the RuboCop Grape
41
41
  cops together with the standard cops.
42
42
 
43
+ > [!NOTE]
44
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
45
+
43
46
  ## Contributing
44
47
 
45
48
  Bug reports and pull requests are welcome on GitHub at https://github.com/kakubin/rubocop-grape.
data/config/default.yml CHANGED
@@ -19,6 +19,10 @@ Grape/FieldName:
19
19
  - snake_case
20
20
  - camelCase
21
21
 
22
+ Grape/RouteParamGrouping:
23
+ Enabled: true
24
+ VersionAdded: '0.4.3'
25
+
22
26
  Grape/RouteParamType:
23
27
  Enabled: true
24
28
  Safe: false
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Grape
6
+ #
7
+ # @example
8
+ #
9
+ # # bad
10
+ # get ':id' do
11
+ # end
12
+ #
13
+ # # good
14
+ # route_param :id, type: Integer do
15
+ # get do
16
+ # end
17
+ # end
18
+ #
19
+ class RouteParamGrouping < Base
20
+ include EndpointHelper
21
+
22
+ MSG = 'Use route_param for route parameter'
23
+
24
+ def on_block(node)
25
+ return unless (method_send_node = http_method_node?(node))
26
+ return unless (first_argument_node = method_send_node.arguments.first)
27
+ return unless first_argument_node.value.match?(/:\w/)
28
+
29
+ add_offense(first_argument_node)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -7,4 +7,5 @@ require_relative 'grape/field_name'
7
7
  require_relative 'grape/ivar'
8
8
  require_relative 'grape/params_position'
9
9
  require_relative 'grape/present_with'
10
+ require_relative 'grape/route_param_grouping'
10
11
  require_relative 'grape/route_param_type'
@@ -7,7 +7,7 @@ module RuboCop
7
7
  extend NodePattern::Macros
8
8
 
9
9
  def_node_matcher :http_method_node?, <<~PATTERN
10
- (block (send _ {:get :post :put :patch :delete} ...) ...)
10
+ (block $(send _ {:get :post :put :patch :delete} ...) ...)
11
11
  PATTERN
12
12
 
13
13
  def_node_matcher :params_node?, <<~PATTERN
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module Grape
7
+ # A plugin that integrates RuboCop Grape with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ # :nocov:
10
+ def about
11
+ LintRoller::About.new(
12
+ name: 'rubocop-grape',
13
+ version: VERSION,
14
+ homepage: 'https://github.com/kakubin/rubocop-grape',
15
+ description: 'Code style checking for Grape files.'
16
+ )
17
+ end
18
+
19
+ # :nocov:
20
+ def supported?(context)
21
+ context.engine == :rubocop
22
+ end
23
+
24
+ def rules(_context)
25
+ project_root = Pathname.new(__dir__).join('../../..')
26
+ LintRoller::Rules.new(
27
+ type: :path,
28
+ config_format: :rubocop,
29
+ value: project_root.join('config/default.yml')
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Grape
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
data/lib/rubocop/grape.rb CHANGED
@@ -5,10 +5,5 @@ require_relative 'grape/version'
5
5
  module RuboCop
6
6
  # RuboCop Grape project namespace
7
7
  module Grape
8
- PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
9
- CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
10
- CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
11
-
12
- private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
13
8
  end
14
9
  end
data/lib/rubocop-grape.rb CHANGED
@@ -4,9 +4,7 @@ require 'rubocop'
4
4
 
5
5
  require_relative 'rubocop/grape'
6
6
  require_relative 'rubocop/grape/version'
7
- require_relative 'rubocop/grape/inject'
8
-
9
- RuboCop::Grape::Inject.defaults!
7
+ require_relative 'rubocop/grape/plugin'
10
8
 
11
9
  require_relative 'rubocop/grape/grape_files'
12
10
 
metadata CHANGED
@@ -1,35 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akito Hikasa
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-04-04 00:00:00.000000000 Z
10
+ date: 2025-02-17 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: lint_roller
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.1'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: rubocop
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - ">="
18
31
  - !ruby/object:Gem::Version
19
- version: 1.7.0
32
+ version: 1.72.1
20
33
  - - "<"
21
34
  - !ruby/object:Gem::Version
22
- version: '2.0'
35
+ version: '2'
23
36
  type: :runtime
24
37
  prerelease: false
25
38
  version_requirements: !ruby/object:Gem::Requirement
26
39
  requirements:
27
40
  - - ">="
28
41
  - !ruby/object:Gem::Version
29
- version: 1.7.0
42
+ version: 1.72.1
30
43
  - - "<"
31
44
  - !ruby/object:Gem::Version
32
- version: '2.0'
45
+ version: '2'
33
46
  description: |
34
47
  Automatic Grape code style checking tool.
35
48
  A RuboCop extension focused on enforcing Grape best practices and coding conventions.
@@ -49,12 +62,13 @@ files:
49
62
  - lib/rubocop/cop/grape/ivar.rb
50
63
  - lib/rubocop/cop/grape/params_position.rb
51
64
  - lib/rubocop/cop/grape/present_with.rb
65
+ - lib/rubocop/cop/grape/route_param_grouping.rb
52
66
  - lib/rubocop/cop/grape/route_param_type.rb
53
67
  - lib/rubocop/cop/grape_cops.rb
54
68
  - lib/rubocop/cop/mixin/endpoint_helper.rb
55
69
  - lib/rubocop/grape.rb
56
70
  - lib/rubocop/grape/grape_files.rb
57
- - lib/rubocop/grape/inject.rb
71
+ - lib/rubocop/grape/plugin.rb
58
72
  - lib/rubocop/grape/version.rb
59
73
  homepage: https://github.com/kakubin/rubocop-grape
60
74
  licenses:
@@ -64,7 +78,7 @@ metadata:
64
78
  homepage_uri: https://github.com/kakubin/rubocop-grape
65
79
  source_code_uri: https://github.com/kakubin/rubocop-grape
66
80
  changelog_uri: https://github.com/kakubin/rubocop-grape/blob/master/CHANGELOG.md
67
- post_install_message:
81
+ default_lint_roller_plugin: RuboCop::Grape::Plugin
68
82
  rdoc_options: []
69
83
  require_paths:
70
84
  - lib
@@ -72,15 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 2.6.0
89
+ version: 2.7.0
76
90
  required_rubygems_version: !ruby/object:Gem::Requirement
77
91
  requirements:
78
92
  - - ">="
79
93
  - !ruby/object:Gem::Version
80
94
  version: '0'
81
95
  requirements: []
82
- rubygems_version: 3.4.19
83
- signing_key:
96
+ rubygems_version: 3.6.2
84
97
  specification_version: 4
85
98
  summary: Automatice Grape code style checking tool.
86
99
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Grape
5
- # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
- # bit of our configuration.
7
- module Inject
8
- def self.defaults!
9
- path = CONFIG_DEFAULT.to_s
10
- hash = ConfigLoader.send(:load_yaml_configuration, path)
11
- config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
- puts "configuration from #{path}" if ConfigLoader.debug?
13
- config = ConfigLoader.merge_with_default(config, path)
14
- ConfigLoader.instance_variable_set(:@default_configuration, config)
15
- end
16
- end
17
- end
18
- end