Skip to content

Conversation

@JoelSpeed
Copy link
Contributor

This expects the recent changes to the struct field extraction out into a helper, so that we can centralise things like ignoring structs that are declared within functions, or ignored json tags "-". This also now makes sure that the linters affected by this change do not inspect interface declarations which was the cause for #48.

Fixes #48

CC @mandre @sivchari

Copy link
Member

@sivchari sivchari left a comment

Choose a reason for hiding this comment

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

I left just small one comment.

Comment on lines +51 to +53
// The 0th node in the stack is the *ast.File.
// The 1st node in the stack is the *ast.GenDecl.
Copy link
Member

Choose a reason for hiding this comment

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

		// The 0th node in the stack is the *ast.File.
		// The 1st node in the stack is the *ast.GenDecl.

Is this description is necessary ? If so, I think it requires about stack[len(stack)-3]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've got a comment within the if statement, line 61 and 62 that explains what that particular one is about, do you think I need more than that?

Copy link
Member

Choose a reason for hiding this comment

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

oops, sorry.
I've overlooked

@sivchari
Copy link
Member

sivchari commented Mar 3, 2025

Thank you for great improvement 🙇

@mandre
Copy link
Contributor

mandre commented Mar 4, 2025

As far as I'm concerned, I can confirm the PR indeed fixes the bug I was experiencing in #48.

}
}

type Interface interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need to test a type that uses composition of the interface like:

type ComposedThing struct {
        Interface
        Foo string
}

?

Copy link
Contributor Author

@JoelSpeed JoelSpeed Mar 4, 2025

Choose a reason for hiding this comment

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

I don't think you can embed interfaces like that, you can embed other structs, not interfaces, I thought we had that case already though

Apparently you can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would just mean you have to initialise the interface, inside the struct, with something that implements the interface.

At the moment I can't see why anyone would be using that inside a Kube API type, but maybe there are other types in the same package that this might effect?

For now I'm tempted to leave this out until we see a use case

Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

Just a nit, nothing worth holding this up

// Inspector is an interface that allows for the inspection of fields in structs.
type Inspector interface {
// InspectFields is a function that iterates over fields in structs.
InspectFields(func(field *ast.Field, stack []ast.Node, jsonTagInfo extractjsontags.FieldTagInfo, markersAccess markers.Markers))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Make the input func a specific type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had that, and moved away from it as my code completion was being annoying and not understanding how to populate... Maybe will move back in the future

Copy link
Contributor

Choose a reason for hiding this comment

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

Someone's LSP needs an update ;)

@JoelSpeed JoelSpeed merged commit 36e90ff into main Mar 4, 2025
2 checks passed
@JoelSpeed JoelSpeed deleted the inspector-helper branch March 4, 2025 14:37
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.

jsontags linter mistakenly inspects interfaces

5 participants