lint-staged.config.js 1.1 KB
Newer Older
1
const path = require('path');
2
const fs = require('fs');
3

4
module.exports = {
5
    // lint all files when global package.json or eslint config changes.
6 7
    './(package.json|.eslintrc.js)': () =>
        `eslint --ext .tsx,.jsx.ts,.js --ignore-path ${path.join(__dirname, '.gitignore')} ${__dirname}`,
8 9

    // check types when ts file or package.json changes.
10
    './(packages/*/package.json|packages/*/**/*.ts?(x))': filenames =>
11 12
        [
            ...new Set(
13
                filenames.map(filename => path.relative(path.join(__dirname, 'packages'), filename).split(path.sep)[0])
14
            )
15
        ]
16 17 18 19 20 21 22 23
            .map(p => path.join(__dirname, 'packages', p, 'tsconfig.json'))
            .filter(p => {
                try {
                    return fs.statSync(p).isFile();
                } catch (e) {
                    return false;
                }
            })
24 25 26
            .map(p => `tsc -p ${p} --noEmit`),

    // lint changed files
27 28 29 30
    '**/*.(j|t)s?(x)': filenames => [
        `eslint ${filenames.join(' ')}`,
        `yarn test --silent --bail --findRelatedTests ${filenames.join(' ')}`
    ]
31
};