Skip to content

Add cpplint and ruff linter to pre-commit and fix lint violations#2853

Open
pstjohn wants to merge 2 commits intoNVIDIA:mainfrom
pstjohn:pstjohn/move-lint-to-precommit
Open

Add cpplint and ruff linter to pre-commit and fix lint violations#2853
pstjohn wants to merge 2 commits intoNVIDIA:mainfrom
pstjohn:pstjohn/move-lint-to-precommit

Conversation

@pstjohn
Copy link
Copy Markdown
Contributor

@pstjohn pstjohn commented Apr 8, 2026

Replace pylint with ruff for Python linting in pre-commit config and CI scripts. Keep black as the formatter. Fix all 14 ruff lint violations:

  • F841: Remove unused variables
  • F811: Remove unused import shadowed by local definition
  • F821: Remove erroneous del of variables used later (bug fix)
  • E721: Use is/is not for type comparisons
  • PLR1714: Merge duplicate comparisons
  • PLW0406: Add noqa for intentional self-imports

Also adds cpplint to pre-commit

Replace pylint with ruff for Python linting in pre-commit config and CI
scripts. Keep black as the formatter. Fix all 14 ruff lint violations:
- F841: Remove unused variables
- F811: Remove unused import shadowed by local definition
- F821: Remove erroneous `del` of variables used later (bug fix)
- E721: Use `is`/`is not` for type comparisons
- PLR1714: Merge duplicate comparisons
- PLW0406: Add noqa for intentional self-imports

Also adds cpplint to pre-commit

Signed-off-by: Peter St. John <pstjohn@nvidia.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 8, 2026

Greptile Summary

This PR replaces pylint with ruff for Python linting, adds cpplint as a pre-commit hook, deletes pylintrc, and fixes all 14 ruff violations across several files. The lint fixes are all semantically correct: PLR1714 transformations preserve logical equivalence, E721 is/is not replacements are appropriate, and the F811/F841 removals are clean-ups with no behavioral impact.

Confidence Score: 5/5

Safe to merge — all lint fixes are semantically equivalent transformations with no behavioral changes.

All PLR1714, E721, F841, F811, and F821 fixes have been verified as logically equivalent. No P0/P1 issues found. The one remaining comment (stale pylint disable in grouped_linear.py) is a P2 cleanup item that doesn't affect runtime behavior.

transformer_engine/pytorch/ops/basic/grouped_linear.py has a lingering stale comment; otherwise no files require special attention.

Vulnerabilities

No security concerns identified. Changes are limited to linter configuration and mechanical lint-driven code clean-ups.

Important Files Changed

Filename Overview
.pre-commit-config.yaml Adds ruff (Python lint) and cpplint (C++/CUDA lint) hooks; existing black formatter and clang-format hooks untouched. The cpplint exclude pattern aligns with CI; the --root flag omission (noted in a prior thread) only affects error-message path formatting.
pyproject.toml Adds comprehensive ruff configuration mirroring the disabled pylint rules; per-file ignores for known re-export patterns (fp8.py, export.py, etc.) are appropriate.
transformer_engine/pytorch/distributed.py Removes the shadowed import of _get_module_fsdp_state from torch.distributed.fsdp._common_utils; the local definition at line 1957 (used at line 2091) correctly takes precedence.
transformer_engine/pytorch/attention/dot_product_attention/context_parallel.py Two PLR1714 fixes merge duplicate window_size equality comparisons into in-membership tests; both are semantically equivalent to the originals.
transformer_engine/pytorch/ops/basic/grouped_linear.py E721 fix replaces type(weight.data) != weight_tensor_type with is not; the now-inert # pylint: disable=unidiomatic-typecheck comment was not removed.
transformer_engine/debug/pytorch/debug_quantization.py PLR1714 fix merges two == API_CALL_MODIFY comparisons into a single in check; semantically equivalent. Several # pylint: disable= comments remain but are now inert.
transformer_engine/pytorch/ops/fused/forward_linear_bias_activation.py F841 fix replaces the dead activation_op = None assignment with a pass comment; no behavioral change.
transformer_engine/debug/features/_test_dummy_feature.py PLW0406 suppressed with # noqa: PLW0406 for the intentional self-import pattern; both noqa and legacy pylint comments coexist harmlessly.
transformer_engine/debug/features/api.py E721 fix replaces type(ret) == torch.Tensor with is; the inline # pylint: disable=unidiomatic-typecheck was removed along with the refactored expression.
transformer_engine/debug/init.py F841 fix removes unused as e from bare except ImportError clause; no behavioral change.
qa/L0_pytorch_lint/test.sh Replaces pylint with ruff and adds cpplint; pins both to the same versions used in the pre-commit hook.
qa/L0_jax_lint/test.sh Mirrors L0_pytorch_lint changes; installs same cpplint/ruff versions and replaces the pylint invocation with ruff.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Developer commits code] --> B[pre-commit hooks]

    B --> C[black\nPython formatter]
    B --> D[ruff\nPython linter]
    B --> E[cpplint\nC++/CUDA linter]
    B --> F[clang-format\nC++ formatter]
    B --> G[vermin\nPython version check]

    D --> D1["select: E, F, W, PL\nignore: E402, E501, PLR*, PLW*..."]
    E --> E1["files: transformer_engine/common|jax|pytorch\nexclude: build_tools/build/"]

    B --> H{All checks pass?}
    H -- Yes --> I[CI: qa/L0_pytorch_lint/test.sh\nqa/L0_jax_lint/test.sh]
    H -- No --> J[Block commit / auto-fix]

    I --> I1[cpplint + ruff\npinned to same versions\nas pre-commit]
Loading

Reviews (2): Last reviewed commit: "addressing greptile review" | Re-trigger Greptile

Signed-off-by: Peter St. John <pstjohn@nvidia.com>
Copy link
Copy Markdown
Collaborator

@timmoon10 timmoon10 left a comment

Choose a reason for hiding this comment

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

LGTM, although is there a reason to prefer Ruff over Pylint? Speed?

Copy link
Copy Markdown
Member

@ksivaman ksivaman left a comment

Choose a reason for hiding this comment

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

We should remove all the pylint: disable comments

@pstjohn
Copy link
Copy Markdown
Contributor Author

pstjohn commented Apr 8, 2026

LGTM, although is there a reason to prefer Ruff over Pylint? Speed?

Yeah pretty much. If we're running it as a pre-commit check it's nice if it's fast. But I'm happy to check the pylint version speed that wouldn't require any changes 🤷

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.

3 participants