Skip to content

Commit 2ae637b

Browse files
committed
feat: add jest mutation to eslint
1 parent e08a2cf commit 2ae637b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/categories/js/eslint/config/default.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { prettierMutation } from '../eslint.utils';
1+
import { jestMutation, prettierMutation } from '../eslint.utils';
22
import { Config } from './config.interface';
33

44
export const defaultConfig: Config = {
@@ -12,7 +12,6 @@ export const defaultConfig: Config = {
1212
es6: true,
1313
node: true,
1414
browser: true,
15-
jest: true,
1615
},
1716
root: true,
1817
extends: ['eslint:recommended'],
@@ -21,5 +20,5 @@ export const defaultConfig: Config = {
2120
{ name: 'lint', script: 'eslint "src/**/*.js"' },
2221
{ name: 'lint:fix', script: 'eslint "src/**/*.js" --fix' },
2322
],
24-
mutations: [prettierMutation],
23+
mutations: [prettierMutation, jestMutation],
2524
};

src/categories/js/eslint/config/node:ts.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { prettierMutation } from '../eslint.utils';
1+
import { jestMutation, prettierMutation } from '../eslint.utils';
22
import { Config } from './config.interface';
33

44
export const nodeTsConfig: Config = {
@@ -14,7 +14,6 @@ export const nodeTsConfig: Config = {
1414
root: true,
1515
env: {
1616
node: true,
17-
jest: true,
1817
},
1918
ignorePatterns: ['.eslintrc.js'],
2019
rules: {
@@ -37,5 +36,5 @@ export const nodeTsConfig: Config = {
3736
{ name: 'lint', script: 'eslint "src/**/*.ts"' },
3837
{ name: 'lint:fix', script: 'eslint "src/**/*.ts" --fix' },
3938
],
40-
mutations: [prettierMutation],
39+
mutations: [prettierMutation, jestMutation],
4140
};

src/categories/js/eslint/eslint.utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isInstalledAndInRootCheck } from 'src/utils/installed';
2+
import { isJestInstalled } from '../jest/jest.utils';
23
import { isPrettierInstalled } from '../prettier/prettier.utils';
34
import { Config } from './config/config.interface';
45
import { CONFIG_FILE_NAME, SCRIPT_NAME } from './eslint.const';
@@ -9,6 +10,12 @@ export const prettierMutation = async (config: Config) => {
910
}
1011
};
1112

13+
export const jestMutation = async (config: Config) => {
14+
if (await isJestInstalled()) {
15+
config.eslintConfig.env = { ...config.eslintConfig.env, jest: true };
16+
}
17+
};
18+
1219
const addPrettierToConfig = (config: Config) => {
1320
const dependenciesSet = new Set([...config.dependencies, 'eslint-plugin-prettier', 'eslint-config-prettier']);
1421
const dependencies = Array.from(dependenciesSet);

0 commit comments

Comments
 (0)