Commit Graph

10 Commits

Author SHA1 Message Date
3255e7872b Enable all flake8-logging-format rules (#164655)
These rules are enabled by removing existing suppressions.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/164655
Approved by: https://github.com/janeyx99, https://github.com/mlazos
2025-10-19 00:59:28 +00:00
9a8c42ff94 Get rid of unused code in linters (#154043)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/154043
Approved by: https://github.com/XuehaiPan, https://github.com/Skylion007
2025-05-22 15:24:54 +00:00
d0b9874603 Teach ruff_linter to report syntax errors (fix #140228) (#142312)
Now syntax errors look like this:

```
torch/_dynamo/variables/base.py:20:

  Error (RUFF) E999
    SyntaxError: Expected ',', found indent.
    See https://beta.ruff.rs/docs/rules/
    >>>  19  |class SourceType(Enum]:
         20  |    """
         21  |    This Enum divides VariableTracker into 2 cases, depending on the variable
         22  |    it represents:

[...more errors...]
```

Note that most syntax errors lead to a cascade of other errors, so the exception is generally wrong, but the location and name are good.

Before they looked like this:

```
>>> General linter failure:

  Error (RUFF) Linter failed
    Linter failed. This a bug, please file an issue against the linter
    maintainer.

    CONTEXT:
    Linter command failed with non-zero exit code.
    STDERR:
    <MainThread:DEBUG> $ /home/rec/.conda/envs/pytorch-dev-constant/
    bin/python3 -m ruff check --exit-zero --quiet --output-format=json
    --config=pyproject.toml /home/rec/git-constant/pytorch/torch/_dynamo/
    variables/base.py
    <MainThread:DEBUG> took 38ms
    Traceback (most recent call last):
      File "/home/rec/git-constant/pytorch/tools/linter/adapters/
    ruff_linter.py", line 465, in <module>
        main()
      File "/home/rec/git-constant/pytorch/tools/linter/adapters/
    ruff_linter.py", line 424, in main
        lint_messages = check_files(
      File "/home/rec/git-constant/pytorch/tools/linter/adapters/
    ruff_linter.py", line 273, in check_files
        return [
      File "/home/rec/git-constant/pytorch/tools/linter/adapters/
    ruff_linter.py", line 288, in <listcomp>
        severity=severities.get(vuln["code"],
    get_issue_severity(vuln["code"])),
      File "/home/rec/git-constant/pytorch/tools/linter/adapters/
    ruff_linter.py", line 172, in get_issue_severity
        if any(
      File "/home/rec/git-constant/pytorch/tools/linter/adapters/
    ruff_linter.py", line 173, in <genexpr>
        code.startswith(x)
    AttributeError: 'NoneType' object has no attribute 'startswith'

    STDOUT:
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/142312
Approved by: https://github.com/Skylion007
2024-12-08 16:48:05 +00:00
8a67daf283 [BE][Easy] enable postponed annotations in tools (#129375)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129375
Approved by: https://github.com/malfet
2024-06-29 09:23:35 +00:00
a32ce5ce34 Revert "[BE][Easy] enable postponed annotations in tools (#129375)"
This reverts commit 59eb2897f1745f513edb6c63065ffad481c4c8d0.

Reverted https://github.com/pytorch/pytorch/pull/129375 on behalf of https://github.com/huydhn due to Sorry for reverting your change but I need to revert to cleanly revert https://github.com/pytorch/pytorch/pull/129374, please do a rebase and reland this ([comment](https://github.com/pytorch/pytorch/pull/129375#issuecomment-2197800541))
2024-06-29 00:44:25 +00:00
7bda23ef84 [BE]: Update ruff to 0.5.0 (#129744)
Update ruff to 0.5.0 so we can enable all the some of the new checks I've been wanting to add to the codebase. First just updating the code to comply with some rule changes and a couple minor API changes / deprecations.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129744
Approved by: https://github.com/ezyang
2024-06-28 21:49:56 +00:00
59eb2897f1 [BE][Easy] enable postponed annotations in tools (#129375)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/129375
Approved by: https://github.com/malfet
2024-06-28 15:37:54 +00:00
847c7c6da6 Update ruff to v0.1.4 (#112966)
Updates ruff which fixes some bugs and updates an API to be used more consistently `rule now takes --output-format with the old argname deprecated`. A lot of rule bugfixes and autofixes have been added to the pydocstyle rules which will be useful for the docathon.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/112966
Approved by: https://github.com/kit1980, https://github.com/justinchuby
2023-11-05 00:00:11 +00:00
c8a72db432 [BE]: Update ruff to 0.1.0 (#111391)
Updates RUFF to the latest and greatest version

Pull Request resolved: https://github.com/pytorch/pytorch/pull/111391
Approved by: https://github.com/albanD, https://github.com/malfet
2023-10-17 01:09:16 +00:00
7d2a18da0b Enable ruff in lintrunner (#99785)
### This change

- Implements the ruff linter in pytorch lintrunner. It is adapted from https://github.com/justinchuby/lintrunner-adapters/blob/main/lintrunner_adapters/adapters/ruff_linter.py. It does **both linting and fixing**. 🔧
- Migrated all flake8 configs to the ruff config and enabled it for the repo. 
- **`ruff` lints the whole repo in under 2s** 🤯

Fixes https://github.com/pytorch/pytorch/issues/94737 Replaces #99280

@huydhn @Skylion007

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 6b982dd</samp>

### Summary
🧹🛠️🎨

<!--
1.  🧹 This emoji represents cleaning or tidying up, which is what `ruff` does by formatting and linting the code. It also suggests improving the code quality and removing unnecessary or redundant code.
2.  🛠️ This emoji represents tools or fixing, which is what `ruff` is as a code formatter and linter. It also suggests enhancing the code functionality and performance, and resolving potential issues or bugs.
3.  🎨 This emoji represents art or creativity, which is what `ruff` allows by providing a consistent and configurable style for the code. It also suggests adding some flair or personality to the code, and making it more readable and enjoyable.
-->
Add `[tool.ruff]` section to `pyproject.toml` to configure `ruff` code formatter and linter. This change aims to improve code quality and consistency with a single tool.

> _`ruff` cleans the code_
> _like a spring breeze in the fields_
> _`pyproject.toml`_

### Walkthrough
*  Configure `ruff` code formatter and linter for the whole project ([link](https://github.com/pytorch/pytorch/pull/99785/files?diff=unified&w=0#diff-50c86b7ed8ac2cf95bd48334961bf0530cdc77b5a56f852c5c61b89d735fd711R22-R79))

Pull Request resolved: https://github.com/pytorch/pytorch/pull/99785
Approved by: https://github.com/malfet, https://github.com/Skylion007
2023-04-24 16:18:44 +00:00