Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Fix #220] changed namespace to DatarocketsStyle * obey Layout/MultilineMethodCallIndentation cop * update changelog
- Loading branch information
1 parent
ea95a9d
commit 2701703
Showing
22 changed files
with
206 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require: datarockets/style | ||
require: datarockets_style | ||
|
||
AllCops: | ||
NewCops: enable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
83 changes: 0 additions & 83 deletions
83
lib/datarockets/style/cop/layout/array_alignment_extended.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
lib/datarockets/style/formatter/todo_list_formatter/report_summary.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "rubocop" | ||
require "datarockets_style/formatter/todo_list_formatter" | ||
|
||
require "datarockets_style/version" | ||
|
||
require "datarockets_style/cop/layout/array_alignment_extended" | ||
require "datarockets_style/cop/style/nested_interpolation" | ||
|
||
# Top level module for datarockets-style | ||
module DatarocketsStyle | ||
# Datarickors sharable config | ||
end |
81 changes: 81 additions & 0 deletions
81
lib/datarockets_style/cop/layout/array_alignment_extended.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
module DatarocketsStyle | ||
module Cop | ||
module Layout | ||
# Here we check if the elements of a multi-line array literal are | ||
# aligned. | ||
# | ||
# @example EnforcedStyle: with_first_argument (default) | ||
# # good | ||
# | ||
# array = [1, 2, 3, | ||
# 4, 5, 6] | ||
# array = ['run', | ||
# 'forrest', | ||
# 'run'] | ||
# | ||
# # bad | ||
# | ||
# array = [1, 2, 3, | ||
# 4, 5, 6] | ||
# array = ['run', | ||
# 'forrest', | ||
# 'run'] | ||
# | ||
# @example EnforcedStyle: with_fixed_indentation | ||
# # good | ||
# | ||
# array = [1, 2, 3, | ||
# 4, 5, 6] | ||
# | ||
# # bad | ||
# | ||
# array = [1, 2, 3, | ||
# 4, 5, 6] | ||
class ArrayAlignmentExtended < RuboCop::Cop::Cop | ||
include RuboCop::Cop::Alignment | ||
|
||
ALIGN_PARAMS_MSG = "Align the elements of an array literal if they span more than one line." | ||
|
||
FIXED_INDENT_MSG = "Use one level of indentation for elements " \ | ||
"following the first line of a multi-line array." | ||
|
||
def on_array(node) | ||
return if node.children.size < 2 | ||
|
||
check_alignment(node.children, base_column(node, node.children)) | ||
end | ||
|
||
def autocorrect(node) | ||
RuboCop::Cop::AlignmentCorrector.correct(processed_source, node, column_delta) | ||
end | ||
|
||
private | ||
|
||
def message(_node) | ||
fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG | ||
end | ||
|
||
def fixed_indentation? | ||
cop_config["EnforcedStyle"] == "with_fixed_indentation" | ||
end | ||
|
||
def base_column(node, args) | ||
fixed_indentation? ? line_indentation(node) : display_column(args.first.source_range) | ||
end | ||
|
||
def line_indentation(node) | ||
lineno = target_method_lineno(node) | ||
line = node.source_range.source_buffer.source_line(lineno) | ||
line_indentation = /\S.*/.match(line).begin(0) | ||
line_indentation + configured_indentation_width | ||
end | ||
|
||
def target_method_lineno(node) | ||
node.loc.line | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module DatarocketsStyle | ||
module Cop | ||
module Style | ||
# This cop checks nested interpolations | ||
# | ||
# @example | ||
# | ||
# # bad | ||
# "Hello, #{user.blank? ? 'guest' : "dear #{user.name}"}" | ||
# | ||
# # good | ||
# user_name = user.blank? ? 'guest' : "dear #{user.name}" | ||
# "Hello, #{user_name}" | ||
class NestedInterpolation < RuboCop::Cop::Cop | ||
include RuboCop::Cop::Interpolation | ||
|
||
MSG = "Redundant nested interpolation.".freeze | ||
|
||
def on_interpolation(node) | ||
node.each_descendant(:dstr) do |descendant_node| | ||
detect_double_interpolation(descendant_node) | ||
end | ||
end | ||
|
||
private | ||
|
||
def detect_double_interpolation(node) | ||
node.each_child_node(:begin) do |begin_node| | ||
add_offense(begin_node) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.