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

refactor: apply a bunch of lints #974

Closed
wants to merge 43 commits into from

Conversation

EdJoPaTo
Copy link
Member

In the beginning I wanted to add const improvements to widgets I use, but then I thought I should apply a bunch of lints first before doing more refacting like const new methods.
Applying them to the whole project is similar in comparison to just a few files, so I did that.

I ran my personal bunch of lints over the entire project (pedantic, nursery and some restricted) and applied some of them. I went through the lints and checked what is at least partially done already in this repo to ensure a consistent state. For example use_self is partially used in this repo. The lint ensures its done everywhere consistently. The same with the other lints.
Currently, lints which did not trigger at least some kind of refactoring are not added. In the long run I would like to enable clippy::pedantic (except lints like module_name_repetitions) for this project.

This creates a lot of changes but except the change to the WidgetRef it should not be a breaking change. (It somewhat amazed me that the WidgetRef API required ownership and not a reference or have I overlooked something? It's in its own commit)

This probably creates some churn with other PR created before this is merged.

Looking at all the changes together is somewhat pointless. Each commit should be checked on its own. It should also be considered if this should be squashed on merge like the other PR do normally. I think it's useful to keep the commits individually. But that is not my decision.

I can rebase this and add/improve/remove commits/lints. I can also cherry-pick some into their own PR to fast-lane them. We should discuss the lints.

Copy link

codecov bot commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 91.57706% with 47 lines in your changes are missing coverage. Please review.

Project coverage is 91.9%. Comparing base (c12bcfe) to head (1c2e86a).

Files Patch % Lines
src/backend/crossterm.rs 38.8% 22 Missing ⚠️
src/backend/termwiz.rs 77.5% 9 Missing ⚠️
src/style/palette/material.rs 0.0% 4 Missing ⚠️
src/widgets/sparkline.rs 80.0% 2 Missing ⚠️
src/widgets/tabs.rs 80.0% 2 Missing ⚠️
src/buffer/buffer.rs 88.8% 1 Missing ⚠️
src/layout/constraint.rs 96.7% 1 Missing ⚠️
src/layout/rect.rs 94.1% 1 Missing ⚠️
src/style/color.rs 97.4% 1 Missing ⚠️
src/widgets/barchart.rs 95.0% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #974   +/-   ##
=====================================
  Coverage   91.9%   91.9%           
=====================================
  Files         61      61           
  Lines      15964   15905   -59     
=====================================
- Hits       14673   14632   -41     
+ Misses      1291    1273   -18     

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

Copy link
Member

@joshka joshka left a comment

Choose a reason for hiding this comment

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

This looks good to me. I agree with all the changes generally (with a couple of questions / comments). I ended up just looking at the entire PR as I saw your comment about looking at each commit after I reviewed.

I like your thoughts on merging this as multiple commits generally, but I think I'm also fine with squashing the changes as this fits better with the workflow (and avoids having to split this into multiple PRs). There's only a few outstanding PRs right now, and the benefit of this PR outweighs the extra work to rebase them if needed.

I recall that there's a way to mark specific commits not to be included when annotating the file with git blame - perhaps we need that for this PR?

P.s. thanks for all the effort on this one - much appreciated!

CONTRIBUTING.md Show resolved Hide resolved
examples/scrollbar.rs Show resolved Hide resolved
examples/vhs/custom_widget.tape Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/terminal/frame.rs Outdated Show resolved Hide resolved
src/widgets/barchart/bar.rs Show resolved Hide resolved
src/widgets/block/padding.rs Show resolved Hide resolved
src/widgets/scrollbar.rs Show resolved Hide resolved
src/widgets/table/table.rs Show resolved Hide resolved
joshka added a commit that referenced this pull request Mar 2, 2024
Fixes many not yet enabled lints (mostly pedantic) on everything that is
not the lib (examples, benchs, tests). Therefore, this is not containing
anything that can be a breaking change.

Lints are not enabled as that should be the job of #974. I created this
as a separate PR as its mostly independent and would only clutter up the
diff of #974 even more.

Also see
#974 (comment)

---------

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
CONTRIBUTING.md Show resolved Hide resolved
@EdJoPaTo
Copy link
Member Author

EdJoPaTo commented Mar 2, 2024

I applied the suggestions and added more lints. So its probably a good idea to review this completely again.

@EdJoPaTo EdJoPaTo requested a review from joshka March 2, 2024 12:27
Copy link
Member

@joshka joshka left a comment

Choose a reason for hiding this comment

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

LGTM (I re-reviewed all the changed files since last review line by line).

I'd like to undo the changes to the u32 literals in the Color files, because the 3 byte values are actually more readable than the 4 byte values Perhaps keep the warn in the lint config, but add allows on the 3 files in question. d76a789 is the commit in question. Does that make sense?

I plan to merge this as a rebase - do you think it would be worth adding the PR number to all the commit messages to make it easy to link back to this PR and the comments (for anyone spelunking the codebase at some later date)?

Perhaps as a last thing to add for this, would you mind creating a .git-blame-ignore-revs file that marks these commits from blame (to make it easier to understand the blame output)? See https://git-scm.com/docs/git-blame / https://www.michaelheap.com/git-ignore-rev/ (or other blog posts for details).

CONTRIBUTING.md Show resolved Hide resolved
src/style/color.rs Outdated Show resolved Hide resolved
src/style/palette/material.rs Outdated Show resolved Hide resolved
src/style/palette/tailwind.rs Outdated Show resolved Hide resolved
src/widgets/canvas.rs Show resolved Hide resolved
@joshka
Copy link
Member

joshka commented Mar 3, 2024

P.s. this was really done well. I wonder if you might might consider writing an article / blog post on the approach you took to doing this in a controlled manner. Some things I'd really like to read about (and I'm sure others might feel the same) were:

  • how - i.e. were you using an automated tool, iterating on cargo clippy --fix, using regex magic
  • what / why? How were you picking the lints (just going down the pedantic list?) Which lints did you ignore based on experience and why?
  • What problems did you run into while doing this?
  • How long did it take
  • How should the project move on from this - i.e. what's now enabled for all users.
  • How easy was the process generally?
  • What could make it better?
    etc.

joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
Lint enabled by default but only nightly finds this yet
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
enabled by default, only detected on nightly yet
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
enabled by default, only detected by nightly yet
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
configure lints in Cargo.toml requires 1.74.0

BREAKING CHANGE: rust 1.74 is required now
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
its not needed and can just be assumed

related: clippy::(un)separated_literal_suffix
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
joshka pushed a commit to nowNick/ratatui that referenced this pull request May 24, 2024
These lints dont generate warnings and therefore dont need refactoring.
I think they are useful in the future.
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.

None yet

2 participants