mllint

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachTask

func ForEachTask(tasks chan *RunnerTask, f func(task *RunnerTask, result LinterResult))

Types

type BasicRunnerProgress

type BasicRunnerProgress struct {
	Out io.Writer
}

func (*BasicRunnerProgress) AllTasksDone

func (p *BasicRunnerProgress) AllTasksDone()

func (*BasicRunnerProgress) CompletedTask

func (p *BasicRunnerProgress) CompletedTask(task *RunnerTask)

func (*BasicRunnerProgress) RunningTask

func (p *BasicRunnerProgress) RunningTask(task *RunnerTask)

func (*BasicRunnerProgress) Start

func (p *BasicRunnerProgress) Start()

func (*BasicRunnerProgress) TaskAwaiting

func (p *BasicRunnerProgress) TaskAwaiting(task *RunnerTask)

func (*BasicRunnerProgress) TaskResuming

func (p *BasicRunnerProgress) TaskResuming(task *RunnerTask)

type ConfigurableLinterWithRunner

type ConfigurableLinterWithRunner interface {
	api.ConfigurableLinter
	WithRunner
}

type LinterResult

type LinterResult struct {
	api.Report
	Err error
}

LinterResult represents the two-valued return type of a Linter, containing a report and an error.

type LinterWithRunner

type LinterWithRunner interface {
	api.Linter
	WithRunner
}

type LiveRunnerProgress

type LiveRunnerProgress struct {
	// contains filtered or unexported fields
}

LiveRunnerProgress is used by an `mllint.Runner` to keep track of and pretty-print the progress of the runner in running its tasks.

Unless you're changing the implementation of `mllint.Runner`, you probably don't need to interact with this.

func (*LiveRunnerProgress) AllTasksDone

func (p *LiveRunnerProgress) AllTasksDone()

AllTasksDone is the way for the `mllint.Runner` to signal that it has finished running all tasks, and that it won't call p.CompletedTask anymore (if it does, it panics because `p.done` is closed). This method will wait until the printWorker has finished printing and has shutdown.

func (*LiveRunnerProgress) CompletedTask

func (p *LiveRunnerProgress) CompletedTask(task *RunnerTask)

CompletedTask is the way for the `mllint.Runner` to signal that it has completed running a task.

func (*LiveRunnerProgress) RunningTask

func (p *LiveRunnerProgress) RunningTask(task *RunnerTask)

RunningTask is the way for the `mllint.Runner` to signal that it has started running a task.

func (*LiveRunnerProgress) Start

func (p *LiveRunnerProgress) Start()

Start starts the printWorker process on a new go-routine.

func (*LiveRunnerProgress) TaskAwaiting

func (p *LiveRunnerProgress) TaskAwaiting(task *RunnerTask)

func (*LiveRunnerProgress) TaskResuming

func (p *LiveRunnerProgress) TaskResuming(task *RunnerTask)

type MLLintRunner

type MLLintRunner struct {
	// contains filtered or unexported fields
}

Runner implements a parallel linter runner for mllint. Use `r := NewRunner()` to create a runner, then call r.Start() on it (and defer r.Close()) to start a queue worker process that will watch for incoming tasks to run a linter, as added to the queue by calls to r.RunLinter().

The Runner will ensure that all tasks added to its queue are executed, run in parallel across all `runtime.NumCPU()` available logical cores (CPU threads, aka the amount of bars you see in `htop` :P). No more than this number of tasks will be running in parallel, any additional tasks are parked and executed as running tasks complete.

`r.RunLinter()` returns a *RunnerTask, use `result := <-task.Result` to await the completion of the linter task and receive the result of the task.

Alternatively, if you have a list of tasks to await and want to receive their results as soon as each completes, use `mllint.CollectTasks(tasks...)` to get a channel where each completed task will be sent. A task you receive through this channel will have a `LinterResult` in the `task.Result`'s buffer, so `<-task.Result` will not block. The channel closes once all tasks have completed.

Example usage with `mllint.ForEachTask()`:

```go

mllint.ForEachTask(mllint.CollectTasks(tasks...), func(task *RunnerTask, result LinterResult) {
  // do something with the completed task and its result
})

```

func NewMLLintRunner

func NewMLLintRunner(progress RunnerProgress) *MLLintRunner

NewMLLintRunner initialises an *mllint.MLLintRunner

func (*MLLintRunner) Close

func (r *MLLintRunner) Close()

Close stops the runner by closing its queue channel. Calls to `runner.RunLinter()` after Close will panic. Close blocks until all tasks added to its queue by `runner.RunLinter()` have completed, and all progress output has finished printing to the terminal.

func (*MLLintRunner) CollectTasks

func (r *MLLintRunner) CollectTasks(tasks ...*RunnerTask) chan *RunnerTask

func (*MLLintRunner) RunLinter

func (r *MLLintRunner) RunLinter(id string, linter api.Linter, project api.Project, options ...TaskOption) *RunnerTask

RunLinter creates a task to run an api.Linter on a project.This method does not block. The task will be executed in parallel with other tasks by the runner. If the runner is `nil`, then the linter will be executed directly on the current thread, returning its result the usual way.

Once the task completes, the linter's report and error will be sent to the task's `Result` channel, i.e. use `<-task.Result` to await the linter's result.

func (*MLLintRunner) Start

func (r *MLLintRunner) Start()

Start starts the runner by running a queue worker go-routine in the background that will await tasks and run them as they come in. After calling `runner.Start()`, make sure to also `defer runner.Close()`

type Runner

type Runner interface {
	RunLinter(id string, linter api.Linter, project api.Project, options ...TaskOption) *RunnerTask
	CollectTasks(tasks ...*RunnerTask) chan *RunnerTask
}

type RunnerProgress

type RunnerProgress interface {
	Start()
	RunningTask(task *RunnerTask)
	TaskAwaiting(task *RunnerTask)
	TaskResuming(task *RunnerTask)
	CompletedTask(task *RunnerTask)
	AllTasksDone()
}

func NewBasicRunnerProgress

func NewBasicRunnerProgress() RunnerProgress

func NewLiveRunnerProgress

func NewLiveRunnerProgress() RunnerProgress

type RunnerTask

type RunnerTask struct {
	Id      string
	Linter  api.Linter
	Project api.Project
	Result  chan LinterResult
	// contains filtered or unexported fields
}

RunnerTask represents a task to run a linter on a project that was created by a call to runner.RunLinter(...)

type TaskOption

type TaskOption func(task *RunnerTask)

TaskOption is an option for a task created by RunLinter, e.g. setting a custom display name.

func DisplayName

func DisplayName(name string) TaskOption

type WithRunner

type WithRunner interface {
	SetRunner(runner Runner)
}

Directories

Path Synopsis
Package mock_mllint is a generated GoMock package.
Package mock_mllint is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL