Verify and Fix
Purpose
Automate the process of ensuring code quality, functional correctness, and buildability within the Terraform Provider Lightdash project. This skill provides a comprehensive local verification loop using trunk, make, and pre-commit.
Safety & Restrictions
- •NO Acceptance Tests: Do NOT run
make testaccor any command that setsTF_ACC=1. This skill is intended for fast, local feedback loops (linting, building, unit testing) and should not interact with live infrastructure.
Workflow
1. Formatting
Start by ensuring consistent code formatting across the repository.
- •Command:
trunk fmt --all - •Action: Run this command to automatically format all files. If any changes are made, they will be reflected in the working directory.
2. Linting
Execute the project's linting suite to identify violations.
- •Command:
make lint - •Details: This command runs
trunk check --allandpre-commit run --all-files. - •Analysis: Review the output for any errors or warnings.
3. Unit Testing
Execute the project's unit tests to ensure functional correctness.
- •Command:
make test - •Details: This runs
go teston the internal packages without settingTF_ACC. - •Action: Verify that all tests pass.
4. Automated Fixing
If linter violations are detected, attempt to resolve them automatically.
- •Condition: Only if
make lintreports fixable issues. - •Command:
trunk check --all --fix - •Action: This will apply automated fixes provided by the linters integrated into Trunk.
5. Build Verification
Ensure the project compiles successfully and passes security/deadcode checks.
- •Command:
make build - •Details: This triggers
gen-docs,go-tidy,gosec,deadcode, and finallygo build. - •Action: Verify that the build completes without errors.
6. Iterative Manual Fixes
If issues remain after automated attempts, proceed with manual intervention.
- •Analyze: Examine the specific error messages from
trunk check,make test, ormake build. - •Fix: Use the
Edittool to address the root causes of the violations in the source code. - •Verify: Re-run the loop starting from Step 2 (Linting) until all checks pass and the build is successful.
Termination Criteria
- •
make lintreturns no errors. - •
make testreturns no failures. - •
make buildcompletes successfully. - •No remaining linter violations are reported by
trunk check --all.
Examples
Scenario: Fixing a Bug Found by Unit Tests
- •Format:
trunk fmt --all(Success). - •Lint:
make lint(Success). - •Unit Testing:
make test(Fails ininternal/lightdash/api/utils_test.go). - •Manual Fix:
- •Analyze the test failure.
- •Edit
internal/lightdash/api/utils.goto fix the logic.
- •Verify: Re-run
make test. (Success). - •Build:
make build. (Success).