salsify_rubocop 0.47.0 → 0.47.1.rc0

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
  SHA1:
3
- metadata.gz: 54eeb7c8935c758f5c04a6004192c22dda001a96
4
- data.tar.gz: ea4c89cf4327a24fa1d8e8dab2ca5c764f87ccb4
3
+ metadata.gz: 5dcbe21b6de7a233cf330a202722885b87a49a91
4
+ data.tar.gz: 2da2ae030c4cd422fecab9b16846759800b7e289
5
5
  SHA512:
6
- metadata.gz: 7b6e358f57155c0af444e5d541d2647c5fa5aae878d074a50fa160a392278c799ec2453db811eca0de802248d3af162dbbd152f8858177b1e7bb656af2ce515d
7
- data.tar.gz: bc7f74274cf5f7a729af34b178fa69f414848f6ae66c61426e9ba7f020b03823ab09f1cc51f9f93c9577fdfabc19643afce82b28cd2ccdc3a5d4c6ca0f82b7b9
6
+ metadata.gz: b12655ea2c8447a16bf5036f7576929b896fdff422d3b77b4274978edea6dd1042cde48da63502860735839642fb69f6fb4646ef00a0ed6ce740263cd6436c40
7
+ data.tar.gz: c9d2e1785dfded5b97b815456d6fd76a1f7f1edb68827cad7bb5ef7e9b59df1e1dd72379625426597756f8747384155dbf1c00708cb2f027d815642471c97b2f
data/.travis.yml CHANGED
@@ -1,7 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.4
3
+ - 2.4.0
4
4
  - 2.3.3
5
+ - 2.2.6
6
+ before_install:
7
+ # Workaround for https://github.com/sickill/rainbow/issues/48
8
+ - gem update --system
5
9
  script:
6
10
  - bundle exec rubocop
7
11
  - bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # salsify_rubocop
2
2
 
3
+ ## v0.47.1
4
+ - Add `Salsify/StyleDig` cop to recommend using `#dig` for deeply nested access.
5
+
3
6
  ## v0.47.0
4
7
  - Update to `rubocop` v0.47.1 and `rubocop-rspec` v1.10.0.
5
8
  - Enable `Bundler/OrderedGems` now that auto-correct is supported.
data/config/default.yml CHANGED
@@ -18,3 +18,8 @@ Salsify/RspecStringLiterals:
18
18
  # Include:
19
19
  # - 'spec/**/*'
20
20
 
21
+ Salsify/StyleDig:
22
+ Description: 'Recommend `dig` for deeply nested access.'
23
+ Enabled: true
24
+ AutoCorrect: false
25
+
@@ -6,8 +6,6 @@ module RuboCop
6
6
  # Check that doc strings for example groups and examples use either
7
7
  # single-quoted or double-quoted strings based on the enforced style.
8
8
  #
9
- # This cop is disabled by default.
10
- #
11
9
  # @example
12
10
  #
13
11
  # # When EnforcedStyle is double_quotes
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SalsifyRubocop
2
- VERSION = '0.47.0'.freeze
2
+ VERSION = '0.47.1.rc0'.freeze
3
3
  end
@@ -15,3 +15,4 @@ RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
15
15
  # cops
16
16
  require 'rubocop/cop/salsify/rspec_doc_string'
17
17
  require 'rubocop/cop/salsify/rspec_string_literals'
18
+ require 'rubocop/cop/salsify/style_dig'
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.0
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-01-20 00:00:00.000000000 Z
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: '0'
130
+ version: 1.3.1
130
131
  requirements: []
131
132
  rubyforge_project:
132
- rubygems_version: 2.6.8
133
+ rubygems_version: 2.6.10
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: Shared shared RuboCop configuration