Skip to content

Commit

Permalink
initial attempt. unfinished. can check packages/modules. cannot check…
Browse files Browse the repository at this point in the history
… functions.
  • Loading branch information
radbasa committed Jan 12, 2024
1 parent 321e6ee commit e8e7bbf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rhino
Title: A Framework for Enterprise Shiny Applications
Version: 1.7.0.9000
Version: 1.7.0.9005
Authors@R:
c(
person("Kamil", "Żyła", role = c("aut", "cre"), email = "[email protected]"),
Expand Down
39 changes: 39 additions & 0 deletions R/linter_box_alphabetical.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
box_alphabetical_imports <- function() {
xpath_base <- "//SYMBOL_PACKAGE[(text() = 'box' and following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])]
/parent::expr
/parent::expr"

xpath <- paste(xpath_base, "
/child::expr[
descendant::SYMBOL
]")

xpath_modules <- "child::expr[1]/SYMBOL | child::SYMBOL"

lint_message <- "Must be alphabetical."

lintr::Linter(function(source_expression) {
if (!lintr::is_lint_level(source_expression, "expression")) {
return(list())
}

xml <- source_expression$xml_parsed_content

xml_root <- xml2::xml_find_all(xml, xpath_base)

xml_nodes <- xml2::xml_find_all(xml, xpath)

modules_called <- xml2::xml_text(
xml2::xml_find_all(xml_nodes, xpath_modules)
)

if (!all(modules_called == sort(modules_called))) {
lintr::xml_nodes_to_lints(
xml_root,
source_expression = source_expression,
lint_message = lint_message,
type = "style"
)
}
})
}
3 changes: 3 additions & 0 deletions tests/testthat/test-linter_box_alphabetical.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

0 comments on commit e8e7bbf

Please sign in to comment.