datarockets-style 0.6.2 → 0.7.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 +5 -5
- data/.github/PULL_REQUEST_TEMPLATE.md +1 -1
- data/.github/workflows/main.yml +41 -0
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +28 -9
- data/Gemfile.lock +6 -6
- data/Makefile +10 -0
- data/README.md +3 -3
- data/config/base.yml +35 -4
- data/config/rspec.yml +3 -0
- data/doc/STYLE_GUIDE.md +31 -10
- data/doc/STYLE_GUIDE_RSPEC.md +31 -2
- data/lib/datarockets/style.rb +2 -0
- data/lib/datarockets/style/cop/layout/array_alignment_extended.rb +84 -0
- data/lib/datarockets/style/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4344b6ab0459c0d422d77d2138d4fdd459ec65e4
|
4
|
+
data.tar.gz: 74cde7a5b535323c47c0ac6670fe79b3a803a27b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89939e5bf7174b4be6c2cee93d9d19d26232cb034b19818a6bf2ac87cf557f39cf72834c67a812edd92845cf757e97eb51faf9f668484a0d3a38baa72757432a
|
7
|
+
data.tar.gz: da83a217a19f55e2721f496cc1de35d752cc1699e52f9b5a7557986d67b5e43eadd0ecb6e4c300795f6c67f35d2aff4cca8bab7417b65b0feaa8538a8385959b
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Before you submit a pull request, please make sure you have to follow:
|
2
2
|
|
3
|
-
- [ ] read and know items from the [Contributing Guide](CONTRIBUTING.md#pull-requests)
|
3
|
+
- [ ] read and know items from the [Contributing Guide](https://github.com/datarockets/datarockets-style/blob/master/CONTRIBUTING.md#pull-requests)
|
4
4
|
- [ ] add a description of the problem you're trying to solve (short summary from related issue)
|
5
5
|
- [ ] verified that cops are ordered by alphabet
|
6
6
|
- [ ] add a note to the style guide docs (if it needs)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Run tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- 'master'
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- 'master'
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v1
|
17
|
+
|
18
|
+
- uses: actions/cache@v1
|
19
|
+
with:
|
20
|
+
path: vendor/bundle
|
21
|
+
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
|
22
|
+
restore-keys: |
|
23
|
+
${{ runner.os }}-gem-
|
24
|
+
|
25
|
+
- name: Set up Ruby 2.6
|
26
|
+
uses: actions/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: 2.6.x
|
29
|
+
|
30
|
+
- name: Install and run bundler
|
31
|
+
run: |
|
32
|
+
gem install bundler
|
33
|
+
bundle config path vendor/bundle
|
34
|
+
bundle install --jobs 4 --retry 3
|
35
|
+
|
36
|
+
- name: Run linter
|
37
|
+
run: make lint
|
38
|
+
|
39
|
+
- name: Run tests
|
40
|
+
run: make test
|
41
|
+
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,26 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
4
4
|
|
5
5
|
## master (unreleased)
|
6
6
|
|
7
|
+
## 0.7.0 (2020-01-27)
|
7
8
|
|
8
|
-
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* [#130](https://github.com/datarockets/datarockets-style/issues/130): Add Layout/ArrayAlignmentExtended cop ([@nikitasakov][])
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
* Update rubocop to `0.79.0`.
|
16
|
+
* Update rubocop-rspec to `1.37.1`.
|
17
|
+
* Add notes for setting up Rspec configuration for fixing Rspec internal style issues. ([@r.dubrovsky][])
|
18
|
+
* [#58](https://github.com/datarockets/datarockets-style/issues/58): Disable `RSpec/LetSetup` cop by default. ([@ula][])
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
|
22
|
+
* [#80](https://github.com/datarockets/datarockets-style/issues/80): Allows adding additional files and directories to excluding block for rubocop. ([@nikitasakov][])
|
23
|
+
* Fix documentation issues. ([@ula][])
|
24
|
+
|
25
|
+
|
26
|
+
## 0.6.2 (2019-12-05)
|
9
27
|
|
10
28
|
### Changed
|
11
29
|
|
@@ -52,11 +70,11 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
52
70
|
### Changed
|
53
71
|
|
54
72
|
* Update rubocop-rspec to `1.35.0`. ([@r.dubrovsky][])
|
55
|
-
* Use
|
73
|
+
* Use context-dependent style for curly braces around hash params. ([@v.kuzmik][])
|
56
74
|
* Use leading underscores in cached instance variable name (cop: `Naming/MemoizedInstanceVariableName`). ([@ula][])
|
57
|
-
* Allow use `for`
|
58
|
-
* Change `Layout/AlignArguments` and `Layout/IndentFirstHashElement` cops for
|
59
|
-
* Enable `Layout/MultilineMethodCallIndentation` cop for
|
75
|
+
* Allow use `for` with `RSpec/ContextWording` cop. ([@r.dubrovsky][])
|
76
|
+
* Change `Layout/AlignArguments` and `Layout/IndentFirstHashElement` cops for aligning arguments with fixed indentation. ([@r.dubrovsky][])
|
77
|
+
* Enable `Layout/MultilineMethodCallIndentation` cop for aligning arguments with fixed indentation. ([@r.dubrovsky][], [@ula][])
|
60
78
|
|
61
79
|
## 0.3.0 (2019-08-02)
|
62
80
|
|
@@ -78,7 +96,7 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
78
96
|
### Changed
|
79
97
|
|
80
98
|
* Update rubocop to `0.73.0`. ([@r.dubrovsky][])
|
81
|
-
* Use
|
99
|
+
* Use preferred variable name in rescued exceptions (cop: `Naming/RescuedExceptionsVariableName`). ([@ula][])
|
82
100
|
* Disable `RSpec/ImplicitSubject` cop for rspec files. ([@r.dubrovsky][])
|
83
101
|
|
84
102
|
## 0.1.0 (2019-06-27)
|
@@ -97,16 +115,17 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
97
115
|
* Change the limit for size of line to 120 symbols. ([@r.dubrovsky][])
|
98
116
|
* Disable `Metrics/BlockLength` cop for rspec files. ([@r.dubrovsky][])
|
99
117
|
* Exclude rubocop checking for some config directories. ([@r.dubrovsky][])
|
100
|
-
* Enable
|
101
|
-
* Do not add spaces
|
118
|
+
* Enable preferring double quotes for string literals. ([@r.dubrovsky][])
|
119
|
+
* Do not add spaces between hash literal braces (cop `Layout/SpaceInsideHashLiteralBraces`). ([@r.dubrovsky][])
|
102
120
|
* Prefer normal style for `Layout/IndentationConsistency` cop for Rails apps too. ([@r.dubrovsky][])
|
103
121
|
* Change style to `variable` for `Layout/EndAlignment` cop. ([@r.dubrovsky][])
|
104
122
|
* Change style to `with_fixed_indentation` with indentation width 2 for `Layout/AlignParameter` cop. ([@r.dubrovsky][])
|
105
|
-
* Always
|
123
|
+
* Always ignore hash aligning for key word arguments. (cop: `Layout/AlignHash`) ([@r.dubrovsky][])
|
106
124
|
|
107
125
|
[@r.dubrovsky]: https://github.com/roman-dubrovsky
|
108
126
|
[@aleks]: https://github.com/AleksSenkou
|
109
127
|
[@ula]: https://github.com/lazycoder9
|
110
128
|
[@v.kuzmik]: https://github.com/TheBlackArroVV/
|
111
129
|
[@a.branzeanu]: https://github.com/texpert
|
130
|
+
[@nikitasakov]: https://github.com/nikitasakov
|
112
131
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
datarockets-style (0.
|
4
|
+
datarockets-style (0.7.0)
|
5
5
|
rubocop (~> 0.76)
|
6
6
|
rubocop-rspec (~> 1.36)
|
7
7
|
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
jaro_winkler (1.5.4)
|
16
16
|
method_source (0.9.2)
|
17
17
|
parallel (1.19.1)
|
18
|
-
parser (2.
|
18
|
+
parser (2.7.0.2)
|
19
19
|
ast (~> 2.4.0)
|
20
20
|
pry (0.12.2)
|
21
21
|
coderay (~> 1.1.0)
|
@@ -38,17 +38,17 @@ GEM
|
|
38
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
39
|
rspec-support (~> 3.9.0)
|
40
40
|
rspec-support (3.9.0)
|
41
|
-
rubocop (0.
|
41
|
+
rubocop (0.79.0)
|
42
42
|
jaro_winkler (~> 1.5.1)
|
43
43
|
parallel (~> 1.10)
|
44
|
-
parser (>= 2.
|
44
|
+
parser (>= 2.7.0.1)
|
45
45
|
rainbow (>= 2.2.2, < 4.0)
|
46
46
|
ruby-progressbar (~> 1.7)
|
47
47
|
unicode-display_width (>= 1.4.0, < 1.7)
|
48
|
-
rubocop-rspec (1.37.
|
48
|
+
rubocop-rspec (1.37.1)
|
49
49
|
rubocop (>= 0.68.1)
|
50
50
|
ruby-progressbar (1.10.1)
|
51
|
-
unicode-display_width (1.6.
|
51
|
+
unicode-display_width (1.6.1)
|
52
52
|
|
53
53
|
PLATFORMS
|
54
54
|
ruby
|
data/Makefile
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Datarockets::Style [](https://badge.fury.io/rb/datarockets-style)
|
2
2
|
|
3
|
-
Datarockets shared style configs and notes of code-style
|
3
|
+
Datarockets shared style configs and notes of code-style conventions. Based on the [Rubocop](https://github.com/rubocop-hq/rubocop) util.
|
4
4
|
|
5
5
|
This config enforces many of the guidelines outlined in the datarockets [Ruby Style Guide](doc/STYLE_GUIDE.md).
|
6
6
|
|
@@ -86,13 +86,13 @@ P.S. The string literals in this gem are using double quotes by default.
|
|
86
86
|
|
87
87
|
##### Tips
|
88
88
|
|
89
|
-
For an existing project, we suggest
|
89
|
+
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
90
|
|
91
91
|
## Formatters
|
92
92
|
|
93
93
|
### ToDo list formatter
|
94
94
|
|
95
|
-
This formatter allows us to get list of files for some offense and with number of offenses in each file. This file can be useful if you need to fix a large some cop
|
95
|
+
This formatter allows us to get list of files for some offense and with number of offenses in each file. This file can be useful if you need to fix a large some cop step by step.
|
96
96
|
|
97
97
|
Result of the formatter is compatible with rubocop config or rubocop todo file.
|
98
98
|
|
data/config/base.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require: datarockets/style
|
2
|
+
|
1
3
|
Bundler/DuplicatedGem:
|
2
4
|
Enabled: true
|
3
5
|
|
@@ -7,6 +9,35 @@ Bundler/OrderedGems:
|
|
7
9
|
Layout/ArgumentAlignment:
|
8
10
|
EnforcedStyle: with_fixed_indentation
|
9
11
|
|
12
|
+
Layout/ArrayAlignment:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Layout/ArrayAlignmentExtended:
|
16
|
+
Description: >-
|
17
|
+
Align the elements of an array literal if they span more than
|
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
|
+
EnforcedStyle: with_fixed_indentation
|
33
|
+
SupportedStyles:
|
34
|
+
- with_first_parameter
|
35
|
+
- 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
|
+
IndentationWidth: ~
|
39
|
+
|
40
|
+
|
10
41
|
Layout/HashAlignment:
|
11
42
|
EnforcedLastArgumentHashStyle: always_ignore
|
12
43
|
|
@@ -20,19 +51,19 @@ Layout/EndAlignment:
|
|
20
51
|
Layout/IndentationConsistency:
|
21
52
|
EnforcedStyle: normal
|
22
53
|
|
54
|
+
Layout/LineLength:
|
55
|
+
Max: 120
|
56
|
+
|
23
57
|
Layout/FirstHashElementIndentation:
|
24
58
|
EnforcedStyle: consistent
|
25
59
|
|
26
60
|
Layout/MultilineMethodCallIndentation:
|
27
|
-
|
61
|
+
EnforcedStyle: indented
|
28
62
|
|
29
63
|
Layout/SpaceInsideHashLiteralBraces:
|
30
64
|
EnforcedStyle: no_space
|
31
65
|
EnforcedStyleForEmptyBraces: no_space
|
32
66
|
|
33
|
-
Metrics/LineLength:
|
34
|
-
Max: 120
|
35
|
-
|
36
67
|
Naming/MemoizedInstanceVariableName:
|
37
68
|
EnforcedStyleForLeadingUnderscores: required
|
38
69
|
|
data/config/rspec.yml
CHANGED
data/doc/STYLE_GUIDE.md
CHANGED
@@ -18,11 +18,11 @@ This is a small list of differences which we have when compared with community s
|
|
18
18
|
## Bundler
|
19
19
|
|
20
20
|
* <a name="bundler-add-once"></a>
|
21
|
-
A Gem's requirements should be listed only once in a Gemfile
|
21
|
+
A Gem's requirements should be listed only once in a Gemfile.
|
22
22
|
<sup>[[link](#bundler-add-once)]</sup>
|
23
23
|
|
24
24
|
* <a name="bundler-ordering"></a>
|
25
|
-
Gems should be alphabetically sorted within groups. Also you can use a line comment as a group separator.
|
25
|
+
Gems should be alphabetically sorted within groups. Also, you can use a line comment as a group separator.
|
26
26
|
<sup>[[link](#bundler-ordering)]</sup>
|
27
27
|
|
28
28
|
## Style
|
@@ -36,7 +36,7 @@ This is a small list of differences which we have when compared with community s
|
|
36
36
|
<sup>[[link](#style-string-quotes)]</sup>
|
37
37
|
|
38
38
|
* <a name="style-hash-aligning"></a>
|
39
|
-
If elements of a hash literal span more than one line we're aligning them by keys.
|
39
|
+
If elements of a hash literal span more than one line, we're aligning them by keys.
|
40
40
|
Also, the first hash key is aligned by an indentation level.
|
41
41
|
<sup>[[link](#style-hash-aligning)]</sup>
|
42
42
|
|
@@ -89,7 +89,7 @@ method_call({
|
|
89
89
|
|
90
90
|
* <a name="style-arguments-aligning"></a>
|
91
91
|
All arguments on a multi-line method definition are aligning by an indentation level.
|
92
|
-
This rule works as for
|
92
|
+
This rule works as for keyword arguments, as for usual arguments.
|
93
93
|
<sup>[[link](#style-arguments-aligning)]</sup>
|
94
94
|
|
95
95
|
```ruby
|
@@ -151,7 +151,28 @@ def foo(
|
|
151
151
|
end
|
152
152
|
```
|
153
153
|
|
154
|
-
* <a name="style-
|
154
|
+
* <a name="style-array-aligning"></a>
|
155
|
+
The elements of a multi-line array are aligning by an indentation level.
|
156
|
+
<sup>[[link](#style-array-aligning)]</sup>
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
# bad
|
160
|
+
|
161
|
+
array = [1, 2, 3,
|
162
|
+
4, 5, 6]
|
163
|
+
|
164
|
+
# bad
|
165
|
+
|
166
|
+
array = [1, 2, 3,
|
167
|
+
4, 5, 6]
|
168
|
+
|
169
|
+
# good
|
170
|
+
|
171
|
+
array = [1, 2, 3,
|
172
|
+
4, 5, 6]
|
173
|
+
```
|
174
|
+
|
175
|
+
* <a name="style-multiline-method-call-indentation"></a>
|
155
176
|
The indentation of the method name part in method calls that span more than one line are aligning by an indentation level.
|
156
177
|
<sup>[[link](#style-multiline-method-call-indentation)]</sup>
|
157
178
|
|
@@ -227,7 +248,7 @@ end
|
|
227
248
|
```
|
228
249
|
|
229
250
|
* <a name="style-method-indentations"></a>
|
230
|
-
We're
|
251
|
+
We're preferring a ruby style for methods indentations, not rails. You can check it [here](https://github.com/rubocop-hq/ruby-style-guide#indent-public-private-protected).
|
231
252
|
<sup>[[link](#style-method-indentations)]</sup>
|
232
253
|
|
233
254
|
```ruby
|
@@ -285,7 +306,7 @@ end
|
|
285
306
|
```
|
286
307
|
|
287
308
|
* <a name="style-hash-spaces"></a>
|
288
|
-
For hash literals not to add
|
309
|
+
For hash literals not to add spaces after `{` or before `}`. We want to have the advantage of adding visual difference between block and hash literals.
|
289
310
|
<sup>[[link](#style-hash-spaces)]</sup>
|
290
311
|
|
291
312
|
```ruby
|
@@ -338,7 +359,7 @@ end
|
|
338
359
|
```
|
339
360
|
|
340
361
|
* <a name="style-cached-instance-variable-name"></a>
|
341
|
-
Use leading underscores in cached instance variable name
|
362
|
+
Use leading underscores in cached instance variable name.
|
342
363
|
<sup>[[link](#style-cached-instance-variable-name)]</sup>
|
343
364
|
|
344
365
|
```ruby
|
@@ -359,8 +380,8 @@ end
|
|
359
380
|
```
|
360
381
|
|
361
382
|
* <a name="style-magic-link"></a>
|
362
|
-
There are not any
|
363
|
-
Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends
|
383
|
+
There are not any required rules for `frozen_string_literal` magic url.
|
384
|
+
Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends on the project.
|
364
385
|
So set up it on the local rubocop config manually.
|
365
386
|
<sup>[[link](#style-magic-link)]</sup>
|
366
387
|
|
data/doc/STYLE_GUIDE_RSPEC.md
CHANGED
@@ -16,7 +16,7 @@ This style guide recommends best practices for writing a clear Rspec tests and e
|
|
16
16
|
<sup>[[link](#rspec-nested-groups)]</sup>
|
17
17
|
|
18
18
|
* <a name="rspec-subject"></a>
|
19
|
-
Each subject should be named and we should not use `subject` in our test cases.
|
19
|
+
Each subject should be named, and we should not use `subject` in our test cases.
|
20
20
|
Prefer to use `is_expected` that `expect(subject_name)` for small tests.
|
21
21
|
<sup>[[link](#rspec-subject)]</sup>
|
22
22
|
|
@@ -60,7 +60,7 @@ end
|
|
60
60
|
```
|
61
61
|
|
62
62
|
* <a name="rspec-example-length"></a>
|
63
|
-
A long example is usually more difficult to understand. Consider extracting out some
|
63
|
+
A long example is usually more difficult to understand. Consider extracting out some behavior, e.g. with a `let` block, or a helper method.
|
64
64
|
|
65
65
|
<sup>[[link](#rspec-example-length)]</sup>
|
66
66
|
|
@@ -153,3 +153,32 @@ end
|
|
153
153
|
```
|
154
154
|
|
155
155
|
**Note:** this is a Part of Rspec configuration. Read more [by link](https://github.com/rubocop-hq/rubocop-rspec#enforcing-an-explicit-rspec-receiver-for-top-level-methods-disabling-monkey-patching).
|
156
|
+
|
157
|
+
* <a name="rspec-let-setup"></a>
|
158
|
+
We allow using let! in your test, but suggest not to use it for setting up testing data.
|
159
|
+
<sup>[[link](#rspec-let-setup)]</sup>
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
# ok
|
163
|
+
let!(:my_widget) { create(:widget) }
|
164
|
+
|
165
|
+
it "counts widgets" do
|
166
|
+
expect(Widget.count).to eq(1)
|
167
|
+
end
|
168
|
+
|
169
|
+
# better
|
170
|
+
before do
|
171
|
+
create(:widget)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "counts widgets" do
|
175
|
+
expect(Widget.count).to eq(1)
|
176
|
+
end
|
177
|
+
|
178
|
+
# good
|
179
|
+
let!(:my_widget) { create(:widget) }
|
180
|
+
|
181
|
+
it "returns the last widget" do
|
182
|
+
expect(Widget.last).to eq my_widget
|
183
|
+
end
|
184
|
+
```
|
data/lib/datarockets/style.rb
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datarockets
|
4
|
+
module Style
|
5
|
+
module Cop
|
6
|
+
module Layout
|
7
|
+
# Here we check if the elements of a multi-line array literal are
|
8
|
+
# aligned.
|
9
|
+
#
|
10
|
+
# @example EnforcedStyle: with_first_argument (default)
|
11
|
+
# # good
|
12
|
+
#
|
13
|
+
# array = [1, 2, 3,
|
14
|
+
# 4, 5, 6]
|
15
|
+
# array = ['run',
|
16
|
+
# 'forrest',
|
17
|
+
# 'run']
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
#
|
21
|
+
# array = [1, 2, 3,
|
22
|
+
# 4, 5, 6]
|
23
|
+
# array = ['run',
|
24
|
+
# 'forrest',
|
25
|
+
# 'run']
|
26
|
+
#
|
27
|
+
# @example EnforcedStyle: with_fixed_indentation
|
28
|
+
# # good
|
29
|
+
#
|
30
|
+
# array = [1, 2, 3,
|
31
|
+
# 4, 5, 6]
|
32
|
+
#
|
33
|
+
# # bad
|
34
|
+
#
|
35
|
+
# array = [1, 2, 3,
|
36
|
+
# 4, 5, 6]
|
37
|
+
class ArrayAlignmentExtended < RuboCop::Cop::Cop
|
38
|
+
include RuboCop::Cop::Alignment
|
39
|
+
|
40
|
+
ALIGN_PARAMS_MSG = "Align the elements of an array literal if they span more " \
|
41
|
+
"than one line."
|
42
|
+
|
43
|
+
FIXED_INDENT_MSG = "Use one level of indentation for elements " \
|
44
|
+
"following the first line of a multi-line array."
|
45
|
+
|
46
|
+
def on_array(node)
|
47
|
+
return if node.children.size < 2
|
48
|
+
|
49
|
+
check_alignment(node.children, base_column(node, node.children))
|
50
|
+
end
|
51
|
+
|
52
|
+
def autocorrect(node)
|
53
|
+
RuboCop::Cop::AlignmentCorrector.correct(processed_source, node, column_delta)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def message(_node)
|
59
|
+
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
|
60
|
+
end
|
61
|
+
|
62
|
+
def fixed_indentation?
|
63
|
+
cop_config["EnforcedStyle"] == "with_fixed_indentation"
|
64
|
+
end
|
65
|
+
|
66
|
+
def base_column(node, args)
|
67
|
+
if fixed_indentation?
|
68
|
+
lineno = target_method_lineno(node)
|
69
|
+
line = node.source_range.source_buffer.source_line(lineno)
|
70
|
+
indentation_of_line = /\S.*/.match(line).begin(0)
|
71
|
+
indentation_of_line + configured_indentation_width
|
72
|
+
else
|
73
|
+
display_column(args.first.source_range)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def target_method_lineno(node)
|
78
|
+
node.loc.line
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
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.
|
4
|
+
version: 0.7.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:
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- ".github/ISSUE_TEMPLATE/new-issue.md"
|
49
49
|
- ".github/ISSUE_TEMPLATE/update-dependencies.md"
|
50
50
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
51
|
+
- ".github/workflows/main.yml"
|
51
52
|
- ".gitignore"
|
52
53
|
- ".rspec"
|
53
54
|
- ".rubocop.yml"
|
@@ -57,6 +58,7 @@ files:
|
|
57
58
|
- Gemfile
|
58
59
|
- Gemfile.lock
|
59
60
|
- LICENSE.txt
|
61
|
+
- Makefile
|
60
62
|
- README.md
|
61
63
|
- RELEASING.md
|
62
64
|
- Rakefile
|
@@ -71,6 +73,7 @@ files:
|
|
71
73
|
- doc/STYLE_GUIDE_RAILS.md
|
72
74
|
- doc/STYLE_GUIDE_RSPEC.md
|
73
75
|
- lib/datarockets/style.rb
|
76
|
+
- lib/datarockets/style/cop/layout/array_alignment_extended.rb
|
74
77
|
- lib/datarockets/style/formatter/todo_list_formatter.rb
|
75
78
|
- lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb
|
76
79
|
- lib/datarockets/style/version.rb
|
@@ -95,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
98
|
version: '0'
|
96
99
|
requirements: []
|
97
100
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.6.14
|
99
102
|
signing_key:
|
100
103
|
specification_version: 4
|
101
104
|
summary: Datarockets style guides and shared style configs
|