Skip to content

S038: Check Schema declares Default with incompatible Type#329

Open
magodo wants to merge 3 commits into
bflad:mainfrom
magodo:S038
Open

S038: Check Schema declares Default with incompatible Type#329
magodo wants to merge 3 commits into
bflad:mainfrom
magodo:S038

Conversation

@magodo
Copy link
Copy Markdown
Contributor

@magodo magodo commented Feb 20, 2025

This PR adds a new schema check that reports cases of Schemas which has Default value declared with incompatible Type.

The logic is to look at the schema definitions that have non-nil Default declared in AST, then check if the "Default" field in the schema info is evaluated to be nil, which only happens when the Default value doesn't have the same type as the schema type (covers int, string and bool).

Since the existing basic literal check only checks for the ast.BasicLit node, whilst it can happen that the Default value can be some other expression (e.g. string(MyStringABC), where const MyStringABC MyString = "abc"; Or even MyStringABC). This PR also extends a set of similar functions, but account for the constant value of the expression assigned as the Default value.

Test

tfproviderlint/passes/S038 on  S038 via 🐹 v1.24.0
💤  go test ./...
ok      github.com/bflad/tfproviderlint/passes/S038     (cached)

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.

1 participant