lint

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package lint contains core functionality used by Folx to check a text for compliance to a style guide.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Truncate

func Truncate(s string, count int) string

truncate a string to a given length and add ellipsis to denote truncation

Types

type FolxLinter

type FolxLinter struct {
	RuleBook rule.Book
	// contains filtered or unexported fields
}

FolxLinter implements Linter.

func NewInitialisedFolxLinter

func NewInitialisedFolxLinter(ruleBook rule.Book) (linter *FolxLinter, err error)

NewInitialisedFolxLinter is a helper factory that returns a fully initialised linter ready for Lint().

func (*FolxLinter) Init

func (t *FolxLinter) Init(ruleBook rule.Book) error

Init the Linter using the given style guide.

func (*FolxLinter) Lint

func (t *FolxLinter) Lint(lx lex.Lexer) (*Report, error)

Lint a source text using the given Lexer. TODO: add advice from solver to lint report

type Linter

type Linter interface {
	Init(ruleBook rule.Book) error
	Lint(lx lex.Lexer) (Report, error)
}

Linter evaluates a source text using a style guide.

type Report

type Report struct {
	ParentGUID string
	GUID       string

	CreateTime time.Time
	LexerExec  time.Duration
	LinterExec time.Duration

	StyleGuideName string

	SourceContent  string
	SourceEncoding string
	SourceName     string
	TokenCount     int

	RuleCount      int
	FailedRules    int
	FailedRulesPct float64
	PassedRules    int
	PassedRulesPct float64

	RunCount      int
	FailedRuns    int
	FailedRunsPct float64
	PassedRuns    int
	PassedRunsPct float64

	FailResults []Result
}

Report is a description of the results of the linting process.

func NewReport

func NewReport() Report

NewReport is factory that creates a new report with initialised GUID

func (*Report) UpdateStats

func (t *Report) UpdateStats(failedRuleCount int)

UpdateStats recalculates report stats based on the given failedRuleCount, and the lenth of the FailResults slice

func (*Report) WriteResultToCSV

func (t *Report) WriteResultToCSV(w io.Writer, withHeader bool) error

WriteResultToCSV writes a CSV representation of the fail results array to an IO stream.

func (*Report) WriteSummaryToCSV

func (t *Report) WriteSummaryToCSV(w io.Writer, withHeader bool) error

WriteSummary writes a summary of the report stats (excl. detailed fail results)

type ReportSection

type ReportSection int
const (
	Summary ReportSection = iota
	Results
)

type ReportSet

type ReportSet struct {
	GUID    string
	Reports []*Report
}

ReportSet is a set of reports that share a ParentGUID

func NewReportSet

func NewReportSet() ReportSet

NewReportSet is factory that creates a new report with initialised GUID

func (*ReportSet) Add

func (t *ReportSet) Add(r *Report)

Add adds the given report and updates the ParentGUID to that of the set

type Result

type Result struct {
	Match   rule.CheckMatch
	IsPass  bool
	Advice  string
	Token   *lex.Token
	Rule    rule.Checker
	RuleSet *rule.CategorySet
}

Result is returned when a Rule is evaluated by the linter.

Jump to

Keyboard shortcuts

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