Skip to content

Commit 10879f3

Browse files
author
Sinelnikov Michail
committed
add rule
Signed-off-by: Sinelnikov Michail <mikhail.sinelnikov@flant.com>
1 parent 4c423c5 commit 10879f3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

pkg/linters/module/rules/module_yaml.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ func (r *DefinitionFileRule) CheckDefinitionFile(modulePath string, errorList *e
282282
if yml.Critical && yml.Weight == 0 {
283283
errorList.Error("Field 'weight' must not be zero for critical modules")
284284
}
285+
286+
if !yml.Critical && yml.Weight > 0 {
287+
errorList.Warn("Field 'weight' is ignored for non-critical modules")
288+
}
285289
}
286290

287291
func (m ModuleRequirements) validateRequirements(errorList *errors.LintRuleErrorsList) {

pkg/linters/module/rules/module_yaml_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,35 @@ descriptions:
254254
assert.Contains(t, errorList.GetErrors()[0].Text, "Field 'weight' must not be zero for critical modules")
255255
}
256256

257+
func TestCheckDefinitionFile_NonCriticalModuleWithWeight(t *testing.T) {
258+
tempDir := t.TempDir()
259+
moduleFilePath := filepath.Join(tempDir, ModuleConfigFilename)
260+
261+
err := os.WriteFile(moduleFilePath, []byte(`
262+
name: test-non-critical
263+
weight: 10
264+
stage: Experimental
265+
descriptions:
266+
en: "Test description"
267+
`), 0600)
268+
require.NoError(t, err)
269+
270+
rule := NewDefinitionFileRule(false)
271+
errorList := errors.NewLintRuleErrorsList()
272+
rule.CheckDefinitionFile(tempDir, errorList)
273+
274+
assert.False(t, errorList.ContainsErrors(), "Expected no errors for non-critical module with weight")
275+
276+
found := false
277+
for _, e := range errorList.GetErrors() {
278+
if e.Level == pkg.Warn && e.Text == "Field 'weight' is ignored for non-critical modules" {
279+
found = true
280+
break
281+
}
282+
}
283+
assert.True(t, found, "Expected warning for non-critical module with weight")
284+
}
285+
257286
func TestCheckDefinitionFile_InvalidStage(t *testing.T) {
258287
tempDir := t.TempDir()
259288
moduleFilePath := filepath.Join(tempDir, ModuleConfigFilename)

0 commit comments

Comments
 (0)