[dmt] add module-package-consistency rule with --fix support#381
Open
diyliv wants to merge 6 commits into
Open
[dmt] add module-package-consistency rule with --fix support#381diyliv wants to merge 6 commits into
diyliv wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new module-package-consistency cross-validation capability with an optional --fix mode that rewrites module.yaml fields to match package.yaml (as the source of truth), plus CLI wiring and expanded test coverage.
Changes:
- Introduce AST-based YAML patcher to auto-fix
module.yaml(name,requirements.deckhouse/kubernetes,requirements.modules) frompackage.yaml. - Extend the consistency rule to optionally run the fixer and emit warnings for
package.yamlsections that can’t be represented inmodule.yaml(anyOf,subscribe). - Wire
--fixflag intodmt lintand add fix-mode tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/linters/module/rules/module_package_fix.go | New YAML AST patching implementation for module.yaml rewrite. |
| pkg/linters/module/rules/module_package_consistency.go | Adds --fix integration via FixFn and fix/warn flow before comparisons. |
| pkg/linters/module/rules/module_package_consistency_test.go | Adds fix-mode tests validating rewrite behavior and warnings. |
| pkg/linters/module/module.go | Wires CLI flags.Fix into the consistency rule invocation. |
| internal/flags/flags.go | Adds dmt lint --fix boolean flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
6a5c8c3 to
52d6935
Compare
…module-package-consistency-fix
Comment on lines
+66
to
+70
| if err := os.WriteFile(path, out, fixFilePerm); err != nil { | ||
| return fmt.Errorf("write %s: %w", ModuleConfigFilename, err) | ||
| } | ||
|
|
||
| return nil |
…n patchModuleYAML and re-run lint after --fix applies changes Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
module_package_consistency.go): compares overlapping fields (name,requirements.deckhouse,requirements.kubernetes,requirements.modules) betweenmodule.yamlandpackage.yamlwhen both files exist, reporting any divergence.package.yamlis treated as source of truth.--fixmode (module_package_fix.go): AST-based YAML patching rewritesmodule.yamlfields to matchpackage.yamlvalues. Preserves comments, field ordering, and untouched fields. Atomic write via temp file + rename. Mapspackage.yamlmandatory/conditional module groups to old-spec flat map format (!optionalsuffix).lint_errors.go:ReportUnmappedFields): emits warnings foranyOfandsubscribesections inpackage.yamlthat have no representation inmodule.yaml.--fixboolean flag todmt lintcommand (flags.go).ModulePackageConsistencyRuleconfig field;module.gonow passesflags.Fixto the rule check.anyOfhandling, fix mode for all field types, comment/ordering preservation in fix, and integration test matching user-provided example with non-standardrequiredkey and prefix!optionalformat.Context
When both
module.yamlandpackage.yamlexist in a module directory, their overlapping fields (name, deckhouse/kubernetes constraints, module dependencies) can diverge over time. This rule detects inconsistencies and--fixautomatically patchesmodule.yamlto matchpackage.yaml(old spec format), treatingpackage.yamlas the authoritative source.Example
Module with diverging
module.yamlandpackage.yaml:module.yaml (before fix):
package.yaml (source of truth):
Before:
dmt lintreports 6 errors (name, deckhouse, kubernetes, missing stronghold, wrong prompp constraint, extra missing-mod).After
dmt lint --fix:module.yamlrewritten to:package.yaml has anyOf modules which cannot be represented in module.yaml