spellchecker

package module
v0.0.0-...-e468015 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

README

go-check-spellchecker

A quick tool to automatically insert 'spellchecker:words' comment for every '.go' source file import and package statements.

Usage:

go run ./cmd/go-check-spellchecker -fix ./...

This tool is currently still lacking documentation.

License

GPL-3.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SpellcheckerImportComments = &analysis.Analyzer{
	Name: "spellchecker_import_comments",
	Doc:  "Checks that each import declaration has exactly one 'spellchecker:words' comment containing the words in the imports",
	Run: func(pass *analysis.Pass) (interface{}, error) {
		for _, file := range pass.Files {

			if isDoNotEdit(file) || isDisabled(file) {
				continue
			}

			analyzeImportWordDirective(pass, file)
		}

		return nil, nil
	},
}
View Source
var SpellcheckerPackageComments = &analysis.Analyzer{
	Name: "spellchecker_package_comments",
	Doc:  "Checks that each package name has exactly one 'spellchecker:words' comment containing the words in the package name",
	Run: func(pass *analysis.Pass) (interface{}, error) {
		for _, file := range pass.Files {

			if isDoNotEdit(file) || isDisabled(file) {
				continue
			}

			analyzePackageWordDirective(pass, file)
		}

		return nil, nil
	},
}
View Source
var SpellcheckerWords = &analysis.Analyzer{
	Name: "spellchecker_word_comments",
	Doc:  "Checks that each 'spellchecker:words' comment is formatted correctly and not empty",
	Run: func(pass *analysis.Pass) (interface{}, error) {
		for _, file := range pass.Files {

			if isDoNotEdit(file) || isDisabled(file) {
				continue
			}

			analyzeWordsDirectives(pass, file)
		}

		return nil, nil
	},
}

Functions

func CountWords

func CountWords(text string) int

CountWords counts the number of words in the given text. It is an efficient version of len(SplitWords(text))

func FormatDirective

func FormatDirective(directive, value string) string

FormatDirective formats a directive into a string

func ParseSpellComment

func ParseSpellComment(text string) (keyword, directive, value string, ok bool)

ParseSpellComment parses text belonging to a spellchecker comment. It is expected to be of the form `keyword:directive args`. Each part may contain spaces at the edges and is matched under case folding.

func SplitWords

func SplitWords(text string) []string

SplitWords splits text into words.

A word is a sequence of runes within the text. Each word may consist of upper and lowercase letters.

Uppercase letters may only appear contiguously at the beginning of the word. "HELLOworld" is one word, whereas "HelloWorld" is two words "Hello" and "World".

To count the number of words in text, use CountWords instead.

Types

type CommentText

type CommentText struct {
	Keyword   string
	Directive string
	Value     string
}

CommentText represents the text belonging to a parsed spellchecker directive. A comment looks like:

keyword:directive Value

A keyword must be one of 'spellchecker', 'cSpell' or 'spell-checker'. Keywords and directives are parsed under case-folding.

func (CommentText) IsDirective

func (ct CommentText) IsDirective(directive string) bool

IsDirective checks if this CommentText represents the given directive. Directives are compared under case folding.

func (CommentText) Normalize

func (ct CommentText) Normalize() CommentText

CommentText returns a normalized copy of comment.

The picks the default keyword, and lowercases the directive.

func (*CommentText) Parse

func (ct *CommentText) Parse(text string) bool

Parse parses the given text into a comment. If the comment does not represent a text, returns false.

func (CommentText) String

func (ct CommentText) String() string

String formats the contents of this CommentText, that is it brings it back into the form:

Keyword:Directive Value

func (CommentText) Text

func (ct CommentText) Text() string

Text is like string, but includes the comment character ("//").

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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