-
Notifications
You must be signed in to change notification settings - Fork 184
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
Add text argument to lint #503
Conversation
If https://github.com/jimhester/lintr/blob/42b49c1ba6d74a4910419d7ef78df804914d2b4e/R/lint.R#L30-L36 |
@renkun-ken is this ready for review? if so please help to merge to HEAD 😄 |
I update this PR to latest master.
I guess we might need to keep it that way for a while and might give a warning in the future if Now the behavior is:
If you think this behavior makes sense, then I'll update some test cases to fix the tests. |
I test the latest commit with languageserver using the |
Yes, please. This PR is ready for review and merge now. |
please remove .DS_Store |
R/lint.R
Outdated
#' @param text Optional argument for supplying a string or lines or lines directly, | ||
#' e.g. if the file is already in memory or linting is being done ad hoc. | ||
#' If \code{text} is supplied but \code{filename} is missing, then \code{tempfile()} | ||
#' will be used as the \code{filename}. |
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 looks like <text>
will be used as the file name, this reads like the output would have the tempfile path instead... could you clarify what we mean here?
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 is indeed a bit ambiguous here. Here I mean that if text
is provided but filename
is not, then we'll write the text to a temp file (same behavior as before when filename
is detected to be code), but the lint result will show as <text>
which I believe should be the desired output rather than showing the tempfile in the lint result.
Looks like I should update this doc here, maybe just removing the text
without filename
case in the doc looks enough since writing the text to a file is just an internal implementation?
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.
a string or lines or lines directly
looks a bit redundant?
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 think so. Removed the last sentence
almost there, thanks! |
tests/testthat/test-lint_file.R
Outdated
@@ -119,6 +119,7 @@ test_that("lint() results from file or text should be consistent", { | |||
"x<-1", | |||
"x+1" | |||
) | |||
on.exit(unlink(file)) |
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 didn't use on.exit()
here because I want to ensure that lintr does not assume that the file exists when linting with both filename
and text
supplied. Therefore, I remove the file before linting so that if lint reads the file somehow it would fail as it should, which is the point of lint_from_text2
.
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.
ah ok, please revert
Thanks for the review! |
Looks like we forgot to add a news item. I'll create a quick PR for this soon. |
Close #475
This PR adds a
text=
argument tolintr::lint
so that user could lint a file with suppliedtext
as if the file is being linted. This is particularly useful for code editors to lively lint a file being edited but not saved while keeping the.lintr
config (if found) effective.text=
argument tolintr::lint