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

Cleaning lints across easystats packages #334

Open
IndrajeetPatil opened this issue Dec 19, 2022 · 12 comments
Open

Cleaning lints across easystats packages #334

IndrajeetPatil opened this issue Dec 19, 2022 · 12 comments
Labels
Beginner-friendly 🤝 Friendly for new contributors Code Style 👩‍💻 Core Packages 📦 Discussion and planning about core packages of easystats Help wanted 🆘 Extra attention is needed
Milestone

Comments

@IndrajeetPatil
Copy link
Member

Preamble

Lints are code quality issues that can be detected in R using {lintr} and need to be either fixed (if it's really an issue) or annotated so that they are ignored. We detect lints using GHA workflow, and every package includes this workflow. Static code analysis is not always correct, esp. in edge cases, and so you should also see if the lints false positives. If yes, let me know, and I can report and try to fix this in lintr itself.

Example

What does lint output look like?

For an example, {insight} lint workflow currently shows the following lint (alongside many others):

Warning: file=R/check_if_installed.R,line=123,col=7,[outer_negation_linter] !all(x) is better than any(!x). The former applies negation only once after aggregation instead of many times for each element of x.

The code in question is:

  if (any(!x)) {
    if (any(x)) {
      cat("\n\n")
    }
    cat("Following packages are not installed:\n")
    print_color(paste0("- ", names(x)[!x], collapse = "\n"), "red")
  }

As the lint message says, this code can be rewritten to the equivalent and more efficient version:

  if (!all(x)) {
    if (any(x)) {
      cat("\n\n")
    }
    cat("Following packages are not installed:\n")
    print_color(paste0("- ", names(x)[!x], collapse = "\n"), "red")
  }

Once you make this change, the lint workflow will no longer flag these lines of code.

Help wanted

Although Daniel and I have been cleaning lints once in a while, this requires a much more concerted effort from the larger team since there are a ton of lints to be cleaned across repos.

I am tagging this issue with "Help wanted" and "Beginner-friendly" labels, hoping that we might get some community help to do this clean-up.

@IndrajeetPatil IndrajeetPatil added Help wanted 🆘 Extra attention is needed Beginner-friendly 🤝 Friendly for new contributors labels Dec 19, 2022
@IndrajeetPatil IndrajeetPatil added this to the 1.0.0 milestone Dec 19, 2022
@IndrajeetPatil IndrajeetPatil added Core Packages 📦 Discussion and planning about core packages of easystats Code Style 👩‍💻 labels Dec 19, 2022
IndrajeetPatil added a commit to easystats/see that referenced this issue Dec 19, 2022
IndrajeetPatil added a commit to easystats/datawizard that referenced this issue Dec 20, 2022
IndrajeetPatil added a commit to easystats/datawizard that referenced this issue Dec 20, 2022
IndrajeetPatil added a commit to easystats/datawizard that referenced this issue Dec 21, 2022
@IndrajeetPatil
Copy link
Member Author

I have also updated .lintr files in all our repos to be in sync with the GHA workflow.

So, if you want, you can also run the linters locally (lintr::lint_package()), and you should see similar results to GHA.

@etiennebacher
Copy link
Member

So, if you want, you can also run the linters locally (lintr::lint_package())

Note that you'll need the development version (r-lib/lintr)

@IndrajeetPatil
Copy link
Member Author

Yes, as a good practice, always work with the development version of lintr to get the best and the latest.

@strengejacke
Copy link
Member

This lintr-expression unnecessary_concatenation_linter(allow_single_expression = FALSE), is causing problems.

@etiennebacher
Copy link
Member

You need the dev version of lintr, this function was called unneeded_concatenation_linter() before

@IndrajeetPatil
Copy link
Member Author

Daniel has already removed that particular linter from config files.

@strengejacke
Copy link
Member

Short question, what does the "test-example-coverage" workflow do? It's always failing, and I can't see the benefits from this workflow.

@IndrajeetPatil
Copy link
Member Author

Short question, what does the "test-example-coverage" workflow do? It's always failing, and I can't see the benefits from this workflow.

See #331 for full details.

IndrajeetPatil added a commit to easystats/insight that referenced this issue Dec 28, 2022
@IndrajeetPatil
Copy link
Member Author

Okay, so in order to make this task more manageable, we can rely on The Boy Scout Rule:

Leave your code better than you found it.

A way to do this would be to clean lints only in the files that have changed in a given PR.

For example, if a given repo has over 200 files, but the PR has changed only 5 files, the GHA workflow for linting will fail only if the lints in these 5 files have not been cleaned. I think this is a much more manageable task than cleaning lints across all 200 files. If we do this for a few months, we should have made a significant headway on this task.

So, if you make a PR, watch for the build failures due to lint-changed-files workflow. This means that you haven't cleaned the lints in the files you have touched in the given PR.

Once again, if you can't figure out why something is producing a lint or how to get rid of it, let me know. Don't remove the workflow to make your life easier. That's just going to lead to us acquiring more technical debt.

IndrajeetPatil added a commit to easystats/correlation that referenced this issue Dec 29, 2022
IndrajeetPatil added a commit to easystats/performance that referenced this issue Dec 30, 2022
@strengejacke
Copy link
Member

this one is to torture @DominiqueMakowski

IndrajeetPatil added a commit that referenced this issue Jan 3, 2023
IndrajeetPatil added a commit that referenced this issue Jan 4, 2023
* Clean lints in utils.R

#334

* Apply automatic changes

* Update utils.R

* Revert "Update utils.R"

This reverts commit cb4c0ff.

* unlist Map output

Co-authored-by: IndrajeetPatil <IndrajeetPatil@users.noreply.github.com>
IndrajeetPatil added a commit to easystats/insight that referenced this issue Jan 9, 2023
IndrajeetPatil added a commit to easystats/parameters that referenced this issue Jan 10, 2023
@rempsyc
Copy link
Sponsor Member

rempsyc commented Jan 20, 2023

report should be good now

@IndrajeetPatil
Copy link
Member Author

@rempsyc is on fire! 🔥🔥🔥

Suddenly, {report} is competing with {effectsize}. 😅

IndrajeetPatil added a commit to easystats/modelbased that referenced this issue Mar 17, 2023
IndrajeetPatil added a commit to easystats/parameters that referenced this issue Mar 21, 2023
IndrajeetPatil added a commit to easystats/modelbased that referenced this issue Mar 22, 2023
IndrajeetPatil added a commit to easystats/correlation that referenced this issue Mar 24, 2023
IndrajeetPatil added a commit to easystats/performance that referenced this issue Mar 31, 2023
IndrajeetPatil added a commit to easystats/parameters that referenced this issue Apr 3, 2023
IndrajeetPatil added a commit to easystats/parameters that referenced this issue Apr 3, 2023
IndrajeetPatil added a commit to easystats/parameters that referenced this issue Apr 4, 2023
* replace `requiet()` by `skip_if_not_installed()` + `::`

* replace `.runThisTest` by `skip_on_cran()`

* style and fix a few errors

* clean `tests/testthat.R`

* style + clean messages

* fix errors with R CMD check strict

* fix some errors in tests

* add missing packages in "Suggests"

* add missing `skip_if_not_installed()`

* clean a few lints related to `expect_equal()`

cf. easystats/easystats#334

* clean `line_length_linter()` lints

cf. easystats/easystats#334

* fix two failing tests

* fix styling workflow

* fix options for message on exponentiating coeffs

* don't skip survival test

* fix some messages / errors

* fix some messages / errors

* silence some messages

* silence some messages, fix a few TODOs

* add missing snapshot

* fix styling workflow

* fix new test added in the main branch

* fix some errors and messages

* fixes?

---------

Co-authored-by: Indrajeet Patil <patilindrajeet.science@gmail.com>
Co-authored-by: Daniel <mail@danielluedecke.de>
IndrajeetPatil added a commit to easystats/datawizard that referenced this issue Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Beginner-friendly 🤝 Friendly for new contributors Code Style 👩‍💻 Core Packages 📦 Discussion and planning about core packages of easystats Help wanted 🆘 Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants