rubocop-nueca 2.1.0 → 2.2.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: 81918c1ee3c1d72d3bfdf6914398dab599378c4a37ae66419afb23792c35386e
4
- data.tar.gz: a4348608537bc0876333bb78e4757770f91859623e83c3353b013e4d7233f1a2
3
+ metadata.gz: 9e2e8263941b4c5f0934ad7fb9f8df991e90583476f10fc3290a3c7dd2f917ff
4
+ data.tar.gz: 0e503986f5bfd5003b40beee3844cfeb9ae5cdc179b2d4576d139e1d244ba18f
5
5
  SHA512:
6
- metadata.gz: 3e41c08ebed4ab33a3b41227cc97d1506d3c289aedf7468f8d8925d8b0ef792f8780d5a510aade458dfd08624bdb36aee4975d63c9689c68f8f9283a0dc7e679
7
- data.tar.gz: a0c05dfcf12646d2c881bfa80f87d70bddfed41916b317f2544823b47b93a71233be42331b7926c9a41be39211dfed96cfaa9f07d7b723df18faee1cd41a87a9
6
+ metadata.gz: dc56766f7ecaa64cb93001e8ee3cd4eca0250bbf4b509d41f2fb6bcbe36d3d30e1d34dba4bdcdbcd26a4f8cd143600000364c5b9ad184793b99bc24f3992373e
7
+ data.tar.gz: 1e89c75c3f19fea9dc29979dd38af0695f4ea4e77f126e7d3d0bc407853f2a3e61baef1f9862016101ee280775bf4ca0c1a24f5cac2f1a48c4418d8cb4c03f05
data/README.md CHANGED
@@ -18,7 +18,7 @@ Add to your `.rubocop.yml` the following code.
18
18
 
19
19
  ```yaml
20
20
  plugins:
21
- - rubocop-nueca
21
+ - rubocop-nueca
22
22
  ```
23
23
 
24
24
  ## License
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../shared/route_helper'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Rails
8
+ class RouteUnnecessaryArrayNotation < RuboCop::Cop::Base
9
+ include RouteHelper
10
+ extend AutoCorrector
11
+
12
+ MSG = 'Unnecessary array notation for single element. ' \
13
+ 'Use `%<key>s: %<value>s` instead of `%<key>s: [%<value>s]`.'
14
+
15
+ def on_send(node)
16
+ return unless route_file?
17
+ return unless route_method?(node)
18
+
19
+ node.arguments.each do |arg|
20
+ next unless arg.hash_type?
21
+
22
+ check_hash_pairs(arg)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def route_method?(node)
29
+ return false unless node.send_type?
30
+
31
+ route_methods = [
32
+ :get, :post, :put, :patch, :delete, :head, :options, :match, :root,
33
+ :resource, :resources,
34
+ :namespace, :scope, :concern, :member, :collection,
35
+ :draw
36
+ ]
37
+
38
+ route_methods.include?(node.method_name)
39
+ end
40
+
41
+ def check_hash_pairs(hash_node)
42
+ hash_node.pairs.each do |pair|
43
+ check_single_element_array(pair)
44
+ end
45
+ end
46
+
47
+ def check_single_element_array(pair)
48
+ value = pair.value
49
+ return unless value.array_type?
50
+ return unless value.children.size == 1
51
+
52
+ element = value.children.first
53
+ return unless element.sym_type? || element.str_type?
54
+
55
+ key = pair.key
56
+ key_source = key.source
57
+ element_source = element.source
58
+
59
+ message = format(
60
+ MSG,
61
+ key: key_source,
62
+ value: element_source
63
+ )
64
+
65
+ add_offense(value, message: message) do |corrector|
66
+ corrector.replace(value, element_source)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Nueca
5
- VERSION = '2.1.0'
5
+ VERSION = '2.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-nueca
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
@@ -152,6 +152,7 @@ files:
152
152
  - lib/rubocop/cop/rails/route_root_position.rb
153
153
  - lib/rubocop/cop/rails/route_separation.rb
154
154
  - lib/rubocop/cop/rails/route_sorting.rb
155
+ - lib/rubocop/cop/rails/route_unnecessary_array_notation.rb
155
156
  - lib/rubocop/cop/rails/time_zone_today.rb
156
157
  - lib/rubocop/cop/rswag/scattered_setup.rb
157
158
  - lib/rubocop/cop/shared/collection_context.rb