Giter Site home page Giter Site logo

yemchenko-dan / linelint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fernandrone/linelint

0.0 0.0 0.0 83 KB

Linter that validates simple newline and whitespace rules in all sorts of files.

License: MIT License

Go 97.79% Dockerfile 2.21%

linelint's Introduction

linelint

lint Build Status Go Report Card

A linter that validates simple newline and whitespace rules in all sorts of files. It can:

  • Recursively check a directory tree for files that do not end in a newline
  • Automatically fix these files by adding a newline or trimming extra newlines

Very useful in avoiding these warnings from GitHub ๐Ÿ‘‡

Install

Check the Releases page for the latest version for your platform.

Alternatively, use go get to build from HEAD (might be unstable).

go get github.com/fernandrone/linelint

See the #GitHub Actions and the #Docker for their respective setup instructions.

Usage

This is a project in development. Use it at your own risk!

Executing the binary will automatically search the local directory tree for linting errors.

$ linelint .
[EOF Rule] File "LICENSE" has lint errors
[EOF Rule] File "linter/eof.go" has lint errors

Total of 2 lint errors!

Pass a list of files or directories to limit your search.

$ linelint README.md LICENSE linter/config.go
[EOF Rule] File "LICENSE" has lint errors

Total of 1 lint errors!

After checking all files, in case any rule has failed, Linelint will finish with an error (exit code 1).

AutoFix

If the autofix option is set to true (it is false by default, activate it with the -a flag or set it in the configuration file), Linelint will attempt to fix any linting error by rewriting the file.

$ linelint -a .
[EOF Rule] File "LICENSE" has lint errors
[EOF Rule] File "LICENSE" lint errors fixed
[EOF Rule] File "linter/eof.go" has lint errors
[EOF Rule] File "linter/eof.go" lint errors fixed

If all files are fixed successfully, Linelint terminates with exit code 0.

Stdin

Pass "-" as an argument to read data from standard input instead of a list of files.

$ cat hello.txt
Hello World

$ cat hello.txt | linelint -
Hello World

When reading from stdin, linelint behavior changes and it won't report lint errors. Instead when autofix is on, it will fix them and output the result to /dev/stdout. When autofix is off, it will terminate the program with an error code in case there are any linting violations, but won't output anything.

Help

At any time run linenlint --help for a list of available command line arguments.

Configuration

Create a .linelint.yml file in the same working directory you run linelint to adjust your settings. See .linelint.yml for an up-to-date example.

Rules

Right now it supports only a single rule, "End of File", which is enabled by default.

EndOfFile

The End of File rule checks if the file ends in a newline character, or \n. You may find it useful if you dislike seeing these ๐Ÿšซ symbols at the end of files on GitHub Pull Requests.

By default it also checks if it strictly ends in a single newline character. This behavior can be disabled by setting the single-new-line parameter to false.

rules:
  # checks if file ends in a newline character
  end-of-file:
    # set to true to enable this rule
    enable: true

    # set to true to disable autofix (if enabled globally)
    disable-autofix: false

    # will be ignored only by this rule
    ignore:
      - README.md

    # if true also checks if file ends in a single newline character
    single-new-line: true

GitHub Actions

This project is available at the GitHub Actions Marketplace.

Create a workflow file at your repository's Workflow folder, like .github/workflows/lint.yml (see lint.yml for an updated example):

# .github/workflows/main.yml
on: [push]
name: lint

jobs:
  linelint:
    runs-on: ubuntu-latest
    name: Check if all files end in newline
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Linelint
        uses: actions/linelint@master
        id: linelint

This will trigger a validation of all your files. Configure it using a .linelint.yml file at the root of your repository. See #Configuration for more information.

Docker

Public Docker images exist at docker.io/fernandrone/linelint. To use it, share any files or directories you want linted with the container's /data directory.

docker run -it -v $(pwd):/data fernandrone/linelint

To add a configuration file, share it with the root volume of the container:

docker run -it -v $(pwd)/.linelint.yml:/.linelint.yml -v $(pwd):/data fernandrone/linelint

linelint's People

Contributors

fernandrone avatar

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.