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

[Rule] Prefer let-bindings over var-bindings wherever possible #10

Closed
marcelofabri opened this issue May 19, 2015 · 9 comments
Closed

Comments

@marcelofabri
Copy link
Collaborator

Check if a var ever changes. If not, let should be used.

key.setter_accessibility might be useful.

@segiddins
Copy link
Contributor

Wouldn't you also need to check if any mutating methods /input functions are called with it?

@marcelofabri
Copy link
Collaborator Author

Yeah, this will be a trick one. We can't also predict anything on properties from public API (they might not change inside the file itself, but a consumer may change it).

@marcelofabri
Copy link
Collaborator Author

An easier way to do this is trying to replace every (non-public?) var with let and let the compiler check if it's still ok.

The problems are that this will probably be much slower and that neither syntax nor structure expose this error (but swiftc does).

@jpsim
Copy link
Collaborator

jpsim commented May 19, 2015

@mrackwitz is working on a parser for swiftc -dump-ast so hopefully that'll make it easier to build different kinds of SwiftLint rules based on that version of the AST.

@marcelofabri
Copy link
Collaborator Author

👍

I was just about to comment about swiftc -dump-ast and how helpful it would be.

@marcelofabri
Copy link
Collaborator Author

This is now a compiler warning on Swift 2.0, so maybe it should be closed.

@jpsim
Copy link
Collaborator

jpsim commented Jun 24, 2015

This is now a compiler warning on Swift 2.0, so maybe it should be closed.

Agreed. Plus, this would have been difficult to do without LLMV IR access.

@jpsim jpsim closed this as completed Jun 24, 2015
@cprovatas
Copy link

cprovatas commented Mar 5, 2021

Any chance of supporting this for class / struct properties? I noticed the swift compiler doesn't catch this. Is it too complex to support?

@jpsim
Copy link
Collaborator

jpsim commented Mar 5, 2021

It would be possible to build an analyzer rule to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants