Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- DRYs things up a bit. - Ensures each cop correctly handles heredocs. - Unifies highlighting format. * Note: It was very hard to find some sort of unified way to highlight the different possible node endings, so I just went with highlighting the lowest offending line starting right of any whitespace. - Ensures each cop allows comments immediately following the offending line, notably to provide support for rubocop:disable directives (especially disable/enable pairs that might surround the block).
- Loading branch information
Showing
8 changed files
with
115 additions
and
78 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module RuboCop | ||
module RSpec | ||
# Helps determine the offending location if there is not a blank line | ||
# following the node. Allows comments to follow directly after. | ||
module BlankLineSeparation | ||
include FinalEndLocation | ||
include RuboCop::Cop::RangeHelp | ||
|
||
def missing_separating_line(node) | ||
line = final_end_location(node).line | ||
|
||
line += 1 while comment_line?(processed_source[line]) | ||
|
||
return if processed_source[line].blank? | ||
|
||
yield offending_loc(line) | ||
end | ||
|
||
def offending_loc(last_line) | ||
offending_line = processed_source[last_line - 1] | ||
|
||
content_length = offending_line.lstrip.length | ||
start = offending_line.length - content_length | ||
|
||
source_range(processed_source.buffer, last_line, start, content_length) | ||
end | ||
|
||
def autocorrect(node) | ||
lambda do |corrector| | ||
missing_separating_line(node) do |location| | ||
corrector.insert_after(location.end, "\n") | ||
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
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