% 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}
}
