gitlab-styles 5.1.0 → 5.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: 30bceb716d5e39ed5e48f4d42fd4457eb0a0608be5419e03ac325a3db385da08
4
- data.tar.gz: 50058ac5c12783bd57e55e9cf19973ffb9aec21c277e3ff20839849271feb64c
3
+ metadata.gz: 73ee648b7b50478acc9d34d9a84e108a69ea1067b28b9bd9ab04f364b09f5ee1
4
+ data.tar.gz: a157fb76a7d78910b51231f3cda7388e1db87080e0b52a9b623322ba35664bff
5
5
  SHA512:
6
- metadata.gz: b5f700edd701ed7b465a1e5bac5971dee3e7f31df2603a03dc76fd048feb98ec23e4fb1e70b2704e5f3899eecb0c2f6817a1d508bcf1708a092587e9ba2a4f86
7
- data.tar.gz: 3ba624b97b7bab08fa1fb26b82cae5f72494e639a1c7cc000d95098ad39807218e15e118654a2518076ae3409f31ee55caa980e3d88cac26394d26e10f079b0f
6
+ metadata.gz: 9a46d0faf108cf1a4a33209dd1e4f6e6021c28e0d877e4835d07980bcc1810bb0d378198505f146d7175111449c3d919923970a0550ecdd55bb43a66310f199e
7
+ data.tar.gz: 621abc0dbb787baec9491369a45061d608c5bf71b31b31530bb63426b3ee0bb3e53ea16d0a63656bf136097023953eab287dabeb274d8a95bd9af991686cdaa0
@@ -0,0 +1,21 @@
1
+ ## Description of the proposal
2
+
3
+ <!--
4
+ Please describe the proposal and add a link to the source (for example, http://www.betterspecs.org/).
5
+ -->
6
+
7
+ ### Check-list
8
+
9
+ - [ ] Mention this proposal in the relevant Slack channels (e.g. `#development`, `#backend`, `#frontend`)
10
+ - [ ] If there is a choice to make between two potential styles, set up an emoji vote in the MR:
11
+ - CHOICE_A: :a:
12
+ - CHOICE_B: :b:
13
+ - Vote yourself for both choices so that people know these are the choices
14
+ - [ ] The MR doesn't have significant objections, and is getting a majority of :+1: vs :-1: (remember that [we don't need to reach a consensus](https://about.gitlab.com/handbook/values/#collaboration-is-not-consensus))
15
+ - [ ] (If applicable) One style is getting a majority of vote (compared to the other choice)
16
+ - [ ] (If applicable) Update the MR with the chosen style
17
+ - [ ] Follow the [review process](https://docs.gitlab.com/ee/development/code_review.html) as usual
18
+
19
+ /label ~"Engineering Productivity" ~"development guidelines" ~"static code analysis"
20
+
21
+ /cc @gitlab-org/maintainers/rails-backend
@@ -17,6 +17,7 @@ require 'gitlab/styles/rubocop/cop/rspec/have_link_parameters'
17
17
  require 'gitlab/styles/rubocop/cop/rspec/verbose_include_metadata'
18
18
  require 'gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example'
19
19
  require 'gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block'
20
+ require 'gitlab/styles/rubocop/cop/rspec/example_starting_character'
20
21
 
21
22
  module Gitlab
22
23
  module Styles
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop-rspec'
4
+ require_relative 'base'
5
+
6
+ module Gitlab
7
+ module Styles
8
+ module Rubocop
9
+ module Cop
10
+ module RSpec
11
+ # Checks for common mistakes in example descriptions.
12
+ #
13
+ # This cop will correct docstrings that begin/end with space or words that start with a capital letter.
14
+ #
15
+ # @see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/46336#note_442669518
16
+ #
17
+ # @example
18
+ # # bad
19
+ # it 'Does something' do
20
+ # end
21
+ #
22
+ # # good
23
+ # it 'does nothing' do
24
+ # end
25
+ #
26
+ # @example
27
+ # # bad
28
+ # it ' does something' do
29
+ # end
30
+ #
31
+ # # good
32
+ # it 'does something' do
33
+ # end
34
+ #
35
+ # @example
36
+ # # bad
37
+ # it 'does something ' do
38
+ # end
39
+ #
40
+ # # good
41
+ # it 'does something' do
42
+ # end
43
+ #
44
+ # @example
45
+ # # bad
46
+ # it ' does something ' do
47
+ # end
48
+ #
49
+ # # good
50
+ # it 'does something' do
51
+ # end
52
+ class ExampleStartingCharacter < Base
53
+ extend RuboCop::Cop::AutoCorrector
54
+
55
+ MSG = 'Only start words with lowercase alpha with no leading/trailing spaces when describing your tests.'
56
+
57
+ def_node_matcher :it_description, <<-PATTERN
58
+ (block (send _ :it ${
59
+ (str $_)
60
+ (dstr (str $_ ) ...)
61
+ } ...) ...)
62
+ PATTERN
63
+
64
+ def on_block(node)
65
+ it_description(node) do |description_node, _message|
66
+ add_wording_offense(description_node, MSG) if invalid_description?(text(description_node))
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def add_wording_offense(node, message)
73
+ docstring = docstring(node)
74
+ add_offense(docstring, message: message) do |corrector|
75
+ corrector.replace(docstring, replacement_text(node))
76
+ end
77
+ end
78
+
79
+ def docstring(node)
80
+ expr = node.loc.expression
81
+
82
+ Parser::Source::Range.new(
83
+ expr.source_buffer,
84
+ expr.begin_pos + 1,
85
+ expr.end_pos - 1
86
+ )
87
+ end
88
+
89
+ def invalid_description?(message)
90
+ message.match?(/(^([A-Z]{1}[a-z]+\s|\s)|\s$)/)
91
+ end
92
+
93
+ def replacement_text(node)
94
+ text = text(node)
95
+
96
+ text.strip!
97
+
98
+ text = downcase_first_letter(text) if invalid_description?(text)
99
+
100
+ text
101
+ end
102
+
103
+ # Recursive processing is required to process nested dstr nodes
104
+ # that is the case for \-separated multiline strings with interpolation.
105
+ def text(node)
106
+ case node.type
107
+ when :dstr
108
+ node.node_parts.map { |child_node| text(child_node) }.join
109
+ when :str
110
+ node.value
111
+ when :begin
112
+ node.source
113
+ end
114
+ end
115
+
116
+ def downcase_first_letter(str)
117
+ str[0].downcase + str[1..]
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '5.1.0'
5
+ VERSION = '5.2.0'
6
6
  end
7
7
  end
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: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-10 00:00:00.000000000 Z
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - gitlab_rubygems@gitlab.com
128
128
  executables: []
@@ -132,6 +132,7 @@ files:
132
132
  - ".editorconfig"
133
133
  - ".gitignore"
134
134
  - ".gitlab-ci.yml"
135
+ - ".gitlab/merge_request_templates/New Static Analysis Check.md"
135
136
  - ".gitlab/merge_request_templates/Release.md"
136
137
  - ".rspec"
137
138
  - ".rubocop.yml"
@@ -160,6 +161,7 @@ files:
160
161
  - lib/gitlab/styles/rubocop/cop/rspec/base.rb
161
162
  - lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_let_block.rb
162
163
  - lib/gitlab/styles/rubocop/cop/rspec/empty_line_after_shared_example.rb
164
+ - lib/gitlab/styles/rubocop/cop/rspec/example_starting_character.rb
163
165
  - lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
164
166
  - lib/gitlab/styles/rubocop/cop/rspec/single_line_hook.rb
165
167
  - lib/gitlab/styles/rubocop/cop/rspec/verbose_include_metadata.rb
@@ -187,7 +189,7 @@ homepage: https://gitlab.com/gitlab-org/gitlab-styles
187
189
  licenses:
188
190
  - MIT
189
191
  metadata: {}
190
- post_install_message:
192
+ post_install_message:
191
193
  rdoc_options: []
192
194
  require_paths:
193
195
  - lib
@@ -203,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
205
  version: '0'
204
206
  requirements: []
205
207
  rubygems_version: 3.1.4
206
- signing_key:
208
+ signing_key:
207
209
  specification_version: 4
208
210
  summary: GitLab style guides and shared style configs.
209
211
  test_files: []