Packages

lint-staged

lint-staged repositoryView Repository
This package is used by the current site.

This package gives us a simple way to ensure all staged files have been linted.

Setup

yarn add -D lint-staged
lintstagedrc.js
const path = require('path')
 
const buildEslintCommand = (filenames) =>
  `next lint --fix --file ${filenames
    .map((f) => path.relative(process.cwd(), f))
    .join(' --file ')}`
 
module.exports = {
  '*.{js,jsx,ts,tsx}': [buildEslintCommand],
}

Automating via Husky

This pre-commit hook, ensures that all staged files have been linted through lint-staged.

./husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
 
yarn lint-staged