README.md
1# go-header
2[![Actions Status](https://github.com/denis-tingajkin/go-header/workflows/ci/badge.svg)](https://github.com/denis-tingajkin/go-header/actions)
3
4Go source code linter providing checks for license headers.
5
6## Installation
7
8For installation you can simply use `go get`.
9
10```bash
11go get github.com/denis-tingajkin/go-header/cmd/go-header
12```
13
14## Configuration
15
16To configuring `.go-header.yml` linter you simply need to fill the next fields:
17
18```yaml
19---
20temaplte: # expects header template string.
21tempalte-path: # expects path to file with license header string.
22values: # expects `const` or `regexp` node with values where values is a map string to string.
23 const:
24 key1: value1 # const value just checks equality. Note `key1` should be used in template string as {{ key1 }} or {{ KEY1 }}.
25 regexp:
26 key2: value2 # regexp value just checks regex match. The value should be a valid regexp pattern. Note `key2` should be used in template string as {{ key2 }} or {{ KEY2 }}.
27```
28
29Where `values` also can be used recursively. Example:
30
31```yaml
32values:
33 const:
34 key1: "value"
35 regexp:
36 key2: "{{key1}} value1" # Reads as regex pattern "value value1"
37```
38
39## Bult-in values
40
41- **YEAR** - Expects current year. Example header value: `2020`. Example of template using: `{{YEAR}}` or `{{year}}`.
42- **YEAR-RANGE** - Expects any valid year interval or current year. Example header value: `2020` or `2000-2020`. Example of template using: `{{year-range}}` or `{{YEAR-RANGE}}`.
43
44## Execution
45
46`go-header` linter expects file paths on input. If you want to run `go-header` only on diff files, then you can use this command:
47
48```bash
49go-header $(git diff --name-only | grep -E '.*\.go')
50```
51
52## Setup example
53
54### Step 1
55
56Create configuration file `.go-header.yml` in the root of project.
57
58```yaml
59---
60values:
61 const:
62 MY COMPANY: mycompany.com
63template: |
64 {{ MY COMPANY }}
65 SPDX-License-Identifier: Apache-2.0
66
67 Licensed under the Apache License, Version 2.0 (the "License");
68 you may not use this file except in compliance with the License.
69 You may obtain a copy of the License at:
70
71 http://www.apache.org/licenses/LICENSE-2.0
72
73 Unless required by applicable law or agreed to in writing, software
74 distributed under the License is distributed on an "AS IS" BASIS,
75 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76 See the License for the specific language governing permissions and
77 limitations under the License.
78```
79
80### Step 2
81You are ready! Execute `go-header ${PATH_TO_FILES}` from the root of the project.
82