goheader

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

README

go-header

Actions Status

Go source code linter providing checks for license headers.

Installation

For installation you can simply use go get.

go get github.com/denis-tingajkin/go-header/cmd/go-header

Configuration

To configuring go-header.yaml linter you simply need to fill the next structures in YAML format.

// Configuration represents go-header linter setup parameters
type Configuration struct {
	// Values is map of values. Supports two types 'const` and `regexp`. Values can be used recursively.
	Values       map[string]map[string]string `yaml:"values"'`
	// Template is template for checking. Uses values.
	Template     string                       `yaml:"template"`
	// TemplatePath path to the template file. Useful if need to load the template from a specific file.
	TemplatePath string                       `yaml:"template-path"`
}

Examples

Step 1

Create configuration file .go-header.yaml in the root of project.

---
values:
  const:
    MY COMPANY: mycompany.com
template-path: ./mypath/mytemplate.txt

Step 2

Write the template file. For example for config above mytemplate.txt could be

{{ MY COMPANY }}
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Step 3

You are ready! Execute go-header from the root of the project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer interface {
	Analyze(file *ast.File) Issue
}

func New

func New(options ...AnalyzerOption) Analyzer

type AnalyzerOption

type AnalyzerOption interface {
	// contains filtered or unexported methods
}

func WithTemplate

func WithTemplate(template string) AnalyzerOption

func WithValues

func WithValues(values map[string]Value) AnalyzerOption

type Calculable

type Calculable interface {
	Calculate(map[string]Value) error
	Get() string
}

type Configuration

type Configuration struct {
	// Values is map of values. Supports two types 'const` and `regexp`. Values can be used recursively.
	Values map[string]map[string]string `yaml:"values"'`
	// Template is template for checking. Uses values.
	Template string `yaml:"template"`
	// TemplatePath path to the template file. Useful if need to load the template from a specific file.
	TemplatePath string `yaml:"template-path"`
}

Configuration represents go-header linter setup parameters

func (*Configuration) GetTemplate

func (c *Configuration) GetTemplate() (string, error)

func (*Configuration) GetValues

func (c *Configuration) GetValues() (map[string]Value, error)

func (*Configuration) Parse

func (c *Configuration) Parse(p string) error

type ConstValue

type ConstValue struct {
	RawValue string
}

func (*ConstValue) Calculate

func (c *ConstValue) Calculate(values map[string]Value) error

func (*ConstValue) Get

func (c *ConstValue) Get() string

func (*ConstValue) Read

func (c *ConstValue) Read(s Reader) Issue

type Issue

type Issue interface {
	Location() Location
	Message() string
}

func NewIssue

func NewIssue(msg string) Issue

func NewIssueWithLocation

func NewIssueWithLocation(msg string, location Location) Issue

type Location

type Location struct {
	Line     int
	Position int
}

func (Location) String

func (l Location) String() string

type Reader

type Reader interface {
	Peek() rune
	Next() rune
	Done() bool
	Finish() string
	Position() int
	Location() Location
	SetPosition(int)
	ReadWhile(func(rune) bool) string
}

func NewReader

func NewReader(text string) Reader

type RegexpValue

type RegexpValue struct {
	RawValue string
}

func (*RegexpValue) Calculate

func (r *RegexpValue) Calculate(values map[string]Value) error

func (*RegexpValue) Get

func (r *RegexpValue) Get() string

func (*RegexpValue) Read

func (r *RegexpValue) Read(s Reader) Issue

type Value

type Value interface {
	Calculable
	Read(Reader) Issue
}

Directories

Path Synopsis
cmd
go-header command

Jump to

Keyboard shortcuts

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