• Stars
    star
    568
  • Rank 78,234 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 25 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โœจ GitHub Action for detecting and auto-fixing lint errors

โœจ Lint Action

Note: The behavior of actions like this one is currently limited in the context of forks. See Limitations.

Screenshots

  • Checks on pull requests:

    Screenshot of check runs
  • Commit annotations:

    Screenshot of ESLint annotations

Supported tools

Usage

Create a new GitHub Actions workflow in your project, e.g. at .github/workflows/lint.yml. The content of the file should be in the following format:

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  # Replace pull_request with pull_request_target if you
  # plan to use this action with forks, see the Limitations section
  pull_request:
    branches:
      - main

# Down scope as necessary via https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
  checks: write
  contents: write

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      # Install your linters here

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          # Enable your linters here

Examples

All linters are disabled by default. To enable a linter, simply set the option with its name to true, e.g. eslint: true.

The action doesn't install the linters for you; you are responsible for installing them in your CI environment.

JavaScript example (ESLint and Prettier)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v1
        with:
          node-version: 12

      # ESLint and Prettier must be in `package.json`
      - name: Install Node.js dependencies
        run: npm ci

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          eslint: true
          prettier: true

Important: Make sure to exclude the .github directory in your ESLint and Prettier configs as the default GITHUB_TOKEN cannot be used to update workflow files due to the missing workflow permission. See Limitations.

PHP example (PHP_CodeSniffer)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.4"
          coverage: none
          tools: phpcs

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          php_codesniffer: true
          # Optional: Ignore warnings
          php_codesniffer_args: "-n"

If you prefer to use Composer you can also use this:

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "7.4"
          coverage: none
          tools: composer

      - name: Install PHP dependencies
        run: |
          composer install --prefer-dist --no-progress --no-ansi --no-interaction
          echo "${PWD}/vendor/bin" >> $GITHUB_PATH

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          php_codesniffer: true

Python example (Flake8 and Black)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.8

      - name: Install Python dependencies
        run: pip install black flake8

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          black: true
          flake8: true

C, C++, Objective-C and Objective-C++ example (clang_format)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Install ClangFormat
        run: sudo apt-get install -y clang-format

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          clang_format: true

C# and VB.NET example (dotnet_format)

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up .NET
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: "6.0.x"

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          dotnet_format: true

AutoFix example

name: Lint

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.8

      - name: Install Python dependencies
        run: pip install black flake8

      - name: Run linters
        uses: wearerequired/lint-action@v2
        with:
          auto_fix: true
          black: true
          black_auto_fix: true
          flake8: true
          flake8_auto_fix: false

With auto_fix set to true, by default the action will try and fix code issues automatically and commit and push them automatically. Here however, flake8 linter does not support auto-fixing, so setting flake8_auto_fix to false will prevent any unnecessary warnings.

Configuration

Linter-specific options

[linter] can be one of autopep8, black, clang_format, dotnet_format, erblint, eslint, flake8, gofmt, golint, mypy, oitnb, php_codesniffer, prettier, pylint, rubocop, stylelint, swift_format_official, swift_format_lockwood, swiftlint and xo:

  • [linter]: Enables the linter in your repository. Default: false
  • [linter]_args: Additional arguments to pass to the linter. Example: eslint_args: "--max-warnings 0" if ESLint checks should fail even if there are no errors and only warnings. Default: ""
  • [linter]_dir: Directory where the linting command should be run. Example: eslint_dir: server/ if ESLint is installed in the server subdirectory. Default: Repository root
  • [linter]_extensions: Extensions of files to check with the linter. Example: eslint_extensions: js,ts to lint JavaScript and TypeScript files with ESLint. Default: Varies by linter, see action.yml
  • [linter]_command_prefix: Command prefix to be run before the linter command. Default: "".
  • [linter]_auto_fix: Whether the linter should try to fix code style issues automatically. This option is useful to commit and push changes only for specific linters and not all of them when auto_fix option is set. Default: true if linter supports auto-fixing, false if not.

General options

  • github_token: The GITHUB_TOKEN to authenticate on behalf of GitHub Actions. Defaults to the GitHub token.

  • continue_on_error: Whether the workflow run should also fail when linter failures are detected. Default: true

  • auto_fix: Whether linters should try to fix code style issues automatically. If some issues can be fixed, the action will apply the needed changes. Default: false

    Screenshot of auto-fix commit

  • commit: Whether to commit and push the changes made by auto_fix. Default: true

  • git_name: Username for auto-fix commits. Default: "Lint Action"

  • git_email: Email address for auto-fix commits. Default: "[email protected]"

  • git_no_verify: Bypass the pre-commit and pre-push git hooks. Default: false

  • commit_message: Template for auto-fix commit messages. The ${linter} variable can be used to insert the name of the linter. Default: "Fix code style issues with ${linter}"

  • check_name: Template for the name of the check run. Use this to ensure unique names when the action is used more than once in a workflow. The ${linter} and ${dir} variables can be used to insert the name and directory of the linter. Default: "${linter}"

  • neutral_check_on_warning: Whether the check run should conclude with a neutral status instead of success when the linter finds only warnings. Default: false

Linter support

Some options are not available for specific linters:

Linter auto-fixing extensions
autopep8 โœ… โŒ (py)
black โœ… โœ…
clang_format โœ… โœ…
clippy โœ… โŒ (rs)
dotnet_format โœ… โŒ (cs)
erblint โŒ โŒ (erb)
eslint โœ… โœ…
flake8 โŒ โœ…
gofmt โœ… โŒ (go)
golint โŒ โŒ (go)
mypy โŒ โŒ (py)
oitnb โœ… โœ…
php_codesniffer โŒ โœ…
prettier โœ… โœ…
pylint โŒ โŒ (py)
rubocop โœ… โŒ (rb)
rustfmt โœ… โŒ (rs)
stylelint โœ… โœ…
swift_format_official โœ… โœ…
swift_format_lockwood โœ… โŒ (swift)
swiftlint โœ… โŒ (swift)
tsc โŒ โŒ (ts)
xo โœ… โœ…

Limitations

Pull requests

There are currently some limitations as to how this action (or any other action) can be used in the context of pull_request events from forks:

  • The action doesn't have permission to push auto-fix changes to the fork. This is because the pull_request event runs on the upstream repo, where the github_token is lacking permissions for the fork. Source
  • The action doesn't have permission to create annotations for commits on forks unless you use the pull_request_target event. You can modify the default permissions granted to the GITHUB_TOKEN by using the permissions key and set the checks scope to write. See GitHub documentation for more.

Auto-fixing workflow files

If auto_fix is enabled and the default GITHUB_TOKEN is used, none of the linters should be allowed to change files in .github/workflows as the token doesn't have the necessary workflow permission. This can be achieved by adding the directory to the ignore config of the used linter. Source

For details and comments, please refer to #65 and #74.


a required open source product - let's get in touch

More Repositories

1

required-foundation

DISCONTINUED: A responsive parent theme for WordPress, based on the fantastic Foundation framework.
PHP
147
star
2

git-mirror-action

โญ A GitHub Action for mirroring a git repository to another location via SSH.
Shell
143
star
3

traduttore

๐Ÿ—ผ A WordPress plugin to improve the I18N workflow for your own projects based on @GlotPress.
PHP
72
star
4

admin-menu-manager

Manage the WordPress admin menu using a simple drag & drop interface.
JavaScript
61
star
5

user-feedback

Collect user feedback directly from your WordPress site
PHP
52
star
6

required-starter

DISCONTINUED: A sample child theme for required+ Foundation, the responsive WordPress parent theme based on Foundation.
PHP
23
star
7

slack-messaging-action

๐Ÿ’Œ A GitHub Action for sending (and updating) messages of any layout and formatting from GitHub Actions to Slack.
JavaScript
20
star
8

required-foundation-shortcodes

DISCONTINUED: A collection of WordPress shortcode plugins for themes based on Foundation.
19
star
9

wp-cli-clear-opcache

๐Ÿ”ง Use WP-CLI to clear the OPcache for a site via HTTP.
PHP
17
star
10

wp-team-list

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ง A WordPress plugin to display your teammates (users) anywhere on your WordPress site.
PHP
17
star
11

WP-Widget-Disable

๐Ÿ–ผ A WordPress plugin that allows you to disable Sidebar and Dashboard Widgets.
PHP
17
star
12

required-email-notifications

WordPress plugin to handle email notifications with custom adapters like Mandrill or Sendgrid
PHP
14
star
13

harvest-api-php-client

โฑ PHP client library for the Harvest REST API v2.
PHP
14
star
14

custom-menu-item-types

Additional menu item types that can be easily added to the menu like line breaks and titles.
PHP
14
star
15

wp-requirements-check

Simple drop-in library for WordPress plugins to check for PHP and WordPress version requirements
PHP
14
star
16

traduttore-registry

Allows loading translation files from a custom GlotPress site running Traduttore
PHP
13
star
17

coding-standards

๐Ÿ’ป required coding standards for PHP, JavaScript and CSS.
JavaScript
11
star
18

rest-likes

A simple post like plugin that uses the WP REST API for endorsing posts & pages.
PHP
11
star
19

simple-user-adding

A WordPress plugin that makes adding new users to your site easier than ever.
PHP
11
star
20

local-google-fonts

Get Google Fonts for local hosting.
TypeScript
10
star
21

digest

๐Ÿ“ง Get a daily/weekly/monthly digest of what's happening on your WordPress site instead of receiving a single email each time.
PHP
10
star
22

composer-wp-config

๐Ÿงƒ Composer plugin to create a wp-config.php when installing WordPress.
PHP
9
star
23

hide-jetpack-promotions

WordPress plugin to remove all admin notices for promotions added by Jetpack.
PHP
8
star
24

wp-feed-post-thumbnail

๐Ÿž๏ธ WordPress Plugin to add MRSS namespace to RSS2 feed and featured image to the RSS2 feed item.
PHP
7
star
25

common-php

Common PHP components used by our WordPress plugins.
PHP
6
star
26

translations-cache

WordPress mu-plugin to reduces file reads for translations by caching the first read via APCu.
PHP
6
star
27

required-google-analytics

A lightweight WordPress plugin to add Google's analytics.js to your site, the modern way.
PHP
5
star
28

filename-normalizer

Normalizes filenames before they are uploaded.
PHP
5
star
29

h2push

Sends Link headers to bring HTTP/2 Server Push for scripts and styles to WordPress.
PHP
5
star
30

composer-deployer

๐Ÿš€ Composer plugin to create a deployer config (deploy.php) with custom deployment tasks.
PHP
5
star
31

private-page-login

Redirects non-logged in visitors to a private page to the login page.
PHP
4
star
32

required-wp-rating

WordPress plugin to make ratings for every post / page.
PHP
4
star
33

composer-scripts

๐Ÿงฐ A collection of useful Composer scripts and commands, especially for WordPress projects.
PHP
4
star
34

.github

Repository for GitHub stuff like workflow templates.
3
star
35

post-header-image

WordPress plugin for adding a custom header image to posts. Only supports the block editor.
JavaScript
2
star
36

capistrano-wearerequired

Collection of recipes and tasks specialized on WordPress deployment.
Ruby
2
star
37

rest-api-same-origin

WordPress plugin to limit the Access-Control-Allow-Origin header to only allowed origins.
PHP
1
star
38

jquery-light

Removes jQuery Migrate from the list of jQuery dependencies and allows jQuery to enqueue before `</body>` instead of in the `<head>`.
PHP
1
star
39

register-default-theme-directory

Must-use plugin: Registers the theme directory for default WordPress themes.
PHP
1
star
40

user-roles-adjustments

Custom functionality for user editing in combination with the Members plugin. Retains user levels and limits user editing capabilities.
PHP
1
star
41

members-unfiltered-html

WordPress mu-plugin which allows to add the `unfiltered_html` capability to a role in a multisite install via Members
PHP
1
star
42

required-wp-top-content

WordPress plugin for getting analytics data for posts & pages.
PHP
1
star
43

lint-action-test

Test repo for https://github.com/wearerequired/lint-action
JavaScript
1
star
44

harvest-chrome

Harvest Chrome extension with Helpscout support
JavaScript
1
star
45

required-foundation-column-shortcode

DISCONTINUED: Shortcode plugin to create columns according to the grid of Foundation in the required+ Foundation theme.
PHP
1
star
46

required-tobii

A WordPress plugin to implement lightbox functionality for images and galleries.
PHP
1
star