Skip to content

Commit

Permalink
feature: Migrate jest config to flat config format
Browse files Browse the repository at this point in the history
  • Loading branch information
Karibash committed Jul 29, 2024
1 parent 583d03e commit 5adb24f
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 89 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-toes-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@agaroot/eslint-config-jest": major
---

Migrate jest config to flat config format
9 changes: 0 additions & 9 deletions packages/jest/.eslintrc.cjs

This file was deleted.

46 changes: 22 additions & 24 deletions packages/jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,35 @@ Use this setting to ensure consistent code writing and maintain high code qualit
## 🚀 Installation

```shell
$ npm install -D @agaroot/eslint-config-jest
npm install -D eslint @agaroot/eslint-config-common @agaroot/eslint-config-definer @agaroot/eslint-config-javascript @agaroot/eslint-config-jest

# Needs install peer dependencies
$ npm install -D eslint-plugin-jest
# If you are using TypeScript, install the following package.
npm install -D @agaroot/eslint-config-typescript
```

## 👏 Getting Started

Create a `.eslintrc.js` file in the root directory of your project, and add `@agaroot/eslint-config-jest` to the `extends` array.

The following is the recommended configuration when using TypeScript.
Create a `eslint.config.js` file in the root directory of your project.

```js
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: [
'@agaroot/eslint-config-common',
'@agaroot/eslint-config-jest',
],
parserOptions: {
project: './tsconfig.json',
},
settings: {
'import/resolver': {
typescript: {
project: './tsconfig.json',
},
},
},
};
import { common } from '@agaroot/eslint-config-common';
import { define } from '@agaroot/eslint-config-definer';
import { javascript } from '@agaroot/eslint-config-javascript';
import { jest } from '@agaroot/eslint-config-jest';
import { typescript } from '@agaroot/eslint-config-typescript';

const config = define([
common,
javascript,
jest,
// If you are using TypeScript, add the following line.
typescript,
]);

export default config({
// If you are using TypeScript, add the following line.
tsconfigPath: './tsconfig.json',
});
```

## 🤝 Contributing
Expand Down
14 changes: 14 additions & 0 deletions packages/jest/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { common } from '@agaroot/eslint-config-common';
import { define } from '@agaroot/eslint-config-definer';
import { javascript } from '@agaroot/eslint-config-javascript';
import { typescript } from '@agaroot/eslint-config-typescript';

const config = define([
common,
javascript,
typescript,
]);

export default config({
tsconfigPath: './tsconfig.json',
});
27 changes: 0 additions & 27 deletions packages/jest/index.cjs

This file was deleted.

48 changes: 37 additions & 11 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@agaroot/eslint-config-jest",
"type": "module",
"version": "2.1.2",
"description": "ESLint config for AGAROOT",
"keywords": [
Expand All @@ -19,27 +20,52 @@
"url": "git+https://github.com/agaroot-technologies/eslint-config.git"
},
"license": "MIT",
"main": "index.cjs",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"exports": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"files": [
"index.cjs",
"dist",
"LICENSE",
"README.md"
],
"scripts": {
"lint": "eslint . --ext .js,.cjs"
"build": "pkgroll",
"lint": "eslint ."
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.17.0",
"eslint-plugin-jest": "^28.6.0",
"globals": "^15.8.0"
},
"devDependencies": {
"@agaroot/eslint-config-common": "workspace:*",
"@typescript-eslint/eslint-plugin": "7.17.0",
"@typescript-eslint/parser": "7.17.0",
"@agaroot/eslint-config-definer": "workspace:*",
"@agaroot/eslint-config-javascript": "workspace:*",
"@agaroot/eslint-config-typescript": "workspace:*",
"@tsconfig/strictest": "2.0.5",
"@types/eslint": "8.56.11",
"eslint": "8.57.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "28.6.0",
"eslint-plugin-unused-imports": "3.2.0"
"pkgroll": "2.4.1"
},
"peerDependencies": {
"eslint": "^8.0.0",
"eslint-plugin-jest": "^28.0.0"
"@agaroot/eslint-config-common": "workspace:*",
"@agaroot/eslint-config-javascript": "workspace:*",
"@agaroot/eslint-config-typescript": "workspace:*",
"eslint": "^8.0.0"
},
"peerDependenciesMeta": {
"@agaroot/eslint-config-typescript": {
"optional": true
}
}
}
19 changes: 19 additions & 0 deletions packages/jest/src/configurators/globals-configurator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import g from 'globals';

import { files } from '../files';

import type { Configurator } from '@agaroot/eslint-config-definer';

export const globalsConfigurator: Configurator = () => {
return [
{
name: 'agaroot/jest/globals',
files,
languageOptions: {
globals: {
...g.jest,
},
},
},
];
};
33 changes: 33 additions & 0 deletions packages/jest/src/configurators/jest-configurator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import eslintPluginJest from 'eslint-plugin-jest';

import { files } from '../files';

import type { Configurator } from '@agaroot/eslint-config-definer';
import type { Linter } from 'eslint';

export const jestConfigurator: Configurator = () => {
return [
{
name: 'jest/recommended',
files,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintPluginJest.configs['flat/recommended'] as Linter.FlatConfig,
},
{
name: 'jest/style',
files,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintPluginJest.configs['flat/style'] as Linter.FlatConfig,
},
{
name: 'agaroot/jest/rules',
files,
rules: {
'@typescript-eslint/unbound-method': 'off',
'jest/unbound-method': 'error',
},
},
];
};
4 changes: 4 additions & 0 deletions packages/jest/src/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const files = [
'*.test.{js,jsx,ts,tsx}',
'**/__tests__/**/*.{js,jsx,ts,tsx}',
];
9 changes: 9 additions & 0 deletions packages/jest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { define } from '@agaroot/eslint-config-definer';

import { globalsConfigurator } from './configurators/globals-configurator';
import { jestConfigurator } from './configurators/jest-configurator';

export const jest = define([
globalsConfigurator,
jestConfigurator,
]);
12 changes: 12 additions & 0 deletions packages/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": [
"@tsconfig/strictest/tsconfig.json"
],
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true
}
}
46 changes: 28 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5adb24f

Please sign in to comment.