Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFencedCB ¶
AddFencedCB addresses MD040 issues found with markdownlint by adding the input language to fenced code blocks in the input filePath.
**Parameters:**
filePath: Path to the markdown file to modify. language: Language to be added to the fenced code block.
**Returns:**
error: An error if the markdown file fails to be modified.
Example ¶
package main
import (
"log"
lint "github.com/l50/goutils/v2/dev/lint"
)
func main() {
if err := lint.AddFencedCB("README.md", "go"); err != nil {
log.Fatalf("error modifying markdown file: %v", err)
}
}
Output:
func ClearPCCache ¶
func ClearPCCache() error
ClearPCCache clears the pre-commit cache.
**Returns:**
error: An error if the cache fails to clear.
Example ¶
package main
import (
"log"
"path/filepath"
lint "github.com/l50/goutils/v2/dev/lint"
"github.com/l50/goutils/v2/sys"
)
func main() {
if err := sys.Cd(filepath.Join("..", "..")); err != nil {
log.Fatalf("failed to change directory: %v", err)
}
if err := lint.ClearPCCache(); err != nil {
log.Fatalf("error clearing cache: %v", err)
}
}
Output:
func InstallGoPCDeps ¶
func InstallGoPCDeps() error
InstallGoPCDeps installs dependencies used for pre-commit with Golang projects.
**Returns:**
error: An error if the dependencies fail to install.
Example ¶
package main
import (
"log"
"path/filepath"
lint "github.com/l50/goutils/v2/dev/lint"
"github.com/l50/goutils/v2/sys"
)
func main() {
if err := sys.Cd(filepath.Join("..", "..")); err != nil {
log.Fatalf("failed to change directory: %v", err)
}
if err := lint.InstallGoPCDeps(); err != nil {
log.Fatalf("error installing dependencies: %v", err)
}
}
Output:
func InstallPCHooks ¶
func InstallPCHooks() error
InstallPCHooks installs pre-commit hooks locally.
**Returns:**
error: An error if the hooks fail to install.
func RunHookTool ¶ added in v2.2.0
RunHookTool executes the specified pre-commit hook on a set of files. It constructs a command to run 'pre-commit' with the given hook and file arguments. If no files are provided, it defaults to "all". The function then executes the command and handles any resulting error.
**Parameters:**
hook: A string specifying the name of the pre-commit hook to be run. files: A variadic string slice containing file paths to be included in the pre-commit hook execution. If no files are specified, it defaults to running the hook on all files.
**Returns:**
error: An error if any issue occurs during the execution of the pre-commit hook, otherwise nil if the hook runs successfully.
Example ¶
package main
import (
"log"
lint "github.com/l50/goutils/v2/dev/lint"
)
func main() {
if err := lint.RunHookTool("golangci-lint", "run"); err != nil {
log.Fatalf("error running hook tool: %v", err)
}
}
Output:
func RunPCHooks ¶
RunPCHooks runs pre-commit hooks with a provided timeout. If no timeout is provided, it defaults to 600.
**Parameters:**
timeout (optional): An integer specifying the timeout duration in seconds.
**Returns:**
error: An error if the pre-commit hook execution fails.
Example ¶
package main
import (
"log"
"path/filepath"
lint "github.com/l50/goutils/v2/dev/lint"
"github.com/l50/goutils/v2/sys"
)
func main() {
if err := sys.Cd(filepath.Join("..", "..")); err != nil {
log.Fatalf("failed to change directory: %v", err)
}
// Run with a default timeout of 600.
if err := lint.RunPCHooks(); err != nil {
log.Fatalf("failed to run pre-commit hooks: %v", err)
}
// Runs with a specified timeout of 300.
if err := lint.RunPCHooks(300); err != nil {
log.Fatalf("failed to run pre-commit hooks: %v", err)
}
if err := lint.RunPCHooks(300); err != nil {
log.Fatalf("failed to run pre-commit hooks: %v", err)
}
}
Output:
func UpdatePCHooks ¶
func UpdatePCHooks() error
UpdatePCHooks updates pre-commit hooks locally.
**Returns:**
error: An error if the hooks fail to update.
Example ¶
package main
import (
"log"
"path/filepath"
lint "github.com/l50/goutils/v2/dev/lint"
"github.com/l50/goutils/v2/sys"
)
func main() {
if err := sys.Cd(filepath.Join("..", "..")); err != nil {
log.Fatalf("failed to change directory: %v", err)
}
if err := lint.UpdatePCHooks(); err != nil {
log.Fatalf("error updating hooks: %v", err)
}
}
Output:
Types ¶
This section is empty.