One Linter to Rule Them All

One linter to bind them. Okay, okay. Jokes aside. Linting should be easy. Here at InfernoRed Technology, we work on many different technologies. This can lead to lots of variations in how linting or code checking works. I've been searching for an easy way to lint multiple projects with a similar process and lead to a similar quality. Here are two of the solutions I've come across. Happy coding!

GitHub's Super Linter

GitHub - super-linter/super-linter: Combination of multiple linters to run as a GitHub Action or standalone
Combination of multiple linters to run as a GitHub Action or standalone - GitHub - super-linter/super-linter: Combination of multiple linters to run as a GitHub Action or standalone

GitHub's SuperLinter has been around since 2020, but not everyone has heard of it. The pitch was simple. One linter to rule them all. Only install one linter and it'll lint all your various different types of code. From Kotlin to Typescript, this linter has it all.

Keep in mind you can still use the customization on many of your favorite linters. For example, you can still have a custom eslintrc. This just reduces the setup on having the linter run on CI.

Introducing GitHub Super Linter: one linter to rule them all
Setting up a new repository with all the right linters for the different types of code can be time consuming and tedious. So many tools and configurations to choose from and often more than one linter is needed to cover all the languages used. The GitHub Super Linter was built out of necessity by the […]

Quick Setup on GitHub

  1. Create a workflow file named super-linter.yml in .github/workflows
  2. Copy the code below and commit file to a branch.
    Note: Be sure to pin the versions with git hashes and use the latest version.
  3. Merge your branch to your main
  4. You're done! 🎉
name: SuperLinter

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

permissions: read-all

jobs:
  build:
    name: Lint
    runs-on: ubuntu-latest

    permissions:
      contents: read
      packages: read
      statuses: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Super-linter
        uses: super-linter/super-linter@v6.0.0 # NOTE: Update with hash
        env:
          DEFAULT_BRANCH: main
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/super-linter.yml

Ox Security's MegaLinter

🦙 MegaLinter analyzes 48 languages, 22 formats, 19 tooling formats, excessive copy-pastes and spelling mistakes in your repository sources with a GitHub Action, other CI tools or locally.
🦙 MegaLinter analyzes 48 languages, 22 formats, 19 tooling formats, excessive copy-pastes and spelling mistakes in your repository sources with a GitHub Action, other CI tools or locally.

Well, if SuperLinter is so good, why would you need anything else? There's a couple gaps that SuperLinter doesn't fill. MegaLinter has their own comparison here, but I noticed some of these items are already out of date. For example, C++ has recently been added to SuperLinter. For many, I think the reason will be simple. It has both Android (Kotlin) and iOS (Swift). I think swiftlint is the biggest missing component of SuperLinter. However, feel free to compare SuperLinter's list against MegaLinter's below.

List of the 100+ supported linters embedded in MegaLinter
Full list of all linters for all languages and formats that are available in MegaLinter

Quick Setup for GitHub

  1. Create a workflow file named mega-linter.yml in .github/workflows
  2. Copy the code below and commit file to a branch.
    Note: Be sure to pin the versions with git hashes and use the latest version.
  3. Merge your branch to your main
  4. You're done! 🎉
name: MegaLinter

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

permissions: read-all

jobs:
  build:
    name: Lint
    runs-on: ubuntu-latest

    permissions:
      contents: write
      issues: write
      pull-requests: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          fetch-depth: 0

      - name: MegaLinter
        uses: oxsecurity/megalinter@v7 # NOTE: Update with hash
        env:
          VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/mega-linter.yml

Quicker Setup

MegaLinter comes with an assisted setup for an even quick setup. Just run this command and follow the prompts to setup MegaLinter for your codebase with your CI of choice such as GitHub Actions, GitLab CI, Azure Pipelines, BitBucket Pipelines, Jenkins and so much more.

npx mega-linter-runner --install

Closing Notes

Thanks for taking the time to read this quick way to improve linters for your team. I hope that this can help your teams be more consistent together. Curious about tweaks you could make to these linters specific to your teams? Reach out to the InfernoRed Technology team.