Skip to content

Commit

Permalink
refactor: flat-eslint-config (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: F <[email protected]>
  • Loading branch information
Feshchenko and F authored Sep 4, 2024
1 parent 40a50b8 commit 76986c2
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 439 deletions.
110 changes: 59 additions & 51 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,67 +1,75 @@
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import reactHooks from "eslint-plugin-react-hooks";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import prettier from "eslint-plugin-prettier";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
import { fixupPluginRules } from '@eslint/compat';
import js from '@eslint/js';
import playwright from 'eslint-plugin-playwright';
import prettier from 'eslint-plugin-prettier/recommended';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import tseslint from 'typescript-eslint';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["node_modules", "dist", "rollup"],
}, ...fixupConfigRules(compat.extends(
"plugin:playwright/recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"prettier",
)), {
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
{
name: 'ignore',
ignores: [
'node_modules',
'**/dist',
'**/rollup',
'**/node_modules',
'**/babel.config.js',
],
},
{
name: 'main',
plugins: {
"@typescript-eslint": fixupPluginRules(typescriptEslint),
"react-hooks": fixupPluginRules(reactHooks),
"simple-import-sort": simpleImportSort,
prettier,
react,
'react-hooks': fixupPluginRules(reactHooks),
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2020,
sourceType: "module",
ecmaVersion: 2020,
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
jsx: true,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},

settings: {
react: {
pragma: "React",
version: "detect",
},
react: {
pragma: 'React',
version: 'detect',
},
},

rules: {
"prettier/prettier": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-var": 0,
'no-var': 0,
},
}, {
files: ["**/*.test.ts", "**/*.test.tsx"],

},
{
name: 'simple-import-sort',
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
},
},
{
name: 'typescript',
files: ['**/*.test.ts', '**/*.test.tsx'],
rules: {
"@typescript-eslint/ban-ts-comment": "off",
'@typescript-eslint/ban-ts-comment': 'off',
},
}];
},
{
name: 'playwright',
...playwright.configs['flat/recommended'],
files: ['./packages/examples-e2e/test/*.spec.ts'],
},
prettier,
);
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@
"homepage": "https://github.com/rehookify/datepicker#readme",
"devDependencies": {
"@eslint/compat": "^1.1.1",
"@testing-library/react": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"eslint": "^9.6.0",
"@testing-library/react": "^16.0.1",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-playwright": "^1.6.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.2",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-simple-import-sort": "^12.1.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"typescript": "^5.5.3"
"husky": "^9.1.5",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0"
},
"lint-staged": {
"**/*.{ts,tsx}": [
Expand All @@ -64,5 +64,8 @@
},
"engines": {
"node": ">=16"
},
"dependencies": {
"@eslint/js": "^9.9.1"
}
}
2 changes: 1 addition & 1 deletion packages/datepicker/src/__test__/create-month.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('createMonth', () => {
// This manipulation is needed to prevent selecting month in the next year
// for example if today is December then next month will be January
// and test will fail because in current year selected only 1 month 😅
// eslint-disable-next-line playwright/no-conditional-in-test

const nextMonth = M === 11 ? M - 1 : M + 1;

// with 2 selected dates
Expand Down
4 changes: 2 additions & 2 deletions packages/datepicker/src/__test__/offset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('setDPOffset', () => {
}),
);

act(() => setDPOffset(result.current)(d)),
expect(result.current.offsetDate).toEqual(d);
act(() => setDPOffset(result.current)(d));
expect(result.current.offsetDate).toEqual(d);
});

test('should set offset with onOffsetChange', () => {
Expand Down
Loading

0 comments on commit 76986c2

Please sign in to comment.