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

Interpret strings in excluded option of *_name rules as regular expressions #4655

Merged
merged 18 commits into from
Jan 10, 2023

Conversation

kyounh12
Copy link
Contributor

There already exists an option called excluded to prevent some unwanted checks.

However, excluded option has limitations when we need to exclude names with similar patterns since it requires exact match.

So we may solve this problem by adding excluded_regular_expressions option to identifier_name rule and exclude some names by regex.

This would be extremely helpful in situations like below:

  • exclude identifier names with other languages. ( Xcode allows identifier names with some other languages )
  • exclude identifier names having similar patterns
  • ...
identifier_name:
  excluded_regular_expressions:
    - Apple
    - ^[가-힣_]$

@SwiftLintBot
Copy link

SwiftLintBot commented Dec 22, 2022

18 Messages
📖 Linting Aerial with this PR took 1.1s vs 1.11s on main (0% faster)
📖 Linting Alamofire with this PR took 1.41s vs 1.4s on main (0% slower)
📖 Linting Brave with this PR took 7.43s vs 7.43s on main (0% slower)
📖 Linting DuckDuckGo with this PR took 3.03s vs 3.0s on main (0% slower)
📖 Linting Firefox with this PR took 9.61s vs 9.58s on main (0% slower)
📖 Linting Kickstarter with this PR took 10.24s vs 10.24s on main (0% slower)
📖 Linting Moya with this PR took 0.57s vs 0.57s on main (0% slower)
📖 Linting NetNewsWire with this PR took 3.26s vs 3.23s on main (0% slower)
📖 Linting Nimble with this PR took 0.62s vs 0.63s on main (1% faster)
📖 Linting PocketCasts with this PR took 7.59s vs 7.57s on main (0% slower)
📖 Linting Quick with this PR took 0.24s vs 0.24s on main (0% slower)
📖 Linting Realm with this PR took 12.01s vs 12.05s on main (0% faster)
📖 Linting SourceKitten with this PR took 0.47s vs 0.44s on main (6% slower)
📖 Linting Sourcery with this PR took 2.33s vs 2.34s on main (0% faster)
📖 Linting Swift with this PR took 4.49s vs 4.49s on main (0% slower)
📖 Linting VLC with this PR took 1.37s vs 1.37s on main (0% slower)
📖 Linting Wire with this PR took 8.99s vs 8.95s on main (0% slower)
📖 Linting WordPress with this PR took 11.29s vs 11.24s on main (0% slower)

Generated by 🚫 Danger

Copy link
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

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

I like the idea of supporting patterns for excluded names. However, the NameConfiguration already contains a few options and I would like to avoid adding a new one. The existing list of excluded names would only become a subset of the new excluded_pattern option.

What do you think about just interpreting the strings in the excluded list as regular expression that must match a whole name? If there is a list element "MyName" it would only match the name MyName but not MyName_v1. That makes sure that existing configurations work as before. With the possibility to add regular expressions to the list, one could add "^MyName_v\d+$" to match the other (versioned) name, too.

Furthermore, NameConfiguration is also used in GenericTypeNameRule and TypeNameRule. This should be tested as well.

CHANGELOG.md Outdated Show resolved Hide resolved
@kyounh12 kyounh12 force-pushed the feature/excluded-regex branch 2 times, most recently from eb79c29 to ac8f38f Compare January 4, 2023 11:34
@SimplyDanny
Copy link
Collaborator

Well done! Thank you for all the work and your patience.

@SimplyDanny SimplyDanny merged commit 5ec6112 into realm:main Jan 10, 2023
@SimplyDanny SimplyDanny changed the title Add excluded_regular_expressions option for identifier_name rule Interpret strings in excluded option of *_name rules as regex Jan 11, 2023
@SimplyDanny SimplyDanny changed the title Interpret strings in excluded option of *_name rules as regex Interpret strings in excluded option of *_name rules as regular expressions Jan 11, 2023
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.

4 participants