• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/workflows/H28-Dec-2020-3425

cmd/go-header/H28-Dec-2020-8866

version/H28-Dec-2020-224

.gitignoreH A D28-Dec-20206 11

.go-header.ymlH A D28-Dec-2020704 1915

LICENSEH A D28-Dec-202034.3 KiB675553

README.mdH A D28-Dec-20202.5 KiB8259

analyzer.goH A D28-Dec-20203.4 KiB147119

analyzer_test.goH A D28-Dec-20204.5 KiB178146

config.goH A D28-Dec-20202.6 KiB10074

go.modH A D28-Dec-2020193 118

go.sumH A D28-Dec-20202.8 KiB3231

issue.goH A D28-Dec-20201.1 KiB4926

location.goH A D28-Dec-2020962 3615

option.goH A D28-Dec-20201.1 KiB4522

reader.goH A D28-Dec-20202.2 KiB11786

value.goH A D28-Dec-20202.9 KiB12999

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