-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[R-package] added R linting and changed R code to comma-first (fixes #2373) #2437
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
37b294b
added R linting and changed R code to comma-first (fixes #2373)
jameslamb 68687b5
exit from R linting task
jameslamb 1f30204
simplified setup for R linting
jameslamb 5cfb2ff
fixed long lines and alignment of roxygen blocks
jameslamb ede360b
updated roxygen files
jameslamb 83502e9
added more R linters
jameslamb eaf4631
updated list of R linters
jameslamb 1eca955
fixed bad object reference in linting code
jameslamb 3936709
fixed cpplint bad rebase
jameslamb d807aa3
more minor changes to style
jameslamb 14d285a
regenned roxygen documentation
jameslamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
library(lintr) | ||
|
||
args <- commandArgs( | ||
trailingOnly = TRUE | ||
) | ||
SOURCE_DIR <- args[[1]] | ||
|
||
FILES_TO_LINT <- list.files( | ||
path = SOURCE_DIR | ||
, pattern = "\\.r$" | ||
, all.files = TRUE | ||
, ignore.case = TRUE | ||
, full.names = TRUE | ||
, recursive = TRUE | ||
, include.dirs = FALSE | ||
) | ||
|
||
# Some linters from the lintr package have not made it to CRAN yet | ||
# We build lintr from source to address that. | ||
LINTERS_TO_USE <- list( | ||
Laurae2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"closed_curly" = lintr::closed_curly_linter | ||
, "infix_spaces" = lintr::infix_spaces_linter | ||
, "long_lines" = lintr::line_length_linter(length = 120) | ||
, "tabs" = lintr::no_tab_linter | ||
, "open_curly" = lintr::open_curly_linter | ||
, "spaces_inside" = lintr::spaces_inside_linter | ||
, "spaces_left_parens" = lintr::spaces_left_parentheses_linter | ||
, "trailing_blank" = lintr::trailing_blank_lines_linter | ||
, "trailing_white" = lintr::trailing_whitespace_linter | ||
) | ||
|
||
cat(sprintf("Found %i R files to lint\n", length(FILES_TO_LINT))) | ||
|
||
results <- c() | ||
|
||
for (r_file in FILES_TO_LINT){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space before |
||
|
||
this_result <- lintr::lint( | ||
filename = r_file | ||
, linters = LINTERS_TO_USE | ||
, cache = FALSE | ||
) | ||
|
||
cat(sprintf( | ||
"Found %i linting errors in %s\n" | ||
, length(this_result) | ||
, r_file | ||
)) | ||
|
||
results <- c(results, this_result) | ||
|
||
} | ||
|
||
issues_found <- length(results) | ||
|
||
if (issues_found > 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space before |
||
cat("\n") | ||
print(results) | ||
} | ||
|
||
quit(save = "no", status = issues_found) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many (approximately: 1, 2, or more) linters are not available with the package version installed from CRAN? I guess, there will be many problems with the installation from sources (perhaps, we already have them, refer to
Error in library(lintr) : there is no package called ‘lintr’
). So, maybe introduce new linters when they will be available on CRAN?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's on the order of 4-6. Yeah, I kind of wanted to test how the installation from source plays with
conda
R, and the only way I knew to reliably reproduce the environment on Travis was to just directly try on Travis.I'll take out the unreleased ones for now and create an issue (closed and attached to #2302 ) for adding the new ones once
lintr
gets updated. I'm also going to gently open a "can you please do a release" issue onlintr
, since it has been almost a year since the last one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! I think it's the most appropriate way to introduce the linting and do not suffer from it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a comment on r-lib/lintr#318 asking for a new release.