Skip to contents

Checks that module and function imports are sorted alphabetically. Aliases are ignored. The sort check is on package/module names and attached function names. See the Explanation: Rhino style guide to learn about the details.

Usage

box_alphabetical_calls_linter()

Value

A custom linter function for use with r-lib/lintr.

Examples

# will produce lints
lintr::lint(
  text = "box::use(packageB, packageA)",
  linters = box_alphabetical_calls_linter()
)
#> ::warning file=<text>,line=1,col=10::file=<text>,line=1,col=10,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.
#> ::warning file=<text>,line=1,col=20::file=<text>,line=1,col=20,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.

lintr::lint(
  text = "box::use(package[functionB, functionA])",
  linters = box_alphabetical_calls_linter()
)
#> ::warning file=<text>,line=1,col=18::file=<text>,line=1,col=18,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.
#> ::warning file=<text>,line=1,col=29::file=<text>,line=1,col=29,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.

lintr::lint(
  text = "box::use(path/to/B, path/to/A)",
  linters = box_alphabetical_calls_linter()
)
#> ::warning file=<text>,line=1,col=10::file=<text>,line=1,col=10,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.
#> ::warning file=<text>,line=1,col=21::file=<text>,line=1,col=21,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.

lintr::lint(
  text = "box::use(path/to/A[functionB, functionA])",
  linters = box_alphabetical_calls_linter()
)
#> ::warning file=<text>,line=1,col=20::file=<text>,line=1,col=20,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.
#> ::warning file=<text>,line=1,col=31::file=<text>,line=1,col=31,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.

lintr::lint(
  text = "box::use(path/to/A[alias = functionB, functionA])",
  linters = box_alphabetical_calls_linter()
)
#> ::warning file=<text>,line=1,col=28::file=<text>,line=1,col=28,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.
#> ::warning file=<text>,line=1,col=39::file=<text>,line=1,col=39,[box_alphabetical_calls_linter] Module and function imports must be sorted alphabetically.

# okay
lintr::lint(
  text = "box::use(packageA, packageB)",
  linters = box_alphabetical_calls_linter()
)

lintr::lint(
  text = "box::use(package[functionA, functionB])",
  linters = box_alphabetical_calls_linter()
)

lintr::lint(
  text = "box::use(path/to/A, path/to/B)",
  linters = box_alphabetical_calls_linter()
)

lintr::lint(
  text = "box::use(path/to/A[functionA, functionB])",
  linters = box_alphabetical_calls_linter()
)

lintr::lint(
  text = "box::use(path/to/A[functionA, alias = functionB])",
  linters = box_alphabetical_calls_linter()
)