GitHub Action for detecting and fixing linting errors
This action…
- Shows linting errors on GitHub PRs and commits
- Allows auto-fixing code style issues
- Supports many linters and formatters
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: push
jobs:
run-linters:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v1
# Install your dependencies here
- name: Run linters
uses: samuelmeuli/lint-action@v0.2
with:
github_token: ${{ secrets.github_token }}
# Enable your linters here
The GitHub token is required for creating checks on commits and pull requests. It's provided automatically by GitHub, so there's no need to define the secret on GitHub.
The action doesn't install the linters for you, you'll need to make sure they're installed in your CI environment. For example, if you'd like to use the Lint Action to check your code with ESLint, make sure it's declared as a dependency in your project's package.json
file and run npm install
before the action.
name: Lint
on: push
jobs:
run-linters:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v1
- name: Install Node.js and NPM
uses: actions/setup-node@v1
with:
node-version: 10
- name: Install dependencies
run: npm install
- name: Run linters
uses: samuelmeuli/lint-action@v0.2
with:
github_token: ${{ secrets.github_token }}
eslint: true
prettier: true
prettier_extensions: js,json,md,yml
name: Lint
on: push
jobs:
run-linters:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v1
- name: Install Python and pip
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install linters
run: pip install black flake8
- name: Run linters
uses: samuelmeuli/lint-action@v0.2
with:
github_token: ${{ secrets.github_token }}
black: true
flake8: true
All linters are disabled by default. To enable a linter, simply set the option with its name to true
. For example, if you'd like to enable ESLint:
- name: Run linters
uses: samuelmeuli/lint-action@v0.2
with:
github_token: ${{ secrets.github_token }}
eslint: true # Enables ESLint checks
[linter]
can be one of black
, eslint
, flake8
, gofmt
, golint
, prettier
, stylelint
, and swiftlint
:
[linter]
: Enables the linter in your repository. Default:false
[linter]_extensions
: Extensions of files to check with the linter. Example:eslint_extensions: js,ts
to lint both JavaScript and TypeScript files with ESLint. Default: Seeaction.yml
[linter]_dir
: Directory where the linting command should be run. Example:eslint_dir: server/
if ESLint is installed in theserver
subdirectory. Default:.
Besides the linter-specific options, there's a general auto_fix
setting:
auto_fix
: Whether linters should try to fix code style issues automatically. If some issues can be fixed, the action will commit and push the changes to the corresponding branch. Default:false
Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.
If you want to add support for an additional linter, please open an issue to discuss its inclusion in the project. Afterwards, you can follow these steps to add support for your linter:
- Clone the repository and install its dependencies with
yarn install
. - Create a new class for the linter, e.g.
src/linters/my-linter.js
. Have a look at the other files in that directory to see what functions the class needs to implement. - Import your class in the
src/linters/index.js
file. - Provide a sample project for the linter under
test/linters/projects/my-linter/
. It should be simple and contain a few linting errors which your tests will detect. - Provide the expected linting output for your sample project in a
test/linters/params/my-linter.js
file. Import this file intest/linters/linters.test.js
. You can run the tests withyarn test
. - Update the
action.yml
file with the options provided by the new linter. - Mention your linter in the
README.md
file.
- Electron Builder Action – GitHub Action for building and releasing Electron apps
- Maven Publish Action – GitHub Action for automatically publishing Maven packages