Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement linter tags file compatible lintr 3.0.0 #130

Merged
merged 2 commits into from
Aug 20, 2024
Merged

Conversation

m-kolomanski
Copy link
Contributor

Issue #102

Description

Added linters.csv file in /inst/lintr/ with linters and tags, compatiblie with linter 3.0.0. and lintr::available_linters(), lintr::available_tags() functions.

Added unit tests for this feature, although those need to be run with devtools::check() as the mentioned functions expect the package to be installed. Otherwise, related tests will be skipped.

Definition of Done

  • The change is thoroughly documented.
  • The CI passes (R CMD check, linter, unit tests, spelling).
  • Any generated files have been updated (e.g. .Rd files with roxygen2::roxygenise())

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.21%. Comparing base (e5658e4) to head (597430b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #130   +/-   ##
=======================================
  Coverage   97.21%   97.21%           
=======================================
  Files          23       23           
  Lines        1112     1112           
=======================================
  Hits         1081     1081           
  Misses         31       31           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@m-kolomanski m-kolomanski marked this pull request as ready for review August 12, 2024 08:16
#' `linters_csv_location` variable to "./inst/lintr/linters.csv", then running
#' tests in the console.
#'
linters_csv_location <- "../../box.linters/lintr/linters.csv"
Copy link
Collaborator

@radbasa radbasa Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To switch between local file and package file, how about checking if it is running under R CMD check? Refer to https://testthat.r-lib.org/reference/is_testing.html.

Also, take a look at {rprojroot} functions to determine the root path for the two different situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointers, the following could be done to clean up the code a little:

linters_csv_location <- file.path(
  rprojroot::find_root_file(criterion = rprojroot::is_r_package),
  "lintr/linters.csv"
)

and later in the tests:

skip_if(!is_checking())

But I don't think I follow the logic with switching files? To my understanding, changing the linters_csv_location based on execution context does not matter, as it is the lintr::available_tags() function that is failing to read the file when running devtools::test(), and we cannot change the bahaviour of that function. Am I missing or misunderstanding something?

@radbasa
Copy link
Collaborator

radbasa commented Aug 12, 2024

It might be worth adding @evalRd rd_tags("<function_name>") to the roxygen blocks.

https://lintr.r-lib.org/articles/creating_linters.html#writing-the-linter

@m-kolomanski
Copy link
Contributor Author

m-kolomanski commented Aug 12, 2024

It might be worth adding @evalRd rd_tags("<function_name>") to the roxygen blocks.

https://lintr.r-lib.org/articles/creating_linters.html#writing-the-linter

@radbasa

rd_tags is not exported from lintr package, therefore this would require creating ./R/linters_tags.R helper file with this function definition.

Since the rd_tags function from lintr package generates tags with links that forward to doc pages for specific tags, this would need to be followed with rd_linters function and documentation file for each of the tags, with list of linters that have that particular tag assigned.

Alternatively, a different schema could be created for this usecase (like section with list of tags, without links to further doc).

What do you think would be the best for this case?

For details, see rd_tags(), rd_linters(), linter_tags_docs.R file and generated example doc for lintr.

@radbasa
Copy link
Collaborator

radbasa commented Aug 12, 2024

@m-kolomanski Try looking at the following lines of code to use non-exported functions from packages:

parse_spec <- get0("parse_spec", envir = base::loadNamespace("box"))
find_mod <- get0("find_mod.box$mod_spec", envir = base::loadNamespace("box"))
load_mod <- get0("load_mod.box$mod_info", envir = base::loadNamespace("box"))
namespace_info <- get0("namespace_info", envir = base::loadNamespace("box"))

Maybe, it will work. Maybe, it won't.

@m-kolomanski
Copy link
Contributor Author

m-kolomanski commented Aug 12, 2024

@m-kolomanski Try looking at the following lines of code to use non-exported functions from packages:

parse_spec <- get0("parse_spec", envir = base::loadNamespace("box"))
find_mod <- get0("find_mod.box$mod_spec", envir = base::loadNamespace("box"))
load_mod <- get0("load_mod.box$mod_info", envir = base::loadNamespace("box"))
namespace_info <- get0("namespace_info", envir = base::loadNamespace("box"))

Maybe, it will work. Maybe, it won't.

@radbasa Importing the functions themselves does work, however both needed functions contain call to lintr::available_linters() function, which fails to find the tags when roxygen2::roxygenise() is run (similarly to when devtools::test() is run).

@radbasa
Copy link
Collaborator

radbasa commented Aug 20, 2024

@m-kolomanski Try looking at the following lines of code to use non-exported functions from packages:

parse_spec <- get0("parse_spec", envir = base::loadNamespace("box"))
find_mod <- get0("find_mod.box$mod_spec", envir = base::loadNamespace("box"))
load_mod <- get0("load_mod.box$mod_info", envir = base::loadNamespace("box"))
namespace_info <- get0("namespace_info", envir = base::loadNamespace("box"))

Maybe, it will work. Maybe, it won't.

@radbasa Importing the functions themselves does work, however both needed functions contain call to lintr::available_linters() function, which fails to find the tags when roxygen2::roxygenise() is run (similarly to when devtools::test() is run).

@jakubnowicki It would be nice if we had a list of linter tags similar to lintr Meta-tooling. But, that is automatically generated by lintr:::rd_tags() and lintr:::rd_linters() that have a lot of internal dependencies.

Do we have time to manually write documentation pages for these tags? We have 12 tags, and 15 functions.

@jakubnowicki
Copy link
Member

@m-kolomanski Try looking at the following lines of code to use non-exported functions from packages:

parse_spec <- get0("parse_spec", envir = base::loadNamespace("box"))
find_mod <- get0("find_mod.box$mod_spec", envir = base::loadNamespace("box"))
load_mod <- get0("load_mod.box$mod_info", envir = base::loadNamespace("box"))
namespace_info <- get0("namespace_info", envir = base::loadNamespace("box"))

Maybe, it will work. Maybe, it won't.

@radbasa Importing the functions themselves does work, however both needed functions contain call to lintr::available_linters() function, which fails to find the tags when roxygen2::roxygenise() is run (similarly to when devtools::test() is run).

@jakubnowicki It would be nice if we had a list of linter tags similar to lintr Meta-tooling. But, that is automatically generated by lintr:::rd_tags() and lintr:::rd_linters() that have a lot of internal dependencies.

Do we have time to manually write documentation pages for these tags? We have 12 tags, and 15 functions.

I would rather leave it for the next release.

Copy link
Collaborator

@radbasa radbasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@radbasa radbasa merged commit 293a178 into main Aug 20, 2024
7 checks passed
@radbasa radbasa deleted the Appsilon/linter-tags branch August 20, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants