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

[ci] [R-package] enforce more {lintr} checks #6130

Merged
merged 6 commits into from
Oct 8, 2023
Merged

Conversation

jameslamb
Copy link
Collaborator

Proposes the following:

  • adds more linters from {lintr} to this project's R linting
  • alphabetizes the list of linters in the R linting script
  • adds the base R pipe (|>) to the list of operators not allowed to be used in this project's R code

Fixes the following new errors from {lintr}:

[[1]]
/.ci/lint_r_code.R:2:1: warning: [unused_import] Package 'lintr' is only used by namespace. Check that it is installed using loadNamespace() instead.
library(lintr)
^~~~~~~~~~~~~~

[[2]]
/R-package/demo/basic_walkthrough.R:2:1: warning: [unused_import] Package 'methods' is attached but never used.
library(methods)
^~~~~~~~~~~~~~~~

[[3]]
/R-package/demo/boost_from_prediction.R:2:1: warning: [unused_import] Package 'methods' is attached but never used.
library(methods)
^~~~~~~~~~~~~~~~

[[4]]
/R-package/demo/early_stopping.R:2:1: warning: [unused_import] Package 'methods' is attached but never used.
library(methods)
^~~~~~~~~~~~~~~~

[[5]]
/R-package/tests/testthat.R:2:1: warning: [unused_import] Package 'lightgbm' is attached but never used.
library(lightgbm)
^~~~~~~~~~~~~~~~~

[[6]]
/R-package/tests/testthat/test_dataset.R:186:33: warning: [implicit_assignment] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
  expect_silent(colnames(dtest) <- new_names)
                                ^~

[[7]]
/R-package/tests/testthat/test_learning_to_rank.R:40:9: warning: [conjunct_test] Instead of expect_true(A && B), write multiple expectations like expect_true(A) and expect_true(B) The latter will produce better error messages in the case of failure.
        expect_true(result[["value"]] > 0.0 && result[["value"]] < 1.0)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[[8]]
/R-package/tests/testthat/test_learning_to_rank.R:107:5: warning: [conjunct_test] Instead of expect_true(A && B), write multiple expectations like expect_true(A) and expect_true(B) The latter will produce better error messages in the case of failure.
    expect_true(best_iter > 0L && best_iter <= nrounds)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[[9]]
/R-package/tests/testthat/test_learning_to_rank.R:108:5: warning: [conjunct_test] Instead of expect_true(A && B), write multiple expectations like expect_true(A) and expect_true(B) The latter will produce better error messages in the case of failure.
    expect_true(best_score > 0.0 && best_score < 1.0)
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[[10]]
/R-package/tests/testthat/test_lgb.Booster.R:1278:34: warning: [implicit_assignment] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
    expect_warning(bst_from_file <- readRDS.lgb.Booster(file = bst_file))
                                 ^~

Notes for Reviewers

See https://lintr.r-lib.org/reference/index.html for docs on these new linters.

@jameslamb
Copy link
Collaborator Author

jameslamb commented Oct 7, 2023

Ah interesting, having unused_import_linter() throws a bunch of errors on packages that aren't installed: https://github.com/microsoft/LightGBM/actions/runs/6438788536/job/17485700424?pr=6130

Removed that linter in cf40d50, to avoid needing to install all those packages in the lint CI job.

Ah it was actually namespace_linter! My mistake. Removed in f004947.

@jameslamb jameslamb merged commit 3d9ada7 into master Oct 8, 2023
@jameslamb jameslamb deleted the r/more-linters branch October 8, 2023 14:42
Ten0 pushed a commit to Ten0/LightGBM that referenced this pull request Jan 12, 2024
Copy link

github-actions bot commented Oct 9, 2024

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants