gitlab-styles 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6524a0d089736b32d3cade47711da247bac96961d97da814715c11ea977237b7
4
- data.tar.gz: 83876a151dbd560911b4d4c8b92d9692bd3192920521f8e7c2b69f030478faaf
3
+ metadata.gz: a5c5dbefc4cc4e9fce7794623c0688cb4bfb145e186a0c12376e8cf973b09c1b
4
+ data.tar.gz: ce47876a9ac193036759b85aea6ef23d1c2caf3037e057d640849fe2cce8b197
5
5
  SHA512:
6
- metadata.gz: 1c5840d3fc84a7f0979a19cc86cfac8b1408c9d27c5aed1a61f971789ac3feb8b5baeea236f7a16d69a04018d6941152b97a407516fafe1cec69058648158489
7
- data.tar.gz: 93815193b0ead85db1823585a6fffe7a2db1f564fc8f1b02eaac18c286d43b87b2b42e947af4813bfec45d85d6261d973e8ae1984cf282c56388ca68ccb4a0e3
6
+ metadata.gz: 3f2713efa71f126be8e9bf9b44ca4caef0c09f69bdbec2f2abc143184356891341b4b423606f742ea7d517feabec0dadd259553846adcf8c068c80dcc8e588dd
7
+ data.tar.gz: 4c83cc34cebefb7b7d0bc53adeec8b733f9adefbe446c7e46cd81f60fa136de48445de38b71533edf76f32789c3fa4caf46b27860dd23177a3607377f81a6397
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gitlab-rubocop.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ # Pin these dependencies, otherwise a new rule could break the CI pipelines
8
+ gem 'rubocop', '0.52.0'
9
+ gem 'rubocop-rspec', '1.20.1'
10
+ end
@@ -5,6 +5,7 @@ require 'gitlab/styles/rubocop/cop/redirect_with_status'
5
5
  require 'gitlab/styles/rubocop/cop/polymorphic_associations'
6
6
  require 'gitlab/styles/rubocop/cop/active_record_dependent'
7
7
  require 'gitlab/styles/rubocop/cop/in_batches'
8
+ require 'gitlab/styles/rubocop/cop/line_break_after_guard_clauses'
8
9
  require 'gitlab/styles/rubocop/cop/rspec/single_line_hook'
9
10
 
10
11
  module Gitlab
@@ -0,0 +1,102 @@
1
+ module Gitlab
2
+ module Styles
3
+ module Rubocop
4
+ module Cop
5
+ # Ensures a line break after guard clauses.
6
+ #
7
+ # @example
8
+ # # bad
9
+ # return unless condition
10
+ # do_stuff
11
+ #
12
+ # # good
13
+ # return unless condition
14
+ #
15
+ # do_stuff
16
+ #
17
+ # # bad
18
+ # raise if condition
19
+ # do_stuff
20
+ #
21
+ # # good
22
+ # raise if condition
23
+ #
24
+ # do_stuff
25
+ #
26
+ # Multiple guard clauses are allowed without
27
+ # line break.
28
+ #
29
+ # # good
30
+ # return unless condition_a
31
+ # return unless condition_b
32
+ #
33
+ # do_stuff
34
+ #
35
+ # Guard clauses in case statement are allowed without
36
+ # line break.
37
+ #
38
+ # # good
39
+ # case model
40
+ # when condition_a
41
+ # return true unless condition_b
42
+ # when
43
+ # ...
44
+ # end
45
+ #
46
+ # Guard clauses before end are allowed without
47
+ # line break.
48
+ #
49
+ # # good
50
+ # if condition_a
51
+ # do_something
52
+ # else
53
+ # do_something_else
54
+ # return unless condition
55
+ # end
56
+ #
57
+ # do_something_more
58
+ class LineBreakAfterGuardClauses < RuboCop::Cop::Cop
59
+ MSG = 'Add a line break after guard clauses'.freeze
60
+
61
+ def_node_matcher :guard_clause_node?, <<-PATTERN
62
+ [{(send nil? {:raise :fail :throw} ...) return break next} single_line?]
63
+ PATTERN
64
+
65
+ def on_if(node)
66
+ return unless node.single_line?
67
+ return unless guard_clause?(node)
68
+ return if next_line(node).blank? || clause_last_line?(next_line(node)) || guard_clause?(next_sibling(node))
69
+
70
+ add_offense(node, location: :expression, message: MSG)
71
+ end
72
+
73
+ def autocorrect(node)
74
+ lambda do |corrector|
75
+ corrector.insert_after(node.loc.expression, "\n")
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def guard_clause?(node)
82
+ return false unless node.if_type?
83
+
84
+ guard_clause_node?(node.if_branch)
85
+ end
86
+
87
+ def next_sibling(node)
88
+ node.parent.children[node.sibling_index + 1]
89
+ end
90
+
91
+ def next_line(node)
92
+ processed_source[node.loc.line]
93
+ end
94
+
95
+ def clause_last_line?(line)
96
+ line =~ /^\s*(?:end|elsif|else|when|rescue|ensure)/
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Styles
3
- VERSION = '2.1.0'.freeze
3
+ VERSION = '2.2.0'.freeze
4
4
  end
5
5
  end
@@ -191,14 +191,20 @@ Layout/SpaceBeforeComment:
191
191
  Layout/SpaceBeforeSemicolon:
192
192
  Enabled: true
193
193
 
194
- # Checks for spaces inside square brackets.
195
- Layout/SpaceInsideBrackets:
194
+ # Checks that brackets used for array literals have or don't have
195
+ # surrounding space depending on configuration..
196
+ Layout/SpaceInsideArrayLiteralBrackets:
196
197
  Enabled: true
197
198
 
198
199
  # Use spaces inside hash literal braces - or don't.
199
200
  Layout/SpaceInsideHashLiteralBraces:
200
201
  Enabled: true
201
202
 
203
+ # Checks that reference brackets have or don't have
204
+ # surrounding space depending on configuration.
205
+ Layout/SpaceInsideReferenceBrackets:
206
+ Enabled: true
207
+
202
208
  # No spaces inside range literals.
203
209
  Layout/SpaceInsideRangeLiteral:
204
210
  Enabled: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-styles
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
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -121,6 +121,7 @@ files:
121
121
  - lib/gitlab/styles/rubocop/cop/custom_error_class.rb
122
122
  - lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
123
123
  - lib/gitlab/styles/rubocop/cop/in_batches.rb
124
+ - lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb
124
125
  - lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
125
126
  - lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
126
127
  - lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
@@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
161
  version: '0'
161
162
  requirements: []
162
163
  rubyforge_project:
163
- rubygems_version: 2.7.0
164
+ rubygems_version: 2.7.3
164
165
  signing_key:
165
166
  specification_version: 4
166
167
  summary: GitLab style guides and shared style configs.