Skip to content

Commit

Permalink
add clarifications into README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Tingajkin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Dec 28, 2020
1 parent 4f972cc commit 5c90e44
Showing 1 changed file with 40 additions and 36 deletions.
76 changes: 40 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ go get github.com/denis-tingajkin/go-header/cmd/go-header

## Configuration

To configuring `go-header.yml` linter you simply need to fill the next structures in YAML format.
```go
// 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"`
}
To configuring `.go-header.yml` linter you simply need to fill the next fields:

```yaml
---
temaplte: # expects header template string.
tempalte-path: # expects path to file with license header string.
values: # expects `const` or `regexp` node with values where values is a map string to string.
const:
key1: value1 # const value just checks equality. Note `key1` should be used in template string as {{ key1 }} or {{ KEY1 }}.
regexp:
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 }}.
```
Where `values` also can be used recursively. Example:

```yaml
values:
const:
key1: "value"
regexp:
key2: "{{key1}} value1" # Reads as regex pattern "value value1"
```
Where supported two kinds of values: `const` and `regexp`. NOTE: values can be used recursively.
Values ​​with type `const` checks on equality.
Values ​​with type `regexp` checks on the match.

## Bult-in values

Expand All @@ -36,7 +43,7 @@ Values ​​with type `regexp` checks on the match.

## Execution

`go-header` linter expects file path on input. If you want to run `go-header` only on diff files, then you can use this command.
`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:

```bash
go-header $(git diff --name-only | grep -E '.*\.go')
Expand All @@ -45,33 +52,30 @@ go-header $(git diff --name-only | grep -E '.*\.go')
## Setup example

### Step 1
Create configuration file `.go-header.yaml` in the root of project.

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

```yaml
---
values:
const:
MY COMPANY: mycompany.com
template-path: ./mypath/mytemplate.txt
```
template: |
{{ MY COMPANY }}
SPDX-License-Identifier: Apache-2.0
### Step 2
Write the template file. For example for config above `mytemplate.txt` could be
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:
```text
{{ MY COMPANY }}
SPDX-License-Identifier: Apache-2.0
http://www.apache.org/licenses/LICENSE-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.
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 {FILES}` from the root of the project.

### Step 2
You are ready! Execute `go-header ${PATH_TO_FILES}` from the root of the project.

0 comments on commit 5c90e44

Please sign in to comment.