@@ -8,10 +8,9 @@ import { CLI_NAME as ESLINT_CLI_NAME } from '../eslint/eslint.const';
8
8
import { isJestInstalled } from '../jest/jest.utils' ;
9
9
import { isEslintInstalled } from '../eslint/eslint.utils' ;
10
10
import { isStylelintInstalled } from '../stylelint/stylelint.utils' ;
11
- import { getPackageJson } from 'src/utils/npm' ;
12
11
import { STYLELINT_CLI_NAME } from '../stylelint/stylelint.const' ;
13
12
14
- type ScriptFileExtension = '*.js' | '*.ts' ;
13
+ type ScriptFileExtension = '*.js' | '*.ts' | '*.css' | '*.{ts,tsx}' ;
15
14
16
15
interface OptionMutation {
17
16
check : ( config : LintStagedConfig , key : string , value : string ) => boolean ;
@@ -43,13 +42,13 @@ const undefinedOptionMutation: OptionMutation = {
43
42
const optionMutations : OptionMutation [ ] = [ arrayOptionMutation , stringOptionMutation , undefinedOptionMutation ] ;
44
43
45
44
export const addOptionToLintStagedConfig = ( config : LintStagedConfig , key : string , value : string ) => {
46
- const finded = optionMutations . find ( ( { check } ) => check ( config , key , value ) ) ;
45
+ const found = optionMutations . find ( ( { check } ) => check ( config , key , value ) ) ;
47
46
48
- if ( ! finded ) {
47
+ if ( ! found ) {
49
48
throw new Error ( 'option mutator is not found!' ) ;
50
49
}
51
50
52
- finded . mutate ( config , key , value ) ;
51
+ found . mutate ( config , key , value ) ;
53
52
} ;
54
53
55
54
export const huskyIntegration = async ( ) => {
@@ -76,12 +75,10 @@ export const prettierMutation = async (config: LintStagedConfig) => {
76
75
}
77
76
} ;
78
77
79
- export const stylelintMutation = async ( config : LintStagedConfig ) => {
80
- if ( await isStylelintInstalled ( ) ) {
81
- const packageJson = await getPackageJson ( ) ;
82
- const react = packageJson ?. dependencies ?. [ 'react' ] ;
83
- const extensions = react ? '*.{css,js,jsx,ts,tsx}' : '*.css' ;
84
-
85
- addOptionToLintStagedConfig ( config , extensions , `${ STYLELINT_CLI_NAME } --fix` ) ;
86
- }
78
+ export const stylelintMutation = ( fileExtension : ScriptFileExtension ) => {
79
+ return async ( config : LintStagedConfig ) => {
80
+ if ( await isStylelintInstalled ( ) ) {
81
+ addOptionToLintStagedConfig ( config , fileExtension , `${ STYLELINT_CLI_NAME } --fix` ) ;
82
+ }
83
+ } ;
87
84
} ;
0 commit comments