-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint-staged.config.js
More file actions
42 lines (36 loc) · 1.2 KB
/
lint-staged.config.js
File metadata and controls
42 lines (36 loc) · 1.2 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
// Define file extensions
const TYPESCRIPT_EXTENSIONS = ['ts', 'mts', 'cts', 'tsx'];
const JAVASCRIPT_EXTENSIONS = ['js', 'mjs', 'cjs', 'jsx'];
// Construct glob patterns for lint-staged
const ALL_FILES = '*';
const TYPESCRIPT_FILES = `*.{${TYPESCRIPT_EXTENSIONS.join(',')}}`;
const JAVASCRIPT_FILES = `*.{${JAVASCRIPT_EXTENSIONS.join(',')}}`;
// Format code with Oxfmt
function buildOxfmtCommand(stagedFiles) {
return `oxfmt --no-error-on-unmatched-pattern ${stagedFiles.join(' ')}`;
}
// Check and fix code with Oxlint
function buildOxlintCommand(stagedFiles) {
return `oxlint ${stagedFiles.join(' ')}`;
}
// Type check with TypeScript
function buildTypeCheckCommand() {
return 'tsc --noEmit';
}
/**
* Lint staged files
* @description Run commands on staged files based on their types
* @type {import('lint-staged').Configuration}
*/
const lintStagedConfig = {
[ALL_FILES]: function (stagedFiles) {
return [buildOxfmtCommand(stagedFiles)];
},
[JAVASCRIPT_FILES]: function (stagedFiles) {
return [buildOxlintCommand(stagedFiles)];
},
[TYPESCRIPT_FILES]: function (stagedFiles) {
return [buildTypeCheckCommand(), buildOxlintCommand(stagedFiles)];
},
};
export default lintStagedConfig;