datarockets-style 0.9.0 → 1.2.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/.gitignore +4 -0
- data/CHANGELOG.md +70 -3
- data/Gemfile +0 -4
- data/README.md +16 -16
- data/RELEASING.md +16 -0
- data/bin/console +1 -1
- data/config/base.yml +101 -1
- data/config/rails.yml +2 -2
- data/config/rspec.yml +6 -0
- data/datarockets-style.gemspec +9 -5
- data/doc/STYLE_GUIDE.md +120 -0
- data/doc/STYLE_GUIDE_RSPEC.md +20 -0
- data/lib/datarockets_style.rb +13 -0
- data/lib/datarockets_style/cop/layout/array_alignment_extended.rb +81 -0
- data/lib/datarockets_style/cop/rspec/prefer_before_over_setup.rb +43 -0
- data/lib/datarockets_style/cop/style/nested_interpolation.rb +35 -0
- data/lib/{datarockets/style → datarockets_style}/formatter/todo_list_formatter.rb +3 -2
- data/lib/datarockets_style/formatter/todo_list_formatter/report_summary.rb +55 -0
- data/lib/datarockets_style/version.rb +3 -0
- data/manual/cops_layout.md +24 -0
- metadata +62 -21
- data/Gemfile.lock +0 -84
- 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
data/Gemfile.lock
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
datarockets-style (0.9.0)
|
5
|
-
rubocop (~> 0.84)
|
6
|
-
rubocop-rails (~> 2.5.2)
|
7
|
-
rubocop-rspec (~> 1.39)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
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.0)
|
18
|
-
byebug (11.1.3)
|
19
|
-
coderay (1.1.2)
|
20
|
-
concurrent-ruby (1.1.6)
|
21
|
-
diff-lcs (1.3)
|
22
|
-
i18n (1.8.2)
|
23
|
-
concurrent-ruby (~> 1.0)
|
24
|
-
method_source (1.0.0)
|
25
|
-
minitest (5.14.1)
|
26
|
-
parallel (1.19.1)
|
27
|
-
parser (2.7.1.3)
|
28
|
-
ast (~> 2.4.0)
|
29
|
-
pry (0.13.1)
|
30
|
-
coderay (~> 1.1)
|
31
|
-
method_source (~> 1.0)
|
32
|
-
pry-byebug (3.9.0)
|
33
|
-
byebug (~> 11.0)
|
34
|
-
pry (~> 0.13.0)
|
35
|
-
rack (2.2.2)
|
36
|
-
rainbow (3.0.0)
|
37
|
-
rake (13.0.1)
|
38
|
-
rexml (3.2.4)
|
39
|
-
rspec (3.9.0)
|
40
|
-
rspec-core (~> 3.9.0)
|
41
|
-
rspec-expectations (~> 3.9.0)
|
42
|
-
rspec-mocks (~> 3.9.0)
|
43
|
-
rspec-core (3.9.0)
|
44
|
-
rspec-support (~> 3.9.0)
|
45
|
-
rspec-expectations (3.9.0)
|
46
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.9.0)
|
48
|
-
rspec-mocks (3.9.0)
|
49
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.9.0)
|
51
|
-
rspec-support (3.9.0)
|
52
|
-
rubocop (0.84.0)
|
53
|
-
parallel (~> 1.10)
|
54
|
-
parser (>= 2.7.0.1)
|
55
|
-
rainbow (>= 2.2.2, < 4.0)
|
56
|
-
rexml
|
57
|
-
rubocop-ast (>= 0.0.3)
|
58
|
-
ruby-progressbar (~> 1.7)
|
59
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
60
|
-
rubocop-ast (0.0.3)
|
61
|
-
parser (>= 2.7.0.1)
|
62
|
-
rubocop-rails (2.5.2)
|
63
|
-
activesupport
|
64
|
-
rack (>= 1.1)
|
65
|
-
rubocop (>= 0.72.0)
|
66
|
-
rubocop-rspec (1.39.0)
|
67
|
-
rubocop (>= 0.68.1)
|
68
|
-
ruby-progressbar (1.10.1)
|
69
|
-
thread_safe (0.3.6)
|
70
|
-
tzinfo (1.2.7)
|
71
|
-
thread_safe (~> 0.1)
|
72
|
-
unicode-display_width (1.7.0)
|
73
|
-
|
74
|
-
PLATFORMS
|
75
|
-
ruby
|
76
|
-
|
77
|
-
DEPENDENCIES
|
78
|
-
datarockets-style!
|
79
|
-
pry-byebug
|
80
|
-
rake (~> 13.0)
|
81
|
-
rspec (~> 3.7)
|
82
|
-
|
83
|
-
BUNDLED WITH
|
84
|
-
2.1.4
|
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
|