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

Ignoring a rule on a variable declaration doesn't work #771

Open
FranzBusch opened this issue Jul 18, 2024 · 4 comments
Open

Ignoring a rule on a variable declaration doesn't work #771

FranzBusch opened this issue Jul 18, 2024 · 4 comments

Comments

@FranzBusch
Copy link
Member

I tried to ignore a rule on a variable declaration like this:

struct Bar {}
struct Foo {
  // swift-format-ignore: DontRepeatTypeInStaticProperties
  var fooBar: Bar 

However this didn't seem to work and I had to move the ignore to the struct declaration to work.

@ahoppen
Copy link
Member

ahoppen commented Jul 18, 2024

Synced to Apple’s issue tracker as rdar://131991753

@allevato
Copy link
Member

To paraphrase our offline chat here: I suspect it's a bug in the way we visit the nodes. We visit the type/extension and then manually recurse into the member list to emit the violations instead of implementing visit methods directly for the members. That would bypass the swift-format-ignore logic. (The implementation of the rule preceded the implementation of ignore, and we never caught this.)

@shawnhyam
Copy link
Contributor

@allevato It is definitely the case that the issue is with how the nodes are visited. I was looking at converting the DontRepeatTypeInStaticProperties rule to use the visit function on VariableDeclSyntax nodes, which would require knowing the current type name in the visit method. I was going to use the existing visit methods for that purpose, but because of nested types it seems necessary to push/pop the current type name using visit/visitPost pairs. Unfortunately, although everything works fine in the linter.walk(...) flow in LintOrFormatRuleTestCase, the visitPost methods are not called in the pipeline.lint(...) flow. Is this known or expected behavior? Or is there a better way to get the name of the enclosing type from a syntax node?

@shawnhyam
Copy link
Contributor

Update: I changed the code generator to make sure visitPost gets called, but don't use that. I just climb the tree looking for a type name instead.

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

No branches or pull requests

4 participants