-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix line number sometimes wrongly reported by no_tab_linter() (#134)
- Loading branch information
Showing
4 changed files
with
25 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
#' @describeIn linters check that only spaces are used, never tabs. | ||
#' @describeIn linters check that only spaces are used for indentation, not tabs. | ||
#' @export | ||
no_tab_linter <- function(source_file) { | ||
all_res <- re_matches( | ||
all_matches <- re_matches( | ||
source_file$lines, | ||
rex(start, zero_or_more(regex("\\s")), one_or_more("\t")), | ||
locations = TRUE, | ||
global = TRUE | ||
) | ||
names(all_res) <- as.character(seq_along(all_res)) | ||
|
||
# filter out lines with no matches | ||
all_res <- all_res[ | ||
vapply(all_res, function(line_match) {!is.na(line_match[["start"]][[1L]])}, logical(1L)) | ||
] | ||
line_numbers <- as.integer(names(source_file$lines)) | ||
|
||
Map( | ||
function(line_res, line_num) { | ||
function(line_matches, line_number) { | ||
lapply( | ||
split(line_res, seq_len(nrow(line_res))), | ||
function(res) { | ||
split(line_matches, seq_len(nrow(line_matches))), | ||
function(match) { | ||
start <- match[["start"]] | ||
if (is.na(start)) { | ||
return() | ||
} | ||
end <- match[["end"]] | ||
Lint( | ||
filename = source_file$filename, | ||
line_number = line_num, | ||
column_number = res[["start"]], | ||
line_number = line_number, | ||
column_number = start, | ||
type = "style", | ||
message = "Use spaces to indent, not tabs.", | ||
line = source_file$lines[line_num], | ||
line = source_file$lines[[as.character(line_number)]], | ||
|
||
# R outputs tabs with 8 spaces | ||
# TODO: this is incorrect for embedded tabs, I am not going to fix it. | ||
ranges = list(c(res[["start"]], res[["end"]])), | ||
ranges = list(c(start, end)), | ||
linter = "no_tab_linter" | ||
) | ||
} | ||
) | ||
}, | ||
all_res, | ||
names(all_res) | ||
all_matches, | ||
line_numbers | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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