From b6bff444f9595bab69e0bb99265bdd1896b5800b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 11 Aug 2020 14:33:53 +0200 Subject: [PATCH] feat(qa): add a qa about commands without examples (#1298) Co-authored-by: Olivier Cano --- internal/qa/qa.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/qa/qa.go b/internal/qa/qa.go index 86b6ab9eb5..f10a80ea0e 100644 --- a/internal/qa/qa.go +++ b/internal/qa/qa.go @@ -18,6 +18,7 @@ func LintCommands(commands *core.Commands) []error { errors = append(errors, testExampleCanHaveOnlyOneTypeOfExampleError(commands)...) errors = append(errors, testDifferentLocalizationForNamespaceError(commands)...) errors = append(errors, testDuplicatedCommandError(commands)...) + errors = append(errors, testAtLeastOneExampleIsPresentError(commands)...) errors = filterIgnore(errors) @@ -318,3 +319,31 @@ func testDuplicatedCommandError(commands *core.Commands) []error { return errors } + +type MissingExampleError struct { + Command *core.Command +} + +func (err MissingExampleError) Error() string { + return fmt.Sprintf("command without examples '%s'", err.Command.GetCommandLine("scw")) +} + +// testDuplicatedCommandError testes that there is no duplicate command. +func testAtLeastOneExampleIsPresentError(commands *core.Commands) []error { + errors := []error(nil) + + for _, command := range commands.GetAll() { + // Namespace and resources commands do not need examples + // We focus on command with a verb + if command.Run == nil { + continue + } + + if len(command.Examples) == 0 { + errors = append(errors, &MissingExampleError{Command: command}) + continue + } + } + + return errors +}