lintr/ 0000755 0001762 0000144 00000000000 14522460532 011405 5 ustar ligges users lintr/NAMESPACE 0000644 0001762 0000144 00000011563 14522452242 012631 0 ustar ligges users # Generated by roxygen2: do not edit by hand
if (getRversion() >= "4.0.0") {
importFrom(tools, R_user_dir)
} else {
importFrom(backports, R_user_dir)
}
S3method("[",lints)
S3method(as.data.frame,lints)
S3method(format,lint)
S3method(format,lints)
S3method(names,lints)
S3method(print,lint)
S3method(print,lints)
S3method(split,lints)
S3method(summary,lints)
export(Lint)
export(Linter)
export(T_and_F_symbol_linter)
export(absolute_path_linter)
export(all_linters)
export(all_undesirable_functions)
export(all_undesirable_operators)
export(any_duplicated_linter)
export(any_is_na_linter)
export(assignment_linter)
export(available_linters)
export(available_tags)
export(backport_linter)
export(boolean_arithmetic_linter)
export(brace_linter)
export(checkstyle_output)
export(class_equals_linter)
export(clear_cache)
export(closed_curly_linter)
export(commas_linter)
export(commented_code_linter)
export(condition_message_linter)
export(conjunct_test_linter)
export(consecutive_assertion_linter)
export(consecutive_stopifnot_linter)
export(cyclocomp_linter)
export(default_linters)
export(default_settings)
export(default_undesirable_functions)
export(default_undesirable_operators)
export(duplicate_argument_linter)
export(empty_assignment_linter)
export(equals_na_linter)
export(expect_comparison_linter)
export(expect_identical_linter)
export(expect_length_linter)
export(expect_lint)
export(expect_lint_free)
export(expect_named_linter)
export(expect_not_linter)
export(expect_null_linter)
export(expect_s3_class_linter)
export(expect_s4_class_linter)
export(expect_true_false_linter)
export(expect_type_linter)
export(extraction_operator_linter)
export(fixed_regex_linter)
export(for_loop_index_linter)
export(function_argument_linter)
export(function_left_parentheses_linter)
export(function_return_linter)
export(get_r_string)
export(get_source_expressions)
export(ids_with_token)
export(if_not_else_linter)
export(ifelse_censor_linter)
export(implicit_assignment_linter)
export(implicit_integer_linter)
export(indentation_linter)
export(infix_spaces_linter)
export(inner_combine_linter)
export(is_lint_level)
export(is_numeric_linter)
export(keyword_quote_linter)
export(length_levels_linter)
export(length_test_linter)
export(lengths_linter)
export(library_call_linter)
export(line_length_linter)
export(lint)
export(lint_dir)
export(lint_package)
export(linters_with_defaults)
export(linters_with_tags)
export(literal_coercion_linter)
export(make_linter_from_xpath)
export(matrix_apply_linter)
export(missing_argument_linter)
export(missing_package_linter)
export(modify_defaults)
export(namespace_linter)
export(nested_ifelse_linter)
export(no_tab_linter)
export(nonportable_path_linter)
export(numeric_leading_zero_linter)
export(object_length_linter)
export(object_name_linter)
export(object_usage_linter)
export(open_curly_linter)
export(outer_negation_linter)
export(package_hooks_linter)
export(paren_body_linter)
export(paren_brace_linter)
export(paste_linter)
export(pipe_call_linter)
export(pipe_consistency_linter)
export(pipe_continuation_linter)
export(quotes_linter)
export(redundant_equals_linter)
export(redundant_ifelse_linter)
export(regex_subset_linter)
export(repeat_linter)
export(routine_registration_linter)
export(sarif_output)
export(scalar_in_linter)
export(semicolon_linter)
export(semicolon_terminator_linter)
export(seq_linter)
export(single_quotes_linter)
export(sort_linter)
export(spaces_inside_linter)
export(spaces_left_parentheses_linter)
export(sprintf_linter)
export(string_boundary_linter)
export(strings_as_factors_linter)
export(system_file_linter)
export(todo_comment_linter)
export(trailing_blank_lines_linter)
export(trailing_whitespace_linter)
export(undesirable_function_linter)
export(undesirable_operator_linter)
export(unnecessary_concatenation_linter)
export(unnecessary_lambda_linter)
export(unnecessary_nested_if_linter)
export(unnecessary_placeholder_linter)
export(unneeded_concatenation_linter)
export(unreachable_code_linter)
export(unused_import_linter)
export(use_lintr)
export(vector_logic_linter)
export(whitespace_linter)
export(with_defaults)
export(with_id)
export(xml_nodes_to_lints)
export(xp_call_name)
export(yoda_test_linter)
importFrom(cyclocomp,cyclocomp)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(rex,character_class)
importFrom(rex,re_matches)
importFrom(rex,re_substitutes)
importFrom(rex,regex)
importFrom(rex,rex)
importFrom(stats,na.omit)
importFrom(utils,capture.output)
importFrom(utils,getParseData)
importFrom(utils,getTxtProgressBar)
importFrom(utils,globalVariables)
importFrom(utils,head)
importFrom(utils,relist)
importFrom(utils,setTxtProgressBar)
importFrom(utils,tail)
importFrom(utils,txtProgressBar)
importFrom(xml2,as_list)
importFrom(xml2,xml_attr)
importFrom(xml2,xml_find_all)
importFrom(xml2,xml_find_chr)
importFrom(xml2,xml_find_first)
importFrom(xml2,xml_find_lgl)
importFrom(xml2,xml_find_num)
importFrom(xml2,xml_name)
importFrom(xml2,xml_text)
lintr/LICENSE 0000644 0001762 0000144 00000000057 14251630510 012406 0 ustar ligges users YEAR: 2014-2016
COPYRIGHT HOLDER: James Hester
lintr/README.md 0000644 0001762 0000144 00000004617 14377165326 012707 0 ustar ligges users # lintr
[](https://github.com/r-lib/lintr/actions)
[](https://app.codecov.io/gh/r-lib/lintr?branch=main)
[](https://cran.r-project.org/package=lintr)
[](https://lifecycle.r-lib.org/articles/stages.html)
`{lintr}` provides [static code analysis for R](https://en.wikipedia.org/wiki/Static_program_analysis). It checks for adherence to a given style, identifying syntax errors and possible semantic issues, then reports them to you so you can take action. Watch lintr in action in the following animation:

`{lintr}` is complementary to [the `{styler}` package](https://github.com/r-lib/styler) which automatically restyles code, eliminating some of the problems that `{lintr}` can detect.
## Installation
Install the stable version from CRAN:
```R
install.packages("lintr")
```
Or the development version from GitHub:
```R
# install.packages("remotes")
remotes::install_github("r-lib/lintr")
```
## Usage
And then you can create a configuration file and run selected linters:
```R
lintr::use_lintr(type = "tidyverse")
# in a project:
lintr::lint_dir()
# in a package:
lintr::lint_package()
```
To see a list of linters included for each configuration:
```R
# tidyverse (default)
names(lintr::linters_with_defaults())
# full
names(lintr::all_linters())
```
### Setting up GitHub Actions
`{usethis}` provides helper functions to generate lint workflows for GitHub Actions:
```R
# in a project:
usethis::use_github_action("lint-project")
# in a package:
usethis::use_github_action("lint")
```
You can also run lintr during continuous integration or within your IDE or text editor. See `vignette("continuous-integration")` and `vignette("editors")` for more details.
Without further configuration, this will run the [default linters](https://lintr.r-lib.org/reference/default_linters.html). See `vignette("lintr")` to learn how to modify these defaults.
## Code of Conduct
Please note that the lintr project is released with a [Contributor Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). By contributing to this project, you agree to abide by its terms.
lintr/man/ 0000755 0001762 0000144 00000000000 14522452242 012157 5 ustar ligges users lintr/man/unnecessary_concatenation_linter.Rd 0000644 0001762 0000144 00000003676 14377165326 021317 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/unnecessary_concatenation_linter.R
\name{unnecessary_concatenation_linter}
\alias{unnecessary_concatenation_linter}
\title{Unneeded concatenation linter}
\usage{
unnecessary_concatenation_linter(allow_single_expression = TRUE)
}
\arguments{
\item{allow_single_expression}{Logical, default \code{TRUE}. If \code{FALSE}, one-expression
usages of \code{c()} are always linted, e.g. \code{c(x)} and \code{c(matrix(...))}. In some such
cases, \code{c()} is being used for its side-effect of stripping non-name attributes;
it is usually preferable to use the more readable \code{\link[=as.vector]{as.vector()}} instead.
\code{\link[=as.vector]{as.vector()}} is not always preferable, for example with environments
(especially, \code{R6} objects), in which case \code{list()} is the better alternative.}
}
\description{
Check that the \code{\link[=c]{c()}} function is not used without arguments nor with a single constant.
}
\examples{
# will produce lints
lint(
text = "x <- c()",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- c(TRUE)",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- c(1.5 + 2.5)",
linters = unnecessary_concatenation_linter(allow_single_expression = FALSE)
)
# okay
lint(
text = "x <- NULL",
linters = unnecessary_concatenation_linter()
)
# In case the intent here was to seed a vector of known size
lint(
text = "x <- integer(4L)",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- TRUE",
linters = unnecessary_concatenation_linter()
)
lint(
text = "x <- c(1.5 + 2.5)",
linters = unnecessary_concatenation_linter(allow_single_expression = TRUE)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/length_levels_linter.Rd 0000644 0001762 0000144 00000001404 14522452242 016655 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/length_levels_linter.R
\name{length_levels_linter}
\alias{length_levels_linter}
\title{Require usage of nlevels over length(levels(.))}
\usage{
length_levels_linter()
}
\description{
\code{length(levels(x))} is the same as \code{nlevels(x)}, but harder to read.
}
\examples{
# will produce lints
lint(
text = "length(levels(x))",
linters = length_levels_linter()
)
# okay
lint(
text = "length(c(levels(x), levels(y)))",
linters = length_levels_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=consistency_linters]{consistency}, \link[=readability_linters]{readability}
}
lintr/man/system_file_linter.Rd 0000644 0001762 0000144 00000002037 14377165324 016362 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/system_file_linter.R
\name{system_file_linter}
\alias{system_file_linter}
\title{Block usage of \code{file.path()} with \code{system.file()}}
\usage{
system_file_linter()
}
\description{
\code{\link[=system.file]{system.file()}} has a \code{...} argument which, internally, is passed to
\code{\link[=file.path]{file.path()}}, so including it in user code is repetitive.
}
\examples{
# will produce lints
lint(
text = 'system.file(file.path("path", "to", "data"), package = "foo")',
linters = system_file_linter()
)
lint(
text = 'file.path(system.file(package = "foo"), "path", "to", "data")',
linters = system_file_linter()
)
# okay
lint(
text = 'system.file("path", "to", "data", package = "foo")',
linters = system_file_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=consistency_linters]{consistency}, \link[=readability_linters]{readability}
}
lintr/man/ids_with_token.Rd 0000644 0001762 0000144 00000004044 14522452242 015462 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ids_with_token.R, R/with_id.R
\name{ids_with_token}
\alias{ids_with_token}
\alias{with_id}
\title{Get parsed IDs by token}
\usage{
ids_with_token(source_expression, value, fun = `==`, source_file = NULL)
with_id(source_expression, id, source_file)
}
\arguments{
\item{source_expression}{A list of source expressions, the result of a call to \code{\link[=get_source_expressions]{get_source_expressions()}},
for the desired filename.}
\item{value}{Character. String corresponding to the token to search for.
For example:
\itemize{
\item "SYMBOL"
\item "FUNCTION"
\item "EQ_FORMALS"
\item "$"
\item "("
}}
\item{fun}{For additional flexibility, a function to search for in
the \code{token} column of \code{parsed_content}. Typically \code{==} or \code{\%in\%}.}
\item{source_file}{(DEPRECATED) Same as \code{source_expression}. Will be removed.}
\item{id}{Integer. The index corresponding to the desired row
of \code{parsed_content}.}
}
\value{
\code{ids_with_token}: The indices of the \code{parsed_content} data frame
entry of the list of source expressions. Indices correspond to the
\emph{rows} where \code{fun} evaluates to \code{TRUE} for the \code{value} in the \emph{token} column.
\code{with_id}: A data frame corresponding to the row(s) specified in \code{id}.
}
\description{
Gets the source IDs (row indices) corresponding to given token.
}
\section{Functions}{
\itemize{
\item \code{with_id()}: Return the row of the \code{parsed_content} entry of the \verb{[get_source_expressions]()} object. Typically used in
conjunction with \code{ids_with_token} to iterate over rows containing desired tokens.
}}
\examples{
\dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
source_exprs <- get_source_expressions(tmp)
ids_with_token(source_exprs$expressions[[1L]], value = "SYMBOL")
with_id(source_exprs$expressions[[1L]], 2L)
\dontshow{\}) # examplesIf}
}
lintr/man/nonportable_path_linter.Rd 0000644 0001762 0000144 00000001737 14377165326 017406 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nonportable_path_linter.R
\name{nonportable_path_linter}
\alias{nonportable_path_linter}
\title{Non-portable path linter}
\usage{
nonportable_path_linter(lax = TRUE)
}
\arguments{
\item{lax}{Less stringent linting, leading to fewer false positives.
If \code{TRUE}, only lint path strings, which
\itemize{
\item contain at least two path elements, with one having at least two characters and
\item contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
}}
}
\description{
Check that \code{\link[=file.path]{file.path()}} is used to construct safe and portable paths.
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \code{\link[=absolute_path_linter]{absolute_path_linter()}}
}
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=configurable_linters]{configurable}, \link[=robustness_linters]{robustness}
}
lintr/man/infix_spaces_linter.Rd 0000644 0001762 0000144 00000004627 14522452242 016507 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/infix_spaces_linter.R
\name{infix_spaces_linter}
\alias{infix_spaces_linter}
\title{Infix spaces linter}
\usage{
infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE)
}
\arguments{
\item{exclude_operators}{Character vector of operators to exclude from consideration for linting.
Default is to include the following "low-precedence" operators:
\code{+}, \code{-}, \code{~}, \code{>}, \code{>=}, \code{<}, \code{<=}, \code{==}, \code{!=}, \code{&}, \code{&&}, \code{|}, \code{||}, \verb{<-}, \verb{:=}, \verb{<<-}, \verb{->}, \verb{->>},
\code{=}, \code{/}, \code{*}, and any infix operator (exclude infixes by passing \code{"\%\%"}). Note that \code{"="} here includes
three different operators, from the parser's point of view. To lint only some of these, pass the
corresponding parse tags (i.e., some of \code{"EQ_ASSIGN"}, \code{"EQ_SUB"}, and \code{"EQ_FORMALS"}; see
\code{\link[utils:getParseData]{utils::getParseData()}}).}
\item{allow_multiple_spaces}{Logical, default \code{TRUE}. If \code{FALSE}, usage like \code{x = 2} will also be linted;
excluded by default because such usage can sometimes be used for better code alignment, as is allowed
by the style guide.}
}
\description{
Check that infix operators are surrounded by spaces. Enforces the corresponding Tidyverse style guide rule;
see \url{https://style.tidyverse.org/syntax.html#infix-operators}.
}
\examples{
# will produce lints
lint(
text = "x<-1L",
linters = infix_spaces_linter()
)
lint(
text = "1:4 \%>\%sum()",
linters = infix_spaces_linter()
)
# okay
lint(
text = "x <- 1L",
linters = infix_spaces_linter()
)
lint(
text = "1:4 \%>\% sum()",
linters = infix_spaces_linter()
)
code_lines <- "
ab <- 1L
abcdef <- 2L
"
writeLines(code_lines)
lint(
text = code_lines,
linters = infix_spaces_linter(allow_multiple_spaces = TRUE)
)
lint(
text = "a||b",
linters = infix_spaces_linter(exclude_operators = "||")
)
lint(
text = "sum(1:10, na.rm=TRUE)",
linters = infix_spaces_linter(exclude_operators = "EQ_SUB")
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#infix-operators}
}
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/missing_argument_linter.Rd 0000644 0001762 0000144 00000002212 14377165326 017407 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/missing_argument_linter.R
\name{missing_argument_linter}
\alias{missing_argument_linter}
\title{Missing argument linter}
\usage{
missing_argument_linter(
except = c("alist", "quote", "switch"),
allow_trailing = FALSE
)
}
\arguments{
\item{except}{a character vector of function names as exceptions.}
\item{allow_trailing}{always allow trailing empty arguments?}
}
\description{
Check for missing arguments in function calls (e.g. \code{stats::median(1:10, )}).
}
\examples{
# will produce lints
lint(
text = 'tibble(x = "a", )',
linters = missing_argument_linter()
)
# okay
lint(
text = 'tibble(x = "a")',
linters = missing_argument_linter()
)
lint(
text = 'tibble(x = "a", )',
linters = missing_argument_linter(except = "tibble")
)
lint(
text = 'tibble(x = "a", )',
linters = missing_argument_linter(allow_trailing = TRUE)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=common_mistakes_linters]{common_mistakes}, \link[=configurable_linters]{configurable}, \link[=correctness_linters]{correctness}
}
lintr/man/common_mistakes_linters.Rd 0000644 0001762 0000144 00000001412 14522452242 017374 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{common_mistakes_linters}
\alias{common_mistakes_linters}
\title{Common mistake linters}
\description{
Linters highlighting common mistakes, such as duplicate arguments.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'common_mistakes':
\itemize{
\item{\code{\link{duplicate_argument_linter}}}
\item{\code{\link{equals_na_linter}}}
\item{\code{\link{length_test_linter}}}
\item{\code{\link{missing_argument_linter}}}
\item{\code{\link{missing_package_linter}}}
\item{\code{\link{redundant_equals_linter}}}
\item{\code{\link{sprintf_linter}}}
\item{\code{\link{unused_import_linter}}}
}
}
lintr/man/expect_null_linter.Rd 0000644 0001762 0000144 00000002555 14522452242 016354 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_null_linter.R
\name{expect_null_linter}
\alias{expect_null_linter}
\title{Require usage of \code{expect_null} for checking \code{NULL}}
\usage{
expect_null_linter()
}
\description{
Require usage of \code{expect_null(x)} over \code{expect_equal(x, NULL)} and similar
usages.
}
\details{
\code{\link[testthat:expect_null]{testthat::expect_null()}} exists specifically for testing for \code{NULL} objects.
\code{\link[testthat:equality-expectations]{testthat::expect_equal()}}, \code{\link[testthat:equality-expectations]{testthat::expect_identical()}}, and
\code{\link[testthat:logical-expectations]{testthat::expect_true()}} can also be used for such tests,
but it is better to use the tailored function instead.
}
\examples{
# will produce lints
lint(
text = "expect_equal(x, NULL)",
linters = expect_null_linter()
)
lint(
text = "expect_identical(x, NULL)",
linters = expect_null_linter()
)
lint(
text = "expect_true(is.null(x))",
linters = expect_null_linter()
)
# okay
lint(
text = "expect_null(x)",
linters = expect_null_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=package_development_linters]{package_development}, \link[=pkg_testthat_linters]{pkg_testthat}
}
lintr/man/expect_true_false_linter.Rd 0000644 0001762 0000144 00000002601 14522452242 017523 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_true_false_linter.R
\name{expect_true_false_linter}
\alias{expect_true_false_linter}
\title{Require usage of \code{expect_true(x)} over \code{expect_equal(x, TRUE)}}
\usage{
expect_true_false_linter()
}
\description{
\code{\link[testthat:logical-expectations]{testthat::expect_true()}} and \code{\link[testthat:logical-expectations]{testthat::expect_false()}} exist specifically
for testing the \code{TRUE}/\code{FALSE} value of an object.
\code{\link[testthat:equality-expectations]{testthat::expect_equal()}} and \code{\link[testthat:equality-expectations]{testthat::expect_identical()}} can also be
used for such tests, but it is better to use the tailored function instead.
}
\examples{
# will produce lints
lint(
text = "expect_equal(x, TRUE)",
linters = expect_true_false_linter()
)
lint(
text = "expect_equal(x, FALSE)",
linters = expect_true_false_linter()
)
# okay
lint(
text = "expect_true(x)",
linters = expect_true_false_linter()
)
lint(
text = "expect_false(x)",
linters = expect_true_false_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=package_development_linters]{package_development}, \link[=pkg_testthat_linters]{pkg_testthat}, \link[=readability_linters]{readability}
}
lintr/man/trailing_blank_lines_linter.Rd 0000644 0001762 0000144 00000001654 14377165326 020217 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trailing_blank_lines_linter.R
\name{trailing_blank_lines_linter}
\alias{trailing_blank_lines_linter}
\title{Trailing blank lines linter}
\usage{
trailing_blank_lines_linter()
}
\description{
Check that there are no trailing blank lines in source code.
}
\examples{
\dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
# will produce lints
f <- withr::local_tempfile(lines = "x <- 1\n")
readLines(f)
lint(
filename = f,
linters = trailing_blank_lines_linter()
)
# okay
f <- withr::local_tempfile(lines = "x <- 1")
readLines(f)
lint(
filename = f,
linters = trailing_blank_lines_linter()
)
\dontshow{\}) # examplesIf}
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=default_linters]{default}, \link[=style_linters]{style}
}
lintr/man/whitespace_linter.Rd 0000644 0001762 0000144 00000001674 14455765330 016201 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/whitespace_linter.R
\name{whitespace_linter}
\alias{whitespace_linter}
\title{Whitespace linter}
\usage{
whitespace_linter()
}
\description{
Check that the correct character is used for indentation.
}
\details{
Currently, only supports linting in the presence of tabs.
Much ink has been spilled on this topic, and we encourage you to check
out references for more information.
}
\examples{
# will produce lints
lint(
text = "\tx",
linters = whitespace_linter()
)
# okay
lint(
text = " x",
linters = whitespace_linter()
)
}
\references{
\itemize{
\item https://www.jwz.org/doc/tabs-vs-spaces.html
\item https://blog.codinghorror.com/death-to-the-space-infidels/
}
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=consistency_linters]{consistency}, \link[=default_linters]{default}, \link[=style_linters]{style}
}
lintr/man/sort_linter.Rd 0000644 0001762 0000144 00000004343 14522452242 015016 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sort_linter.R
\name{sort_linter}
\alias{sort_linter}
\title{Check for common mistakes around sorting vectors}
\usage{
sort_linter()
}
\description{
This linter checks for some common mistakes when using \code{\link[=order]{order()}} or \code{\link[=sort]{sort()}}.
}
\details{
First, it requires usage of \code{sort()} over \code{.[order(.)]}.
\code{\link[=sort]{sort()}} is the dedicated option to sort a list or vector. It is more legible
and around twice as fast as \code{.[order(.)]}, with the gap in performance
growing with the vector size.
Second, it requires usage of \code{\link[=is.unsorted]{is.unsorted()}} over equivalents using \code{sort()}.
The base function \code{is.unsorted()} exists to test the sortedness of a vector.
Prefer it to inefficient and less-readable equivalents like
\code{x != sort(x)}. The same goes for checking \code{x == sort(x)} -- use
\code{!is.unsorted(x)} instead.
Moreover, use of \code{x == sort(x)} can be risky because \code{\link[=sort]{sort()}} drops missing
elements by default, meaning \code{==} might end up trying to compare vectors
of differing lengths.
}
\examples{
# will produce lints
lint(
text = "x[order(x)]",
linters = sort_linter()
)
lint(
text = "x[order(x, decreasing = TRUE)]",
linters = sort_linter()
)
lint(
text = "sort(x) == x",
linters = sort_linter()
)
# okay
lint(
text = "x[sample(order(x))]",
linters = sort_linter()
)
lint(
text = "y[order(x)]",
linters = sort_linter()
)
lint(
text = "sort(x, decreasing = TRUE) == x",
linters = sort_linter()
)
# If you are sorting several objects based on the order of one of them, such
# as:
x <- sample(1:26)
y <- letters
newx <- x[order(x)]
newy <- y[order(x)]
# This will be flagged by the linter. However, in this very specific case,
# it would be clearer and more efficient to run order() once and assign it
# to an object, rather than mix and match order() and sort()
index <- order(x)
newx <- x[index]
newy <- y[index]
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/scalar_in_linter.Rd 0000644 0001762 0000144 00000001503 14522452242 015755 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scalar_in_linter.R
\name{scalar_in_linter}
\alias{scalar_in_linter}
\title{Block usage like x \%in\% "a"}
\usage{
scalar_in_linter()
}
\description{
\code{vector \%in\% set} is appropriate for matching a vector to a set, but if
that set has size 1, \code{==} is more appropriate. \verb{\%chin\%} from \code{{data.table}}
is matched as well.
}
\details{
\code{scalar \%in\% vector} is OK, because the alternative (\code{any(vector == scalar)})
is more circuitous & potentially less clear.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=consistency_linters]{consistency}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/expect_lint.Rd 0000644 0001762 0000144 00000004143 14377165326 015002 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_lint.R
\name{expect_lint}
\alias{expect_lint}
\title{Lint expectation}
\usage{
expect_lint(content, checks, ..., file = NULL, language = "en")
}
\arguments{
\item{content}{a character vector for the file content to be linted, each vector element representing a line of
text.}
\item{checks}{checks to be performed:
\describe{
\item{NULL}{check that no lints are returned.}
\item{single string or regex object}{check that the single lint returned has a matching message.}
\item{named list}{check that the single lint returned has fields that match. Accepted fields are the same as those
taken by \code{\link[=Lint]{Lint()}}.}
\item{list of named lists}{for each of the multiple lints returned, check that it matches the checks in the
corresponding named list (as described in the point above).}
}
Named vectors are also accepted instead of named lists, but this is a compatibility feature that
is not recommended for new code.}
\item{...}{arguments passed to \code{\link[=lint]{lint()}}, e.g. the linters or cache to use.}
\item{file}{if not \code{NULL}, read content from the specified file rather than from \code{content}.}
\item{language}{temporarily override Rs \code{LANGUAGE} envvar, controlling localization of base R error messages.
This makes testing them reproducible on all systems irrespective of their native R language setting.}
}
\value{
\code{NULL}, invisibly.
}
\description{
This is an expectation function to test that the lints produced by \code{lint} satisfy a number of checks.
}
\examples{
# no expected lint
expect_lint("a", NULL, trailing_blank_lines_linter())
# one expected lint
expect_lint("a\n", "superfluous", trailing_blank_lines_linter())
expect_lint("a\n", list(message = "superfluous", line_number = 2), trailing_blank_lines_linter())
# several expected lints
expect_lint("a\n\n", list("superfluous", "superfluous"), trailing_blank_lines_linter())
expect_lint(
"a\n\n",
list(
list(message = "superfluous", line_number = 2),
list(message = "superfluous", line_number = 3)
),
trailing_blank_lines_linter()
)
}
lintr/man/is_numeric_linter.Rd 0000644 0001762 0000144 00000002445 14377165324 016177 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/is_numeric_linter.R
\name{is_numeric_linter}
\alias{is_numeric_linter}
\title{Redirect \code{is.numeric(x) || is.integer(x)} to just use \code{is.numeric(x)}}
\usage{
is_numeric_linter()
}
\description{
\code{\link[=is.numeric]{is.numeric()}} returns \code{TRUE} when \code{typeof(x)} is \code{double} or \code{integer} --
testing \code{is.numeric(x) || is.integer(x)} is thus redundant.
}
\details{
NB: This linter plays well with \code{\link[=class_equals_linter]{class_equals_linter()}}, which can help
avoid further \code{is.numeric()} equivalents like
\code{any(class(x) == c("numeric", "integer"))}.
}
\examples{
# will produce lints
lint(
text = "is.numeric(y) || is.integer(y)",
linters = is_numeric_linter()
)
lint(
text = 'class(z) \%in\% c("numeric", "integer")',
linters = is_numeric_linter()
)
# okay
lint(
text = "is.numeric(y) || is.factor(y)",
linters = is_numeric_linter()
)
lint(
text = 'class(z) \%in\% c("numeric", "integer", "factor")',
linters = is_numeric_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=consistency_linters]{consistency}, \link[=readability_linters]{readability}
}
lintr/man/expect_length_linter.Rd 0000644 0001762 0000144 00000002104 14522452242 016651 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_length_linter.R
\name{expect_length_linter}
\alias{expect_length_linter}
\title{Require usage of \code{expect_length(x, n)} over \code{expect_equal(length(x), n)}}
\usage{
expect_length_linter()
}
\description{
\code{\link[testthat:expect_length]{testthat::expect_length()}} exists specifically for testing the \code{\link[=length]{length()}} of
an object. \code{\link[testthat:equality-expectations]{testthat::expect_equal()}} can also be used for such tests,
but it is better to use the tailored function instead.
}
\examples{
# will produce lints
lint(
text = "expect_equal(length(x), 2L)",
linters = expect_length_linter()
)
# okay
lint(
text = "expect_length(x, 2L)",
linters = expect_length_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=package_development_linters]{package_development}, \link[=pkg_testthat_linters]{pkg_testthat}, \link[=readability_linters]{readability}
}
lintr/man/pipe_continuation_linter.Rd 0000644 0001762 0000144 00000002644 14377165326 017574 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pipe_continuation_linter.R
\name{pipe_continuation_linter}
\alias{pipe_continuation_linter}
\title{Pipe continuation linter}
\usage{
pipe_continuation_linter()
}
\description{
Check that each step in a pipeline is on a new line, or the entire pipe fits on one line.
}
\examples{
# will produce lints
code_lines <- "1:3 \%>\%\n mean() \%>\% as.character()"
writeLines(code_lines)
lint(
text = code_lines,
linters = pipe_continuation_linter()
)
code_lines <- "1:3 |> mean() |>\n as.character()"
writeLines(code_lines)
lint(
text = code_lines,
linters = pipe_continuation_linter()
)
# okay
lint(
text = "1:3 \%>\% mean() \%>\% as.character()",
linters = pipe_continuation_linter()
)
code_lines <- "1:3 \%>\%\n mean() \%>\%\n as.character()"
writeLines(code_lines)
lint(
text = code_lines,
linters = pipe_continuation_linter()
)
lint(
text = "1:3 |> mean() |> as.character()",
linters = pipe_continuation_linter()
)
code_lines <- "1:3 |>\n mean() |>\n as.character()"
writeLines(code_lines)
lint(
text = code_lines,
linters = pipe_continuation_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/pipes.html#long-lines-2}
}
}
\section{Tags}{
\link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/extraction_operator_linter.Rd 0000644 0001762 0000144 00000004057 14377165324 020136 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/extraction_operator_linter.R
\name{extraction_operator_linter}
\alias{extraction_operator_linter}
\title{Extraction operator linter}
\usage{
extraction_operator_linter()
}
\description{
Check that the \code{[[} operator is used when extracting a single element from an object,
not \code{[} (subsetting) nor \code{$} (interactive use).
}
\details{
There are three subsetting operators in R (\code{[[}, \code{[}, and \code{$}) and they interact differently
with different data structures (atomic vector, list, data frame, etc.).
Here are a few reasons to prefer the \code{[[} operator over \code{[} or \code{$} when you want to extract
an element from a data frame or a list:
\itemize{
\item Subsetting a list with \code{[} always returns a smaller list, while \code{[[} returns
the list element.
\item Subsetting a named atomic vector with \code{[} returns a named vector, while \code{[[} returns
the vector element.
\item Subsetting a data frame (but not tibble) with \code{[} is type unstable; it can return
a vector or a data frame. \code{[[}, on the other hand, always returns a vector.
\item For a data frame (but not tibble), \code{$} does partial matching (e.g. \code{df$a} will subset
\code{df$abc}), which can be a source of bugs. \code{[[} doesn't do partial matching.
}
For data frames (and tibbles), irrespective of the size, the \code{[[} operator is slower than \code{$}.
For lists, however, the reverse is true.
}
\examples{
# will produce lints
lint(
text = 'iris["Species"]',
linters = extraction_operator_linter()
)
lint(
text = "iris$Species",
linters = extraction_operator_linter()
)
# okay
lint(
text = 'iris[["Species"]]',
linters = extraction_operator_linter()
)
}
\references{
\itemize{
\item Subsetting \href{https://adv-r.hadley.nz/subsetting.html}{chapter} from \emph{Advanced R} (Wickham, 2019).
}
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=style_linters]{style}
}
lintr/man/linters_with_tags.Rd 0000644 0001762 0000144 00000004332 14455765330 016213 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/with.R
\name{linters_with_tags}
\alias{linters_with_tags}
\title{Create a tag-based linter configuration}
\usage{
linters_with_tags(tags, ..., packages = "lintr", exclude_tags = "deprecated")
}
\arguments{
\item{tags}{Optional character vector of tags to search. Only linters with at least one matching tag will be
returned. If \code{tags} is \code{NULL}, all linters will be returned. See \code{available_tags("lintr")} to find out what
tags are already used by lintr.}
\item{...}{Arguments of elements to change. If unnamed, the argument is automatically named.
If the named argument already exists in the list of linters, it is replaced by the new element.
If it does not exist, it is added. If the value is \code{NULL}, the linter is removed.}
\item{packages}{A character vector of packages to search for linters.}
\item{exclude_tags}{Tags to exclude from the results. Linters with at least one matching tag will not be returned.
If \code{except_tags} is \code{NULL}, no linters will be excluded. Note that \code{tags} takes priority, meaning that any
tag found in both \code{tags} and \code{exclude_tags} will be included, not excluded.}
}
\value{
A modified list of linters.
}
\description{
Make a new list based on all linters provided by \code{packages} and tagged with \code{tags}.
The result of this function is meant to be passed to the \code{linters} argument of \code{lint()},
or to be put in your configuration file.
}
\examples{
# `linters_with_defaults()` and `linters_with_tags("default")` are the same:
all.equal(linters_with_defaults(), linters_with_tags("default"))
# Get all linters useful for package development
linters <- linters_with_tags(tags = c("package_development", "style"))
names(linters)
# Get all linters tagged as "default" from lintr and mypkg
if (FALSE) {
linters_with_tags("default", packages = c("lintr", "mypkg"))
}
}
\seealso{
\itemize{
\item \link{linters_with_defaults} for basing off lintr's set of default linters.
\item \link{all_linters} for basing off all available linters in lintr.
\item \link{available_linters} to get a data frame of available linters.
\item \link{linters} for a complete list of linters available in lintr.
}
}
lintr/man/for_loop_index_linter.Rd 0000644 0001762 0000144 00000001770 14377165324 017050 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/for_loop_index_linter.R
\name{for_loop_index_linter}
\alias{for_loop_index_linter}
\title{Block usage of for loops directly overwriting the indexing variable}
\usage{
for_loop_index_linter()
}
\description{
\verb{for (x in x)} is a poor choice of indexing variable. This overwrites
\code{x} in the calling scope and is confusing to read.
}
\examples{
# will produce lints
lint(
text = "for (x in x) { TRUE }",
linters = for_loop_index_linter()
)
lint(
text = "for (x in foo(x, y)) { TRUE }",
linters = for_loop_index_linter()
)
# okay
lint(
text = "for (xi in x) { TRUE }",
linters = for_loop_index_linter()
)
lint(
text = "for (col in DF$col) { TRUE }",
linters = for_loop_index_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=readability_linters]{readability}, \link[=robustness_linters]{robustness}
}
lintr/man/keyword_quote_linter.Rd 0000644 0001762 0000144 00000002643 14522452242 016731 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/keyword_quote_linter.R
\name{keyword_quote_linter}
\alias{keyword_quote_linter}
\title{Block unnecessary quoting in calls}
\usage{
keyword_quote_linter()
}
\description{
Any valid symbol can be used as a keyword argument to an R function call.
Sometimes, it is necessary to quote (or backtick) an argument that is
not an otherwise valid symbol (e.g. creating a vector whose names have
spaces); besides this edge case, quoting should not be done.
}
\details{
The most common source of violation for this is creating named vectors,
lists, or data.frame-alikes, but it can be observed in other calls as well.
Similar reasoning applies to extractions with \code{$} or \code{@}.
}
\examples{
# will produce lints
lint(
text = 'data.frame("a" = 1)',
linters = keyword_quote_linter()
)
lint(
text = "data.frame(`a` = 1)",
linters = keyword_quote_linter()
)
lint(
text = 'my_list$"key"',
linters = keyword_quote_linter()
)
lint(
text = 's4obj@"key"',
linters = keyword_quote_linter()
)
# okay
lint(
text = "data.frame(`a b` = 1)",
linters = keyword_quote_linter()
)
lint(
text = "my_list$`a b`",
linters = keyword_quote_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=consistency_linters]{consistency}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/package_development_linters.Rd 0000644 0001762 0000144 00000002041 14251630510 020173 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{package_development_linters}
\alias{package_development_linters}
\title{Package development linters}
\description{
Linters useful to package developers, for example for writing consistent tests.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'package_development':
\itemize{
\item{\code{\link{backport_linter}}}
\item{\code{\link{conjunct_test_linter}}}
\item{\code{\link{expect_comparison_linter}}}
\item{\code{\link{expect_identical_linter}}}
\item{\code{\link{expect_length_linter}}}
\item{\code{\link{expect_named_linter}}}
\item{\code{\link{expect_not_linter}}}
\item{\code{\link{expect_null_linter}}}
\item{\code{\link{expect_s3_class_linter}}}
\item{\code{\link{expect_s4_class_linter}}}
\item{\code{\link{expect_true_false_linter}}}
\item{\code{\link{expect_type_linter}}}
\item{\code{\link{package_hooks_linter}}}
\item{\code{\link{yoda_test_linter}}}
}
}
lintr/man/strings_as_factors_linter.Rd 0000644 0001762 0000144 00000003156 14377165324 017737 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/strings_as_factors_linter.R
\name{strings_as_factors_linter}
\alias{strings_as_factors_linter}
\title{Identify cases where \code{stringsAsFactors} should be supplied explicitly}
\usage{
strings_as_factors_linter()
}
\description{
Designed for code bases written for versions of R before 4.0 seeking to upgrade to R >= 4.0, where
one of the biggest pain points will surely be the flipping of the
default value of \code{stringsAsFactors} from \code{TRUE} to \code{FALSE}.
}
\details{
It's not always possible to tell statically whether the change will break
existing code because R is dynamically typed -- e.g. in \code{data.frame(x)}
if \code{x} is a string, this code will be affected, but if \code{x} is a number,
this code will be unaffected. However, in \code{data.frame(x = "a")}, the
output will unambiguously be affected. We can instead supply
\code{stringsAsFactors = TRUE}, which will make this code backwards-compatible.
See \url{https://developer.r-project.org/Blog/public/2020/02/16/stringsasfactors/}.
}
\examples{
# will produce lints
lint(
text = 'data.frame(x = "a")',
linters = strings_as_factors_linter()
)
# okay
lint(
text = 'data.frame(x = "a", stringsAsFactors = TRUE)',
linters = strings_as_factors_linter()
)
lint(
text = 'data.frame(x = "a", stringsAsFactors = FALSE)',
linters = strings_as_factors_linter()
)
lint(
text = "data.frame(x = 1.2)",
linters = strings_as_factors_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=robustness_linters]{robustness}
}
lintr/man/read_settings.Rd 0000644 0001762 0000144 00000003101 14522452242 015274 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/settings.R
\name{read_settings}
\alias{read_settings}
\title{Read lintr settings}
\usage{
read_settings(filename)
}
\arguments{
\item{filename}{source file to be linted}
}
\description{
Lintr searches for settings for a given source file in the following order:
\enumerate{
\item options defined as \code{linter.setting}.
\item \code{linter_file} in the same directory
\item \code{linter_file} in the project directory
\item \code{linter_file} in the user home directory
\item \code{\link[=default_settings]{default_settings()}}
}
}
\details{
The default linter_file name is \code{.lintr} but it can be changed with option \code{lintr.linter_file}
or the environment variable \code{R_LINTR_LINTER_FILE}
This file is a DCF file, see \code{\link[base:dcf]{base::read.dcf()}} for details.
Experimentally, we also support keeping the config in a plain R file. By default we look for
a file named '.lintr.R' (in the same directories where we search for '.lintr').
We are still deciding the future of config support in lintr, so user feedback is welcome.
The advantage of R is that it maps more closely to how the configs are actually stored,
whereas the DCF approach requires somewhat awkward formatting of parseable R code within
valid DCF key-value pairs. The main disadvantage of the R file is it might be \emph{too} flexible,
with users tempted to write configs with side effects causing hard-to-detect bugs or
like YAML could work, but require new dependencies and are harder to parse
both programmatically and visually.
}
lintr/man/expect_not_linter.Rd 0000644 0001762 0000144 00000002165 14522452242 016177 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_not_linter.R
\name{expect_not_linter}
\alias{expect_not_linter}
\title{Require usage of \code{expect_false(x)} over \code{expect_true(!x)}}
\usage{
expect_not_linter()
}
\description{
\code{\link[testthat:logical-expectations]{testthat::expect_false()}} exists specifically for testing that an output is
\code{FALSE}. \code{\link[testthat:logical-expectations]{testthat::expect_true()}} can also be used for such tests by
negating the output, but it is better to use the tailored function instead.
The reverse is also true -- use \code{expect_false(A)} instead of
\code{expect_true(!A)}.
}
\examples{
# will produce lints
lint(
text = "expect_true(!x)",
linters = expect_not_linter()
)
# okay
lint(
text = "expect_false(x)",
linters = expect_not_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=package_development_linters]{package_development}, \link[=pkg_testthat_linters]{pkg_testthat}, \link[=readability_linters]{readability}
}
lintr/man/unreachable_code_linter.Rd 0000644 0001762 0000144 00000003346 14522452242 017274 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/unreachable_code_linter.R
\name{unreachable_code_linter}
\alias{unreachable_code_linter}
\title{Block unreachable code and comments following return statements}
\usage{
unreachable_code_linter()
}
\description{
Code after e.g. a \code{\link[=return]{return()}} or \code{\link[=stop]{stop()}}
or in deterministically false conditional loops like \verb{if (FALSE)} can't be reached;
typically this is vestigial code left after refactoring or sandboxing code, which
is fine for exploration, but shouldn't ultimately be checked in. Comments
meant for posterity should be placed \emph{before} the final \code{return()}.
}
\examples{
# will produce lints
code_lines <- "f <- function() {\n return(1 + 1)\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "f <- if (FALSE) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "f <- while (FALSE) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
# okay
code_lines <- "f <- function() {\n return(1 + 1)\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "f <- if (foo) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "f <- while (foo) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=readability_linters]{readability}
}
lintr/man/namespace_linter.Rd 0000644 0001762 0000144 00000002640 14377165324 015773 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/namespace_linter.R
\name{namespace_linter}
\alias{namespace_linter}
\title{Namespace linter}
\usage{
namespace_linter(check_exports = TRUE, check_nonexports = TRUE)
}
\arguments{
\item{check_exports}{Check if \code{symbol} is exported from \code{namespace} in \code{namespace::symbol} calls.}
\item{check_nonexports}{Check if \code{symbol} exists in \code{namespace} in \code{namespace:::symbol} calls.}
}
\description{
Check for missing packages and symbols in namespace calls.
Note that using \code{check_exports=TRUE} or \code{check_nonexports=TRUE} will load packages used in user code so it could
potentially change the global state.
}
\examples{
# will produce lints
lint(
text = "xyzxyz::sd(c(1, 2, 3))",
linters = namespace_linter()
)
lint(
text = "stats::ssd(c(1, 2, 3))",
linters = namespace_linter()
)
# okay
lint(
text = "stats::sd(c(1, 2, 3))",
linters = namespace_linter()
)
lint(
text = "stats::ssd(c(1, 2, 3))",
linters = namespace_linter(check_exports = FALSE)
)
lint(
text = "stats:::ssd(c(1, 2, 3))",
linters = namespace_linter(check_nonexports = FALSE)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=correctness_linters]{correctness}, \link[=executing_linters]{executing}, \link[=robustness_linters]{robustness}
}
lintr/man/inner_combine_linter.Rd 0000644 0001762 0000144 00000002260 14377165324 016644 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/inner_combine_linter.R
\name{inner_combine_linter}
\alias{inner_combine_linter}
\title{Require \code{c()} to be applied before relatively expensive vectorized functions}
\usage{
inner_combine_linter()
}
\description{
\code{as.Date(c(a, b))} is logically equivalent to \code{c(as.Date(a), as.Date(b))}.
The same equivalence holds for several other vectorized functions like
\code{\link[=as.POSIXct]{as.POSIXct()}} and math functions like \code{\link[=sin]{sin()}}. The former is to be
preferred so that the most expensive part of the operation (\code{\link[=as.Date]{as.Date()}})
is applied only once.
}
\examples{
# will produce lints
lint(
text = "c(log10(x), log10(y), log10(z))",
linters = inner_combine_linter()
)
# okay
lint(
text = "log10(c(x, y, z))",
linters = inner_combine_linter()
)
lint(
text = "c(log(x, base = 10), log10(x, base = 2))",
linters = inner_combine_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=consistency_linters]{consistency}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/literal_coercion_linter.Rd 0000644 0001762 0000144 00000002544 14377165324 017357 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/literal_coercion_linter.R
\name{literal_coercion_linter}
\alias{literal_coercion_linter}
\title{Require usage of correctly-typed literals over literal coercions}
\usage{
literal_coercion_linter()
}
\description{
\code{as.integer(1)} (or \code{rlang::int(1)}) is the same as \code{1L} but the latter is
more concise and gets typed correctly at compilation.
}
\details{
The same applies to missing sentinels like \code{NA} -- typically, it is not
necessary to specify the storage type of \code{NA}, but when it is, prefer
using the typed version (e.g. \code{NA_real_}) instead of a coercion
(like \code{as.numeric(NA)}).
}
\examples{
# will produce lints
lint(
text = "int(1)",
linters = literal_coercion_linter()
)
lint(
text = "as.character(NA)",
linters = literal_coercion_linter()
)
lint(
text = "rlang::lgl(1L)",
linters = literal_coercion_linter()
)
# okay
lint(
text = "1L",
linters = literal_coercion_linter()
)
lint(
text = "NA_character_",
linters = literal_coercion_linter()
)
lint(
text = "TRUE",
linters = literal_coercion_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=consistency_linters]{consistency}, \link[=efficiency_linters]{efficiency}
}
lintr/man/duplicate_argument_linter.Rd 0000644 0001762 0000144 00000002706 14377165324 017716 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/duplicate_argument_linter.R
\name{duplicate_argument_linter}
\alias{duplicate_argument_linter}
\title{Duplicate argument linter}
\usage{
duplicate_argument_linter(except = c("mutate", "transmute"))
}
\arguments{
\item{except}{A character vector of function names as exceptions. Defaults to
functions that allow sequential updates to variables, currently \code{dplyr::mutate()}
and \code{dplyr::transmute()}.}
}
\description{
Check for duplicate arguments in function calls. Some cases are run-time errors
(e.g. \code{mean(x = 1:5, x = 2:3)}), otherwise this linter is used to discourage
explicitly providing duplicate names to objects (e.g. \code{c(a = 1, a = 2)}).
Duplicate-named objects are hard to work with programmatically and
should typically be avoided.
}
\examples{
# will produce lints
lint(
text = "list(x = 1, x = 2)",
linters = duplicate_argument_linter()
)
lint(
text = "fun(arg = 1, arg = 2)",
linters = duplicate_argument_linter()
)
# okay
lint(
text = "list(x = 1, x = 2)",
linters = duplicate_argument_linter(except = "list")
)
lint(
text = "df \%>\% dplyr::mutate(x = a + b, x = x + d)",
linters = duplicate_argument_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=common_mistakes_linters]{common_mistakes}, \link[=configurable_linters]{configurable}, \link[=correctness_linters]{correctness}
}
lintr/man/nested_ifelse_linter.Rd 0000644 0001762 0000144 00000004507 14522452242 016642 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nested_ifelse_linter.R
\name{nested_ifelse_linter}
\alias{nested_ifelse_linter}
\title{Block usage of nested \code{ifelse()} calls}
\usage{
nested_ifelse_linter()
}
\description{
Calling \code{\link[=ifelse]{ifelse()}} in nested calls is problematic for two main reasons:
\enumerate{
\item It can be hard to read -- mapping the code to the expected output
for such code can be a messy task/require a lot of mental bandwidth,
especially for code that nests more than once
\item It is inefficient -- \code{ifelse()} can evaluate \emph{all} of its arguments at
both yes and no (see \url{https://stackoverflow.com/q/16275149}); this issue
is exacerbated for nested calls
}
}
\details{
Users can instead rely on a more readable alternative modeled after SQL
CASE WHEN statements.
Let's say this is our original code:
\if{html}{\out{
}}\preformatted{ifelse(
x == "a",
2L,
ifelse(x == "b", 3L, 1L)
)
}\if{html}{\out{
}}
Here are a few ways to avoid nesting and make the code more readable:
\itemize{
\item Use \code{data.table::fcase()}
\if{html}{\out{}}\preformatted{data.table::fcase(
x == "a", 2L,
x == "b", 3L,
default = 1L
)
}\if{html}{\out{
}}
\item Use \code{dplyr::case_match()}
\if{html}{\out{}}\preformatted{dplyr::case_match(
x,
"a" ~ 2L,
"b" ~ 3L,
.default = 1L
)
}\if{html}{\out{
}}
\item Use a look-up-and-merge approach (build a mapping table between values
and outputs and merge this to the input)
\if{html}{\out{}}\preformatted{default <- 1L
values <- data.frame(
a = 2L,
b = 3L
)
found_value <- values[[x]]
ifelse(is.null(found_value), default, found_value)
}\if{html}{\out{
}}
}
}
\examples{
# will produce lints
lint(
text = 'ifelse(x == "a", 1L, ifelse(x == "b", 2L, 3L))',
linters = nested_ifelse_linter()
)
# okay
lint(
text = 'dplyr::case_when(x == "a" ~ 1L, x == "b" ~ 2L, TRUE ~ 3L)',
linters = nested_ifelse_linter()
)
lint(
text = 'data.table::fcase(x == "a", 1L, x == "b", 2L, default = 3L)',
linters = nested_ifelse_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/deprecated_linters.Rd 0000644 0001762 0000144 00000001524 14455765330 016322 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{deprecated_linters}
\alias{deprecated_linters}
\title{Deprecated linters}
\description{
Linters that are deprecated and provided for backwards compatibility only.
These linters will be excluded from \code{linters_with_tags()} by default.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'deprecated':
\itemize{
\item{\code{\link{closed_curly_linter}}}
\item{\code{\link{consecutive_stopifnot_linter}}}
\item{\code{\link{no_tab_linter}}}
\item{\code{\link{open_curly_linter}}}
\item{\code{\link{paren_brace_linter}}}
\item{\code{\link{semicolon_terminator_linter}}}
\item{\code{\link{single_quotes_linter}}}
\item{\code{\link{unneeded_concatenation_linter}}}
}
}
lintr/man/undesirable_function_linter.Rd 0000644 0001762 0000144 00000004305 14377165324 020241 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/undesirable_function_linter.R
\name{undesirable_function_linter}
\alias{undesirable_function_linter}
\title{Undesirable function linter}
\usage{
undesirable_function_linter(
fun = default_undesirable_functions,
symbol_is_undesirable = TRUE
)
}
\arguments{
\item{fun}{Named character vector. \code{names(fun)} correspond to undesirable functions,
while the values give a description of why the function is undesirable.
If \code{NA}, no additional information is given in the lint message. Defaults to
\link{default_undesirable_functions}. To make small customizations to this list,
use \code{\link[=modify_defaults]{modify_defaults()}}.}
\item{symbol_is_undesirable}{Whether to consider the use of an undesirable function
name as a symbol undesirable or not.}
}
\description{
Report the use of undesirable functions (e.g. \code{\link[base:function]{base::return()}}, \code{\link[base:options]{base::options()}}, or
\code{\link[base:lapply]{base::sapply()}}) and suggest an alternative.
}
\examples{
# defaults for which functions are considered undesirable
names(default_undesirable_functions)
# will produce lints
lint(
text = "sapply(x, mean)",
linters = undesirable_function_linter()
)
lint(
text = "log10(x)",
linters = undesirable_function_linter(fun = c("log10" = NA))
)
lint(
text = "log10(x)",
linters = undesirable_function_linter(fun = c("log10" = "use log()"))
)
lint(
text = 'dir <- "path/to/a/directory"',
linters = undesirable_function_linter(fun = c("dir" = NA))
)
# okay
lint(
text = "vapply(x, mean, FUN.VALUE = numeric(1))",
linters = undesirable_function_linter()
)
lint(
text = "log(x, base = 10)",
linters = undesirable_function_linter(fun = c("log10" = "use log()"))
)
lint(
text = 'dir <- "path/to/a/directory"',
linters = undesirable_function_linter(fun = c("dir" = NA), symbol_is_undesirable = FALSE)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=configurable_linters]{configurable}, \link[=efficiency_linters]{efficiency}, \link[=robustness_linters]{robustness}, \link[=style_linters]{style}
}
lintr/man/lint-s3.Rd 0000644 0001762 0000144 00000001560 14377165324 013753 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lint.R
\name{lint-s3}
\alias{lint-s3}
\alias{Lint}
\title{Create a \code{lint} object}
\usage{
Lint(
filename,
line_number = 1L,
column_number = 1L,
type = c("style", "warning", "error"),
message = "",
line = "",
ranges = NULL,
linter = ""
)
}
\arguments{
\item{filename}{path to the source file that was linted.}
\item{line_number}{line number where the lint occurred.}
\item{column_number}{column number where the lint occurred.}
\item{type}{type of lint.}
\item{message}{message used to describe the lint error}
\item{line}{code source where the lint occurred}
\item{ranges}{a list of ranges on the line that should be emphasized.}
\item{linter}{deprecated. No longer used.}
}
\value{
an object of class \code{c("lint", "list")}.
}
\description{
Create a \code{lint} object
}
lintr/man/pipe_call_linter.Rd 0000644 0001762 0000144 00000001443 14377165324 015767 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pipe_call_linter.R
\name{pipe_call_linter}
\alias{pipe_call_linter}
\title{Pipe call linter}
\usage{
pipe_call_linter()
}
\description{
Force explicit calls in magrittr pipes, e.g., \code{1:3 \%>\% sum()} instead of \code{1:3 \%>\% sum}.
Note that native pipe always requires a function call, i.e. \verb{1:3 |> sum} will produce an error.
}
\examples{
# will produce lints
lint(
text = "1:3 \%>\% mean \%>\% as.character",
linters = pipe_call_linter()
)
# okay
lint(
text = "1:3 \%>\% mean() \%>\% as.character()",
linters = pipe_call_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/get_r_string.Rd 0000644 0001762 0000144 00000004333 14377165326 015153 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{get_r_string}
\alias{get_r_string}
\title{Extract text from \code{STR_CONST} nodes}
\usage{
get_r_string(s, xpath = NULL)
}
\arguments{
\item{s}{An input string or strings. If \code{s} is an \code{xml_node} or \code{xml_nodeset} and \code{xpath} is \code{NULL},
extract its string value with \code{\link[xml2:xml_text]{xml2::xml_text()}}. If \code{s} is an \code{xml_node} or \code{xml_nodeset}
and \code{xpath} is specified, it is extracted with \code{\link[xml2:xml_find_all]{xml2::xml_find_chr()}}.}
\item{xpath}{An XPath, passed on to \code{\link[xml2:xml_find_all]{xml2::xml_find_chr()}} after wrapping with \code{string()}.}
}
\description{
Convert \code{STR_CONST} \code{text()} values into R strings. This is useful to account for arbitrary
character literals valid since R 4.0, e.g. \code{R"------[hello]------"}, which is parsed in
R as \code{"hello"}. It is quite cumbersome to write XPaths allowing for strings like this,
so whenever your linter logic requires testing a \code{STR_CONST} node's value, use this
function.
NB: this is also properly vectorized on \code{s}, and accepts a variety of inputs. Empty inputs
will become \code{NA} outputs, which helps ensure that \code{length(get_r_string(s)) == length(s)}.
}
\examples{
\dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
tmp <- withr::local_tempfile(lines = "c('a', 'b')")
expr_as_xml <- get_source_expressions(tmp)$expressions[[1L]]$xml_parsed_content
writeLines(as.character(expr_as_xml))
get_r_string(expr_as_xml, "expr[2]") # "a"
get_r_string(expr_as_xml, "expr[3]") # "b"
# more importantly, extract strings under R>=4 raw strings
\dontshow{\}) # examplesIf}
\dontshow{if (getRversion() >= "4.0.0") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
tmp4.0 <- withr::local_tempfile(lines = "c(R'(a\\\\b)', R'--[a\\\\\"\'\"\\\\b]--')")
expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content
writeLines(as.character(expr_as_xml4.0))
get_r_string(expr_as_xml4.0, "expr[2]") # "a\\b"
get_r_string(expr_as_xml4.0, "expr[3]") # "a\\\"'\"\\b"
\dontshow{\}) # examplesIf}
}
lintr/man/best_practices_linters.Rd 0000644 0001762 0000144 00000005257 14522452242 017211 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{best_practices_linters}
\alias{best_practices_linters}
\title{Best practices linters}
\description{
Linters checking the use of coding best practices, such as explicit typing of numeric constants.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'best_practices':
\itemize{
\item{\code{\link{absolute_path_linter}}}
\item{\code{\link{any_duplicated_linter}}}
\item{\code{\link{any_is_na_linter}}}
\item{\code{\link{boolean_arithmetic_linter}}}
\item{\code{\link{class_equals_linter}}}
\item{\code{\link{commented_code_linter}}}
\item{\code{\link{condition_message_linter}}}
\item{\code{\link{conjunct_test_linter}}}
\item{\code{\link{cyclocomp_linter}}}
\item{\code{\link{empty_assignment_linter}}}
\item{\code{\link{expect_comparison_linter}}}
\item{\code{\link{expect_length_linter}}}
\item{\code{\link{expect_named_linter}}}
\item{\code{\link{expect_not_linter}}}
\item{\code{\link{expect_null_linter}}}
\item{\code{\link{expect_s3_class_linter}}}
\item{\code{\link{expect_s4_class_linter}}}
\item{\code{\link{expect_true_false_linter}}}
\item{\code{\link{expect_type_linter}}}
\item{\code{\link{extraction_operator_linter}}}
\item{\code{\link{fixed_regex_linter}}}
\item{\code{\link{for_loop_index_linter}}}
\item{\code{\link{function_argument_linter}}}
\item{\code{\link{function_return_linter}}}
\item{\code{\link{ifelse_censor_linter}}}
\item{\code{\link{implicit_assignment_linter}}}
\item{\code{\link{implicit_integer_linter}}}
\item{\code{\link{is_numeric_linter}}}
\item{\code{\link{length_levels_linter}}}
\item{\code{\link{lengths_linter}}}
\item{\code{\link{library_call_linter}}}
\item{\code{\link{literal_coercion_linter}}}
\item{\code{\link{nonportable_path_linter}}}
\item{\code{\link{outer_negation_linter}}}
\item{\code{\link{paste_linter}}}
\item{\code{\link{redundant_equals_linter}}}
\item{\code{\link{redundant_ifelse_linter}}}
\item{\code{\link{regex_subset_linter}}}
\item{\code{\link{routine_registration_linter}}}
\item{\code{\link{scalar_in_linter}}}
\item{\code{\link{seq_linter}}}
\item{\code{\link{sort_linter}}}
\item{\code{\link{system_file_linter}}}
\item{\code{\link{T_and_F_symbol_linter}}}
\item{\code{\link{undesirable_function_linter}}}
\item{\code{\link{undesirable_operator_linter}}}
\item{\code{\link{unnecessary_lambda_linter}}}
\item{\code{\link{unnecessary_nested_if_linter}}}
\item{\code{\link{unnecessary_placeholder_linter}}}
\item{\code{\link{unreachable_code_linter}}}
\item{\code{\link{unused_import_linter}}}
\item{\code{\link{vector_logic_linter}}}
\item{\code{\link{yoda_test_linter}}}
}
}
lintr/man/lintr-package.Rd 0000644 0001762 0000144 00000001563 14377165324 015206 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lintr-package.R
\docType{package}
\name{lintr-package}
\alias{lintr}
\alias{lintr-package}
\title{Lintr}
\description{
Checks adherence to a given style, syntax errors, and possible semantic issues.
Supports on the fly checking of R code edited with Emacs, Vim, and Sublime Text.
}
\seealso{
\code{\link[=lint]{lint()}}, \code{\link[=lint_package]{lint_package()}}, \code{\link[=lint_dir]{lint_dir()}}, \link{linters}
}
\author{
\strong{Maintainer}: Jim Hester \email{james.f.hester@gmail.com}
Authors:
\itemize{
\item Florent Angly (fangly)
\item Russ Hyde
\item Michael Chirico
\item Kun Ren
\item Alexander Rosenstock (AshesITR)
\item Indrajeet Patil \email{patilindrajeet.science@gmail.com} (\href{https://orcid.org/0000-0003-1995-6531}{ORCID}) (@patilindrajeets)
}
}
\keyword{internal}
lintr/man/quotes_linter.Rd 0000644 0001762 0000144 00000002253 14455765330 015357 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/quotes_linter.R
\name{quotes_linter}
\alias{quotes_linter}
\title{Character string quote linter}
\usage{
quotes_linter(delimiter = c("\\"", "'"))
}
\arguments{
\item{delimiter}{Which quote delimiter to accept. Defaults to the tidyverse
default of \verb{"} (double-quoted strings).}
}
\description{
Check that the desired quote delimiter is used for string constants.
}
\examples{
# will produce lints
lint(
text = "c('a', 'b')",
linters = quotes_linter()
)
# okay
lint(
text = 'c("a", "b")',
linters = quotes_linter()
)
code_lines <- "paste0(x, '\"this is fine\"')"
writeLines(code_lines)
lint(
text = code_lines,
linters = quotes_linter()
)
# okay
lint(
text = "c('a', 'b')",
linters = quotes_linter(delimiter = "'")
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#character-vectors}
}
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=consistency_linters]{consistency}, \link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/vector_logic_linter.Rd 0000644 0001762 0000144 00000004105 14377165326 016516 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vector_logic_linter.R
\name{vector_logic_linter}
\alias{vector_logic_linter}
\title{Enforce usage of scalar logical operators in conditional statements}
\usage{
vector_logic_linter()
}
\description{
Usage of \code{&} in conditional statements is error-prone and inefficient.
\code{condition} in \code{if (condition) expr} must always be of length 1, in which
case \code{&&} is to be preferred. Ditto for \code{|} vs. \code{||}.
}
\details{
This linter covers inputs to \verb{if()} and \verb{while()} conditions and to
\code{\link[testthat:logical-expectations]{testthat::expect_true()}} and \code{\link[testthat:logical-expectations]{testthat::expect_false()}}.
Note that because \code{&} and \code{|} are generics, it is possible that
\code{&&} / \code{||} are not perfect substitutes because \code{&} is doing
method dispatch in an incompatible way.
Moreover, be wary of code that may have side effects, most commonly
assignments. Consider \code{if ((a <- foo(x)) | (b <- bar(y))) { ... }}
vs. \code{if ((a <- foo(x)) || (b <- bar(y))) { ... }}. Because \code{||} exits
early, if \code{a} is \code{TRUE}, the second condition will never be evaluated
and \code{b} will not be assigned. Such usage is not allowed by the Tidyverse
style guide, and the code can easily be refactored by pulling the
assignment outside the condition, so using \code{||} is still preferable.
}
\examples{
# will produce lints
lint(
text = "if (TRUE & FALSE) 1",
linters = vector_logic_linter()
)
lint(
text = "if (TRUE && (TRUE | FALSE)) 4",
linters = vector_logic_linter()
)
# okay
lint(
text = "if (TRUE && FALSE) 1",
linters = vector_logic_linter()
)
lint(
text = "if (TRUE && (TRUE || FALSE)) 4",
linters = vector_logic_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#if-statements}
}
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=default_linters]{default}, \link[=efficiency_linters]{efficiency}
}
lintr/man/object_name_linter.Rd 0000644 0001762 0000144 00000006641 14455765330 016312 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/object_name_linter.R
\name{object_name_linter}
\alias{object_name_linter}
\title{Object name linter}
\usage{
object_name_linter(styles = c("snake_case", "symbols"), regexes = character())
}
\arguments{
\item{styles}{A subset of
\Sexpr[stage=render, results=rd]{lintr:::regexes_rd}. A name should
match at least one of these styles. The \code{"symbols"} style refers to
names containing \emph{only} non-alphanumeric characters; e.g., defining \verb{\%+\%}
from ggplot2 or \verb{\%>\%} from magrittr would not generate lint markers,
whereas \verb{\%m+\%} from lubridate (containing both alphanumeric \emph{and}
non-alphanumeric characters) would.}
\item{regexes}{A (possibly named) character vector specifying a custom naming convention.
If named, the names will be used in the lint message. Otherwise, the regexes enclosed by \code{/} will be used in the
lint message.
Note that specifying \code{regexes} overrides the default \code{styles}. So if you want to combine \code{regexes} and \code{styles},
both need to be explicitly specified.}
}
\description{
Check that object names conform to a naming style.
The default naming styles are "snake_case" and "symbols".
}
\details{
Quotes (\verb{`"'}) and specials (\verb{\%} and trailing \verb{<-}) are not considered part of the object name.
Note when used in a package, in order to ignore objects imported
from other namespaces, this linter will attempt \code{\link[=getNamespaceExports]{getNamespaceExports()}}
whenever an \code{import(PKG)} or \code{importFrom(PKG, ...)} statement is found
in your NAMESPACE file. If \code{\link[=requireNamespace]{requireNamespace()}} fails (e.g., the package
is not yet installed), the linter won't be able to ignore some usages
that would otherwise be allowed.
Suppose, for example, you have \code{import(upstream)} in your NAMESPACE,
which makes available its exported S3 generic function
\code{a_really_quite_long_function_name} that you then extend in your package
by defining a corresponding method for your class \code{my_class}.
Then, if \code{upstream} is not installed when this linter runs, a lint
will be thrown on this object (even though you don't "own" its full name).
The best way to get lintr to work correctly is to install the package so
that it's available in the session where this linter is running.
}
\examples{
# will produce lints
lint(
text = "my_var <- 1L",
linters = object_name_linter(styles = "CamelCase")
)
lint(
text = "xYz <- 1L",
linters = object_name_linter(styles = c("UPPERCASE", "lowercase"))
)
lint(
text = "MyVar <- 1L",
linters = object_name_linter(styles = "dotted.case")
)
lint(
text = "asd <- 1L",
linters = object_name_linter(regexes = c(my_style = "F$", "f$"))
)
# okay
lint(
text = "my_var <- 1L",
linters = object_name_linter(styles = "snake_case")
)
lint(
text = "xyz <- 1L",
linters = object_name_linter(styles = "lowercase")
)
lint(
text = "my.var <- 1L; myvar <- 2L",
linters = object_name_linter(styles = c("dotted.case", "lowercase"))
)
lint(
text = "asdf <- 1L; asdF <- 1L",
linters = object_name_linter(regexes = c(my_style = "F$", "f$"))
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=consistency_linters]{consistency}, \link[=default_linters]{default}, \link[=executing_linters]{executing}, \link[=style_linters]{style}
}
lintr/man/paren_body_linter.Rd 0000644 0001762 0000144 00000001410 14377165326 016155 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/paren_body_linter.R
\name{paren_body_linter}
\alias{paren_body_linter}
\title{Parenthesis before body linter}
\usage{
paren_body_linter()
}
\description{
Check that there is a space between right parenthesis and a body expression.
}
\examples{
# will produce lints
lint(
text = "function(x)x + 1",
linters = paren_body_linter()
)
# okay
lint(
text = "function(x) x + 1",
linters = paren_body_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#parentheses}
}
}
\section{Tags}{
\link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/available_linters.Rd 0000644 0001762 0000144 00000005343 14455765330 016145 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tags.R
\name{available_linters}
\alias{available_linters}
\alias{available_tags}
\title{Get Linter metadata from a package}
\usage{
available_linters(packages = "lintr", tags = NULL, exclude_tags = "deprecated")
available_tags(packages = "lintr")
}
\arguments{
\item{packages}{A character vector of packages to search for linters.}
\item{tags}{Optional character vector of tags to search. Only linters with at least one matching tag will be
returned. If \code{tags} is \code{NULL}, all linters will be returned. See \code{available_tags("lintr")} to find out what
tags are already used by lintr.}
\item{exclude_tags}{Tags to exclude from the results. Linters with at least one matching tag will not be returned.
If \code{except_tags} is \code{NULL}, no linters will be excluded. Note that \code{tags} takes priority, meaning that any
tag found in both \code{tags} and \code{exclude_tags} will be included, not excluded.}
}
\value{
\code{available_linters} returns a data frame with columns 'linter', 'package' and 'tags':
\describe{
\item{linter}{A character column naming the function associated with the linter.}
\item{package}{A character column containing the name of the package providing the linter.}
\item{tags}{A list column containing tags associated with the linter.}
}
\code{available_tags} returns a character vector of linter tags used by the packages.
}
\description{
\code{available_linters()} obtains a tagged list of all Linters available in a package.
\code{available_tags()} searches for available tags.
}
\section{Package Authors}{
To implement \code{available_linters()} for your package, include a file \code{inst/lintr/linters.csv} in your
package.
The CSV file must contain the columns 'linter' and 'tags', and be UTF-8 encoded.
Additional columns will be silently ignored if present and the columns are identified by name.
Each row describes a linter by
\enumerate{
\item its function name (e.g. \code{"assignment_linter"}) in the column 'linter'.
\item space-separated tags associated with the linter (e.g. \code{"style consistency default"}) in the column 'tags'.
}
Tags should be snake_case.
See \code{available_tags("lintr")} to find out what tags are already used by lintr.
}
\examples{
lintr_linters <- available_linters()
# If the package doesn't exist or isn't installed, an empty data frame will be returned
available_linters("does-not-exist")
lintr_linters2 <- available_linters(c("lintr", "does-not-exist"))
identical(lintr_linters, lintr_linters2)
available_tags()
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \code{\link[=available_tags]{available_tags()}} to retrieve the set of valid tags.
}
}
lintr/man/absolute_path_linter.Rd 0000644 0001762 0000144 00000002526 14377165326 016676 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/absolute_path_linter.R
\name{absolute_path_linter}
\alias{absolute_path_linter}
\title{Absolute path linter}
\usage{
absolute_path_linter(lax = TRUE)
}
\arguments{
\item{lax}{Less stringent linting, leading to fewer false positives.
If \code{TRUE}, only lint path strings, which
\itemize{
\item contain at least two path elements, with one having at least two characters and
\item contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
}}
}
\description{
Check that no absolute paths are used (e.g. "/var", "C:\\System", "~/docs").
}
\examples{
\dontshow{if (getRversion() >= "4.0") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
# Following examples use raw character constant syntax introduced in R 4.0.
# will produce lints
lint(
text = 'R"--[/blah/file.txt]--"',
linters = absolute_path_linter()
)
# okay
lint(
text = 'R"(./blah)"',
linters = absolute_path_linter()
)
\dontshow{\}) # examplesIf}
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \code{\link[=nonportable_path_linter]{nonportable_path_linter()}}
}
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=configurable_linters]{configurable}, \link[=robustness_linters]{robustness}
}
lintr/man/string_boundary_linter.Rd 0000644 0001762 0000144 00000004714 14377165324 017254 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/string_boundary_linter.R
\name{string_boundary_linter}
\alias{string_boundary_linter}
\title{Require usage of \code{startsWith()} and \code{endsWith()} over \code{grepl()}/\code{substr()} versions}
\usage{
string_boundary_linter(allow_grepl = FALSE)
}
\arguments{
\item{allow_grepl}{Logical, default \code{FALSE}. If \code{TRUE}, usages with \code{grepl()}
are ignored. Some authors may prefer the conciseness offered by \code{grepl()} whereby
\code{NA} input maps to \code{FALSE} output, which doesn't have a direct equivalent
with \code{startsWith()} or \code{endsWith()}.}
}
\description{
\code{\link[=startsWith]{startsWith()}} is used to detect fixed initial substrings; it is more
readable and more efficient than equivalents using \code{\link[=grepl]{grepl()}} or \code{\link[=substr]{substr()}}.
c.f. \code{startsWith(x, "abc")}, \code{grepl("^abc", x)},
\code{substr(x, 1L, 3L) == "abc"}.
}
\details{
Ditto for using \code{\link[=endsWith]{endsWith()}} to detect fixed terminal substrings.
Note that there is a difference in behavior between how \code{grepl()} and \code{startsWith()}
(and \code{endsWith()}) handle missing values. In particular, for \code{grepl()}, \code{NA} inputs
are considered \code{FALSE}, while for \code{startsWith()}, \code{NA} inputs have \code{NA} outputs.
That means the strict equivalent of \code{grepl("^abc", x)} is
\code{!is.na(x) & startsWith(x, "abc")}.
We lint \code{grepl()} usages by default because the \code{!is.na()} version is more explicit
with respect to \code{NA} handling -- though documented, the way \code{grepl()} handles
missing inputs may be surprising to some users.
}
\examples{
# will produce lints
lint(
text = 'grepl("^a", x)',
linters = string_boundary_linter()
)
lint(
text = 'grepl("z$", x)',
linters = string_boundary_linter()
)
# okay
lint(
text = 'startsWith(x, "a")',
linters = string_boundary_linter()
)
lint(
text = 'endsWith(x, "z")',
linters = string_boundary_linter()
)
# If missing values are present, the suggested alternative wouldn't be strictly
# equivalent, so this linter can also be turned off in such cases.
lint(
text = 'grepl("z$", x)',
linters = string_boundary_linter(allow_grepl = TRUE)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/unused_import_linter.Rd 0000644 0001762 0000144 00000003564 14522452242 016730 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/unused_import_linter.R
\name{unused_import_linter}
\alias{unused_import_linter}
\title{Check that imported packages are actually used}
\usage{
unused_import_linter(
allow_ns_usage = FALSE,
except_packages = c("bit64", "data.table", "tidyverse"),
interpret_glue = TRUE
)
}
\arguments{
\item{allow_ns_usage}{Suppress lints for packages only used via namespace.
This is \code{FALSE} by default because \code{pkg::fun()} doesn't require \code{library(pkg)}.
You can use \link[=requireNamespace]{requireNamespace("pkg")} to ensure a package is
installed without loading it.}
\item{except_packages}{Character vector of packages that are ignored.
These are usually attached for their side effects.}
\item{interpret_glue}{If \code{TRUE}, interpret \code{\link[glue:glue]{glue::glue()}} calls to avoid false positives caused by local variables
which are only used in a glue expression.}
}
\description{
Check that imported packages are actually used
}
\examples{
# will produce lints
code_lines <- "library(dplyr)\n1 + 1"
writeLines(code_lines)
lint(
text = code_lines,
linters = unused_import_linter()
)
code_lines <- "library(dplyr)\ndplyr::tibble(a = 1)"
writeLines(code_lines)
lint(
text = code_lines,
linters = unused_import_linter()
)
# okay
code_lines <- "library(dplyr)\ntibble(a = 1)"
writeLines(code_lines)
lint(
text = code_lines,
linters = unused_import_linter()
)
code_lines <- "library(dplyr)\ndplyr::tibble(a = 1)"
writeLines(code_lines)
lint(
text = code_lines,
linters = unused_import_linter(allow_ns_usage = TRUE)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=common_mistakes_linters]{common_mistakes}, \link[=configurable_linters]{configurable}, \link[=executing_linters]{executing}
}
lintr/man/ifelse_censor_linter.Rd 0000644 0001762 0000144 00000002226 14377165324 016657 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ifelse_censor_linter.R
\name{ifelse_censor_linter}
\alias{ifelse_censor_linter}
\title{Block usage of \code{ifelse()} where \code{pmin()} or \code{pmax()} is more appropriate}
\usage{
ifelse_censor_linter()
}
\description{
\code{ifelse(x > M, M, x)} is the same as \code{pmin(x, M)}, but harder
to read and requires several passes over the vector.
}
\details{
The same goes for other similar ways to censor a vector, e.g.
\code{ifelse(x <= M, x, M)} is \code{pmin(x, M)},
\code{ifelse(x < m, m, x)} is \code{pmax(x, m)}, and
\code{ifelse(x >= m, x, m)} is \code{pmax(x, m)}.
}
\examples{
# will produce lints
lint(
text = "ifelse(5:1 < pi, 5:1, pi)",
linters = ifelse_censor_linter()
)
lint(
text = "ifelse(x > 0, x, 0)",
linters = ifelse_censor_linter()
)
# okay
lint(
text = "pmin(5:1, pi)",
linters = ifelse_censor_linter()
)
lint(
text = "pmax(x, 0)",
linters = ifelse_censor_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=efficiency_linters]{efficiency}
}
lintr/man/executing_linters.Rd 0000644 0001762 0000144 00000001674 14522452242 016211 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{executing_linters}
\alias{executing_linters}
\title{Code executing linters}
\description{
Linters that evaluate parts of the linted code, such as loading referenced packages.
These linters should not be used with untrusted code, and may need dependencies of the linted package or project to
be available in order to function correctly. For package authors, note that this includes loading the package itself,
e.g. with \code{pkgload::load_all()} or installing and attaching the package.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'executing':
\itemize{
\item{\code{\link{namespace_linter}}}
\item{\code{\link{object_length_linter}}}
\item{\code{\link{object_name_linter}}}
\item{\code{\link{object_usage_linter}}}
\item{\code{\link{unused_import_linter}}}
}
}
lintr/man/is_lint_level.Rd 0000644 0001762 0000144 00000002467 14377165326 015323 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/is_lint_level.R
\name{is_lint_level}
\alias{is_lint_level}
\title{Is this an expression- or a file-level source object?}
\usage{
is_lint_level(source_expression, level = c("expression", "file"))
}
\arguments{
\item{source_expression}{A parsed expression object, i.e., an element
of the object returned by \code{\link[=get_source_expressions]{get_source_expressions()}}.}
\item{level}{Which level of expression is being tested? \code{"expression"}
means an individual expression, while \code{"file"} means all expressions
in the current file are available.}
}
\description{
Helper for determining whether the current \code{source_expression} contains
all expressions in the current file, or just a single expression.
}
\examples{
\dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
source_exprs <- get_source_expressions(tmp)
is_lint_level(source_exprs$expressions[[1L]], level = "expression")
is_lint_level(source_exprs$expressions[[1L]], level = "file")
is_lint_level(source_exprs$expressions[[3L]], level = "expression")
is_lint_level(source_exprs$expressions[[3L]], level = "file")
\dontshow{\}) # examplesIf}
}
lintr/man/unnecessary_lambda_linter.Rd 0000644 0001762 0000144 00000002524 14522452242 017665 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/unnecessary_lambda_linter.R
\name{unnecessary_lambda_linter}
\alias{unnecessary_lambda_linter}
\title{Block usage of anonymous functions in iteration functions when unnecessary}
\usage{
unnecessary_lambda_linter()
}
\description{
Using an anonymous function in, e.g., \code{\link[=lapply]{lapply()}} is not always necessary,
e.g. \code{lapply(DF, sum)} is the same as \code{lapply(DF, function(x) sum(x))} and
the former is more readable.
}
\details{
Cases like \verb{lapply(x, \\(xi) grep("ptn", xi))} are excluded because, though
the anonymous function \emph{can} be avoided, doing so is not always more
readable.
}
\examples{
# will produce lints
lint(
text = "lapply(list(1:3, 2:4), function(xi) sum(xi))",
linters = unnecessary_lambda_linter()
)
# okay
lint(
text = "lapply(list(1:3, 2:4), sum)",
linters = unnecessary_lambda_linter()
)
lint(
text = 'lapply(x, function(xi) grep("ptn", xi))',
linters = unnecessary_lambda_linter()
)
lint(
text = "lapply(x, function(xi) data.frame(col = xi))",
linters = unnecessary_lambda_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/expect_comparison_linter.Rd 0000644 0001762 0000144 00000003340 14522452242 017545 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expect_comparison_linter.R
\name{expect_comparison_linter}
\alias{expect_comparison_linter}
\title{Require usage of \code{expect_gt(x, y)} over \code{expect_true(x > y)} (and similar)}
\usage{
expect_comparison_linter()
}
\description{
\code{\link[testthat:comparison-expectations]{testthat::expect_gt()}}, \code{\link[testthat:comparison-expectations]{testthat::expect_gte()}}, \code{\link[testthat:comparison-expectations]{testthat::expect_lt()}},
\code{\link[testthat:comparison-expectations]{testthat::expect_lte()}}, and \code{\link[testthat:equality-expectations]{testthat::expect_equal()}} exist specifically
for testing comparisons between two objects. \code{\link[testthat:logical-expectations]{testthat::expect_true()}} can
also be used for such tests, but it is better to use the tailored function
instead.
}
\examples{
# will produce lints
lint(
text = "expect_true(x > y)",
linters = expect_comparison_linter()
)
lint(
text = "expect_true(x <= y)",
linters = expect_comparison_linter()
)
lint(
text = "expect_true(x == (y == 2))",
linters = expect_comparison_linter()
)
# okay
lint(
text = "expect_gt(x, y)",
linters = expect_comparison_linter()
)
lint(
text = "expect_lte(x, y)",
linters = expect_comparison_linter()
)
lint(
text = "expect_identical(x, y == 2)",
linters = expect_comparison_linter()
)
lint(
text = "expect_true(x < y | x > y^2)",
linters = expect_comparison_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=package_development_linters]{package_development}, \link[=pkg_testthat_linters]{pkg_testthat}
}
lintr/man/style_linters.Rd 0000644 0001762 0000144 00000003737 14522452242 015360 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{style_linters}
\alias{style_linters}
\title{Style linters}
\description{
Linters highlighting code style issues.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'style':
\itemize{
\item{\code{\link{assignment_linter}}}
\item{\code{\link{brace_linter}}}
\item{\code{\link{commas_linter}}}
\item{\code{\link{commented_code_linter}}}
\item{\code{\link{consecutive_assertion_linter}}}
\item{\code{\link{cyclocomp_linter}}}
\item{\code{\link{extraction_operator_linter}}}
\item{\code{\link{function_argument_linter}}}
\item{\code{\link{function_left_parentheses_linter}}}
\item{\code{\link{implicit_assignment_linter}}}
\item{\code{\link{implicit_integer_linter}}}
\item{\code{\link{indentation_linter}}}
\item{\code{\link{infix_spaces_linter}}}
\item{\code{\link{keyword_quote_linter}}}
\item{\code{\link{library_call_linter}}}
\item{\code{\link{line_length_linter}}}
\item{\code{\link{numeric_leading_zero_linter}}}
\item{\code{\link{object_length_linter}}}
\item{\code{\link{object_name_linter}}}
\item{\code{\link{object_usage_linter}}}
\item{\code{\link{package_hooks_linter}}}
\item{\code{\link{paren_body_linter}}}
\item{\code{\link{pipe_call_linter}}}
\item{\code{\link{pipe_consistency_linter}}}
\item{\code{\link{pipe_continuation_linter}}}
\item{\code{\link{quotes_linter}}}
\item{\code{\link{repeat_linter}}}
\item{\code{\link{semicolon_linter}}}
\item{\code{\link{spaces_inside_linter}}}
\item{\code{\link{spaces_left_parentheses_linter}}}
\item{\code{\link{T_and_F_symbol_linter}}}
\item{\code{\link{todo_comment_linter}}}
\item{\code{\link{trailing_blank_lines_linter}}}
\item{\code{\link{trailing_whitespace_linter}}}
\item{\code{\link{undesirable_function_linter}}}
\item{\code{\link{undesirable_operator_linter}}}
\item{\code{\link{unnecessary_concatenation_linter}}}
\item{\code{\link{whitespace_linter}}}
}
}
lintr/man/consecutive_assertion_linter.Rd 0000644 0001762 0000144 00000002211 14455765330 020447 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/consecutive_assertion_linter.R
\name{consecutive_assertion_linter}
\alias{consecutive_assertion_linter}
\title{Force consecutive calls to assertions into just one when possible}
\usage{
consecutive_assertion_linter()
}
\description{
\code{\link[=stopifnot]{stopifnot()}} accepts any number of tests, so sequences like
\verb{stopifnot(x); stopifnot(y)} are redundant. Ditto for tests using
\code{assertthat::assert_that()} without specifying \verb{msg=}.
}
\examples{
# will produce lints
lint(
text = "stopifnot(x); stopifnot(y)",
linters = consecutive_assertion_linter()
)
lint(
text = "assert_that(x); assert_that(y)",
linters = consecutive_assertion_linter()
)
# okay
lint(
text = "stopifnot(x, y)",
linters = consecutive_assertion_linter()
)
lint(
text = 'assert_that(x, msg = "Bad x!"); assert_that(y)',
linters = consecutive_assertion_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=consistency_linters]{consistency}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/spaces_inside_linter.Rd 0000644 0001762 0000144 00000001753 14377165326 016656 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spaces_inside_linter.R
\name{spaces_inside_linter}
\alias{spaces_inside_linter}
\title{Spaces inside linter}
\usage{
spaces_inside_linter()
}
\description{
Check that parentheses and square brackets do not have spaces directly
inside them, i.e., directly following an opening delimiter or directly
preceding a closing delimiter.
}
\examples{
# will produce lints
lint(
text = "c( TRUE, FALSE )",
linters = spaces_inside_linter()
)
lint(
text = "x[ 1L ]",
linters = spaces_inside_linter()
)
# okay
lint(
text = "c(TRUE, FALSE)",
linters = spaces_inside_linter()
)
lint(
text = "x[1L]",
linters = spaces_inside_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#parentheses}
}
}
\section{Tags}{
\link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/assignment_linter.Rd 0000644 0001762 0000144 00000004326 14522452242 016200 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assignment_linter.R
\name{assignment_linter}
\alias{assignment_linter}
\title{Assignment linter}
\usage{
assignment_linter(
allow_cascading_assign = TRUE,
allow_right_assign = FALSE,
allow_trailing = TRUE,
allow_pipe_assign = FALSE
)
}
\arguments{
\item{allow_cascading_assign}{Logical, default \code{TRUE}.
If \code{FALSE}, \code{\link[base:assignOps]{<<-}} and \verb{->>} are not allowed.}
\item{allow_right_assign}{Logical, default \code{FALSE}. If \code{TRUE}, \verb{->} and \verb{->>} are allowed.}
\item{allow_trailing}{Logical, default \code{TRUE}. If \code{FALSE} then assignments aren't allowed at end of lines.}
\item{allow_pipe_assign}{Logical, default \code{FALSE}. If \code{TRUE}, magrittr's \verb{\%<>\%} assignment is allowed.}
}
\description{
Check that \verb{<-} is always used for assignment.
}
\examples{
# will produce lints
lint(
text = "x = mean(x)",
linters = assignment_linter()
)
code_lines <- "1 -> x\n2 ->> y"
writeLines(code_lines)
lint(
text = code_lines,
linters = assignment_linter()
)
lint(
text = "x \%<>\% as.character()",
linters = assignment_linter()
)
# okay
lint(
text = "x <- mean(x)",
linters = assignment_linter()
)
code_lines <- "x <- 1\ny <<- 2"
writeLines(code_lines)
lint(
text = code_lines,
linters = assignment_linter()
)
# customizing using arguments
code_lines <- "1 -> x\n2 ->> y"
writeLines(code_lines)
lint(
text = code_lines,
linters = assignment_linter(allow_right_assign = TRUE)
)
lint(
text = "x <<- 1",
linters = assignment_linter(allow_cascading_assign = FALSE)
)
writeLines("foo(bar = \n 1)")
lint(
text = "foo(bar = \n 1)",
linters = assignment_linter(allow_trailing = FALSE)
)
lint(
text = "x \%<>\% as.character()",
linters = assignment_linter(allow_pipe_assign = TRUE)
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#assignment-1}
\item \url{https://style.tidyverse.org/pipes.html#assignment-2}
}
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=consistency_linters]{consistency}, \link[=default_linters]{default}, \link[=style_linters]{style}
}
lintr/man/function_return_linter.Rd 0000644 0001762 0000144 00000002730 14377165324 017263 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/function_return_linter.R
\name{function_return_linter}
\alias{function_return_linter}
\title{Lint common mistakes/style issues cropping up from return statements}
\usage{
function_return_linter()
}
\description{
\code{return(x <- ...)} is either distracting (because \code{x} is ignored), or
confusing (because assigning to \code{x} has some side effect that is muddled
by the dual-purpose expression).
}
\examples{
# will produce lints
lint(
text = "foo <- function(x) return(y <- x + 1)",
linters = function_return_linter()
)
lint(
text = "foo <- function(x) return(x <<- x + 1)",
linters = function_return_linter()
)
writeLines("e <- new.env() \nfoo <- function(x) return(e$val <- x + 1)")
lint(
text = "e <- new.env() \nfoo <- function(x) return(e$val <- x + 1)",
linters = function_return_linter()
)
# okay
lint(
text = "foo <- function(x) return(x + 1)",
linters = function_return_linter()
)
code_lines <- "
foo <- function(x) {
x <<- x + 1
return(x)
}
"
lint(
text = code_lines,
linters = function_return_linter()
)
code_lines <- "
e <- new.env()
foo <- function(x) {
e$val <- x + 1
return(e$val)
}
"
writeLines(code_lines)
lint(
text = code_lines,
linters = function_return_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=readability_linters]{readability}
}
lintr/man/any_is_na_linter.Rd 0000644 0001762 0000144 00000002055 14377165324 015777 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/any_is_na_linter.R
\name{any_is_na_linter}
\alias{any_is_na_linter}
\title{Require usage of \code{anyNA(x)} over \code{any(is.na(x))}}
\usage{
any_is_na_linter()
}
\description{
\code{\link[=anyNA]{anyNA()}} exists as a replacement for \code{any(is.na(x))} which is more efficient
for simple objects, and is at worst equally efficient.
Therefore, it should be used in all situations instead of the latter.
}
\examples{
# will produce lints
lint(
text = "any(is.na(x), na.rm = TRUE)",
linters = any_is_na_linter()
)
lint(
text = "any(is.na(foo(x)))",
linters = any_is_na_linter()
)
# okay
lint(
text = "anyNA(x)",
linters = any_is_na_linter()
)
lint(
text = "anyNA(foo(x))",
linters = any_is_na_linter()
)
lint(
text = "any(!is.na(x), na.rm = TRUE)",
linters = any_is_na_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=efficiency_linters]{efficiency}
}
lintr/man/unnecessary_placeholder_linter.Rd 0000644 0001762 0000144 00000002241 14377165324 020735 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/unnecessary_placeholder_linter.R
\name{unnecessary_placeholder_linter}
\alias{unnecessary_placeholder_linter}
\title{Block usage of pipeline placeholders if unnecessary}
\usage{
unnecessary_placeholder_linter()
}
\description{
The argument placeholder \code{.} in magrittr pipelines is unnecessary if
passed as the first positional argument; using it can cause confusion
and impacts readability.
}
\details{
This is true for forward (\verb{\%>\%}), assignment (\verb{\%<>\%}), and tee (\verb{\%T>\%}) operators.
}
\examples{
# will produce lints
lint(
text = "x \%>\% sum(., na.rm = TRUE)",
linters = unnecessary_placeholder_linter()
)
# okay
lint(
text = "x \%>\% sum(na.rm = TRUE)",
linters = unnecessary_placeholder_linter()
)
lint(
text = "x \%>\% lm(data = ., y ~ z)",
linters = unnecessary_placeholder_linter()
)
lint(
text = "x \%>\% outer(., .)",
linters = unnecessary_placeholder_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=readability_linters]{readability}
}
lintr/man/pkg_testthat_linters.Rd 0000644 0001762 0000144 00000002011 14522452242 016701 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{pkg_testthat_linters}
\alias{pkg_testthat_linters}
\title{Testthat linters}
\description{
Linters encouraging best practices within testthat suites.
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://testthat.r-lib.org}
\item \url{https://r-pkgs.org/testing-basics.html}
}
}
\section{Linters}{
The following linters are tagged with 'pkg_testthat':
\itemize{
\item{\code{\link{conjunct_test_linter}}}
\item{\code{\link{expect_comparison_linter}}}
\item{\code{\link{expect_identical_linter}}}
\item{\code{\link{expect_length_linter}}}
\item{\code{\link{expect_named_linter}}}
\item{\code{\link{expect_not_linter}}}
\item{\code{\link{expect_null_linter}}}
\item{\code{\link{expect_s3_class_linter}}}
\item{\code{\link{expect_s4_class_linter}}}
\item{\code{\link{expect_true_false_linter}}}
\item{\code{\link{expect_type_linter}}}
\item{\code{\link{yoda_test_linter}}}
}
}
lintr/man/configurable_linters.Rd 0000644 0001762 0000144 00000003475 14522452242 016657 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{configurable_linters}
\alias{configurable_linters}
\title{Configurable linters}
\description{
Generic linters which support custom configuration to your needs.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'configurable':
\itemize{
\item{\code{\link{absolute_path_linter}}}
\item{\code{\link{assignment_linter}}}
\item{\code{\link{backport_linter}}}
\item{\code{\link{brace_linter}}}
\item{\code{\link{commas_linter}}}
\item{\code{\link{conjunct_test_linter}}}
\item{\code{\link{cyclocomp_linter}}}
\item{\code{\link{duplicate_argument_linter}}}
\item{\code{\link{fixed_regex_linter}}}
\item{\code{\link{if_not_else_linter}}}
\item{\code{\link{implicit_assignment_linter}}}
\item{\code{\link{implicit_integer_linter}}}
\item{\code{\link{indentation_linter}}}
\item{\code{\link{infix_spaces_linter}}}
\item{\code{\link{library_call_linter}}}
\item{\code{\link{line_length_linter}}}
\item{\code{\link{missing_argument_linter}}}
\item{\code{\link{namespace_linter}}}
\item{\code{\link{nonportable_path_linter}}}
\item{\code{\link{object_length_linter}}}
\item{\code{\link{object_name_linter}}}
\item{\code{\link{object_usage_linter}}}
\item{\code{\link{paste_linter}}}
\item{\code{\link{pipe_consistency_linter}}}
\item{\code{\link{quotes_linter}}}
\item{\code{\link{redundant_ifelse_linter}}}
\item{\code{\link{semicolon_linter}}}
\item{\code{\link{string_boundary_linter}}}
\item{\code{\link{todo_comment_linter}}}
\item{\code{\link{trailing_whitespace_linter}}}
\item{\code{\link{undesirable_function_linter}}}
\item{\code{\link{undesirable_operator_linter}}}
\item{\code{\link{unnecessary_concatenation_linter}}}
\item{\code{\link{unused_import_linter}}}
}
}
lintr/man/backport_linter.Rd 0000644 0001762 0000144 00000002250 14522452242 015627 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/backport_linter.R
\name{backport_linter}
\alias{backport_linter}
\title{Backport linter}
\usage{
backport_linter(r_version = getRversion(), except = character())
}
\arguments{
\item{r_version}{Minimum R version to test for compatibility}
\item{except}{Character vector of functions to be excluded from linting.
Use this to list explicitly defined backports, e.g. those imported from the \code{{backports}} package or manually
defined in your package.}
}
\description{
Check for usage of unavailable functions. Not reliable for testing r-devel dependencies.
}
\examples{
# will produce lints
lint(
text = "trimws(x)",
linters = backport_linter("3.0.0")
)
lint(
text = "str2lang(x)",
linters = backport_linter("3.2.0")
)
# okay
lint(
text = "trimws(x)",
linters = backport_linter("3.6.0")
)
lint(
text = "str2lang(x)",
linters = backport_linter("4.0.0")
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=package_development_linters]{package_development}, \link[=robustness_linters]{robustness}
}
lintr/man/outer_negation_linter.Rd 0000644 0001762 0000144 00000002041 14377165324 017054 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/outer_negation_linter.R
\name{outer_negation_linter}
\alias{outer_negation_linter}
\title{Require usage of \code{!any(x)} over \code{all(!x)}, \code{!all(x)} over \code{any(!x)}}
\usage{
outer_negation_linter()
}
\description{
\code{any(!x)} is logically equivalent to \code{!any(x)}; ditto for the equivalence of
\code{all(!x)} and \code{!any(x)}. Negating after aggregation only requires inverting
one logical value, and is typically more readable.
}
\examples{
# will produce lints
lint(
text = "all(!x)",
linters = outer_negation_linter()
)
lint(
text = "any(!x)",
linters = outer_negation_linter()
)
# okay
lint(
text = "!any(x)",
linters = outer_negation_linter()
)
lint(
text = "!all(x)",
linters = outer_negation_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/xp_call_name.Rd 0000644 0001762 0000144 00000003102 14522452242 015064 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xp_utils.R
\name{xp_call_name}
\alias{xp_call_name}
\title{Get the name of the function matched by an XPath}
\usage{
xp_call_name(expr, depth = 1L, condition = NULL)
}
\arguments{
\item{expr}{An \code{xml_node} or \code{xml_nodeset}, e.g. from \code{\link[xml2:xml_find_all]{xml2::xml_find_all()}}.}
\item{depth}{Integer, default \code{1L}. How deep in the AST represented by \code{expr}
should we look to find the call? By default, we assume \code{expr} is matched
to an \verb{} node under which the corresponding \verb{}
node is found directly. \code{depth = 0L} means \code{expr} is matched directly
to the \code{SYMBOL_FUNCTION_CALL}; \code{depth > 1L} means \code{depth} total \verb{}
nodes must be traversed before finding the call.}
\item{condition}{An additional (XPath condition on the \code{SYMBOL_FUNCTION_CALL}
required for a match. The default (\code{NULL}) is no condition. See examples.}
}
\description{
Often, it is more helpful to tailor the \code{message} of a lint to record
which function was matched by the lint logic. This function encapsulates
the logic to pull out the matched call in common situations.
}
\examples{
xml_from_code <- function(str) {
xml2::read_xml(xmlparsedata::xml_parse_data(parse(text = str, keep.source = TRUE)))
}
xml <- xml_from_code("sum(1:10)")
xp_call_name(xml, depth = 2L)
xp_call_name(xml2::xml_find_first(xml, "expr"))
xml <- xml_from_code(c("sum(1:10)", "sd(1:10)"))
xp_call_name(xml, depth = 2L, condition = "text() = 'sum'")
}
lintr/man/all_linters.Rd 0000644 0001762 0000144 00000002061 14377165326 014771 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/with.R
\name{all_linters}
\alias{all_linters}
\title{Create a linter configuration based on all available linters}
\usage{
all_linters(packages = "lintr", ...)
}
\arguments{
\item{packages}{A character vector of packages to search for linters.}
\item{...}{Arguments of elements to change. If unnamed, the argument is automatically named.
If the named argument already exists in the list of linters, it is replaced by the new element.
If it does not exist, it is added. If the value is \code{NULL}, the linter is removed.}
}
\description{
Create a linter configuration based on all available linters
}
\examples{
names(all_linters())
}
\seealso{
\itemize{
\item \link{linters_with_defaults} for basing off lintr's set of default linters.
\item \link{linters_with_tags} for basing off tags attached to linters, possibly across multiple packages.
\item \link{available_linters} to get a data frame of available linters.
\item \link{linters} for a complete list of linters available in lintr.
}
}
lintr/man/lint.Rd 0000644 0001762 0000144 00000007743 14522452242 013427 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lint.R
\name{lint}
\alias{lint}
\alias{lint_file}
\alias{lint_dir}
\alias{lint_package}
\title{Lint a file, directory, or package}
\usage{
lint(
filename,
linters = NULL,
...,
cache = FALSE,
parse_settings = TRUE,
text = NULL
)
lint_dir(
path = ".",
...,
relative_path = TRUE,
exclusions = list("renv", "packrat"),
pattern = "(?i)[.](r|rmd|qmd|rnw|rhtml|rrst|rtex|rtxt)$",
parse_settings = TRUE,
show_progress = NULL
)
lint_package(
path = ".",
...,
relative_path = TRUE,
exclusions = list("R/RcppExports.R"),
parse_settings = TRUE,
show_progress = NULL
)
}
\arguments{
\item{filename}{Either the filename for a file to lint, or a character string of inline R code for linting.
The latter (inline data) applies whenever \code{filename} has a newline character (\\n).}
\item{linters}{A named list of linter functions to apply. See \link{linters} for a full list of default and available
linters.}
\item{...}{Provide additional arguments to be passed to:
\itemize{
\item \code{\link[=exclude]{exclude()}} (in case of \code{lint()}; e.g. \code{lints} or \code{exclusions})
\item \code{\link[=lint]{lint()}} (in case of \code{lint_dir()} and \code{lint_package()}; e.g. \code{linters} or \code{cache})
}}
\item{cache}{When logical, toggle caching of lint results. I1f passed a character string, store the cache in this
directory.}
\item{parse_settings}{Logical, default \code{TRUE}. Whether to try and parse the settings;
otherwise, the \code{\link[=default_settings]{default_settings()}} are used.}
\item{text}{Optional argument for supplying a string or lines directly, e.g. if the file is already in memory or
linting is being done ad hoc.}
\item{path}{For the base directory of the project (for \code{lint_dir()}) or
package (for \code{lint_package()}).}
\item{relative_path}{if \code{TRUE}, file paths are printed using their path relative to the base directory.
If \code{FALSE}, use the full absolute path.}
\item{exclusions}{exclusions for \code{\link[=exclude]{exclude()}}, relative to the package path.}
\item{pattern}{pattern for files, by default it will take files with any of the extensions
.R, .Rmd, .qmd, .Rnw, .Rhtml, .Rrst, .Rtex, .Rtxt allowing for lowercase r (.r, ...).}
\item{show_progress}{Logical controlling whether to show linting progress with a simple text
progress bar \emph{via} \code{\link[utils:txtProgressBar]{utils::txtProgressBar()}}. The default behavior is to show progress in
\code{\link[=interactive]{interactive()}} sessions not running a testthat suite.}
}
\value{
An object of class \code{c("lints", "list")}, each element of which is a \code{"list"} object.
}
\description{
\itemize{
\item \code{lint()} lints a single file.
\item \code{lint_dir()} lints all files in a directory.
\item \code{lint_package()} lints all likely locations for R files in a package, i.e.
\verb{R/}, \verb{tests/}, \verb{inst/}, \verb{vignettes/}, \verb{data-raw/}, \verb{demo/}, and \verb{exec/}.
}
}
\details{
Read \code{vignette("lintr")} to learn how to configure which linters are run
by default.
Note that if files contain unparseable encoding problems, only the encoding problem will be linted to avoid
unintelligible error messages from other linters.
}
\examples{
\dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
f <- withr::local_tempfile(lines = "a=1", fileext = "R")
lint(f) # linting a file
lint("a = 123\n") # linting inline-code
lint(text = "a = 123") # linting inline-code
\dontshow{\}) # examplesIf}
if (FALSE) {
lint_dir()
lint_dir(
linters = list(semicolon_linter()),
exclusions = list(
"inst/doc/creating_linters.R" = 1,
"inst/example/bad.R",
"renv"
)
)
}
if (FALSE) {
lint_package()
lint_package(
linters = linters_with_defaults(semicolon_linter = semicolon_linter()),
exclusions = list("inst/doc/creating_linters.R" = 1, "inst/example/bad.R")
)
}
}
lintr/man/readability_linters.Rd 0000644 0001762 0000144 00000005237 14522452242 016506 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{readability_linters}
\alias{readability_linters}
\title{Readability linters}
\description{
Linters highlighting readability issues, such as missing whitespace.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'readability':
\itemize{
\item{\code{\link{boolean_arithmetic_linter}}}
\item{\code{\link{brace_linter}}}
\item{\code{\link{commas_linter}}}
\item{\code{\link{commented_code_linter}}}
\item{\code{\link{conjunct_test_linter}}}
\item{\code{\link{consecutive_assertion_linter}}}
\item{\code{\link{cyclocomp_linter}}}
\item{\code{\link{empty_assignment_linter}}}
\item{\code{\link{expect_length_linter}}}
\item{\code{\link{expect_named_linter}}}
\item{\code{\link{expect_not_linter}}}
\item{\code{\link{expect_true_false_linter}}}
\item{\code{\link{fixed_regex_linter}}}
\item{\code{\link{for_loop_index_linter}}}
\item{\code{\link{function_left_parentheses_linter}}}
\item{\code{\link{function_return_linter}}}
\item{\code{\link{if_not_else_linter}}}
\item{\code{\link{implicit_assignment_linter}}}
\item{\code{\link{indentation_linter}}}
\item{\code{\link{infix_spaces_linter}}}
\item{\code{\link{inner_combine_linter}}}
\item{\code{\link{is_numeric_linter}}}
\item{\code{\link{keyword_quote_linter}}}
\item{\code{\link{length_levels_linter}}}
\item{\code{\link{lengths_linter}}}
\item{\code{\link{library_call_linter}}}
\item{\code{\link{line_length_linter}}}
\item{\code{\link{matrix_apply_linter}}}
\item{\code{\link{nested_ifelse_linter}}}
\item{\code{\link{numeric_leading_zero_linter}}}
\item{\code{\link{object_length_linter}}}
\item{\code{\link{object_usage_linter}}}
\item{\code{\link{outer_negation_linter}}}
\item{\code{\link{paren_body_linter}}}
\item{\code{\link{pipe_call_linter}}}
\item{\code{\link{pipe_consistency_linter}}}
\item{\code{\link{pipe_continuation_linter}}}
\item{\code{\link{quotes_linter}}}
\item{\code{\link{redundant_equals_linter}}}
\item{\code{\link{repeat_linter}}}
\item{\code{\link{scalar_in_linter}}}
\item{\code{\link{semicolon_linter}}}
\item{\code{\link{sort_linter}}}
\item{\code{\link{spaces_inside_linter}}}
\item{\code{\link{spaces_left_parentheses_linter}}}
\item{\code{\link{string_boundary_linter}}}
\item{\code{\link{system_file_linter}}}
\item{\code{\link{T_and_F_symbol_linter}}}
\item{\code{\link{unnecessary_concatenation_linter}}}
\item{\code{\link{unnecessary_lambda_linter}}}
\item{\code{\link{unnecessary_nested_if_linter}}}
\item{\code{\link{unnecessary_placeholder_linter}}}
\item{\code{\link{unreachable_code_linter}}}
\item{\code{\link{yoda_test_linter}}}
}
}
lintr/man/redundant_equals_linter.Rd 0000644 0001762 0000144 00000002713 14377165326 017400 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/redundant_equals_linter.R
\name{redundant_equals_linter}
\alias{redundant_equals_linter}
\title{Block usage of \code{==}, \code{!=} on logical vectors}
\usage{
redundant_equals_linter()
}
\description{
Testing \code{x == TRUE} is redundant if \code{x} is a logical vector. Wherever this is
used to improve readability, the solution should instead be to improve the
naming of the object to better indicate that its contents are logical. This
can be done using prefixes (is, has, can, etc.). For example, \code{is_child},
\code{has_parent_supervision}, \code{can_watch_horror_movie} clarify their logical
nature, while \code{child}, \code{parent_supervision}, \code{watch_horror_movie} don't.
}
\examples{
# will produce lints
lint(
text = "if (any(x == TRUE)) 1",
linters = redundant_equals_linter()
)
lint(
text = "if (any(x != FALSE)) 0",
linters = redundant_equals_linter()
)
# okay
lint(
text = "if (any(x)) 1",
linters = redundant_equals_linter()
)
lint(
text = "if (!all(x)) 0",
linters = redundant_equals_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \code{\link[=outer_negation_linter]{outer_negation_linter()}}
}
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=common_mistakes_linters]{common_mistakes}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/semicolon_linter.Rd 0000644 0001762 0000144 00000003233 14377165326 016030 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/semicolon_linter.R
\name{semicolon_linter}
\alias{semicolon_linter}
\title{Semicolon linter}
\usage{
semicolon_linter(allow_compound = FALSE, allow_trailing = FALSE)
}
\arguments{
\item{allow_compound}{Logical, default \code{FALSE}. If \code{TRUE}, "compound"
semicolons (e.g. as in \verb{x; y}, i.e., on the same line of code) are allowed.}
\item{allow_trailing}{Logical, default \code{FALSE}. If \code{TRUE}, "trailing"
semicolons (i.e., those that terminate lines of code) are allowed.}
}
\description{
Check that no semicolons terminate expressions.
}
\examples{
# will produce lints
lint(
text = "a <- 1;",
linters = semicolon_linter()
)
lint(
text = "a <- 1; b <- 1",
linters = semicolon_linter()
)
lint(
text = "function() { a <- 1; b <- 1 }",
linters = semicolon_linter()
)
# okay
lint(
text = "a <- 1",
linters = semicolon_linter()
)
lint(
text = "a <- 1;",
linters = semicolon_linter(allow_trailing = TRUE)
)
code_lines <- "a <- 1\nb <- 1"
writeLines(code_lines)
lint(
text = code_lines,
linters = semicolon_linter()
)
lint(
text = "a <- 1; b <- 1",
linters = semicolon_linter(allow_compound = TRUE)
)
code_lines <- "function() { \n a <- 1\n b <- 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = semicolon_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#semicolons}
}
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/get_source_expressions.Rd 0000644 0001762 0000144 00000006420 14522452242 017251 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_source_expressions.R
\name{get_source_expressions}
\alias{get_source_expressions}
\title{Parsed sourced file from a filename}
\usage{
get_source_expressions(filename, lines = NULL)
}
\arguments{
\item{filename}{the file to be parsed.}
\item{lines}{a character vector of lines.
If \code{NULL}, then \code{filename} will be read.}
}
\value{
A \code{list} with three components:
\describe{
\item{expressions}{a \code{list} of
\code{n+1} objects. The first \code{n} elements correspond to each expression in
\code{filename}, and consist of a list of 9 elements:
\itemize{
\item{\code{filename} (\code{character})}
\item{\code{line} (\code{integer}) the line in \code{filename} where this expression begins}
\item{\code{column} (\code{integer}) the column in \code{filename} where this expression begins}
\item{\code{lines} (named \code{character}) vector of all lines spanned by this
expression, named with the line number corresponding to \code{filename}}
\item{\code{parsed_content} (\code{data.frame}) as given by \code{\link[utils:getParseData]{utils::getParseData()}} for this expression}
\item{\code{xml_parsed_content} (\code{xml_document}) the XML parse tree of this
expression as given by \code{\link[xmlparsedata:xml_parse_data]{xmlparsedata::xml_parse_data()}}}
\item{\code{content} (\code{character}) the same as \code{lines} as a single string (not split across lines)}
}
The final element of \code{expressions} is a list corresponding to the full file
consisting of 6 elements:
\itemize{
\item{\code{filename} (\code{character})}
\item{\code{file_lines} (\code{character}) the \code{\link[=readLines]{readLines()}} output for this file}
\item{\code{content} (\code{character}) for .R files, the same as \code{file_lines};
for .Rmd or .qmd scripts, this is the extracted R source code (as text)}
\item{\code{full_parsed_content} (\code{data.frame}) as given by
\code{\link[utils:getParseData]{utils::getParseData()}} for the full content}
\item{\code{full_xml_parsed_content} (\code{xml_document}) the XML parse tree of all
expressions as given by \code{\link[xmlparsedata:xml_parse_data]{xmlparsedata::xml_parse_data()}}}
\item{\code{terminal_newline} (\code{logical}) records whether \code{filename} has a terminal
newline (as determined by \code{\link[=readLines]{readLines()}} producing a corresponding warning)}
}
}
\item{error}{A \code{Lint} object describing any parsing error.}
\item{lines}{The \code{\link[=readLines]{readLines()}} output for this file.}
}
}
\description{
This object is given as input to each linter.
}
\details{
The file is read using the \code{encoding} setting.
This setting is found by taking the first valid result from the following locations
\enumerate{
\item The \code{encoding} key from the usual lintr configuration settings.
\item The \code{Encoding} field from a Package \code{DESCRIPTION} file in a parent directory.
\item The \code{Encoding} field from an R Project \code{.Rproj} file in a parent directory.
\item \code{"UTF-8"} as a fallback.
}
}
\examples{
\dontshow{if (requireNamespace("withr", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
tmp <- withr::local_tempfile(lines = c("x <- 1", "y <- x + 1"))
get_source_expressions(tmp)
\dontshow{\}) # examplesIf}
}
lintr/man/function_argument_linter.Rd 0000644 0001762 0000144 00000002631 14522452242 017554 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/function_argument_linter.R
\name{function_argument_linter}
\alias{function_argument_linter}
\title{Function argument linter}
\usage{
function_argument_linter()
}
\description{
Check that arguments with defaults come last in all function declarations,
as per the tidyverse design guide.
Changing the argument order can be a breaking change. An alternative to changing the argument order
is to instead set the default for such arguments to \code{NULL}.
}
\examples{
# will produce lints
lint(
text = "function(y = 1, z = 2, x) {}",
linters = function_argument_linter()
)
lint(
text = "function(x, y, z = 1, ..., w) {}",
linters = function_argument_linter()
)
# okay
lint(
text = "function(x, y = 1, z = 2) {}",
linters = function_argument_linter()
)
lint(
text = "function(x, y, w, z = 1, ...) {}",
linters = function_argument_linter()
)
lint(
text = "function(y = 1, z = 2, x = NULL) {}",
linters = function_argument_linter()
)
lint(
text = "function(x, y, z = 1, ..., w = NULL) {}",
linters = function_argument_linter()
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://design.tidyverse.org/required-no-defaults.html}
}
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=consistency_linters]{consistency}, \link[=style_linters]{style}
}
lintr/man/commented_code_linter.Rd 0000644 0001762 0000144 00000001664 14377165324 017011 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/comment_linters.R
\name{commented_code_linter}
\alias{commented_code_linter}
\title{Commented code linter}
\usage{
commented_code_linter()
}
\description{
Check that there is no commented code outside roxygen blocks.
}
\examples{
# will produce lints
lint(
text = "# x <- 1",
linters = commented_code_linter()
)
lint(
text = "x <- f() # g()",
linters = commented_code_linter()
)
lint(
text = "x + y # + z[1, 2]",
linters = commented_code_linter()
)
# okay
lint(
text = "x <- 1; x <- f(); x + y",
linters = commented_code_linter()
)
lint(
text = "#' x <- 1",
linters = commented_code_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/default_linters.Rd 0000644 0001762 0000144 00000003546 14455765330 015654 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/zzz.R
\docType{data}
\name{default_linters}
\alias{default_linters}
\title{Default linters}
\format{
An object of class \code{list} of length 25.
}
\usage{
default_linters
}
\description{
List of default linters for \code{\link[=lint]{lint()}}. Use
\code{\link[=linters_with_defaults]{linters_with_defaults()}} to customize it. Most of the default linters
are based on \href{https://style.tidyverse.org/}{the tidyverse style guide}.
The set of default linters is as follows (any parameterized linters, e.g., \code{line_length_linter} use their default
argument(s), see \verb{?} for details):
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\keyword{datasets}
\section{Linters}{
The following linters are tagged with 'default':
\itemize{
\item{\code{\link{assignment_linter}}}
\item{\code{\link{brace_linter}}}
\item{\code{\link{commas_linter}}}
\item{\code{\link{commented_code_linter}}}
\item{\code{\link{cyclocomp_linter}}}
\item{\code{\link{equals_na_linter}}}
\item{\code{\link{function_left_parentheses_linter}}}
\item{\code{\link{indentation_linter}}}
\item{\code{\link{infix_spaces_linter}}}
\item{\code{\link{line_length_linter}}}
\item{\code{\link{object_length_linter}}}
\item{\code{\link{object_name_linter}}}
\item{\code{\link{object_usage_linter}}}
\item{\code{\link{paren_body_linter}}}
\item{\code{\link{pipe_continuation_linter}}}
\item{\code{\link{quotes_linter}}}
\item{\code{\link{semicolon_linter}}}
\item{\code{\link{seq_linter}}}
\item{\code{\link{spaces_inside_linter}}}
\item{\code{\link{spaces_left_parentheses_linter}}}
\item{\code{\link{T_and_F_symbol_linter}}}
\item{\code{\link{trailing_blank_lines_linter}}}
\item{\code{\link{trailing_whitespace_linter}}}
\item{\code{\link{vector_logic_linter}}}
\item{\code{\link{whitespace_linter}}}
}
}
lintr/man/numeric_leading_zero_linter.Rd 0000644 0001762 0000144 00000001663 14377165324 020227 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/numeric_leading_zero_linter.R
\name{numeric_leading_zero_linter}
\alias{numeric_leading_zero_linter}
\title{Require usage of a leading zero in all fractional numerics}
\usage{
numeric_leading_zero_linter()
}
\description{
While .1 and 0.1 mean the same thing, the latter is easier to read due
to the small size of the '.' glyph.
}
\examples{
# will produce lints
lint(
text = "x <- .1",
linters = numeric_leading_zero_linter()
)
lint(
text = "x <- -.1",
linters = numeric_leading_zero_linter()
)
# okay
lint(
text = "x <- 0.1",
linters = numeric_leading_zero_linter()
)
lint(
text = "x <- -0.1",
linters = numeric_leading_zero_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=consistency_linters]{consistency}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/library_call_linter.Rd 0000644 0001762 0000144 00000002434 14522452242 016465 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/library_call_linter.R
\name{library_call_linter}
\alias{library_call_linter}
\title{Library call linter}
\usage{
library_call_linter(allow_preamble = TRUE)
}
\arguments{
\item{allow_preamble}{Logical, default \code{TRUE}. If \code{FALSE},
no code is allowed to precede the first \code{library()} call,
otherwise some setup code is allowed, but all \code{library()}
calls must follow consecutively after the first one.}
}
\description{
Force library calls to all be at the top of the script.
}
\examples{
# will produce lints
lint(
text = "
library(dplyr)
print('test')
library(tidyr)
",
linters = library_call_linter()
)
lint(
text = "
library(dplyr)
print('test')
library(tidyr)
library(purrr)
",
linters = library_call_linter()
)
# okay
lint(
text = "
library(dplyr)
print('test')
",
linters = library_call_linter()
)
lint(
text = "
# comment
library(dplyr)
",
linters = library_call_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=configurable_linters]{configurable}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/brace_linter.Rd 0000644 0001762 0000144 00000003706 14377165326 015121 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/brace_linter.R
\name{brace_linter}
\alias{brace_linter}
\title{Brace linter}
\usage{
brace_linter(allow_single_line = FALSE)
}
\arguments{
\item{allow_single_line}{if \code{TRUE}, allow an open and closed curly pair on the same line.}
}
\description{
Perform various style checks related to placement and spacing of curly braces:
}
\details{
\itemize{
\item Opening curly braces are never on their own line and are always followed by a newline.
\item Opening curly braces have a space before them.
\item Closing curly braces are on their own line unless they are followed by an \verb{else}.
\item Closing curly braces in \code{if} conditions are on the same line as the corresponding \verb{else}.
\item Either both or neither branch in \code{if}/\verb{else} use curly braces, i.e., either both branches use \code{{...}} or neither
does.
\item Functions spanning multiple lines use curly braces.
}
}
\examples{
# will produce lints
lint(
text = "f <- function() { 1 }",
linters = brace_linter()
)
writeLines("if (TRUE) {\n return(1) }")
lint(
text = "if (TRUE) {\n return(1) }",
linters = brace_linter()
)
# okay
writeLines("f <- function() {\n 1\n}")
lint(
text = "f <- function() {\n 1\n}",
linters = brace_linter()
)
writeLines("if (TRUE) { \n return(1) \n}")
lint(
text = "if (TRUE) { \n return(1) \n}",
linters = brace_linter()
)
# customizing using arguments
writeLines("if (TRUE) { return(1) }")
lint(
text = "if (TRUE) { return(1) }",
linters = brace_linter(allow_single_line = TRUE)
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#indenting}
\item \url{https://style.tidyverse.org/syntax.html#if-statements}
}
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/efficiency_linters.Rd 0000644 0001762 0000144 00000002740 14522452242 016315 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/linter_tag_docs.R
\name{efficiency_linters}
\alias{efficiency_linters}
\title{Efficiency linters}
\description{
Linters highlighting code efficiency problems, such as unnecessary function calls.
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Linters}{
The following linters are tagged with 'efficiency':
\itemize{
\item{\code{\link{any_duplicated_linter}}}
\item{\code{\link{any_is_na_linter}}}
\item{\code{\link{boolean_arithmetic_linter}}}
\item{\code{\link{fixed_regex_linter}}}
\item{\code{\link{ifelse_censor_linter}}}
\item{\code{\link{inner_combine_linter}}}
\item{\code{\link{length_test_linter}}}
\item{\code{\link{lengths_linter}}}
\item{\code{\link{literal_coercion_linter}}}
\item{\code{\link{matrix_apply_linter}}}
\item{\code{\link{nested_ifelse_linter}}}
\item{\code{\link{outer_negation_linter}}}
\item{\code{\link{redundant_equals_linter}}}
\item{\code{\link{redundant_ifelse_linter}}}
\item{\code{\link{regex_subset_linter}}}
\item{\code{\link{routine_registration_linter}}}
\item{\code{\link{scalar_in_linter}}}
\item{\code{\link{seq_linter}}}
\item{\code{\link{sort_linter}}}
\item{\code{\link{string_boundary_linter}}}
\item{\code{\link{undesirable_function_linter}}}
\item{\code{\link{undesirable_operator_linter}}}
\item{\code{\link{unnecessary_concatenation_linter}}}
\item{\code{\link{unnecessary_lambda_linter}}}
\item{\code{\link{vector_logic_linter}}}
}
}
lintr/man/clear_cache.Rd 0000644 0001762 0000144 00000000767 14251630510 014664 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cache.R
\name{clear_cache}
\alias{clear_cache}
\title{Clear the lintr cache}
\usage{
clear_cache(file = NULL, path = NULL)
}
\arguments{
\item{file}{filename whose cache to clear. If you pass \code{NULL}, it will delete all of the caches.}
\item{path}{directory to store caches. Reads option 'lintr.cache_directory' as the default.}
}
\value{
0 for success, 1 for failure, invisibly.
}
\description{
Clear the lintr cache
}
lintr/man/indentation_linter.Rd 0000644 0001762 0000144 00000006764 14377165326 016370 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/indentation_linter.R
\name{indentation_linter}
\alias{indentation_linter}
\title{Check that indentation is consistent}
\usage{
indentation_linter(
indent = 2L,
hanging_indent_style = c("tidy", "always", "never"),
assignment_as_infix = TRUE
)
}
\arguments{
\item{indent}{Number of spaces, that a code block should be indented by relative to its parent code block.
Used for multi-line code blocks (\code{{ ... }}), function calls (\code{( ... )}) and extractions (\verb{[ ... ]}, \verb{[[ ... ]]}).
Defaults to 2.}
\item{hanging_indent_style}{Indentation style for multi-line function calls with arguments in their first line.
Defaults to tidyverse style, i.e. a block indent is used if the function call terminates with \verb{)} on a separate
line and a hanging indent if not.
Note that function multi-line function calls without arguments on their first line will always be expected to have
block-indented arguments.
If \code{hanging_indent_style} is \code{"tidy"}, multi-line function definitions are expected to be double-indented if the
first line of the function definition contains no arguments and the closing parenthesis is not on its own line.
\if{html}{\out{}}\preformatted{# complies to any style
map(
x,
f,
additional_arg = 42
)
# complies to "tidy" and "never"
map(x, f,
additional_arg = 42
)
# complies to "always"
map(x, f,
additional_arg = 42
)
# complies to "tidy" and "always"
map(x, f,
additional_arg = 42)
# complies to "never"
map(x, f,
additional_arg = 42)
# complies to "tidy"
function(
a,
b) \{
# body
\}
}\if{html}{\out{
}}}
\item{assignment_as_infix}{Treat \verb{<-} as a regular (i.e. left-associative) infix operator?
This means, that infix operators on the right hand side of an assignment do not trigger a second level of
indentation:
\if{html}{\out{}}\preformatted{# complies to any style
variable <- a \%+\%
b \%+\%
c
# complies to assignment_as_infix = TRUE
variable <-
a \%+\%
b \%+\%
c
# complies to assignment_as_infix = FALSE
variable <-
a \%+\%
b \%+\%
c
}\if{html}{\out{
}}}
}
\description{
Check that indentation is consistent
}
\examples{
# will produce lints
code_lines <- "if (TRUE) {\n1 + 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter()
)
code_lines <- "if (TRUE) {\n 1 + 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter()
)
code_lines <- "map(x, f,\n additional_arg = 42\n)"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter(hanging_indent_style = "always")
)
code_lines <- "map(x, f,\n additional_arg = 42)"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter(hanging_indent_style = "never")
)
# okay
code_lines <- "map(x, f,\n additional_arg = 42\n)"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter()
)
code_lines <- "if (TRUE) {\n 1 + 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter(indent = 4)
)
}
\seealso{
\itemize{
\item \link{linters} for a complete list of linters available in lintr.
\item \url{https://style.tidyverse.org/syntax.html#indenting}
\item \url{https://style.tidyverse.org/functions.html#long-lines-1}
}
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=default_linters]{default}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/boolean_arithmetic_linter.Rd 0000644 0001762 0000144 00000001776 14377165324 017700 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/boolean_arithmetic_linter.R
\name{boolean_arithmetic_linter}
\alias{boolean_arithmetic_linter}
\title{Require usage of boolean operators over equivalent arithmetic}
\usage{
boolean_arithmetic_linter()
}
\description{
\code{length(which(x == y)) == 0} is the same as \code{!any(x == y)}, but the latter
is more readable and more efficient.
}
\examples{
# will produce lints
lint(
text = "length(which(x == y)) == 0L",
linters = boolean_arithmetic_linter()
)
lint(
text = "sum(grepl(pattern, x)) == 0",
linters = boolean_arithmetic_linter()
)
# okay
lint(
text = "!any(x == y)",
linters = boolean_arithmetic_linter()
)
lint(
text = "!any(grepl(pattern, x))",
linters = boolean_arithmetic_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=efficiency_linters]{efficiency}, \link[=readability_linters]{readability}
}
lintr/man/conjunct_test_linter.Rd 0000644 0001762 0000144 00000006557 14522452242 016722 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/conjunct_test_linter.R
\name{conjunct_test_linter}
\alias{conjunct_test_linter}
\title{Force \code{&&} conditions to be written separately where appropriate}
\usage{
conjunct_test_linter(
allow_named_stopifnot = TRUE,
allow_filter = c("never", "not_dplyr", "always")
)
}
\arguments{
\item{allow_named_stopifnot}{Logical, \code{TRUE} by default. If \code{FALSE}, "named" calls to \code{stopifnot()},
available since R 4.0.0 to provide helpful messages for test failures, are also linted.}
\item{allow_filter}{Character naming the method for linting calls to \code{filter()}. The default, \code{"never"}, means
\code{filter()} and \code{dplyr::filter()} calls are linted; \code{"not_dplyr"} means only \code{dplyr::filter()} calls are linted;
and \code{"always"} means no calls to \code{filter()} are linted. Calls like \code{stats::filter()} are never linted.}
}
\description{
For readability of test outputs, testing only one thing per call to
\code{\link[testthat:logical-expectations]{testthat::expect_true()}} is preferable, i.e.,
\verb{expect_true(A); expect_true(B)} is better than \code{expect_true(A && B)}, and
\verb{expect_false(A); expect_false(B)} is better than \code{expect_false(A || B)}.
}
\details{
Similar reasoning applies to \code{&&} usage inside \code{\link[=stopifnot]{stopifnot()}} and \code{assertthat::assert_that()} calls.
Relatedly, \code{dplyr::filter(DF, A & B)} is the same as \code{dplyr::filter(DF, A, B)}, but the latter will be more readable
/ easier to format for long conditions. Note that this linter assumes usages of \code{filter()} are \code{dplyr::filter()};
if you're using another function named \code{filter()}, e.g. \code{\link[stats:filter]{stats::filter()}}, please namespace-qualify it to avoid
false positives. You can omit linting \code{filter()} expressions altogether via \code{allow_filter = TRUE}.
}
\examples{
# will produce lints
lint(
text = "expect_true(x && y)",
linters = conjunct_test_linter()
)
lint(
text = "expect_false(x || (y && z))",
linters = conjunct_test_linter()
)
lint(
text = "stopifnot('x must be a logical scalar' = length(x) == 1 && is.logical(x) && !is.na(x))",
linters = conjunct_test_linter(allow_named_stopifnot = FALSE)
)
lint(
text = "dplyr::filter(mtcars, mpg > 20 & vs == 0)",
linters = conjunct_test_linter()
)
lint(
text = "filter(mtcars, mpg > 20 & vs == 0)",
linters = conjunct_test_linter()
)
# okay
lint(
text = "expect_true(x || (y && z))",
linters = conjunct_test_linter()
)
lint(
text = 'stopifnot("x must be a logical scalar" = length(x) == 1 && is.logical(x) && !is.na(x))',
linters = conjunct_test_linter(allow_named_stopifnot = TRUE)
)
lint(
text = "dplyr::filter(mtcars, mpg > 20 & vs == 0)",
linters = conjunct_test_linter(allow_filter = "always")
)
lint(
text = "filter(mtcars, mpg > 20 & vs == 0)",
linters = conjunct_test_linter(allow_filter = "not_dplyr")
)
lint(
text = "stats::filter(mtcars$cyl, mtcars$mpg > 20 & mtcars$vs == 0)",
linters = conjunct_test_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=configurable_linters]{configurable}, \link[=package_development_linters]{package_development}, \link[=pkg_testthat_linters]{pkg_testthat}, \link[=readability_linters]{readability}
}
lintr/man/object_length_linter.Rd 0000644 0001762 0000144 00000003114 14377165324 016643 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/object_length_linter.R
\name{object_length_linter}
\alias{object_length_linter}
\title{Object length linter}
\usage{
object_length_linter(length = 30L)
}
\arguments{
\item{length}{maximum variable name length allowed.}
}
\description{
Check that object names are not too long.
The length of an object name is defined as the length in characters, after removing extraneous parts:
}
\details{
\itemize{
\item generic prefixes for implementations of S3 generics, e.g. \code{as.data.frame.my_class} has length 8.
\item leading \code{.}, e.g. \code{.my_hidden_function} has length 18.
\item "\%\%" for infix operators, e.g. \verb{\%my_op\%} has length 5.
\item trailing \verb{<-} for assignment functions, e.g. \verb{my_attr<-} has length 7.
}
Note that this behavior relies in part on having packages in your Imports available;
see the detailed note in \code{\link[=object_name_linter]{object_name_linter()}} for more details.
}
\examples{
# will produce lints
lint(
text = "very_very_long_variable_name <- 1L",
linters = object_length_linter(length = 10L)
)
# okay
lint(
text = "very_very_long_variable_name <- 1L",
linters = object_length_linter(length = 30L)
)
lint(
text = "var <- 1L",
linters = object_length_linter(length = 10L)
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=configurable_linters]{configurable}, \link[=default_linters]{default}, \link[=executing_linters]{executing}, \link[=readability_linters]{readability}, \link[=style_linters]{style}
}
lintr/man/empty_assignment_linter.Rd 0000644 0001762 0000144 00000001724 14377165326 017431 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/empty_assignment_linter.R
\name{empty_assignment_linter}
\alias{empty_assignment_linter}
\title{Block assignment of \code{{}}}
\usage{
empty_assignment_linter()
}
\description{
Assignment of \code{{}} is the same as assignment of \code{NULL}; use the latter
for clarity. Closely related: \code{\link[=unnecessary_concatenation_linter]{unnecessary_concatenation_linter()}}.
}
\examples{
# will produce lints
lint(
text = "x <- {}",
linters = empty_assignment_linter()
)
writeLines("x = {\n}")
lint(
text = "x = {\n}",
linters = empty_assignment_linter()
)
# okay
lint(
text = "x <- { 3 + 4 }",
linters = empty_assignment_linter()
)
lint(
text = "x <- NULL",
linters = empty_assignment_linter()
)
}
\seealso{
\link{linters} for a complete list of linters available in lintr.
}
\section{Tags}{
\link[=best_practices_linters]{best_practices}, \link[=readability_linters]{readability}
}
lintr/man/figures/ 0000755 0001762 0000144 00000000000 14251630510 013616 5 ustar ligges users lintr/man/figures/demo.gif 0000644 0001762 0000144 00001017404 14251630510 015240 0 ustar ligges users GIF89aj ͻѼibKd]FٙxoRne]K[nyk\EĺVs帤g{ԊyPXiػx{Òwdvi]KcmjֺĊekDdsLcjCdlM{Z^P;^fh8{Qf]mi% !NETSCAPE2.0 ! , H*\ȰC,&T1℉3jȱǏ CYq#ɓ(S\ɲ˗aʜ9c缂I HԤQ3$80ӧLiƔJիXjʵVg8`$W WA+:d0DY#E$!:KW~уj&I
2kn٫ϠCMtԩS#5N)C_FDUh, a)L!)@*̊AJ!b'Oİ`!Vly+@S)Ԅ(I
a[0!ha$0
#
rjVhf!dCN7l#"N|5 &ֲ 53 Rl( x,C#&Dؒ2@Ė2 #6 R7CaX%:c68c7Xj&ܐ8"W`@XMiƋ zuچ*(jjh݈6΄C@Qv-)bE (""8A0J,A
Te@ȧ`jDOheސ9\I31b°jÍ>Ɯ
P'#n