Skip to content

Commit

Permalink
feature: Migrate jest-react 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 5adb24f commit 346e159
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 528 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-kings-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@agaroot/eslint-config-jest-react": major
---

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

This file was deleted.

57 changes: 32 additions & 25 deletions packages/jest-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,45 @@ Use this setting to ensure consistent code writing and maintain high code qualit
## 🚀 Installation

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

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

# If you are using Next.js, install the following package.
npm install -D @agaroot/eslint-config-next
```

## 👏 Getting Started

Create a `.eslintrc.js` file in the root directory of your project, and add `@agaroot/eslint-config-jest-react` 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',
'@agaroot/eslint-config-jest-react',
],
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 { jestReact } from '@agaroot/eslint-config-jest-react';
import { react } from '@agaroot/eslint-config-jest-react';
import { next } from '@agaroot/eslint-config-jest-next';
import { typescript } from '@agaroot/eslint-config-typescript';

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

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-react/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',
});
15 changes: 0 additions & 15 deletions packages/jest-react/index.cjs

This file was deleted.

56 changes: 42 additions & 14 deletions packages/jest-react/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@agaroot/eslint-config-jest-react",
"type": "module",
"version": "2.1.0",
"description": "ESLint config for AGAROOT",
"keywords": [
Expand All @@ -20,30 +21,57 @@
"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": {
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-testing-library": "^6.2.2"
},
"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-jest-dom": "5.4.0",
"eslint-plugin-testing-library": "6.2.2",
"eslint-plugin-unused-imports": "3.2.0"
"pkgroll": "2.4.1"
},
"peerDependencies": {
"eslint": "^8.0.0",
"eslint-plugin-jest-dom": "^5.0.0",
"eslint-plugin-testing-library": "^6.0.0"
"@agaroot/eslint-config-common": "workspace:*",
"@agaroot/eslint-config-javascript": "workspace:*",
"@agaroot/eslint-config-jest": "workspace:*",
"@agaroot/eslint-config-next": "workspace:*",
"@agaroot/eslint-config-react": "workspace:*",
"@agaroot/eslint-config-typescript": "workspace:*",
"eslint": "^8.0.0"
},
"peerDependenciesMeta": {
"@agaroot/eslint-config-next": {
"optional": true
},
"@agaroot/eslint-config-typescript": {
"optional": true
}
}
}
19 changes: 19 additions & 0 deletions packages/jest-react/src/configurators/jest-dom-configurator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import eslintPluginJestDom from 'eslint-plugin-jest-dom';

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

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

export const jestDomConfigurator: Configurator = () => {
return [
{
name: 'jest-dom/recommended',
files,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...eslintPluginJestDom.configs['flat/recommended'] as Linter.FlatConfig,
},
];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import eslintPluginTestingLibrary from 'eslint-plugin-testing-library';

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

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

export const testingLibraryConfigurator: Configurator = () => {
return [
{
name: 'testing-library/recommended',
files,
plugins: {
'testing-library': eslintPluginTestingLibrary as ESLint.Plugin,
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
rules: eslintPluginTestingLibrary.configs.recommended.rules as Linter.RulesRecord,
},
];
};
4 changes: 4 additions & 0 deletions packages/jest-react/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-react/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 { jestDomConfigurator } from './configurators/jest-dom-configurator';
import { testingLibraryConfigurator } from './configurators/testing-library-configurator';

export const jestReact = define([
jestDomConfigurator,
testingLibraryConfigurator,
]);
12 changes: 12 additions & 0 deletions packages/jest-react/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
}
}
Loading

0 comments on commit 346e159

Please sign in to comment.