datarockets-style 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +12 -5
- data/README.md +9 -0
- data/config/base.yml +14 -18
- data/config/rails.yml +7 -0
- data/config/rspec.yml +1 -1
- data/datarockets-style.gemspec +3 -2
- data/doc/STYLE_GUIDE.md +13 -15
- data/doc/STYLE_GUIDE_RAILS.md +27 -1
- data/lib/datarockets/style/cop/layout/array_alignment_extended.rb +9 -10
- data/lib/datarockets/style/cop/style/nested_interpolation.rb +37 -0
- data/lib/datarockets/style/version.rb +1 -1
- data/lib/datarockets/style.rb +1 -0
- data/manual/cops_layout.md +74 -0
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2fd6f40031f396d111c19513fa8e0af187c19ce
|
4
|
+
data.tar.gz: ed7157fb4be39d3c0d62bd3f57cd03fcacf04c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c357e907de9be6791e57a7917597b4d25007e47dadebef87af8d4a2677bf93f39d21217da4710d4aef2efc55834839ff3b26249a24ae3f2eb9c66beca41770c
|
7
|
+
data.tar.gz: e07b9b1d21dc783acf09448ab43a4a78abd8235ec0b03bdfca8ba104aea53650492c873df493f85cf5a64e84b4820e8f5fe57663fde956ec41e5a7a7a5c52343
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,27 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
4
4
|
|
5
5
|
## master (unreleased)
|
6
6
|
|
7
|
+
## 0.8.0 (2020-02-20)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* Add `Style/NestedInterpolation` cop. ([@r.dubrovsky][])
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
* Update rubocop to `0.80.0`. ([@r.dubrovsky][])
|
16
|
+
* Add `Style/HashEachMethods`, `Style/HashTransformKey`, `Style/HashTransformValues` cops.
|
17
|
+
* [#7641](https://github.com/rubocop-hq/rubocop/issues/7641): Remove `Style/BracesAroundHashParameters` cop.
|
18
|
+
|
19
|
+
* Update rubocop-rspec to `1.38.1`.
|
20
|
+
* Add RSpec/RepeatedExampleGroupBody cop. ([@ula][])
|
21
|
+
* Add RSpec/RepeatedExampleGroupDescription cop. ([@ula][])
|
22
|
+
|
23
|
+
* Enable `rubocop-rails` cops for rails config. ([@ula][])
|
24
|
+
* Setup `Style/Documentation` for rails config. ([@r.dubrovsky][])
|
25
|
+
* Setup `Style/ClassAndModuleChildren` cop. ([@r.dubrovsky][])
|
26
|
+
* Enable `RSpec/LetSetup` cop. ([@r.dubrovsky][])
|
27
|
+
|
7
28
|
## 0.7.0 (2020-01-27)
|
8
29
|
|
9
30
|
### Added
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
datarockets-style (0.
|
5
|
-
rubocop (~> 0.
|
6
|
-
rubocop-
|
4
|
+
datarockets-style (0.8.0)
|
5
|
+
rubocop (~> 0.80)
|
6
|
+
rubocop-rails (~> 2.4)
|
7
|
+
rubocop-rspec (~> 1.38)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
@@ -23,8 +24,10 @@ GEM
|
|
23
24
|
pry-byebug (3.7.0)
|
24
25
|
byebug (~> 11.0)
|
25
26
|
pry (~> 0.10)
|
27
|
+
rack (2.2.2)
|
26
28
|
rainbow (3.0.0)
|
27
29
|
rake (13.0.1)
|
30
|
+
rexml (3.2.4)
|
28
31
|
rspec (3.9.0)
|
29
32
|
rspec-core (~> 3.9.0)
|
30
33
|
rspec-expectations (~> 3.9.0)
|
@@ -38,14 +41,18 @@ GEM
|
|
38
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
42
|
rspec-support (~> 3.9.0)
|
40
43
|
rspec-support (3.9.0)
|
41
|
-
rubocop (0.
|
44
|
+
rubocop (0.80.0)
|
42
45
|
jaro_winkler (~> 1.5.1)
|
43
46
|
parallel (~> 1.10)
|
44
47
|
parser (>= 2.7.0.1)
|
45
48
|
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
rexml
|
46
50
|
ruby-progressbar (~> 1.7)
|
47
51
|
unicode-display_width (>= 1.4.0, < 1.7)
|
48
|
-
rubocop-
|
52
|
+
rubocop-rails (2.4.2)
|
53
|
+
rack (>= 1.1)
|
54
|
+
rubocop (>= 0.72.0)
|
55
|
+
rubocop-rspec (1.38.1)
|
49
56
|
rubocop (>= 0.68.1)
|
50
57
|
ruby-progressbar (1.10.1)
|
51
58
|
unicode-display_width (1.6.1)
|
data/README.md
CHANGED
@@ -76,6 +76,11 @@ There are some areas in which there is no clear consensus in datarockets team re
|
|
76
76
|
In such scenarios, all popular styles are acknowledged and it’s up to you to pick one and apply it consistently.
|
77
77
|
For that just set up these cops before starting of usage.
|
78
78
|
|
79
|
+
#### RSpec/LetSetup
|
80
|
+
|
81
|
+
[This cop](https://rubocop-rspec.readthedocs.io/en/latest/cops_rspec/#rspecletsetup) is enabled by default and we suggest not to use unreferenced `let` variables in your test cases.
|
82
|
+
However, if it feels like the cop should be enabled and tests can't be written w/o them, please create an issue with your cases so that we can re-thinking our solution about enabling this cop.
|
83
|
+
|
79
84
|
#### Style/StringLiterals
|
80
85
|
|
81
86
|
There are two popular styles in the Ruby community, both of which are considered good - single quotes by default and double quotes by default.
|
@@ -88,6 +93,10 @@ P.S. The string literals in this gem are using double quotes by default.
|
|
88
93
|
|
89
94
|
For an existing project, we suggest running rubocop with both styles and choose which has fewer offenses (which is more popular in the current project).
|
90
95
|
|
96
|
+
### Custom cops
|
97
|
+
|
98
|
+
We have custom cops. You can find specification for them [here](manual).
|
99
|
+
|
91
100
|
## Formatters
|
92
101
|
|
93
102
|
### ToDo list formatter
|
data/config/base.yml
CHANGED
@@ -16,28 +16,12 @@ Layout/ArrayAlignmentExtended:
|
|
16
16
|
Description: >-
|
17
17
|
Align the elements of an array literal if they span more than
|
18
18
|
one line.
|
19
|
-
# Alignment of elements of a multi-line array.
|
20
|
-
#
|
21
|
-
# The `with_first_parameter` style aligns the following lines along the same
|
22
|
-
# column as the first element.
|
23
|
-
#
|
24
|
-
# array = [1, 2, 3,
|
25
|
-
# 4, 5, 6]
|
26
|
-
#
|
27
|
-
# The `with_fixed_indentation` style aligns the following lines with one
|
28
|
-
# level of indentation relative to the start of the line with start of array.
|
29
|
-
#
|
30
|
-
# array = [1, 2, 3,
|
31
|
-
# 4, 5, 6]
|
32
19
|
EnforcedStyle: with_fixed_indentation
|
33
20
|
SupportedStyles:
|
34
21
|
- with_first_parameter
|
35
22
|
- with_fixed_indentation
|
36
|
-
# By default, the indentation width from Layout/IndentationWidth is used
|
37
|
-
# But it can be overridden by setting this parameter
|
38
23
|
IndentationWidth: ~
|
39
24
|
|
40
|
-
|
41
25
|
Layout/HashAlignment:
|
42
26
|
EnforcedLastArgumentHashStyle: always_ignore
|
43
27
|
|
@@ -70,14 +54,26 @@ Naming/MemoizedInstanceVariableName:
|
|
70
54
|
Naming/RescuedExceptionsVariableName:
|
71
55
|
PreferredName: error
|
72
56
|
|
73
|
-
Style/
|
74
|
-
EnforcedStyle:
|
57
|
+
Style/ClassAndModuleChildren:
|
58
|
+
EnforcedStyle: nested
|
75
59
|
|
76
60
|
Style/EmptyMethod:
|
77
61
|
EnforcedStyle: expanded
|
78
62
|
|
63
|
+
Style/HashEachMethods:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
Style/HashTransformKeys:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
Style/HashTransformValues:
|
70
|
+
Enabled: true
|
71
|
+
|
79
72
|
Style/FrozenStringLiteralComment:
|
80
73
|
Enabled: false
|
81
74
|
|
75
|
+
Style/NestedInterpolation:
|
76
|
+
Enabled: true
|
77
|
+
|
82
78
|
Style/StringLiterals:
|
83
79
|
EnforcedStyle: double_quotes
|
data/config/rails.yml
CHANGED
data/config/rspec.yml
CHANGED
data/datarockets-style.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_dependency "rubocop", "~> 0.
|
34
|
-
spec.add_dependency "rubocop-
|
33
|
+
spec.add_dependency "rubocop", "~> 0.80"
|
34
|
+
spec.add_dependency "rubocop-rails", "~> 2.4"
|
35
|
+
spec.add_dependency "rubocop-rspec", "~> 1.38"
|
35
36
|
end
|
data/doc/STYLE_GUIDE.md
CHANGED
@@ -35,6 +35,19 @@ This is a small list of differences which we have when compared with community s
|
|
35
35
|
Adopt a consistent string literal quoting style.
|
36
36
|
<sup>[[link](#style-string-quotes)]</sup>
|
37
37
|
|
38
|
+
* <a name="style-nested-interpolation"></a>
|
39
|
+
Avoid using nested interpolation.
|
40
|
+
<sup>[[link](#style-nested-interpolation)]</sup>
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# bad
|
44
|
+
"Hello, #{user.blank? ? 'guest' : "dear #{user.name}"}"
|
45
|
+
|
46
|
+
# good
|
47
|
+
user_name = user.blank? ? 'guest' : "dear #{user.name}"
|
48
|
+
"Hello, #{user_name}"
|
49
|
+
```
|
50
|
+
|
38
51
|
* <a name="style-hash-aligning"></a>
|
39
52
|
If elements of a hash literal span more than one line, we're aligning them by keys.
|
40
53
|
Also, the first hash key is aligned by an indentation level.
|
@@ -384,18 +397,3 @@ end
|
|
384
397
|
Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends on the project.
|
385
398
|
So set up it on the local rubocop config manually.
|
386
399
|
<sup>[[link](#style-magic-link)]</sup>
|
387
|
-
|
388
|
-
* <a name="style-braces-around-hash-params"></a>
|
389
|
-
Not to use braces around the last hash literal parameter.
|
390
|
-
But requires braces if the second to last parameter is also a hash literal.
|
391
|
-
<sup>[[link](#style-braces-around-hash-params)]</sup>
|
392
|
-
|
393
|
-
```ruby
|
394
|
-
# bad
|
395
|
-
some_method(x, y, {a: 1, b: 2})
|
396
|
-
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
|
397
|
-
|
398
|
-
# good
|
399
|
-
some_method(x, y, a: 1, b: 2)
|
400
|
-
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
|
401
|
-
```
|
data/doc/STYLE_GUIDE_RAILS.md
CHANGED
@@ -4,6 +4,32 @@ This style is based on rules from [Ruby Style Guide](docs/STYLE_GUIDE.md). Also,
|
|
4
4
|
|
5
5
|
This is a small list of differences which we have when compared with community and our Ruby style guides:
|
6
6
|
|
7
|
-
##
|
7
|
+
## Table of contents
|
8
|
+
|
9
|
+
* [Style](#Style)
|
10
|
+
|
11
|
+
## Style
|
12
|
+
|
13
|
+
* <a name="documentation"></a>
|
14
|
+
Documentation is requeried for all files except `app` directory.
|
15
|
+
<sup>[[link](#documentation)]</sup>
|
16
|
+
|
17
|
+
* <a name="nested-style-and-modules"></a>
|
18
|
+
Prefer to use nested style of children definitions at classes and modules.
|
19
|
+
<sup>[[link](#nested-style-and-modules)]</sup>
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# bad
|
23
|
+
class Api::V1::UsersController
|
24
|
+
end
|
25
|
+
|
26
|
+
# good
|
27
|
+
module Api
|
28
|
+
module V1
|
29
|
+
class UsersController
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
8
34
|
|
9
35
|
[1]: https://github.com/rubocop-hq/rails-style-guide
|
@@ -37,8 +37,7 @@ module Datarockets
|
|
37
37
|
class ArrayAlignmentExtended < RuboCop::Cop::Cop
|
38
38
|
include RuboCop::Cop::Alignment
|
39
39
|
|
40
|
-
ALIGN_PARAMS_MSG = "Align the elements of an array literal if they span more "
|
41
|
-
"than one line."
|
40
|
+
ALIGN_PARAMS_MSG = "Align the elements of an array literal if they span more than one line."
|
42
41
|
|
43
42
|
FIXED_INDENT_MSG = "Use one level of indentation for elements " \
|
44
43
|
"following the first line of a multi-line array."
|
@@ -64,14 +63,14 @@ module Datarockets
|
|
64
63
|
end
|
65
64
|
|
66
65
|
def base_column(node, args)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
fixed_indentation? ? line_indentation(node) : display_column(args.first.source_range)
|
67
|
+
end
|
68
|
+
|
69
|
+
def line_indentation(node)
|
70
|
+
lineno = target_method_lineno(node)
|
71
|
+
line = node.source_range.source_buffer.source_line(lineno)
|
72
|
+
line_indentation = /\S.*/.match(line).begin(0)
|
73
|
+
line_indentation + configured_indentation_width
|
75
74
|
end
|
76
75
|
|
77
76
|
def target_method_lineno(node)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Datarockets
|
2
|
+
module Style
|
3
|
+
module Cop
|
4
|
+
module Style
|
5
|
+
# This cop checks nested interpolations
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
#
|
9
|
+
# # bad
|
10
|
+
# "Hello, #{user.blank? ? 'guest' : "dear #{user.name}"}"
|
11
|
+
#
|
12
|
+
# # good
|
13
|
+
# user_name = user.blank? ? 'guest' : "dear #{user.name}"
|
14
|
+
# "Hello, #{user_name}"
|
15
|
+
class NestedInterpolation < RuboCop::Cop::Cop
|
16
|
+
include RuboCop::Cop::Interpolation
|
17
|
+
|
18
|
+
MSG = "Redundant nested interpolation.".freeze
|
19
|
+
|
20
|
+
def on_interpolation(node)
|
21
|
+
node.each_descendant(:dstr) do |descendant_node|
|
22
|
+
detect_double_interpolation(descendant_node)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def detect_double_interpolation(node)
|
29
|
+
node.each_child_node(:begin) do |begin_node|
|
30
|
+
add_offense(begin_node)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/datarockets/style.rb
CHANGED
@@ -4,6 +4,7 @@ require "datarockets/style/formatter/todo_list_formatter"
|
|
4
4
|
require "datarockets/style/version"
|
5
5
|
|
6
6
|
require "datarockets/style/cop/layout/array_alignment_extended"
|
7
|
+
require "datarockets/style/cop/style/nested_interpolation"
|
7
8
|
|
8
9
|
module Datarockets
|
9
10
|
# Datarickors sharable config
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Layout
|
2
|
+
|
3
|
+
## Layout/ArrayAlignmentExtended
|
4
|
+
|
5
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
6
|
+
--- | --- | --- | --- | ---
|
7
|
+
Enabled | Yes | Yes | 0.7.0 | -
|
8
|
+
|
9
|
+
Here we check if the elements of a multi-line array literal are
|
10
|
+
aligned.
|
11
|
+
|
12
|
+
### Examples
|
13
|
+
|
14
|
+
#### EnforcedStyle: with_fixed_indentation (default)
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# good
|
18
|
+
|
19
|
+
array = [1, 2, 3,
|
20
|
+
4, 5, 6]
|
21
|
+
|
22
|
+
# bad
|
23
|
+
|
24
|
+
array = [1, 2, 3,
|
25
|
+
4, 5, 6]
|
26
|
+
```
|
27
|
+
|
28
|
+
#### EnforcedStyle: with_first_argument
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# good
|
32
|
+
|
33
|
+
array = [1, 2, 3,
|
34
|
+
4, 5, 6]
|
35
|
+
array = ['run',
|
36
|
+
'forrest',
|
37
|
+
'run']
|
38
|
+
|
39
|
+
# bad
|
40
|
+
|
41
|
+
array = [1, 2, 3,
|
42
|
+
4, 5, 6]
|
43
|
+
array = ['run',
|
44
|
+
'forrest',
|
45
|
+
'run']
|
46
|
+
```
|
47
|
+
|
48
|
+
### Configurable attributes
|
49
|
+
|
50
|
+
Name | Default value | Configurable values
|
51
|
+
--- | --- | ---
|
52
|
+
EnforcedStyle | `with_first_parameter` | `with_first_parameter`, `with_fixed_indentation`
|
53
|
+
IndentationWidth | `<none>` | Integer
|
54
|
+
|
55
|
+
# Style
|
56
|
+
|
57
|
+
## Style/NestedInterpolation
|
58
|
+
|
59
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
60
|
+
--- | --- | --- | --- | ---
|
61
|
+
Enabled | Yes | No | 0.8.0 | -
|
62
|
+
|
63
|
+
This cop checks nested interpolations
|
64
|
+
|
65
|
+
### Example
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
# bad
|
69
|
+
"Hello, #{user.blank? ? 'guest' : "dear #{user.name}"}"
|
70
|
+
|
71
|
+
# good
|
72
|
+
user_name = user.blank? ? 'guest' : "dear #{user.name}"
|
73
|
+
"Hello, #{user_name}"
|
74
|
+
```
|
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.
|
4
|
+
version: 0.8.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: 2020-
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -16,28 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.80'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.80'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubocop-rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
47
|
+
version: '1.38'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
54
|
+
version: '1.38'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- r.dubrovsky@datarockets.com
|
@@ -74,9 +88,11 @@ files:
|
|
74
88
|
- doc/STYLE_GUIDE_RSPEC.md
|
75
89
|
- lib/datarockets/style.rb
|
76
90
|
- lib/datarockets/style/cop/layout/array_alignment_extended.rb
|
91
|
+
- lib/datarockets/style/cop/style/nested_interpolation.rb
|
77
92
|
- lib/datarockets/style/formatter/todo_list_formatter.rb
|
78
93
|
- lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb
|
79
94
|
- lib/datarockets/style/version.rb
|
95
|
+
- manual/cops_layout.md
|
80
96
|
homepage: https://github.com/datarockets/datarockets-style
|
81
97
|
licenses:
|
82
98
|
- MIT
|