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

use Ruff for linting #16751

Merged
merged 20 commits into from
Jun 28, 2024
Merged

use Ruff for linting #16751

merged 20 commits into from
Jun 28, 2024

Conversation

seanbudd
Copy link
Member

@seanbudd seanbudd commented Jun 27, 2024

Link to issue number:

Fixes #14817

Summary of the issue:

Our linting system has the following issues:

  • we are stuck on an old version of flake8, as the flake8tabs module is no longer being updated
  • we can't perform automatic lint fixes
  • Ruff is becoming more maintained than flake8

Description of user facing changes

  • The entire repository is linted with Ruff, rather than diffs
  • Developers can now automatically fix certain linting issues with runlint.bat
  • If using pre-commit hooks, linting is automatically applied: https://pre-commit.com/#usage
  • CodeRabbit now scans code using our Ruff config

Description of development approach

To lint the whole code base:

  1. ruff check --fix to apply automatic fixes
  2. ruff check --add-noqa to add no-qa comments to all lint failures, so that issues that can't be automatically fixed don't trigger future failures
  3. add these commits to .git-ignore-blame-revs

See #16752 for an example

Testing strategy:

Known issues with pull request:

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

Summary by CodeRabbit

  • New Features

    • Introduced Ruff linter for Python code style enforcement.
    • Added pre-commit hooks for automated linting and formatting.
  • Bug Fixes

    • Updated NVDA build system for compatibility with Visual Studio 2022 version 17.10 and above.
    • Improved readability in Log Viewer and NVDA Python Console by using a fixed-width font.
  • Documentation

    • Updated documentation to reflect the switch from Flake8 to Ruff for linting.
    • Added new documentation on integrating Ruff with development tools.
  • Chores

    • Replaced Flake8 with Ruff in configuration and script files.

runlint.bat Outdated Show resolved Hide resolved
@AppVeyorBot
Copy link

See test results for failed build of commit 7db2452973

@seanbudd seanbudd marked this pull request as ready for review June 27, 2024 06:16
@seanbudd seanbudd requested review from a team as code owners June 27, 2024 06:16
Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The project has transitioned from the Flake8 linter to the faster and more comprehensive Ruff linter. This change streamlines the linting process, simplifying configuration files and instructions while improving speed and coverage. Associated documentation and scripts have been updated accordingly.

Changes

Files Change Summary
.coderabbit.yml, .pre-commit-config.yaml Enabled Ruff linter; added pre-commit configurations for Ruff.
appveyor/scripts/tests/lintCheck.ps1 Modified to simplify linting process, using Ruff output file and removing Flake8-specific commands.
projectDocs/.../codingStandards.md, contributing.md Updated to reflect switch from Flake8 to Ruff, including linting commands and expectations.
projectDocs/dev/lint.md New file providing details on integrating and using Ruff linter.
projectDocs/testing/automated.md Updated linting process description to use Ruff, replacing Flake8.
pyproject.toml Added Ruff configuration settings for line length, exclusions, built-ins, and linting rules.
requirements.txt Replaced Flake8 and related plugins with Ruff and pre-commit.
runlint.bat Modified to use Ruff for linting, removing Flake8-specific commands and configurations.
user_docs/en/changes.md Documented switch to Ruff for linting and other updates.

Sequence Diagram(s)

The changes primarily involve configuration and script updates, thus no sequence diagrams are necessary.

Assessment against linked issues

Objective Addressed Explanation
Replace Flake8 with Ruff for linting (### #14817)
Update all relevant documentation to reflect the change from Flake8 to Ruff (### #14817)
Ensure Ruff is configured to check only changed files when sending a pull request (### #14817) The provided summaries do not explicitly mention this configuration. Further review of the Ruff setup is needed to confirm this behavior.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (7)
projectDocs/dev/codingStandards.md (3)

Line range hint 18-18: Consider removing the repeated word.

The phrase "Indentation must be done with tabs (one per level), not spaces." has a repeated word Indentation which could be a typo.

- Indentation Indentation must be done with tabs (one per level), not spaces.
+ Indentation must be done with tabs (one per level), not spaces.

Line range hint 101-101: Add missing article "the".

In the sentence "...consider how the code can be moved in future while retaining backwards compatibility.", "the" is missing before "future."

- ...consider how the code can be moved in future while retaining backwards compatibility.
+ ...consider how the code can be moved in the future while retaining backwards compatibility.

Line range hint 107-107: Add missing comma.

A comma might be missing after "import time" in the sentence "...code which executes at import time."

- ...code which executes at import time.
+ ...code which executes at import time,
projectDocs/dev/contributing.md (4)

Line range hint 22-22: Consider rephrasing for standard usage.

The phrase "in regards to" is typically considered nonstandard. Consider using "regarding" or "concerning."

- ...considered in regards to implementation, design, and user experience...
+ ...considered regarding implementation, design, and user experience...

Line range hint 59-59: Strengthen wording.

Consider using a stronger verb than "speed up" in the context of accelerating the review process.

- Being proactive will really help to speed up the process of code review.
+ Being proactive will greatly accelerate the process of code review.

Line range hint 60-60: Add missing comma.

A comma is missing after "approved" in the sentence "When the PR is approved it will be merged..."

- When the PR is approved it will be merged...
+ When the PR is approved, it will be merged...

Line range hint 107-107: Correct verb usage.

The word "checkout" is used incorrectly as a verb. It should be "check out."

- Please checkout our [technical design overview](../design/technicalDesignOverview.md).
+ Please check out our [technical design overview](../design/technicalDesignOverview.md).

runlint.bat Outdated Show resolved Hide resolved
@seanbudd seanbudd requested a review from gerald-hartig June 27, 2024 06:38
@seanbudd seanbudd added this to the 2024.3 milestone Jun 27, 2024
@seanbudd seanbudd marked this pull request as draft June 27, 2024 07:21
@seanbudd seanbudd marked this pull request as ready for review June 27, 2024 07:26
@AppVeyorBot
Copy link

See test results for failed build of commit 1632f19c43

@AppVeyorBot
Copy link

See test results for failed build of commit 33d993cf79

@LeonarddeR
Copy link
Collaborator

I'm so intensely exited with this pr, congratulations!
Note that the VS Code repo will probably need updating as well.

.pre-commit-config.yaml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@AppVeyorBot
Copy link

See test results for failed build of commit 57496359fa

@seanbudd seanbudd merged commit f863a09 into master Jun 28, 2024
2 of 3 checks passed
@seanbudd seanbudd deleted the useRuff branch June 28, 2024 01:17
seanbudd added a commit that referenced this pull request Jun 28, 2024
Lint the repository with Ruff

This is a follow up for #16751
Must be merge commit not squash merge

Using #16751, the following commands were applied:

ruff check --fix to apply automatic fixes
ruff check --add-noqa to add no-qa comments to all lint failures, so that issues that can't be automatically fixed don't trigger future failures
seanbudd added a commit that referenced this pull request Jul 3, 2024
)

Fix up for #16751

Summary of the issue:
Ruff recently updated, so we might as well use the latest version.
a warning is omitted for the section we added logger-objects to in ruff's config.
it was unclear in docs how to avoid pre-commit hooks from triggering.
more pre-commit hooks could be added
ruff whitespace formating is done through ruff format currently we are only linting with ruff check. We should also run a ruff format on the whole NVDA.
ruff was missing scons files, which should also be linted in a mass lint.
Summary of other changes:
Added pre commit hooks for unit tests and translation comment checks.
Added generic pre-commit hooks for python static syntax checking, basic whitespace rules, and file write safety checks
change the output of rununittests.bat to have simpler buffer output, only show failures. Ensure the verbose log is logged in AppVeyor.
add ruff format to lint checks
add scons files to lint checks
update coderabbit prompt for change log entry items
seanbudd added a commit that referenced this pull request Jul 4, 2024
run ruff format to fix whitespace changes

Follow up to #16767
Closes #12261

Summary of the issue:
When migrating to ruff in #16751, we failed to lint scons files, and also run ruff format on the repository.
Ruff format fixes whitespaces issues in python files.

Description of user facing changes
None

Description of development approach
Perform lint fixes on scons files and run ruff format.
@seanbudd seanbudd mentioned this pull request Jul 11, 2024
seanbudd added a commit that referenced this pull request Jul 11, 2024
Summary of the issue:
The documentation for linting was fragmented.
It was not clear why a lint.md file was created as part of #16751 and related changes..
It was probably a result from migrating the Flake8 wiki to the document, and then whittling it down to the point where it became useless.
information on how to actually run the linter was missing from it

Description of development approach
removes lint.md change references to the automated testing doc
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.

Consider ruff for linting and replace Flake8 with it
5 participants