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 +4 -4
- data/README.md +1 -1
- data/lib/rubocop/cop/rails/route_unnecessary_array_notation.rb +72 -0
- data/lib/rubocop/nueca/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e2e8263941b4c5f0934ad7fb9f8df991e90583476f10fc3290a3c7dd2f917ff
|
4
|
+
data.tar.gz: 0e503986f5bfd5003b40beee3844cfeb9ae5cdc179b2d4576d139e1d244ba18f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc56766f7ecaa64cb93001e8ee3cd4eca0250bbf4b509d41f2fb6bcbe36d3d30e1d34dba4bdcdbcd26a4f8cd143600000364c5b9ad184793b99bc24f3992373e
|
7
|
+
data.tar.gz: 1e89c75c3f19fea9dc29979dd38af0695f4ea4e77f126e7d3d0bc407853f2a3e61baef1f9862016101ee280775bf4ca0c1a24f5cac2f1a48c4418d8cb4c03f05
|
data/README.md
CHANGED
@@ -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
|
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.
|
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
|