datarockets-style 1.0.0 → 1.1.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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +15 -1
- data/Gemfile.lock +28 -29
- data/bin/console +1 -1
- data/config/base.yml +7 -1
- data/datarockets-style.gemspec +3 -3
- data/doc/STYLE_GUIDE.md +40 -0
- data/lib/datarockets_style.rb +12 -0
- data/lib/datarockets_style/cop/layout/array_alignment_extended.rb +81 -0
- data/lib/datarockets_style/cop/style/nested_interpolation.rb +35 -0
- data/lib/{datarockets/style → datarockets_style}/formatter/todo_list_formatter.rb +1 -1
- data/lib/datarockets_style/formatter/todo_list_formatter/report_summary.rb +55 -0
- data/lib/datarockets_style/version.rb +3 -0
- metadata +11 -11
- data/lib/datarockets/style.rb +0 -14
- data/lib/datarockets/style/cop/layout/array_alignment_extended.rb +0 -83
- data/lib/datarockets/style/cop/style/nested_interpolation.rb +0 -37
- data/lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb +0 -57
- data/lib/datarockets/style/version.rb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ef40260e95ced035f4c8f86b18c807997a4e79228c72e75a880477fecb8030e
|
|
4
|
+
data.tar.gz: b35d77e092533855df4092585e8af229653859c6cce685bed399f50880d5bc49
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8b0a2bcb81d48837a708f337e3f37baba4e26d86f1be42fa02c12f441e18286b1164996a0a0026f870886a887c7664300683de2b80dee0e7fc6c4721934fce2
|
|
7
|
+
data.tar.gz: 0dd7f1c7bd2a72a7cbebe4fb5eaf4b399f53d014b0ecfe701be979917e09e7bc7467367d0dced76d25f9a76ad369b88da746285774e092b0078eea180209c913
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
|
4
4
|
|
|
5
5
|
## master
|
|
6
6
|
|
|
7
|
+
## 1.1.0 (2021-02-09)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* Setup `EnforcedStyleForMultiline` for `Style/TrailingCommaInHashLiteral` rule. ([@r.dubrovsky][])
|
|
12
|
+
* Update rubocop to ```1.9.1```.([@paydaylight][])
|
|
13
|
+
* Update rubocop-rails requirement to ```>= 2.8.0, < 2.10.0```. ([@paydaylight][])
|
|
14
|
+
* Update rubocop-rspec to `2.2.0`. ([@paydaylight][])
|
|
15
|
+
* Change ```Datarockets::Style``` module to ```DatarocketsStyle```. ([@paydaylight][])
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
* [#177](https://github.com/datarockets/datarockets-style/issues/177) set ```Layout/MultilineOperationIndentation``` to indented ([@paydaylight][])
|
|
20
|
+
|
|
7
21
|
## 1.0.0 (2020-11-10)
|
|
8
22
|
|
|
9
23
|
### Changed
|
|
@@ -207,4 +221,4 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
|
207
221
|
[@v.kuzmik]: https://github.com/TheBlackArroVV/
|
|
208
222
|
[@a.branzeanu]: https://github.com/texpert
|
|
209
223
|
[@nikitasakov]: https://github.com/nikitasakov
|
|
210
|
-
|
|
224
|
+
[@paydaylight]: https://github.com/paydaylight
|
data/Gemfile.lock
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
datarockets-style (1.
|
|
4
|
+
datarockets-style (1.1.0)
|
|
5
5
|
rubocop (>= 1.2, < 2.0)
|
|
6
|
-
rubocop-rails (>= 2.8.0, < 2.
|
|
6
|
+
rubocop-rails (>= 2.8.0, < 2.10.0)
|
|
7
7
|
rubocop-rspec (~> 2.0)
|
|
8
8
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
activesupport (6.
|
|
12
|
+
activesupport (6.1.1)
|
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
14
|
-
i18n (>=
|
|
15
|
-
minitest (
|
|
16
|
-
tzinfo (~>
|
|
17
|
-
zeitwerk (~> 2.
|
|
18
|
-
ast (2.4.
|
|
14
|
+
i18n (>= 1.6, < 2)
|
|
15
|
+
minitest (>= 5.1)
|
|
16
|
+
tzinfo (~> 2.0)
|
|
17
|
+
zeitwerk (~> 2.3)
|
|
18
|
+
ast (2.4.2)
|
|
19
19
|
byebug (11.1.3)
|
|
20
20
|
coderay (1.1.2)
|
|
21
21
|
concurrent-ruby (1.1.7)
|
|
22
22
|
diff-lcs (1.4.4)
|
|
23
|
-
i18n (1.8.
|
|
23
|
+
i18n (1.8.7)
|
|
24
24
|
concurrent-ruby (~> 1.0)
|
|
25
25
|
method_source (1.0.0)
|
|
26
|
-
minitest (5.14.
|
|
27
|
-
parallel (1.20.
|
|
28
|
-
parser (
|
|
26
|
+
minitest (5.14.3)
|
|
27
|
+
parallel (1.20.1)
|
|
28
|
+
parser (3.0.0.0)
|
|
29
29
|
ast (~> 2.4.1)
|
|
30
30
|
pry (0.13.1)
|
|
31
31
|
coderay (~> 1.1)
|
|
@@ -35,8 +35,8 @@ GEM
|
|
|
35
35
|
pry (~> 0.13.0)
|
|
36
36
|
rack (2.2.3)
|
|
37
37
|
rainbow (3.0.0)
|
|
38
|
-
rake (13.0.
|
|
39
|
-
regexp_parser (
|
|
38
|
+
rake (13.0.3)
|
|
39
|
+
regexp_parser (2.0.3)
|
|
40
40
|
rexml (3.2.4)
|
|
41
41
|
rspec (3.10.0)
|
|
42
42
|
rspec-core (~> 3.10.0)
|
|
@@ -51,30 +51,29 @@ GEM
|
|
|
51
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
52
52
|
rspec-support (~> 3.10.0)
|
|
53
53
|
rspec-support (3.10.0)
|
|
54
|
-
rubocop (1.
|
|
54
|
+
rubocop (1.9.1)
|
|
55
55
|
parallel (~> 1.10)
|
|
56
|
-
parser (>=
|
|
56
|
+
parser (>= 3.0.0.0)
|
|
57
57
|
rainbow (>= 2.2.2, < 4.0)
|
|
58
|
-
regexp_parser (>= 1.8)
|
|
58
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
59
59
|
rexml
|
|
60
|
-
rubocop-ast (>= 1.0.
|
|
60
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
|
61
61
|
ruby-progressbar (~> 1.7)
|
|
62
|
-
unicode-display_width (>= 1.4.0, <
|
|
63
|
-
rubocop-ast (1.
|
|
62
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
63
|
+
rubocop-ast (1.4.1)
|
|
64
64
|
parser (>= 2.7.1.5)
|
|
65
|
-
rubocop-rails (2.
|
|
65
|
+
rubocop-rails (2.9.1)
|
|
66
66
|
activesupport (>= 4.2.0)
|
|
67
67
|
rack (>= 1.1)
|
|
68
|
-
rubocop (>= 0.
|
|
69
|
-
rubocop-rspec (2.
|
|
68
|
+
rubocop (>= 0.90.0, < 2.0)
|
|
69
|
+
rubocop-rspec (2.1.0)
|
|
70
70
|
rubocop (~> 1.0)
|
|
71
71
|
rubocop-ast (>= 1.1.0)
|
|
72
|
-
ruby-progressbar (1.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
zeitwerk (2.4.1)
|
|
72
|
+
ruby-progressbar (1.11.0)
|
|
73
|
+
tzinfo (2.0.4)
|
|
74
|
+
concurrent-ruby (~> 1.0)
|
|
75
|
+
unicode-display_width (2.0.0)
|
|
76
|
+
zeitwerk (2.4.2)
|
|
78
77
|
|
|
79
78
|
PLATFORMS
|
|
80
79
|
ruby
|
data/bin/console
CHANGED
data/config/base.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require:
|
|
1
|
+
require: datarockets_style
|
|
2
2
|
|
|
3
3
|
AllCops:
|
|
4
4
|
NewCops: enable
|
|
@@ -50,6 +50,9 @@ Layout/FirstHashElementIndentation:
|
|
|
50
50
|
Layout/MultilineMethodCallIndentation:
|
|
51
51
|
EnforcedStyle: indented
|
|
52
52
|
|
|
53
|
+
Layout/MultilineOperationIndentation:
|
|
54
|
+
EnforcedStyle: indented
|
|
55
|
+
|
|
53
56
|
Layout/SpaceAroundMethodCallOperator:
|
|
54
57
|
Enabled: true
|
|
55
58
|
|
|
@@ -186,3 +189,6 @@ Style/StringConcatenation:
|
|
|
186
189
|
|
|
187
190
|
Style/StringLiterals:
|
|
188
191
|
EnforcedStyle: double_quotes
|
|
192
|
+
|
|
193
|
+
Style/TrailingCommaInHashLiteral:
|
|
194
|
+
EnforcedStyleForMultiline: comma
|
data/datarockets-style.gemspec
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
lib = File.expand_path("lib", __dir__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require "
|
|
3
|
+
require "datarockets_style/version"
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "datarockets-style"
|
|
7
|
-
spec.version =
|
|
7
|
+
spec.version = DatarocketsStyle::VERSION
|
|
8
8
|
spec.authors = ["Roman Dubrovsky"]
|
|
9
9
|
spec.email = ["r.dubrovsky@datarockets.com"]
|
|
10
10
|
|
|
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
|
|
|
31
31
|
spec.require_paths = ["lib"]
|
|
32
32
|
|
|
33
33
|
spec.add_dependency "rubocop", ">= 1.2 ", "< 2.0"
|
|
34
|
-
spec.add_dependency "rubocop-rails", ">= 2.8.0", "< 2.
|
|
34
|
+
spec.add_dependency "rubocop-rails", ">= 2.8.0", "< 2.10.0"
|
|
35
35
|
spec.add_dependency "rubocop-rspec", "~> 2.0"
|
|
36
36
|
end
|
data/doc/STYLE_GUIDE.md
CHANGED
|
@@ -392,6 +392,46 @@ def foo
|
|
|
392
392
|
end
|
|
393
393
|
```
|
|
394
394
|
|
|
395
|
+
* <a name="style-trailing-comma-in-hash-literal"></a>
|
|
396
|
+
Requires a comma after the last item in a hash.
|
|
397
|
+
<sup>[[link](#style-trailing-comma-in-hash-literal)]</sup>
|
|
398
|
+
|
|
399
|
+
```ruby
|
|
400
|
+
# bad
|
|
401
|
+
a = { foo: 1, bar: 2, }
|
|
402
|
+
|
|
403
|
+
# good
|
|
404
|
+
a = { foo: 1, bar: 2 }
|
|
405
|
+
|
|
406
|
+
# bad
|
|
407
|
+
a = {
|
|
408
|
+
foo: 1, bar: 2,
|
|
409
|
+
qux: 3,
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
# good
|
|
413
|
+
a = {
|
|
414
|
+
foo: 1, bar: 2,
|
|
415
|
+
qux: 3
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
# bad
|
|
419
|
+
a = {
|
|
420
|
+
foo: 1, bar: 2, qux: 3,
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
# good
|
|
424
|
+
a = {
|
|
425
|
+
foo: 1, bar: 2, qux: 3
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
# good
|
|
429
|
+
a = {
|
|
430
|
+
foo: 1,
|
|
431
|
+
bar: 2,
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
395
435
|
* <a name="style-magic-link"></a>
|
|
396
436
|
There are not any required rules for `frozen_string_literal` magic url.
|
|
397
437
|
Set up [this cop](https://rubocop.readthedocs.io/en/latest/cops_style/#stylefrozenstringliteralcomment) depends on the project.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "rubocop"
|
|
2
|
+
require "datarockets_style/formatter/todo_list_formatter"
|
|
3
|
+
|
|
4
|
+
require "datarockets_style/version"
|
|
5
|
+
|
|
6
|
+
require "datarockets_style/cop/layout/array_alignment_extended"
|
|
7
|
+
require "datarockets_style/cop/style/nested_interpolation"
|
|
8
|
+
|
|
9
|
+
# Top level module for datarockets-style
|
|
10
|
+
module DatarocketsStyle
|
|
11
|
+
# Datarickors sharable config
|
|
12
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DatarocketsStyle
|
|
4
|
+
module Cop
|
|
5
|
+
module Layout
|
|
6
|
+
# Here we check if the elements of a multi-line array literal are
|
|
7
|
+
# aligned.
|
|
8
|
+
#
|
|
9
|
+
# @example EnforcedStyle: with_first_argument (default)
|
|
10
|
+
# # good
|
|
11
|
+
#
|
|
12
|
+
# array = [1, 2, 3,
|
|
13
|
+
# 4, 5, 6]
|
|
14
|
+
# array = ['run',
|
|
15
|
+
# 'forrest',
|
|
16
|
+
# 'run']
|
|
17
|
+
#
|
|
18
|
+
# # bad
|
|
19
|
+
#
|
|
20
|
+
# array = [1, 2, 3,
|
|
21
|
+
# 4, 5, 6]
|
|
22
|
+
# array = ['run',
|
|
23
|
+
# 'forrest',
|
|
24
|
+
# 'run']
|
|
25
|
+
#
|
|
26
|
+
# @example EnforcedStyle: with_fixed_indentation
|
|
27
|
+
# # good
|
|
28
|
+
#
|
|
29
|
+
# array = [1, 2, 3,
|
|
30
|
+
# 4, 5, 6]
|
|
31
|
+
#
|
|
32
|
+
# # bad
|
|
33
|
+
#
|
|
34
|
+
# array = [1, 2, 3,
|
|
35
|
+
# 4, 5, 6]
|
|
36
|
+
class ArrayAlignmentExtended < RuboCop::Cop::Cop
|
|
37
|
+
include RuboCop::Cop::Alignment
|
|
38
|
+
|
|
39
|
+
ALIGN_PARAMS_MSG = "Align the elements of an array literal if they span more than one line."
|
|
40
|
+
|
|
41
|
+
FIXED_INDENT_MSG = "Use one level of indentation for elements " \
|
|
42
|
+
"following the first line of a multi-line array."
|
|
43
|
+
|
|
44
|
+
def on_array(node)
|
|
45
|
+
return if node.children.size < 2
|
|
46
|
+
|
|
47
|
+
check_alignment(node.children, base_column(node, node.children))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def autocorrect(node)
|
|
51
|
+
RuboCop::Cop::AlignmentCorrector.correct(processed_source, node, column_delta)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def message(_node)
|
|
57
|
+
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def fixed_indentation?
|
|
61
|
+
cop_config["EnforcedStyle"] == "with_fixed_indentation"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def base_column(node, args)
|
|
65
|
+
fixed_indentation? ? line_indentation(node) : display_column(args.first.source_range)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def line_indentation(node)
|
|
69
|
+
lineno = target_method_lineno(node)
|
|
70
|
+
line = node.source_range.source_buffer.source_line(lineno)
|
|
71
|
+
line_indentation = /\S.*/.match(line).begin(0)
|
|
72
|
+
line_indentation + configured_indentation_width
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def target_method_lineno(node)
|
|
76
|
+
node.loc.line
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module DatarocketsStyle
|
|
2
|
+
module Cop
|
|
3
|
+
module Style
|
|
4
|
+
# This cop checks nested interpolations
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
#
|
|
8
|
+
# # bad
|
|
9
|
+
# "Hello, #{user.blank? ? 'guest' : "dear #{user.name}"}"
|
|
10
|
+
#
|
|
11
|
+
# # good
|
|
12
|
+
# user_name = user.blank? ? 'guest' : "dear #{user.name}"
|
|
13
|
+
# "Hello, #{user_name}"
|
|
14
|
+
class NestedInterpolation < RuboCop::Cop::Cop
|
|
15
|
+
include RuboCop::Cop::Interpolation
|
|
16
|
+
|
|
17
|
+
MSG = "Redundant nested interpolation.".freeze
|
|
18
|
+
|
|
19
|
+
def on_interpolation(node)
|
|
20
|
+
node.each_descendant(:dstr) do |descendant_node|
|
|
21
|
+
detect_double_interpolation(descendant_node)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def detect_double_interpolation(node)
|
|
28
|
+
node.each_child_node(:begin) do |begin_node|
|
|
29
|
+
add_offense(begin_node)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -46,6 +46,6 @@ class TodoListFormatter < RuboCop::Formatter::ProgressFormatter
|
|
|
46
46
|
@total_correctable_count)
|
|
47
47
|
output.puts
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
DatarocketsStyle::Formatter::TodoListFormatter::ReportSummary.new(offense_list).call(output)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module DatarocketsStyle
|
|
2
|
+
module Formatter
|
|
3
|
+
module TodoListFormatter
|
|
4
|
+
# Get file of pairs: file path and cop name - and prepare report for ToDo list formatter.
|
|
5
|
+
#
|
|
6
|
+
# Example of result:
|
|
7
|
+
#
|
|
8
|
+
# LineLength
|
|
9
|
+
# Exclude:
|
|
10
|
+
# - "really/bad/file.rb" # 100500
|
|
11
|
+
# - "almost/ok.rb" # 1
|
|
12
|
+
class ReportSummary
|
|
13
|
+
attr_reader :offense_list
|
|
14
|
+
|
|
15
|
+
FileGroup = Struct.new(:file, :offenses_count) do
|
|
16
|
+
def print(output)
|
|
17
|
+
output.puts " - '#{file}' # #{offenses_count}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
OffenseGroup = Struct.new(:cop_name, :offenses) do
|
|
22
|
+
def file_groups
|
|
23
|
+
@_file_groups ||= offenses.group_by(&:file_path).map do |file, offenses|
|
|
24
|
+
FileGroup.new(file, offenses.length)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def print(output)
|
|
29
|
+
output.puts("#{cop_name}:")
|
|
30
|
+
output.puts(" Exclude:")
|
|
31
|
+
file_groups.sort_by(&:file).each do |file_group|
|
|
32
|
+
file_group.print(output)
|
|
33
|
+
end
|
|
34
|
+
output.puts
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def initialize(offense_list)
|
|
39
|
+
@offense_list = offense_list
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def call(output)
|
|
43
|
+
offense_groups.sort_by(&:cop_name).each { |group| group.print(output) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def offense_groups
|
|
49
|
+
@_offense_groups ||= offense_list.group_by(&:cop_name)
|
|
50
|
+
.map { |cop_name, offenses| OffenseGroup.new(cop_name, offenses) }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
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: 1.
|
|
4
|
+
version: 1.1.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: 2021-02-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
version: 2.8.0
|
|
40
40
|
- - "<"
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 2.
|
|
42
|
+
version: 2.10.0
|
|
43
43
|
type: :runtime
|
|
44
44
|
prerelease: false
|
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -49,7 +49,7 @@ dependencies:
|
|
|
49
49
|
version: 2.8.0
|
|
50
50
|
- - "<"
|
|
51
51
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: 2.
|
|
52
|
+
version: 2.10.0
|
|
53
53
|
- !ruby/object:Gem::Dependency
|
|
54
54
|
name: rubocop-rspec
|
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -98,12 +98,12 @@ files:
|
|
|
98
98
|
- doc/STYLE_GUIDE.md
|
|
99
99
|
- doc/STYLE_GUIDE_RAILS.md
|
|
100
100
|
- doc/STYLE_GUIDE_RSPEC.md
|
|
101
|
-
- lib/
|
|
102
|
-
- lib/
|
|
103
|
-
- lib/
|
|
104
|
-
- lib/
|
|
105
|
-
- lib/
|
|
106
|
-
- lib/
|
|
101
|
+
- lib/datarockets_style.rb
|
|
102
|
+
- lib/datarockets_style/cop/layout/array_alignment_extended.rb
|
|
103
|
+
- lib/datarockets_style/cop/style/nested_interpolation.rb
|
|
104
|
+
- lib/datarockets_style/formatter/todo_list_formatter.rb
|
|
105
|
+
- lib/datarockets_style/formatter/todo_list_formatter/report_summary.rb
|
|
106
|
+
- lib/datarockets_style/version.rb
|
|
107
107
|
- manual/cops_layout.md
|
|
108
108
|
homepage: https://github.com/datarockets/datarockets-style
|
|
109
109
|
licenses:
|
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
125
125
|
- !ruby/object:Gem::Version
|
|
126
126
|
version: '0'
|
|
127
127
|
requirements: []
|
|
128
|
-
rubygems_version: 3.
|
|
128
|
+
rubygems_version: 3.2.5
|
|
129
129
|
signing_key:
|
|
130
130
|
specification_version: 4
|
|
131
131
|
summary: Datarockets style guides and shared style configs
|
data/lib/datarockets/style.rb
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "rubocop"
|
|
2
|
-
require "datarockets/style/formatter/todo_list_formatter"
|
|
3
|
-
|
|
4
|
-
require "datarockets/style/version"
|
|
5
|
-
|
|
6
|
-
require "datarockets/style/cop/layout/array_alignment_extended"
|
|
7
|
-
require "datarockets/style/cop/style/nested_interpolation"
|
|
8
|
-
|
|
9
|
-
module Datarockets
|
|
10
|
-
# Datarickors sharable config
|
|
11
|
-
module Style
|
|
12
|
-
# Your code goes here...
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
module Datarockets
|
|
2
|
-
module Style
|
|
3
|
-
module Formatter
|
|
4
|
-
module TodoListFormatter
|
|
5
|
-
# Get file of pairs: file path and cop name - and prepare report for ToDo list formatter.
|
|
6
|
-
#
|
|
7
|
-
# Example of result:
|
|
8
|
-
#
|
|
9
|
-
# LineLength
|
|
10
|
-
# Exclude:
|
|
11
|
-
# - "really/bad/file.rb" # 100500
|
|
12
|
-
# - "almost/ok.rb" # 1
|
|
13
|
-
class ReportSummary
|
|
14
|
-
attr_reader :offense_list
|
|
15
|
-
|
|
16
|
-
FileGroup = Struct.new(:file, :offenses_count) do
|
|
17
|
-
def print(output)
|
|
18
|
-
output.puts " - '#{file}' # #{offenses_count}"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
OffenseGroup = Struct.new(:cop_name, :offenses) do
|
|
23
|
-
def file_groups
|
|
24
|
-
@_file_groups ||= offenses.group_by(&:file_path).map do |file, offenses|
|
|
25
|
-
FileGroup.new(file, offenses.length)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def print(output)
|
|
30
|
-
output.puts("#{cop_name}:")
|
|
31
|
-
output.puts(" Exclude:")
|
|
32
|
-
file_groups.sort_by(&:file).each do |file_group|
|
|
33
|
-
file_group.print(output)
|
|
34
|
-
end
|
|
35
|
-
output.puts
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def initialize(offense_list)
|
|
40
|
-
@offense_list = offense_list
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def call(output)
|
|
44
|
-
offense_groups.sort_by(&:cop_name).each { |group| group.print(output) }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
def offense_groups
|
|
50
|
-
@_offense_groups ||= offense_list.group_by(&:cop_name)
|
|
51
|
-
.map { |cop_name, offenses| OffenseGroup.new(cop_name, offenses) }
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|