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.

Usage

box_alphabetical_calls_linter()

Value

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

Details

For use in rhino, see the Explanation: Rhino style guide to learn about the details.

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.

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.

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.

# 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()
)