generated from cp-20/nextjs-with-mantine-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.lintstagedrc.js
29 lines (25 loc) · 915 Bytes
/
.lintstagedrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const path = require('path');
const { ESLint } = require('eslint');
const buildEslintCommand = (filenames) =>
`next lint --fix --file ${filenames
.map((f) => path.relative(process.cwd(), f))
.join(' --file ')}`;
const removeIgnoredFiles = async (files) => {
const eslint = new ESLint();
const isIgnored = await Promise.all(
files.map((file) => {
return eslint.isPathIgnored(file);
}),
);
const filteredFiles = files.filter((_, i) => !isIgnored[i]);
return filteredFiles.join(' ');
};
const buildCommand = (command) => async (filenames) => {
const filteredFiles = await removeIgnoredFiles(filenames);
return `${command} ${filteredFiles}`;
};
module.exports = {
'*.{js,jsx,ts,tsx}': [buildEslintCommand, buildCommand('pnpm stylelint')],
'*.{js,jsx,ts,tsx,css,scss}': buildCommand('pnpm stylelint'),
'*.{css,scss,js,jsx,ts,tsx,json,md}': buildCommand('pnpm format'),
};