Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

expect_lint

Lint expectation


Description

This is an expectation function to test that the lints produced by lint satisfy a number of checks.

Usage

expect_lint(content, checks, ..., file = NULL)

Arguments

content

a character vector for the file content to be linted, each vector element representing a line of text.

checks

checks to be performed:

NULL

check that no lints are returned.

single string or regex object

check that the single lint returned has a matching message.

named list

check that the single lint returned has fields that match. Accepted fields are the same as those taken by Lint.

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.

...

arguments passed to lint, e.g. the linters or cache to use.

file

if not NULL, read content from the specified file rather than from content.

Value

NULL, invisibly.

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

A 'Linter' for R Code

v2.0.1
MIT + file LICENSE
Authors
Jim Hester [aut, cre], Florent Angly [aut], Russ Hyde [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.