Skip to content

Commit 76986c2

Browse files
FeshchenkoF
andauthored
refactor: flat-eslint-config (#70)
Co-authored-by: F <f@MacBook-Pro-F.local>
1 parent 40a50b8 commit 76986c2

File tree

5 files changed

+282
-439
lines changed

5 files changed

+282
-439
lines changed

eslint.config.mjs

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,75 @@
1-
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
2-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
3-
import reactHooks from "eslint-plugin-react-hooks";
4-
import simpleImportSort from "eslint-plugin-simple-import-sort";
5-
import prettier from "eslint-plugin-prettier";
6-
import tsParser from "@typescript-eslint/parser";
7-
import path from "node:path";
8-
import { fileURLToPath } from "node:url";
9-
import js from "@eslint/js";
10-
import { FlatCompat } from "@eslint/eslintrc";
1+
import { fixupPluginRules } from '@eslint/compat';
2+
import js from '@eslint/js';
3+
import playwright from 'eslint-plugin-playwright';
4+
import prettier from 'eslint-plugin-prettier/recommended';
5+
import react from 'eslint-plugin-react';
6+
import reactHooks from 'eslint-plugin-react-hooks';
7+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
8+
import tseslint from 'typescript-eslint';
119

12-
const __filename = fileURLToPath(import.meta.url);
13-
const __dirname = path.dirname(__filename);
14-
const compat = new FlatCompat({
15-
baseDirectory: __dirname,
16-
recommendedConfig: js.configs.recommended,
17-
allConfig: js.configs.all
18-
});
19-
20-
export default [{
21-
ignores: ["node_modules", "dist", "rollup"],
22-
}, ...fixupConfigRules(compat.extends(
23-
"plugin:playwright/recommended",
24-
"plugin:react/recommended",
25-
"plugin:@typescript-eslint/recommended",
26-
"plugin:react-hooks/recommended",
27-
"prettier",
28-
)), {
10+
export default tseslint.config(
11+
js.configs.recommended,
12+
...tseslint.configs.recommended,
13+
{
14+
name: 'ignore',
15+
ignores: [
16+
'node_modules',
17+
'**/dist',
18+
'**/rollup',
19+
'**/node_modules',
20+
'**/babel.config.js',
21+
],
22+
},
23+
{
24+
name: 'main',
2925
plugins: {
30-
"@typescript-eslint": fixupPluginRules(typescriptEslint),
31-
"react-hooks": fixupPluginRules(reactHooks),
32-
"simple-import-sort": simpleImportSort,
33-
prettier,
26+
react,
27+
'react-hooks': fixupPluginRules(reactHooks),
3428
},
3529

3630
languageOptions: {
37-
parser: tsParser,
38-
ecmaVersion: 2020,
39-
sourceType: "module",
31+
ecmaVersion: 2020,
32+
sourceType: 'module',
4033

41-
parserOptions: {
42-
ecmaFeatures: {
43-
jsx: true,
44-
},
34+
parserOptions: {
35+
ecmaFeatures: {
36+
jsx: true,
4537
},
38+
},
4639
},
4740

4841
settings: {
49-
react: {
50-
pragma: "React",
51-
version: "detect",
52-
},
42+
react: {
43+
pragma: 'React',
44+
version: 'detect',
45+
},
5346
},
5447

5548
rules: {
56-
"prettier/prettier": "error",
57-
"simple-import-sort/imports": "error",
58-
"simple-import-sort/exports": "error",
59-
"no-var": 0,
49+
'no-var': 0,
6050
},
61-
}, {
62-
files: ["**/*.test.ts", "**/*.test.tsx"],
63-
51+
},
52+
{
53+
name: 'simple-import-sort',
54+
plugins: {
55+
'simple-import-sort': simpleImportSort,
56+
},
57+
rules: {
58+
'simple-import-sort/exports': 'error',
59+
'simple-import-sort/imports': 'error',
60+
},
61+
},
62+
{
63+
name: 'typescript',
64+
files: ['**/*.test.ts', '**/*.test.tsx'],
6465
rules: {
65-
"@typescript-eslint/ban-ts-comment": "off",
66+
'@typescript-eslint/ban-ts-comment': 'off',
6667
},
67-
}];
68+
},
69+
{
70+
name: 'playwright',
71+
...playwright.configs['flat/recommended'],
72+
files: ['./packages/examples-e2e/test/*.spec.ts'],
73+
},
74+
prettier,
75+
);

package.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@
4141
"homepage": "https://github.com/rehookify/datepicker#readme",
4242
"devDependencies": {
4343
"@eslint/compat": "^1.1.1",
44-
"@testing-library/react": "^16.0.0",
45-
"@typescript-eslint/eslint-plugin": "^7.15.0",
46-
"@typescript-eslint/parser": "^7.15.0",
47-
"eslint": "^9.6.0",
44+
"@testing-library/react": "^16.0.1",
45+
"eslint": "^9.9.1",
4846
"eslint-config-prettier": "^9.1.0",
49-
"eslint-plugin-prettier": "^5.1.3",
50-
"eslint-plugin-react": "^7.34.3",
47+
"eslint-plugin-playwright": "^1.6.2",
48+
"eslint-plugin-prettier": "^5.2.1",
49+
"eslint-plugin-react": "^7.35.2",
5150
"eslint-plugin-react-hooks": "^4.6.2",
5251
"eslint-plugin-simple-import-sort": "^12.1.1",
53-
"husky": "^9.0.11",
54-
"lint-staged": "^15.2.7",
55-
"prettier": "^3.3.2",
56-
"rimraf": "^5.0.7",
57-
"typescript": "^5.5.3"
52+
"husky": "^9.1.5",
53+
"lint-staged": "^15.2.10",
54+
"prettier": "^3.3.3",
55+
"rimraf": "^6.0.1",
56+
"typescript": "^5.5.4",
57+
"typescript-eslint": "^8.4.0"
5858
},
5959
"lint-staged": {
6060
"**/*.{ts,tsx}": [
@@ -64,5 +64,8 @@
6464
},
6565
"engines": {
6666
"node": ">=16"
67+
},
68+
"dependencies": {
69+
"@eslint/js": "^9.9.1"
6770
}
6871
}

packages/datepicker/src/__test__/create-month.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('createMonth', () => {
2727
// This manipulation is needed to prevent selecting month in the next year
2828
// for example if today is December then next month will be January
2929
// and test will fail because in current year selected only 1 month 😅
30-
// eslint-disable-next-line playwright/no-conditional-in-test
30+
3131
const nextMonth = M === 11 ? M - 1 : M + 1;
3232

3333
// with 2 selected dates

packages/datepicker/src/__test__/offset.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ describe('setDPOffset', () => {
2020
}),
2121
);
2222

23-
act(() => setDPOffset(result.current)(d)),
24-
expect(result.current.offsetDate).toEqual(d);
23+
act(() => setDPOffset(result.current)(d));
24+
expect(result.current.offsetDate).toEqual(d);
2525
});
2626

2727
test('should set offset with onOffsetChange', () => {

0 commit comments

Comments
 (0)