Code Monkey home page Code Monkey logo

go-header's Introduction

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.yml linter you simply need to fill the next fields:

---
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:

values:
  const:
    key1: "value" 
  regexp:
    key2: "{{key1}} value1" # Reads as regex pattern "value value1"

Bult-in values

  • YEAR - Expects current year. Example header value: 2020. Example of template using: {{YEAR}} or {{year}}.
  • 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}}.

Execution

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:

go-header $(git diff --name-only | grep -E '.*\.go')

Setup example

Step 1

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

---
values:
  const:
    MY COMPANY: mycompany.com
template: |
  {{ 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 2

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.