salsify_rubocop 0.47.0 → 0.47.1.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -1
- data/CHANGELOG.md +3 -0
- data/config/default.yml +5 -0
- data/lib/rubocop/cop/salsify/rspec_doc_string.rb +0 -2
- data/lib/rubocop/cop/salsify/style_dig.rb +64 -0
- data/lib/salsify_rubocop/version.rb +1 -1
- data/lib/salsify_rubocop.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dcbe21b6de7a233cf330a202722885b87a49a91
|
4
|
+
data.tar.gz: 2da2ae030c4cd422fecab9b16846759800b7e289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b12655ea2c8447a16bf5036f7576929b896fdff422d3b77b4274978edea6dd1042cde48da63502860735839642fb69f6fb4646ef00a0ed6ce740263cd6436c40
|
7
|
+
data.tar.gz: c9d2e1785dfded5b97b815456d6fd76a1f7f1edb68827cad7bb5ef7e9b59df1e1dd72379625426597756f8747384155dbf1c00708cb2f027d815642471c97b2f
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/config/default.yml
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Salsify
|
6
|
+
# Use `dig` for deeply nested access.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # good
|
11
|
+
# my_hash.dig('foo', 'bar')
|
12
|
+
# my_array.dig(0, 1)
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# my_hash['foo']['bar']
|
16
|
+
# my_hash['foo'] && my_hash['foo']['bar']
|
17
|
+
# my_array[0][1]
|
18
|
+
|
19
|
+
class StyleDig < Cop
|
20
|
+
extend TargetRubyVersion
|
21
|
+
|
22
|
+
minimum_target_ruby_version 2.3
|
23
|
+
|
24
|
+
MSG = 'Use `dig` for nested access.'.freeze
|
25
|
+
|
26
|
+
def_node_matcher :nested_access_match, <<-PATTERN
|
27
|
+
(send (send (send _receiver !:[]) :[] _) :[] _)
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
nested_access_match(node) do
|
32
|
+
match_node = node
|
33
|
+
# walk to outermost access node
|
34
|
+
match_node = match_node.parent while access_node?(match_node.parent)
|
35
|
+
add_offense(match_node, :expression, MSG)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def autocorrect(node)
|
40
|
+
access_node = node
|
41
|
+
source_args = [access_node.method_args.first.source]
|
42
|
+
while access_node?(access_node.children.first)
|
43
|
+
access_node = access_node.children.first
|
44
|
+
source_args << access_node.method_args.first.source
|
45
|
+
end
|
46
|
+
root_node = access_node.children.first
|
47
|
+
|
48
|
+
lambda do |corrector|
|
49
|
+
range = Parser::Source::Range.new(node.source_range.source_buffer,
|
50
|
+
root_node.source_range.end_pos,
|
51
|
+
node.source_range.end_pos)
|
52
|
+
corrector.replace(range, ".dig(#{source_args.reverse.join(', ')})")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def access_node?(node)
|
59
|
+
node && node.send_type? && node.method_name == :[]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/salsify_rubocop.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salsify_rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.47.
|
4
|
+
version: 0.47.1.rc0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- config/default.yml
|
105
105
|
- lib/rubocop/cop/salsify/rspec_doc_string.rb
|
106
106
|
- lib/rubocop/cop/salsify/rspec_string_literals.rb
|
107
|
+
- lib/rubocop/cop/salsify/style_dig.rb
|
107
108
|
- lib/rubocop/rspec/language/each_selector.rb
|
108
109
|
- lib/salsify_rubocop.rb
|
109
110
|
- lib/salsify_rubocop/version.rb
|
@@ -124,12 +125,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
125
|
version: '0'
|
125
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
127
|
requirements:
|
127
|
-
- - "
|
128
|
+
- - ">"
|
128
129
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
130
|
+
version: 1.3.1
|
130
131
|
requirements: []
|
131
132
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.6.
|
133
|
+
rubygems_version: 2.6.10
|
133
134
|
signing_key:
|
134
135
|
specification_version: 4
|
135
136
|
summary: Shared shared RuboCop configuration
|