Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/linters/module/rules/module_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ func (r *DefinitionFileRule) CheckDefinitionFile(modulePath string, errorList *e
if yml.Critical && yml.Weight == 0 {
errorList.Error("Field 'weight' must not be zero for critical modules")
}

if !yml.Critical && yml.Weight > 0 {
errorList.Warn("Unnecessary field 'weight' must be removed for non-critical module")
}
}

func (m ModuleRequirements) validateRequirements(errorList *errors.LintRuleErrorsList) {
Expand Down
29 changes: 29 additions & 0 deletions pkg/linters/module/rules/module_yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ descriptions:
assert.Contains(t, errorList.GetErrors()[0].Text, "Field 'weight' must not be zero for critical modules")
}

func TestCheckDefinitionFile_NonCriticalModuleWithWeight(t *testing.T) {
tempDir := t.TempDir()
moduleFilePath := filepath.Join(tempDir, ModuleConfigFilename)

err := os.WriteFile(moduleFilePath, []byte(`
name: test-non-critical
weight: 10
stage: Experimental
descriptions:
en: "Test description"
`), 0600)
require.NoError(t, err)

rule := NewDefinitionFileRule(false)
errorList := errors.NewLintRuleErrorsList()
rule.CheckDefinitionFile(tempDir, errorList)

assert.False(t, errorList.ContainsErrors(), "Expected no errors for non-critical module with weight")

found := false
for _, e := range errorList.GetErrors() {
if e.Level == pkg.Warn && e.Text == "Unnecessary field 'weight' must be removed for non-critical module" {
found = true
break
}
}
assert.True(t, found, "Expected warning for non-critical module with weight")
}

func TestCheckDefinitionFile_InvalidStage(t *testing.T) {
tempDir := t.TempDir()
moduleFilePath := filepath.Join(tempDir, ModuleConfigFilename)
Expand Down