Skip to content
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

21 lint #22

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Suggests:
urlchecker,
readr,
xopen,
spelling
spelling,
lintr
Remotes:
github::jmbarbone/fuj,
github::jmbarbone/mark
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export(.Fixmes)
export(.FixmesHere)
export(.GitBranchPrompt)
export(.GitPrepareCommitMsg)
export(.LintFile)
export(.NewsUrls)
export(.NiceMessage)
export(.OpenFile)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Rprofile (development)

* Adds `.LintFile()` for selecting individual files to `lint` (defaults to currently opened file) [#21]
* Adds `.GitPrepareCommitMsg()` to copy one of two templates to `.git/hook/prepare-commit-msg` [#10]
* Adds `.OpenFile()` to open a file path or an object inside a file [#6]

Expand Down
28 changes: 28 additions & 0 deletions R/lint.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' Lint a single file
#'
#' Use `lintr::lint()` to _lint_ a single file
#'
#' @param path The file path. Default (`NULL`) checks for the current file open
#' in the source editor in **RStudio**.
#' @param linters Passed to `linters` argument in `lintr::lint()`; however,
#' when passing a character vector, finds all linters with that tag.
#' @param ... Additional arguments passed to `lintr::lint()`
#' @returns See `lintr::lint()`
#' @export
.LintFile <- function(path = NULL, linters = "default", ...) {
fuj::require_namespace("lintr")

if (is.null(path)) {
fuj::require_namespace("rstudioapi")
path <- rstudioapi::getSourceEditorContext()$path
}

if (is.character(linters)) {
linters <- lintr::available_linters(tags = linters)$linter
linters <- fuj::set_names(linters)
linters <- lapply(linters, get, pos = asNamespace("lintr"))
}

path <- normalizePath(path, .Platform$file.sep, mustWork = TRUE)
lintr::lint(path, linters = linters, ...)
}
23 changes: 23 additions & 0 deletions man/dot-LintFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.