datarockets-style 0.6.2 → 0.10.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
- SHA256:
3
- metadata.gz: cf58c59e6d4a4035c60796ef26a8c999cd2003ea58f0b4c3f018a49fd3d5a9c0
4
- data.tar.gz: 993b7f3c7e99e6a959c328c9f76630eea7227be1fd53038295c1c2d30a0f1507
2
+ SHA1:
3
+ metadata.gz: 5c6dc78f6cd8d3a32d136c4f7a9719ea01f5df29
4
+ data.tar.gz: e4dde397b38468d9d2323a15435bc0a44186bb52
5
5
  SHA512:
6
- metadata.gz: a8ab4c6b3988709ca2d096defb42478ba657f03603dcd0ca63800769f3106478d228c7e41a208771ffae7a34d53386c5052bc7f0e9dde7c60676be6e7ad48223
7
- data.tar.gz: 7b42a8646ba555a70aa9e77b99b729e6fb9f9f8abde73199a219672d5afcbedd02c608461f99a9d7d58a077b6df94188b2b82dace0e517f0613fc32f52b13181
6
+ metadata.gz: b8ced1a8863f844fa904ad34030a8fd7a1f52426fc7623d8e9171914d016a75040d9446e1aabb1daa6082f104a472f85bb93ee400d86566c3b32206e23d2922a
7
+ data.tar.gz: 7d0e9abce97cfea064339749a224f5db4fce7b44de4400218ede97fe42e05699a72a5bc0061d9abf61318d3da900c7449eaf3715326744e75eb3378fbbd1a5a0
@@ -14,3 +14,4 @@ To-Do list:
14
14
  - [ ] update dependencies to the latest version
15
15
  - [ ] investigate how it changes and affect our current styles and cops
16
16
  - [ ] check the required ruby version
17
+ - [ ] enable pending cops
@@ -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
+
@@ -2,5 +2,14 @@ inherit_from:
2
2
  - config/ruby.yml
3
3
  - config/rspec.yml
4
4
 
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
5
9
  AllCops:
6
- TargetRubyVersion: 2.3
10
+ TargetRubyVersion: 2.4
11
+
12
+ # for checking cops with interpolation
13
+ Lint/InterpolationCheck:
14
+ Exclude:
15
+ - 'spec/**/*.rb'
@@ -4,8 +4,83 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
4
4
 
5
5
  ## master (unreleased)
6
6
 
7
+ ## 0.10.0 (2020-07-17)
7
8
 
8
- ## 0.6.2(2019-12-05)
9
+ ### Changed
10
+
11
+ * Update rubocop to `0.88.0`. ([@r.dubrovsky][])
12
+ * Enable new cops `Lint/MixedRegexpCaptureTypes`, `Style/RedundantRegexpCharacterClass` and `Style/RedundantRegexpEscape`. Cops were added in version `0.85`.
13
+ * Enable new cop `Style/RedundantFetchBlock`. Cop was added in version `0.86`.
14
+ * Enable new cops `Style/AccessorGrouping`, `Style/BisectedAttrAccessor` and `Style/RedundantAssignment`. Cops were added in version `0.87`.
15
+ * Enable new cops `Lint/DuplicateElsifCondition`, `Style/ArrayCoercion`, `Style/CaseLikeIf`, `Style/HashAsLastArrayItem`, `Style/HashLikeCase` and `Style/RedundantFileExtensionInRequire`. Cops were added in version `0.88`.
16
+ * Update rubocop-rails to `2.6.0`.
17
+ * Update rubocop-rspec to `1.42.0`.
18
+
19
+ * Setup `no_braces` rule for `Style/HashAsLastArrayItem` cop which added in the rubocop version `0.88`.
20
+
21
+ ## 0.9.0 (2020-05-27)
22
+
23
+ ### Changed
24
+
25
+ * **(Breaking)** Drop support for Ruby 2.3. ([@r.dubrovsky][])
26
+
27
+ * Update rubocop to `0.84.0`. ([@r.dubrovsky][])
28
+ * Enable new cops `Lint/RaiseException` and `Lint/StructNewOverride`. Cops were added in version `0.81`.
29
+ * Enable new cops `Layout/SpaceAroundMethodCallOperator` and `Style/ExponentialNotation`. Cops were added in version `0.82`.
30
+ * Enable new cops `Layout/EmptyLinesAroundAttributeAccessor` and `Style/SlicingWithRange`. Cops were added in version `0.83`.
31
+ * Enable new cop `Lint/DeprecatedOpenSSLConstant`. Cop was added in version `0.84`.
32
+
33
+ * Update rubocop-rails to `2.5.2`.
34
+ * Update rubocop-rspec to `1.39`.
35
+ * Update `activesupport` for fixing security issues.
36
+
37
+ ## 0.8.1 (2020-03-02)
38
+
39
+ ### Changed
40
+
41
+ * Update rubocop to `0.80.1`.
42
+
43
+ ## 0.8.0 (2020-02-20)
44
+
45
+ ### Added
46
+
47
+ * Add `Style/NestedInterpolation` cop. ([@r.dubrovsky][])
48
+
49
+ ### Changed
50
+
51
+ * Update rubocop to `0.80.0`. ([@r.dubrovsky][])
52
+ * Add `Style/HashEachMethods`, `Style/HashTransformKey`, `Style/HashTransformValues` cops.
53
+ * [#7641](https://github.com/rubocop-hq/rubocop/issues/7641): Remove `Style/BracesAroundHashParameters` cop.
54
+
55
+ * Update rubocop-rspec to `1.38.1`.
56
+ * Add RSpec/RepeatedExampleGroupBody cop. ([@ula][])
57
+ * Add RSpec/RepeatedExampleGroupDescription cop. ([@ula][])
58
+
59
+ * Enable `rubocop-rails` cops for rails config. ([@ula][])
60
+ * Setup `Style/Documentation` for rails config. ([@r.dubrovsky][])
61
+ * Setup `Style/ClassAndModuleChildren` cop. ([@r.dubrovsky][])
62
+ * Enable `RSpec/LetSetup` cop. ([@r.dubrovsky][])
63
+
64
+ ## 0.7.0 (2020-01-27)
65
+
66
+ ### Added
67
+
68
+ * [#130](https://github.com/datarockets/datarockets-style/issues/130): Add Layout/ArrayAlignmentExtended cop ([@nikitasakov][])
69
+
70
+ ### Changed
71
+
72
+ * Update rubocop to `0.79.0`.
73
+ * Update rubocop-rspec to `1.37.1`.
74
+ * Add notes for setting up Rspec configuration for fixing Rspec internal style issues. ([@r.dubrovsky][])
75
+ * [#58](https://github.com/datarockets/datarockets-style/issues/58): Disable `RSpec/LetSetup` cop by default. ([@ula][])
76
+
77
+ ### Fixed
78
+
79
+ * [#80](https://github.com/datarockets/datarockets-style/issues/80): Allows adding additional files and directories to excluding block for rubocop. ([@nikitasakov][])
80
+ * Fix documentation issues. ([@ula][])
81
+
82
+
83
+ ## 0.6.2 (2019-12-05)
9
84
 
10
85
  ### Changed
11
86
 
@@ -52,11 +127,11 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
52
127
  ### Changed
53
128
 
54
129
  * Update rubocop-rspec to `1.35.0`. ([@r.dubrovsky][])
55
- * Use contenxt-dependent style for curly braces around hash params. ([@v.kuzmik][])
130
+ * Use context-dependent style for curly braces around hash params. ([@v.kuzmik][])
56
131
  * Use leading underscores in cached instance variable name (cop: `Naming/MemoizedInstanceVariableName`). ([@ula][])
57
- * Allow use `for` wiht `RSpec/ContextWording` cop. ([@r.dubrovsky][])
58
- * Change `Layout/AlignArguments` and `Layout/IndentFirstHashElement` cops for aliging arguments with fixed indentation. ([@r.dubrovsky][])
59
- * Enable `Layout/MultilineMethodCallIndentation` cop for aliging arguments with fixed indentation. ([@r.dubrovsky][], [@ula][])
132
+ * Allow use `for` with `RSpec/ContextWording` cop. ([@r.dubrovsky][])
133
+ * Change `Layout/AlignArguments` and `Layout/IndentFirstHashElement` cops for aligning arguments with fixed indentation. ([@r.dubrovsky][])
134
+ * Enable `Layout/MultilineMethodCallIndentation` cop for aligning arguments with fixed indentation. ([@r.dubrovsky][], [@ula][])
60
135
 
61
136
  ## 0.3.0 (2019-08-02)
62
137
 
@@ -78,7 +153,7 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
78
153
  ### Changed
79
154
 
80
155
  * Update rubocop to `0.73.0`. ([@r.dubrovsky][])
81
- * Use prefered variable name in rescued exceptions (cop: `Naming/RescuedExceptionsVariableName`). ([@ula][])
156
+ * Use preferred variable name in rescued exceptions (cop: `Naming/RescuedExceptionsVariableName`). ([@ula][])
82
157
  * Disable `RSpec/ImplicitSubject` cop for rspec files. ([@r.dubrovsky][])
83
158
 
84
159
  ## 0.1.0 (2019-06-27)
@@ -97,16 +172,17 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
97
172
  * Change the limit for size of line to 120 symbols. ([@r.dubrovsky][])
98
173
  * Disable `Metrics/BlockLength` cop for rspec files. ([@r.dubrovsky][])
99
174
  * Exclude rubocop checking for some config directories. ([@r.dubrovsky][])
100
- * Enable prafering double quotes for string literals. ([@r.dubrovsky][])
101
- * Do not add spaces beetwen hash literal braces (cop `Layout/SpaceInsideHashLiteralBraces`). ([@r.dubrovsky][])
175
+ * Enable preferring double quotes for string literals. ([@r.dubrovsky][])
176
+ * Do not add spaces between hash literal braces (cop `Layout/SpaceInsideHashLiteralBraces`). ([@r.dubrovsky][])
102
177
  * Prefer normal style for `Layout/IndentationConsistency` cop for Rails apps too. ([@r.dubrovsky][])
103
178
  * Change style to `variable` for `Layout/EndAlignment` cop. ([@r.dubrovsky][])
104
179
  * Change style to `with_fixed_indentation` with indentation width 2 for `Layout/AlignParameter` cop. ([@r.dubrovsky][])
105
- * Always ingone hash aligning for key word arguments. (cop: `Layout/AlignHash`) ([@r.dubrovsky][])
180
+ * Always ignore hash aligning for key word arguments. (cop: `Layout/AlignHash`) ([@r.dubrovsky][])
106
181
 
107
182
  [@r.dubrovsky]: https://github.com/roman-dubrovsky
108
183
  [@aleks]: https://github.com/AleksSenkou
109
184
  [@ula]: https://github.com/lazycoder9
110
185
  [@v.kuzmik]: https://github.com/TheBlackArroVV/
111
186
  [@a.branzeanu]: https://github.com/texpert
187
+ [@nikitasakov]: https://github.com/nikitasakov
112
188
 
@@ -1,30 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datarockets-style (0.6.2)
5
- rubocop (~> 0.76)
6
- rubocop-rspec (~> 1.36)
4
+ datarockets-style (0.10.0)
5
+ rubocop (~> 0.88)
6
+ rubocop-rails (>= 2.6.0, < 2.7.0)
7
+ rubocop-rspec (~> 1.42)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- ast (2.4.0)
12
- byebug (11.0.1)
12
+ activesupport (5.2.4.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.4.1)
18
+ byebug (11.1.3)
13
19
  coderay (1.1.2)
20
+ concurrent-ruby (1.1.6)
14
21
  diff-lcs (1.3)
15
- jaro_winkler (1.5.4)
16
- method_source (0.9.2)
17
- parallel (1.19.1)
18
- parser (2.6.5.0)
19
- ast (~> 2.4.0)
20
- pry (0.12.2)
21
- coderay (~> 1.1.0)
22
- method_source (~> 0.9.0)
23
- pry-byebug (3.7.0)
22
+ i18n (1.8.3)
23
+ concurrent-ruby (~> 1.0)
24
+ method_source (1.0.0)
25
+ minitest (5.14.1)
26
+ parallel (1.19.2)
27
+ parser (2.7.1.4)
28
+ ast (~> 2.4.1)
29
+ pry (0.13.1)
30
+ coderay (~> 1.1)
31
+ method_source (~> 1.0)
32
+ pry-byebug (3.9.0)
24
33
  byebug (~> 11.0)
25
- pry (~> 0.10)
34
+ pry (~> 0.13.0)
35
+ rack (2.2.3)
26
36
  rainbow (3.0.0)
27
37
  rake (13.0.1)
38
+ regexp_parser (1.7.1)
39
+ rexml (3.2.4)
28
40
  rspec (3.9.0)
29
41
  rspec-core (~> 3.9.0)
30
42
  rspec-expectations (~> 3.9.0)
@@ -38,17 +50,28 @@ GEM
38
50
  diff-lcs (>= 1.2.0, < 2.0)
39
51
  rspec-support (~> 3.9.0)
40
52
  rspec-support (3.9.0)
41
- rubocop (0.77.0)
42
- jaro_winkler (~> 1.5.1)
53
+ rubocop (0.88.0)
43
54
  parallel (~> 1.10)
44
- parser (>= 2.6)
55
+ parser (>= 2.7.1.1)
45
56
  rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.7)
58
+ rexml
59
+ rubocop-ast (>= 0.1.0, < 1.0)
46
60
  ruby-progressbar (~> 1.7)
47
- unicode-display_width (>= 1.4.0, < 1.7)
48
- rubocop-rspec (1.37.0)
49
- rubocop (>= 0.68.1)
61
+ unicode-display_width (>= 1.4.0, < 2.0)
62
+ rubocop-ast (0.1.0)
63
+ parser (>= 2.7.0.1)
64
+ rubocop-rails (2.6.0)
65
+ activesupport (>= 4.2.0)
66
+ rack (>= 1.1)
67
+ rubocop (>= 0.82.0)
68
+ rubocop-rspec (1.42.0)
69
+ rubocop (>= 0.87.0)
50
70
  ruby-progressbar (1.10.1)
51
- unicode-display_width (1.6.0)
71
+ thread_safe (0.3.6)
72
+ tzinfo (1.2.7)
73
+ thread_safe (~> 0.1)
74
+ unicode-display_width (1.7.0)
52
75
 
53
76
  PLATFORMS
54
77
  ruby
@@ -60,4 +83,4 @@ DEPENDENCIES
60
83
  rspec (~> 3.7)
61
84
 
62
85
  BUNDLED WITH
63
- 1.16.3
86
+ 2.1.4
@@ -0,0 +1,10 @@
1
+ install:
2
+ bundle install
3
+
4
+ test:
5
+ bundle exec rspec spec
6
+
7
+ lint:
8
+ bundle exec rubocop
9
+
10
+ .PHONY: test
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Datarockets::Style [![Gem Version](https://badge.fury.io/rb/datarockets-style.svg)](https://badge.fury.io/rb/datarockets-style)
2
2
 
3
- Datarockets shared style configs and notes of code-style convensions. Based on the [Rubocop](https://github.com/rubocop-hq/rubocop) util.
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
 
@@ -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.
@@ -86,13 +91,17 @@ P.S. The string literals in this gem are using double quotes by default.
86
91
 
87
92
  ##### Tips
88
93
 
89
- 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).
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).
95
+
96
+ ### Custom cops
97
+
98
+ We have custom cops. You can find specification for them [here](manual).
90
99
 
91
100
  ## Formatters
92
101
 
93
102
  ### ToDo list formatter
94
103
 
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 cop step by step.
104
+ 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
105
 
97
106
  Result of the formatter is compatible with rubocop config or rubocop todo file.
98
107
 
@@ -1,3 +1,5 @@
1
+ require: datarockets/style
2
+
1
3
  Bundler/DuplicatedGem:
2
4
  Enabled: true
3
5
 
@@ -7,6 +9,19 @@ 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
+ EnforcedStyle: with_fixed_indentation
20
+ SupportedStyles:
21
+ - with_first_parameter
22
+ - with_fixed_indentation
23
+ IndentationWidth: ~
24
+
10
25
  Layout/HashAlignment:
11
26
  EnforcedLastArgumentHashStyle: always_ignore
12
27
 
@@ -14,24 +29,45 @@ Layout/ParameterAlignment:
14
29
  EnforcedStyle: with_fixed_indentation
15
30
  IndentationWidth: 2
16
31
 
32
+ Layout/EmptyLinesAroundAttributeAccessor:
33
+ Enabled: true
34
+
17
35
  Layout/EndAlignment:
18
36
  EnforcedStyleAlignWith: variable
19
37
 
20
38
  Layout/IndentationConsistency:
21
39
  EnforcedStyle: normal
22
40
 
41
+ Layout/LineLength:
42
+ Max: 120
43
+
23
44
  Layout/FirstHashElementIndentation:
24
45
  EnforcedStyle: consistent
25
46
 
26
47
  Layout/MultilineMethodCallIndentation:
27
- EnforcedStyle: indented
48
+ EnforcedStyle: indented
49
+
50
+ Layout/SpaceAroundMethodCallOperator:
51
+ Enabled: true
28
52
 
29
53
  Layout/SpaceInsideHashLiteralBraces:
30
54
  EnforcedStyle: no_space
31
55
  EnforcedStyleForEmptyBraces: no_space
32
56
 
33
- Metrics/LineLength:
34
- Max: 120
57
+ Lint/DeprecatedOpenSSLConstant:
58
+ Enabled: true
59
+
60
+ Lint/DuplicateElsifCondition:
61
+ Enabled: true
62
+
63
+ Lint/MixedRegexpCaptureTypes:
64
+ Enabled: true
65
+
66
+ Lint/RaiseException:
67
+ Enabled: true
68
+
69
+ Lint/StructNewOverride:
70
+ Enabled: true
35
71
 
36
72
  Naming/MemoizedInstanceVariableName:
37
73
  EnforcedStyleForLeadingUnderscores: required
@@ -39,14 +75,66 @@ Naming/MemoizedInstanceVariableName:
39
75
  Naming/RescuedExceptionsVariableName:
40
76
  PreferredName: error
41
77
 
42
- Style/BracesAroundHashParameters:
43
- EnforcedStyle: context_dependent
78
+ Style/AccessorGrouping:
79
+ Enabled: true
80
+
81
+ Style/ArrayCoercion:
82
+ Enabled: true
83
+
84
+ Style/BisectedAttrAccessor:
85
+ Enabled: true
86
+
87
+ Style/CaseLikeIf:
88
+ Enabled: true
89
+
90
+ Style/ClassAndModuleChildren:
91
+ EnforcedStyle: nested
44
92
 
45
93
  Style/EmptyMethod:
46
94
  EnforcedStyle: expanded
47
95
 
96
+ Style/ExponentialNotation:
97
+ Enabled: true
98
+
99
+ Style/HashAsLastArrayItem:
100
+ Enabled: true
101
+ EnforcedStyle: no_braces
102
+
103
+ Style/HashEachMethods:
104
+ Enabled: true
105
+
106
+ Style/HashLikeCase:
107
+ Enabled: true
108
+
109
+ Style/HashTransformKeys:
110
+ Enabled: true
111
+
112
+ Style/HashTransformValues:
113
+ Enabled: true
114
+
48
115
  Style/FrozenStringLiteralComment:
49
116
  Enabled: false
50
117
 
118
+ Style/NestedInterpolation:
119
+ Enabled: true
120
+
121
+ Style/RedundantAssignment:
122
+ Enabled: true
123
+
124
+ Style/RedundantFetchBlock:
125
+ Enabled: true
126
+
127
+ Style/RedundantFileExtensionInRequire:
128
+ Enabled: true
129
+
130
+ Style/RedundantRegexpCharacterClass:
131
+ Enabled: true
132
+
133
+ Style/RedundantRegexpEscape:
134
+ Enabled: true
135
+
136
+ Style/SlicingWithRange:
137
+ Enabled: true
138
+
51
139
  Style/StringLiterals:
52
140
  EnforcedStyle: double_quotes
@@ -1,3 +1,5 @@
1
+ require: rubocop-rails
2
+
1
3
  AllCops:
2
4
  Exclude:
3
5
  - "db/**/*"
@@ -11,3 +13,8 @@ AllCops:
11
13
  - "Rakefile"
12
14
 
13
15
  inherit_from: base.yml
16
+
17
+ Style/Documentation:
18
+ Enabled: true
19
+ Exclude:
20
+ - "app/**/*"
@@ -25,6 +25,9 @@ RSpec/ExpectChange:
25
25
  RSpec/ImplicitSubject:
26
26
  Enabled: false
27
27
 
28
+ RSpec/LetSetup:
29
+ Enabled: true
30
+
28
31
  RSpec/MessageSpies:
29
32
  EnforcedStyle: have_received
30
33
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "https://github.com/datarockets/datarockets-style"
13
13
  spec.license = "MIT"
14
14
 
15
- spec.required_ruby_version = ">= 2.3.0"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -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.76"
34
- spec.add_dependency "rubocop-rspec", "~> 1.36"
33
+ spec.add_dependency "rubocop", "~> 0.88"
34
+ spec.add_dependency "rubocop-rails", ">= 2.6.0", "< 2.7.0"
35
+ spec.add_dependency "rubocop-rspec", "~> 1.42"
35
36
  end
@@ -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
@@ -35,8 +35,21 @@ 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
- If elements of a hash literal span more than one line we're aligning them by keys.
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.
41
54
  <sup>[[link](#style-hash-aligning)]</sup>
42
55
 
@@ -89,7 +102,7 @@ method_call({
89
102
 
90
103
  * <a name="style-arguments-aligning"></a>
91
104
  All arguments on a multi-line method definition are aligning by an indentation level.
92
- This rule works as for keywork arguments, as for usual arguments.
105
+ This rule works as for keyword arguments, as for usual arguments.
93
106
  <sup>[[link](#style-arguments-aligning)]</sup>
94
107
 
95
108
  ```ruby
@@ -151,7 +164,28 @@ def foo(
151
164
  end
152
165
  ```
153
166
 
154
- * <a name="style-multiline-method-call-indentation">
167
+ * <a name="style-array-aligning"></a>
168
+ The elements of a multi-line array are aligning by an indentation level.
169
+ <sup>[[link](#style-array-aligning)]</sup>
170
+
171
+ ```ruby
172
+ # bad
173
+
174
+ array = [1, 2, 3,
175
+ 4, 5, 6]
176
+
177
+ # bad
178
+
179
+ array = [1, 2, 3,
180
+ 4, 5, 6]
181
+
182
+ # good
183
+
184
+ array = [1, 2, 3,
185
+ 4, 5, 6]
186
+ ```
187
+
188
+ * <a name="style-multiline-method-call-indentation"></a>
155
189
  The indentation of the method name part in method calls that span more than one line are aligning by an indentation level.
156
190
  <sup>[[link](#style-multiline-method-call-indentation)]</sup>
157
191
 
@@ -227,7 +261,7 @@ end
227
261
  ```
228
262
 
229
263
  * <a name="style-method-indentations"></a>
230
- We're prefering 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).
264
+ 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
265
  <sup>[[link](#style-method-indentations)]</sup>
232
266
 
233
267
  ```ruby
@@ -285,7 +319,7 @@ end
285
319
  ```
286
320
 
287
321
  * <a name="style-hash-spaces"></a>
288
- For hash literals not to add scapes after `{` or before `}`. We want to have the advantage of adding visual difference between block and hash literals.
322
+ 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
323
  <sup>[[link](#style-hash-spaces)]</sup>
290
324
 
291
325
  ```ruby
@@ -338,7 +372,7 @@ end
338
372
  ```
339
373
 
340
374
  * <a name="style-cached-instance-variable-name"></a>
341
- Use leading underscores in cached instance variable name
375
+ Use leading underscores in cached instance variable name.
342
376
  <sup>[[link](#style-cached-instance-variable-name)]</sup>
343
377
 
344
378
  ```ruby
@@ -359,22 +393,7 @@ end
359
393
  ```
360
394
 
361
395
  * <a name="style-magic-link"></a>
362
- There are not any requried rules for `frozen_string_literal` magic url.
363
- Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends on the project.
396
+ There are not any required rules for `frozen_string_literal` magic url.
397
+ Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends on the project.
364
398
  So set up it on the local rubocop config manually.
365
399
  <sup>[[link](#style-magic-link)]</sup>
366
-
367
- * <a name="style-braces-around-hash-params"></a>
368
- Not to use braces around the last hash literal parameter.
369
- But requires braces if the second to last parameter is also a hash literal.
370
- <sup>[[link](#style-braces-around-hash-params)]</sup>
371
-
372
- ```ruby
373
- # bad
374
- some_method(x, y, {a: 1, b: 2})
375
- some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
376
-
377
- # good
378
- some_method(x, y, a: 1, b: 2)
379
- some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
380
- ```
@@ -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
- ## TODO
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
@@ -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 behaviour, e.g. with a `let` block, or a helper method.
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
+ ```
@@ -3,6 +3,9 @@ require "datarockets/style/formatter/todo_list_formatter"
3
3
 
4
4
  require "datarockets/style/version"
5
5
 
6
+ require "datarockets/style/cop/layout/array_alignment_extended"
7
+ require "datarockets/style/cop/style/nested_interpolation"
8
+
6
9
  module Datarockets
7
10
  # Datarickors sharable config
8
11
  module Style
@@ -0,0 +1,83 @@
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 than one line."
41
+
42
+ FIXED_INDENT_MSG = "Use one level of indentation for elements " \
43
+ "following the first line of a multi-line array."
44
+
45
+ def on_array(node)
46
+ return if node.children.size < 2
47
+
48
+ check_alignment(node.children, base_column(node, node.children))
49
+ end
50
+
51
+ def autocorrect(node)
52
+ RuboCop::Cop::AlignmentCorrector.correct(processed_source, node, column_delta)
53
+ end
54
+
55
+ private
56
+
57
+ def message(_node)
58
+ fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
59
+ end
60
+
61
+ def fixed_indentation?
62
+ cop_config["EnforcedStyle"] == "with_fixed_indentation"
63
+ end
64
+
65
+ def base_column(node, args)
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
74
+ end
75
+
76
+ def target_method_lineno(node)
77
+ node.loc.line
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -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
@@ -13,9 +13,9 @@ module Datarockets
13
13
  class ReportSummary
14
14
  attr_reader :offense_list
15
15
 
16
- FileGroup = Struct.new(:file, :count) do
16
+ FileGroup = Struct.new(:file, :offenses_count) do
17
17
  def print(output)
18
- output.puts " - '#{file}' # #{count}"
18
+ output.puts " - '#{file}' # #{offenses_count}"
19
19
  end
20
20
  end
21
21
 
@@ -1,5 +1,5 @@
1
1
  module Datarockets
2
2
  module Style
3
- VERSION = "0.6.2".freeze
3
+ VERSION = "0.10.0".freeze
4
4
  end
5
5
  end
@@ -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.6.2
4
+ version: 0.10.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-12-06 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,28 +16,48 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.76'
19
+ version: '0.88'
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.76'
26
+ version: '0.88'
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.6.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 2.7.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.7.0
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rubocop-rspec
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '1.36'
53
+ version: '1.42'
34
54
  type: :runtime
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '1.36'
60
+ version: '1.42'
41
61
  description:
42
62
  email:
43
63
  - r.dubrovsky@datarockets.com
@@ -48,6 +68,7 @@ files:
48
68
  - ".github/ISSUE_TEMPLATE/new-issue.md"
49
69
  - ".github/ISSUE_TEMPLATE/update-dependencies.md"
50
70
  - ".github/PULL_REQUEST_TEMPLATE.md"
71
+ - ".github/workflows/main.yml"
51
72
  - ".gitignore"
52
73
  - ".rspec"
53
74
  - ".rubocop.yml"
@@ -57,6 +78,7 @@ files:
57
78
  - Gemfile
58
79
  - Gemfile.lock
59
80
  - LICENSE.txt
81
+ - Makefile
60
82
  - README.md
61
83
  - RELEASING.md
62
84
  - Rakefile
@@ -71,9 +93,12 @@ files:
71
93
  - doc/STYLE_GUIDE_RAILS.md
72
94
  - doc/STYLE_GUIDE_RSPEC.md
73
95
  - lib/datarockets/style.rb
96
+ - lib/datarockets/style/cop/layout/array_alignment_extended.rb
97
+ - lib/datarockets/style/cop/style/nested_interpolation.rb
74
98
  - lib/datarockets/style/formatter/todo_list_formatter.rb
75
99
  - lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb
76
100
  - lib/datarockets/style/version.rb
101
+ - manual/cops_layout.md
77
102
  homepage: https://github.com/datarockets/datarockets-style
78
103
  licenses:
79
104
  - MIT
@@ -87,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
112
  requirements:
88
113
  - - ">="
89
114
  - !ruby/object:Gem::Version
90
- version: 2.3.0
115
+ version: 2.4.0
91
116
  required_rubygems_version: !ruby/object:Gem::Requirement
92
117
  requirements:
93
118
  - - ">="
@@ -95,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
120
  version: '0'
96
121
  requirements: []
97
122
  rubyforge_project:
98
- rubygems_version: 2.7.6
123
+ rubygems_version: 2.6.14
99
124
  signing_key:
100
125
  specification_version: 4
101
126
  summary: Datarockets style guides and shared style configs