Documentation
¶
Overview ¶
Example (Linter_ExecuteLinter) ¶
runLinter(New(
"no files",
config.LinterSettings{Command: []string{"echo"}},
))
runLinter(New(
"files pattern",
config.LinterSettings{
Command: []string{"echo", "one"},
Filters: config.Filters{Files: []string{"two", "three"}},
},
))
runLinter(New(
"folder pattern",
config.LinterSettings{
Command: []string{"echo", "one"},
Filters: config.Filters{
Folders: []string{"two", "three"},
},
},
))
runLinter(New(
"git pattern",
config.LinterSettings{
Command: []string{"echo", "foo"},
Filters: config.Filters{
GitPattern: []string{"**"},
},
},
))
runLinter(New(
"find pattern",
config.LinterSettings{
Command: []string{"echo", "foo"},
Filters: config.Filters{
FindPattern: []string{"*"},
},
},
))
runBadLinter(
New(
"git error",
config.LinterSettings{
Command: []string{"echo", "foo"},
Filters: config.Filters{
GitPattern: []string{""},
},
},
),
"cannot prepare linter 'git error' execution: exit status 128",
-1,
)
runBadLinter(
New(
"bad linter",
config.LinterSettings{
Command: []string{"/nonexistant"},
Filters: config.Filters{
Folders: []string{"."},
},
},
),
"cannot execute linter 'bad linter': fork/exec /nonexistant: no such file or directory",
-1,
)
{
returnCode, err := New(
"failed linter",
config.LinterSettings{
Command: []string{"sh"},
Filters: config.Filters{
Folders: []string{"-c", "exit 42"},
},
},
).ExecuteLinter()
if err != nil {
panic(err)
}
if returnCode != 42 {
panic(fmt.Sprint("bad return code: ", returnCode))
}
}
Output: ================================================================================ ===== Execute no files ========================================================= ================================================================================ No file to lint. Just skip linter: no files ================================================================================ ===== Execute files pattern ==================================================== ================================================================================ one three two ================================================================================ ===== Execute folder pattern =================================================== ================================================================================ one three two ================================================================================ ===== Execute git pattern ====================================================== ================================================================================ foo linter.go linter_test.go ================================================================================ ===== Execute find pattern ===================================================== ================================================================================ foo ./linter.go ./linter_test.go ================================================================================ ===== Execute git error ======================================================== ================================================================================ ================================================================================ ===== Execute bad linter ======================================================= ================================================================================ ================================================================================ ===== Execute failed linter ==================================================== ================================================================================
Example (Linter_PrintVersion) ¶
l := New("no version", config.LinterSettings{})
if err := l.PrintVersion(); err != nil {
panic(err)
}
l = New("foo bar", config.LinterSettings{Version: []string{"echo", "foo", "bar"}})
if err := l.PrintVersion(); err != nil {
panic(err)
}
l = New("exit 1", config.LinterSettings{Version: []string{"sh", "-c", "echo 'The exit 1 version'; exit 1"}})
if err := l.PrintVersion(); err == nil || err.Error() != "cannot print 'exit 1' version: exit status 1" {
panic(fmt.Sprint("not expected error: ", err))
}
Output: ================================================================================ ===== Version of no version ==================================================== ================================================================================ ================================================================================ ===== Version of foo bar ======================================================= ================================================================================ foo bar ================================================================================ ===== Version of exit 1 ======================================================== ================================================================================ The exit 1 version
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.