datarockets-style 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0dbec2a9995d6607b63dafed5a123bfdb8704e3a
4
- data.tar.gz: 50bee07693998a77cf012e2cff94905095e111fc
3
+ metadata.gz: 803ec04bc148a97a6a025daedf5fb3b59590bfe8
4
+ data.tar.gz: 5a55887fbd7d868a061678cd7a26e020e29c82ee
5
5
  SHA512:
6
- metadata.gz: b6e5844c8bee41e0c621cf732808284d0f7596f1949c65396ef4dcbbccc830141209f3b1e8865d9e9b59b38ff5e2c36dd8dfe35f38cddfaad74a9f87101d9b33
7
- data.tar.gz: '096a00c0585458c1fd3ca87f0b116db3b90588c368e3a4c86dc76f253932516c3b80dd8099f8e09dc810ee4dbc8b14c5b9a7c5e66f0b378245f1eec9174faef9'
6
+ metadata.gz: 23b0c24787daf815f6620a6f9e378c707036f0a928205241740fcb56867d22f7cfd11242f99a99c9bd0d02868a2eef8586a100de83beabae8de2ff64ba0adb87
7
+ data.tar.gz: b925359074352f9bb255a03054affdf2d9b1c03207148267d7df533a09e6498aab6e1c65d9e7ecdd4b4c973472644f735e6729cfd285e6dc05a00b4199ed1a6b
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
4
4
 
5
5
  ## master (unreleased)
6
6
 
7
+ ## 0.4.0 (2019-08-13)
8
+
9
+ ### Changed
10
+
11
+ * Update rubocop-rspec to `1.35.0`. ([@r.dubrovsky][])
12
+ * Use contenxt-dependent style for curly braces around hash params. ([@v.kuzmik][])
13
+ * Use leading underscores in cached instance variable name (cop: `Naming/MemoizedInstanceVariableName`). ([@ula][])
14
+ * Allow use `for` wiht `RSpec/ContextWording` cop. ([@r.dubrovsky][])
15
+ * Change `Layout/AlignArguments` and `Layout/IndentFirstHashElement` cops for aliging arguments with fixed indentation. ([@r.dubrovsky][])
16
+ * Enable `Layout/MultilineMethodCallIndentation` cop for aliging arguments with fixed indentation. ([@r.dubrovsky][], [@ula][])
17
+
7
18
  ## 0.3.0 (2019-08-02)
8
19
 
9
20
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datarockets-style (0.3.0)
4
+ datarockets-style (0.4.0)
5
5
  rubocop (~> 0.74.0)
6
- rubocop-rspec (~> 1.34)
6
+ rubocop-rspec (~> 1.35)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -22,7 +22,7 @@ GEM
22
22
  rainbow (>= 2.2.2, < 4.0)
23
23
  ruby-progressbar (~> 1.7)
24
24
  unicode-display_width (>= 1.4.0, < 1.7)
25
- rubocop-rspec (1.34.1)
25
+ rubocop-rspec (1.35.0)
26
26
  rubocop (>= 0.60.0)
27
27
  ruby-progressbar (1.10.1)
28
28
  unicode-display_width (1.6.0)
data/README.md CHANGED
@@ -44,6 +44,25 @@ $ bundle exec rubocop
44
44
 
45
45
  You do not need to include rubocop directly in your application's dependencies. Datarockets-style will include a specific version of `rubocop` and `rubocop-rspec` that is shared across all projects.
46
46
 
47
+ ### Configurable cops
48
+
49
+ There are some areas in which there is no clear consensus in datarockets team regarding a particular style (like string literal quoting).
50
+ In such scenarios, all popular styles are acknowledged and it’s up to you to pick one and apply it consistently.
51
+ For that just set up these cops before starting of usage.
52
+
53
+ #### Style/StringLiterals
54
+
55
+ There are two popular styles in the Ruby community, both of which are considered good - single quotes by default and double quotes by default.
56
+ There is no clear consensus about this style in the Ruby community and in the datarockets team.
57
+ So we suggest just to set up a [preferable style](https://rubocop.readthedocs.io/en/latest/cops_style/#stylestringliterals) before running this gem.
58
+
59
+ P.S. The string literals in this gem are using double quotes by default.
60
+
61
+ ##### Tips
62
+
63
+ For an existing project, we suggest to run rubocop with both styles and choose which has fewer offenses (which is more popular in the current project).
64
+
65
+
47
66
  ## Changelog
48
67
 
49
68
  Datarockets Style's changelog is available [here](CHANGELOG.md).
data/STYLE_GUIDE.md CHANGED
@@ -26,12 +26,13 @@ This is a small list of differences which we have when compared with community s
26
26
  Limit lines to 120 characters.
27
27
  <sup>[[link](#style-line-length)]</sup>
28
28
 
29
- * <a name="style-double-quotes"></a>
30
- Prefer double-quotes unless your string literal contains " or escape characters you want to suppress.
31
- <sup>[[link](#style-double-quotes)]</sup>
29
+ * <a name="style-string-quotes"></a>
30
+ Adopt a consistent string literal quoting style.
31
+ <sup>[[link](#style-string-quotes)]</sup>
32
32
 
33
33
  * <a name="style-hash-aligning"></a>
34
34
  If elements of a hash literal span more than one line we're aligning them by keys.
35
+ Also, the first hash key is aligned by an indentation level.
35
36
  <sup>[[link](#style-hash-aligning)]</sup>
36
37
 
37
38
 
@@ -41,22 +42,50 @@ This is a small list of differences which we have when compared with community s
41
42
  foo: bar,
42
43
  ba: baz
43
44
  }
45
+
44
46
  {
45
47
  foo: bar,
46
48
  ba: baz
47
49
  }
48
50
 
51
+ {
52
+ foo: bar,
53
+ ba: baz
54
+ }
55
+
56
+ {
57
+ foo: {
58
+ bar: bar,
59
+ ba: baz
60
+ }
61
+ }
62
+
63
+ method_call({
64
+ its_like: :this
65
+ })
66
+
49
67
  # good
50
68
  {
51
69
  foo: bar,
52
70
  ba: baz
53
71
  }
72
+
73
+ {
74
+ foo: {
75
+ bar: bar,
76
+ ba: baz
77
+ }
78
+ }
79
+
80
+ method_call({
81
+ no: :difference
82
+ })
54
83
  ```
55
84
 
56
- * <a name="style-keyword-arguments-aligning"></a>
57
- There is one exception in the rule above when the hash literal is passed as method argument.
58
- In this case we just use an indentation level.
59
- <sup>[[link](#style-keyword-arguments-aligning)]</sup>
85
+ * <a name="style-arguments-aligning"></a>
86
+ All arguments on a multi-line method definition are aligning by an indentation level.
87
+ This rule works as for keywork arguments, as for usual arguments.
88
+ <sup>[[link](#style-arguments-aligning)]</sup>
60
89
 
61
90
  ```ruby
62
91
  # bad
@@ -66,6 +95,14 @@ do_something(foo: 1,
66
95
  # good
67
96
  do_something(foo: 1,
68
97
  bar: 2)
98
+
99
+ # good
100
+ foo :bar,
101
+ :baz
102
+
103
+ # bad
104
+ foo :bar,
105
+ :baz
69
106
  ```
70
107
 
71
108
  * <a name="style-parameters-aligning"></a>
@@ -109,6 +146,35 @@ def foo(
109
146
  end
110
147
  ```
111
148
 
149
+ * <a name="style-multiline-method-call-indentation">
150
+ The indentation of the method name part in method calls that span more than one line are aligning by an indentation level.
151
+ <sup>[[link](#style-multiline-method-call-indentation)]</sup>
152
+
153
+ ```ruby
154
+ # bad
155
+ while myvariable
156
+ .b
157
+ # do something
158
+ end
159
+
160
+ # bad
161
+ Thing.a
162
+ .b
163
+ .c
164
+
165
+ # good
166
+ while myvariable
167
+ .b
168
+
169
+ # do something
170
+ end
171
+
172
+ # good
173
+ Thing.a
174
+ .b
175
+ .c
176
+ ```
177
+
112
178
  * <a name="style-end-aligning"></a>
113
179
  The `end` shall be aligned with the left-hand-side of the variable assignment. But we prefer not to use code blocks with `end` for variable assignment and prefer move it into the separate methods.
114
180
  <sup>[[link](#style-end-aligning)]</sup>
@@ -163,16 +229,16 @@ end
163
229
  # bad
164
230
  class A
165
231
  def test
166
- puts 'hello'
167
- puts 'world'
232
+ puts "hello"
233
+ puts "world"
168
234
  end
169
235
  end
170
236
 
171
237
  # bad
172
238
  class A
173
239
  def test
174
- puts 'hello'
175
- puts 'world'
240
+ puts "hello"
241
+ puts "world"
176
242
  end
177
243
 
178
244
  protected
@@ -189,16 +255,16 @@ end
189
255
  # good
190
256
  class A
191
257
  def test
192
- puts 'hello'
193
- puts 'world'
258
+ puts "hello"
259
+ puts "world"
194
260
  end
195
261
  end
196
262
 
197
263
  # good
198
264
  class A
199
265
  def test
200
- puts 'hello'
201
- puts 'world'
266
+ puts "hello"
267
+ puts "world"
202
268
  end
203
269
 
204
270
  protected
@@ -266,12 +332,48 @@ def self.foo(bar)
266
332
  end
267
333
  ```
268
334
 
335
+ * <a name="style-cached-instance-variable-name"></a>
336
+ Use leading underscores in cached instance variable name
337
+ <sup>[[link](#style-cached-instance-variable-name)]</sup>
338
+
339
+ ```ruby
340
+ # bad
341
+ def foo
342
+ @something ||= calculate_expensive_thing
343
+ end
344
+
345
+ # bad
346
+ def foo
347
+ @foo ||= calculate_expensive_thing
348
+ end
349
+
350
+ # good
351
+ def foo
352
+ @_foo ||= calculate_expensive_thing
353
+ end
354
+ ```
355
+
269
356
  * <a name="style-magic-link"></a>
270
357
  There are not any requried rules for `frozen_string_literal` magic url.
271
358
  Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends on the project.
272
359
  So set up it on the local rubocop config manually.
273
360
  <sup>[[link](#style-magic-link)]</sup>
274
361
 
362
+ * <a name="style-braces-around-hash-params"></a>
363
+ Not to use braces around the last hash literal parameter.
364
+ But requires braces if the second to last parameter is also a hash literal.
365
+ <sup>[[link](#style-braces-around-hash-params)]</sup>
366
+
367
+ ```ruby
368
+ # bad
369
+ some_method(x, y, {a: 1, b: 2})
370
+ some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
371
+
372
+ # good
373
+ some_method(x, y, a: 1, b: 2)
374
+ some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
375
+ ```
376
+
275
377
  ## Rspec
276
378
 
277
379
  * <a name="rspec-betterrspec"></a>
@@ -291,21 +393,37 @@ end
291
393
  # bad
292
394
  subject { service.call }
293
395
 
294
- it 'test' do
396
+ it "test" do
295
397
  expect(subject).to eq value
296
398
  end
297
399
 
298
400
  # ok
299
401
  subject(:service_call) { service.call }
300
402
 
301
- it 'test' do
403
+ it "test" do
302
404
  expect(service_call).to eq value
303
405
  end
304
406
 
305
407
  # better
306
408
  subject { service.call }
307
409
 
308
- it 'test' do
410
+ it "test" do
309
411
  is_expected.to eq value
310
412
  end
311
413
  ```
414
+
415
+ * <a name="rspec-context-wording"></a>
416
+ When describing a context, start its description with "when", "for", with" or "without".
417
+ <sup>[[link](#rspec-context-wording)]</sup>
418
+
419
+ ```ruby
420
+ # bad
421
+ context "the display name not present" do
422
+ # ...
423
+ end
424
+
425
+ # good
426
+ context "when the display name is not present" do
427
+ # ...
428
+ end
429
+ ```
data/config/default.yml CHANGED
@@ -18,6 +18,9 @@ Bundler/DuplicatedGem:
18
18
  Bundler/OrderedGems:
19
19
  TreatCommentsAsGroupSeparators: true
20
20
 
21
+ Layout/AlignArguments:
22
+ EnforcedStyle: with_fixed_indentation
23
+
21
24
  Layout/AlignHash:
22
25
  EnforcedLastArgumentHashStyle: always_ignore
23
26
 
@@ -31,6 +34,12 @@ Layout/EndAlignment:
31
34
  Layout/IndentationConsistency:
32
35
  EnforcedStyle: normal
33
36
 
37
+ Layout/IndentFirstHashElement:
38
+ EnforcedStyle: consistent
39
+
40
+ Layout/MultilineMethodCallIndentation:
41
+ EnforcedStyle: indented
42
+
34
43
  Layout/SpaceInsideHashLiteralBraces:
35
44
  EnforcedStyle: no_space
36
45
  EnforcedStyleForEmptyBraces: no_space
@@ -46,12 +55,25 @@ Metrics/BlockLength:
46
55
  Metrics/LineLength:
47
56
  Max: 120
48
57
 
58
+ Naming/MemoizedInstanceVariableName:
59
+ EnforcedStyleForLeadingUnderscores: required
60
+
49
61
  Naming/RescuedExceptionsVariableName:
50
62
  PreferredName: error
51
63
 
64
+ RSpec/ContextWording:
65
+ Prefixes:
66
+ - when
67
+ - with
68
+ - without
69
+ - for
70
+
52
71
  RSpec/ImplicitSubject:
53
72
  Enabled: false
54
73
 
74
+ Style/BracesAroundHashParameters:
75
+ EnforcedStyle: context_dependent
76
+
55
77
  Style/EmptyMethod:
56
78
  EnforcedStyle: expanded
57
79
 
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "rubocop", "~> 0.74.0"
34
- spec.add_dependency "rubocop-rspec", "~> 1.34"
34
+ spec.add_dependency "rubocop-rspec", "~> 1.35"
35
35
 
36
36
  spec.add_development_dependency "bundler", "~> 1.16"
37
37
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,5 +1,5 @@
1
1
  module Datarockets
2
2
  module Style
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datarockets-style
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Dubrovsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-02 00:00:00.000000000 Z
11
+ date: 2019-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.34'
33
+ version: '1.35'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.34'
40
+ version: '1.35'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement