Skip to content

Add namespace_linter - #551

Merged
AshesITR merged 11 commits into
r-lib:masterfrom
renkun-ken:namespace-linter
Nov 1, 2020
Merged

AshesITR merged 11 commits into
r-lib:masterfrom
renkun-ken:namespace-linter

Conversation

@renkun-ken

@renkun-ken renkun-ken commented Oct 31, 2020 •

Copy link
Copy Markdown
Collaborator

Closes #548

image

  • Check namespace calls (:: and :::)
  • Check exports and non-exports
  • Check unneeded :::
  • Test cases

@renkun-ken
renkun-ken requested a review from jimhester as a code owner October 31, 2020 11:52

@AshesITR AshesITR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

travis logs report that devtools::document() is needed

Comment thread R/namespace_linter.R Resolved
@renkun-ken

Copy link
Copy Markdown
Collaborator Author

travis logs report that devtools::document() is needed

Running devtools::document() will change several unrelated places as my roxygen2 has version 7.1.1 and nothing related to this PR. Does it matter if I commit changes to docs unrelated to this PR and update to RoxygenNote: 7.1.1 in DESCRIPTION?

@AshesITR

AshesITR commented Nov 1, 2020

Copy link
Copy Markdown
Collaborator

It just occurred to me that a lint for unneeded ":::" would also be useful
dplyr:::mutate(iris, a = 1) -> 'mutate' is exported from {dplyr}. Use dplyr::mutate instead.

Do you mind adding that case?

AshesITR
AshesITR previously approved these changes Nov 1, 2020
@AshesITR

AshesITR commented Nov 1, 2020

Copy link
Copy Markdown
Collaborator

It's fine for me. We could document() on master first and merge back if that helps keep the PR diff focussed?

@renkun-ken

Copy link
Copy Markdown
Collaborator Author

Unneeded ::: is checked now via 79899d3.

@AshesITR

AshesITR commented Nov 1, 2020

Copy link
Copy Markdown
Collaborator

Now devtools::document() should introduce minimal changes and make the travis build pass.

AshesITR
AshesITR previously approved these changes Nov 1, 2020
@renkun-ken

Copy link
Copy Markdown
Collaborator Author

I send #553 and once it is merged, then existing PRs could merge back to keep the PR clean.

@AshesITR

AshesITR commented Nov 1, 2020

Copy link
Copy Markdown
Collaborator

@AshesITR

AshesITR commented Nov 1, 2020

Copy link
Copy Markdown
Collaborator

Okay weird, T_and_F_symbol_linter is actually the \name{} of linters.Rd...

@AshesITR
AshesITR merged commit 3828643 into r-lib:master Nov 1, 2020
Comment thread R/namespace_linter.R
ops <- xml2::xml_text(ns_nodes)
syms <- get_node_text(sym_nodes)

installed_packages <- .packages(all.available = TRUE)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think I would prefer if this were a linter with options (function factory), and we can supply installed_packages externally (defaulting to what's used here).

would make this linter more useful in a broader set of use cases

@renkun-ken renkun-ken Nov 4, 2020 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OK. The most general form could be user supplied installed packages. The use case might be customized library location, or a limited set of packages to check against instead of all currently installed packages, or pretend some packages are installed. I think this makes sense. Let me create a PR to make changes for both namespace_linter and missing_package_linter.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As for namespace_linter, if some packages in user supplied packages are not actually installed or the library path is different from the current session that runs the linter, then getNamespace() and other namespace functions won't work so that the linter will think the symbols after :: and ::: are not available and complain. How do you think it should behave?

@renkun-ken renkun-ken mentioned this pull request Nov 4, 2020
2 tasks done
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.

Namespace linter

3 participants