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

Better detection of IntelliJ language injection comments #14094

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Nov 4, 2024

Summary

Enhances #14069.

Test Plan

A few tests are added to cover edge cases.

@InSyncWithFoo
Copy link
Contributor Author

InSyncWithFoo commented Nov 4, 2024

By the way, do we want that giant regex to be case-insensitive? type: ignore, pyright and SPDX-License-Identifier are a few non-examples.

Copy link
Contributor

github-actions bot commented Nov 4, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Could you help me review this more efficiently by listing yoour changes so that I don't have to diff the Regex?

For case-sensitivity: I think we should use case-sensitive for the suppression comments that are case-sensitive and allow case-insensitivity for the ones that are not.

I also think we should gate this change behind preview mode unless all changes relax the rule's strictness.

@InSyncWithFoo
Copy link
Contributor Author

Here's a comparison table:

Before (all case insensitive) After
pylint No change
pyright Case sensitive
noqa No change
nosec No change
region/endregion Case sensitive
type: ignore Case sensitive
fmt fmt:\s*(on|off) fmt:\s*(on|off|skip), case sensitive
isort No change
mypy Case sensitive
SPDX-License-Identifier: Case sensitive
encoding No change

As for language=:

  • Before: (?i) language=[a-zA-Z](?: ?[-_.a-zA-Z0-9]+)+(?:\s+prefix=\S+)?(?:\s+suffix=\S+)?
  • After: language=[-_.a-zA-Z0-9]+

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants