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

identifier_name issue didn't show warning #4767

Closed
2 tasks done
ilikerb0407 opened this issue Feb 15, 2023 · 4 comments · Fixed by #4784
Closed
2 tasks done

identifier_name issue didn't show warning #4767

ilikerb0407 opened this issue Feb 15, 2023 · 4 comments · Fixed by #4784
Labels
bug Unexpected and reproducible misbehavior. documentation Issues related to documentation, either from the tooling side or content-wise. good first issue Issue to be taken up by new contributors yet unfamiliar with the project.

Comments

@ilikerb0407
Copy link

ilikerb0407 commented Feb 15, 2023

New Issue Checklist

Describe the bug

In an exception to the above, variable names may start with a capital letter when they are declared static and immutable.
Above is the sentence on SwiftLint Rules, I found out that when I declared static var AbCvar = 0, and Xcode didn't show the warning because I realize the rule mention static and immutable. What is the reason ?

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.50.3
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
excluded:
  - Pods
disabled_rules:
  - trailing_whitespace
identifier_name:
  excluded: # excluded via string array
    - id
    - URL
    - url
    - app
file_length:
  warning: 500
  error: 800
type_body_length:
  - 500 # warning
  - 700 # error
@ilikerb0407 ilikerb0407 changed the title identifier_name issue didn identifier_name issue didn't show warning Feb 15, 2023
@ilikerb0407 ilikerb0407 reopened this Feb 15, 2023
@SimplyDanny
Copy link
Collaborator

The trigger for this exception was #541 implemented in #1444. However, I cannot find the reason for it. The style guides I've scrolled through don't mention special rules for immutable constants.

The rule has been like that for a long time now. That's why I'd rather avoid to change its behavior. The exception for static variables is there but can be disabled by a configuration option. So if you don't like it, just deactivate this exception. 😉

Yet, you are right that there is an inconsistency in the rule's description and its behavior in that the exception is only valid for immutable static variables while the implementation checks all static variables no matter if they are constants or not.

Again, to avoid bahavioral changes, we should go and fix the description only.

@SimplyDanny SimplyDanny added bug Unexpected and reproducible misbehavior. good first issue Issue to be taken up by new contributors yet unfamiliar with the project. documentation Issues related to documentation, either from the tooling side or content-wise. labels Feb 19, 2023
@mildm8nnered
Copy link
Collaborator

#4784 should resolve this.

Somewhat tangential to the original complaint, it does seem a bit weird that

class Foo {
    static let Bar = 0
}

(or it's var equivalent), does not trigger this rule, but that a top level (i.e. global) static declaration will

e.g. static let Bar = 0 or static var Bar = 0

@JaviSoto
Copy link
Contributor

The exception for static variables is there but can be disabled by a configuration option

Which option is this? Am I missing something? I don't see it in https://realm.github.io/SwiftLint/identifier_name.html

@SimplyDanny
Copy link
Collaborator

The exception for static variables is there but can be disabled by a configuration option

Which option is this? Am I missing something? I don't see it in https://realm.github.io/SwiftLint/identifier_name.html

Well, the case check can be disabled using validates_start_with_lowercase for all variables, so that it doesn't matter anymore. It's not that it can be enabled for static variables. Sorry, if my previous statement was a bit confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior. documentation Issues related to documentation, either from the tooling side or content-wise. good first issue Issue to be taken up by new contributors yet unfamiliar with the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants