Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
align-justify

GitHub Action

Linelint

0.0.3 Pre-release

Linelint

align-justify

Linelint

A linter that validates simple newline and whitespace rules in all sorts of files

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Linelint

uses: fernandrone/[email protected]

Learn more about this action in fernandrone/linelint

Choose a version

linelint

Build Status

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

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

Very useful in avoiding these warnings from GitHub 👇

Install

See 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!

To run it locally, execute the binary and pass a list of file or directories as argument.

$ linelint .
[EOF Rule] File "LICENSE" has lint errors
[EOF Rule] Ignoring file "README.md": in rule ignore path
[EOF Rule] File "linter/eof.go" has lint errors

Total of 2 lint errors!

Or:

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

Total of 1 lint errors!

In case any rule fails, Linelint will fail with an error (exit code 1).

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

$ linelint -a .
[EOF Rule] File "LICENSE" has lint errors
[EOF Rule] File "LICENSE" lint errors fixed
[EOF Rule] Ignoring file "README.md": in rule ignore path
[EOF Rule] File "linter/eof.go" has lint errors
[EOF Rule] File "linter/eof.go" lint errors fixed

When all files are fixed successfully, Linelint terminates with with a success as well (exit code 0).

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 only supports a single rule, "End of File", which is enabled by default.

EndOfFile

EndOfFileRule checks if the file ends in a newline character, or \n. You may find this rule useful if you dislike seeing these 🚫 symbols at the end of files on GitHub Pull Requests.

By default it also checks if it ends strictly 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 it is enabled globally)
    disable-autofix: false

    # will merge with global configuration
    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/main.yml (see main.yml for an updated example):

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

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