Skip to content

Commit

Permalink
Updated dependencies and configs
Browse files Browse the repository at this point in the history
  • Loading branch information
burtek committed Aug 16, 2023
1 parent 287e919 commit 543ee21
Show file tree
Hide file tree
Showing 7 changed files with 1,625 additions and 317 deletions.
18 changes: 3 additions & 15 deletions configs/base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ts from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import * as ts from '@typescript-eslint/eslint-plugin';
import * as tsParser from '@typescript-eslint/parser/dist';
import { defineFlatConfig } from 'eslint-define-config';
import importPlugin from 'eslint-plugin-import';
import promise from 'eslint-plugin-promise';
Expand Down Expand Up @@ -130,7 +130,6 @@ export function prepareConfig() {
'no-param-reassign': 'error',
'no-redeclare': 'error',
'no-return-assign': 'error',
'no-return-await': 'error',
'no-script-url': 'error',
'no-self-assign': 'error',
'no-self-compare': 'error',
Expand Down Expand Up @@ -375,16 +374,6 @@ export function prepareConfig() {
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-type-alias': ['error', {
allowAliases: 'in-unions-and-intersections',
allowCallbacks: 'always',
allowConditionalTypes: 'always',
allowConstructors: 'always',
allowGenerics: 'always',
allowLiterals: 'in-unions-and-intersections',
allowMappedTypes: 'always',
allowTupleTypes: 'always'
}],
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-condition': ['error', { allowConstantLoopConditions: true }],
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
Expand Down Expand Up @@ -447,7 +436,6 @@ export function prepareConfig() {
'no-useless-constructor': 'off',
'quotes': 'off',
'require-await': 'off',
'no-return-await': 'off',
'semi': 'off',
'space-before-blocks': 'off',
'space-before-function-paren': 'off',
Expand Down Expand Up @@ -516,7 +504,7 @@ export function prepareConfig() {
'@typescript-eslint/parameter-properties': ['error', { prefer: 'parameter-property' }],
'@typescript-eslint/quotes': ['error', 'single'],
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/return-await': 'error',
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/semi': 'error',
'@typescript-eslint/space-before-blocks': 'error',
'@typescript-eslint/space-before-function-paren': ['error', {
Expand Down
4 changes: 3 additions & 1 deletion configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { prepareConfig as testingLibrary } from './testing-library.js';
* @typedef {Promise<T> | T} MaybePromise
*/

/** @satisfies {Record<string, (config?: any) => MaybePromise<import('eslint-define-config').FlatESLintConfig[]>>} */
/** @typedef {import('eslint-define-config').FlatESLintConfig} FlatESLintConfig */

/** @satisfies {Record<string, (config?: any) => MaybePromise<FlatESLintConfig[]>>} */
export const configs = {
base,
cypress,
Expand Down
9 changes: 7 additions & 2 deletions configs/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import jsxA11y from 'eslint-plugin-jsx-a11y';
import reactConfigJsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import reactConfigRecommended from 'eslint-plugin-react/configs/recommended.js';
import reactHooks from 'eslint-plugin-react-hooks';
import globals from 'globals';
import * as globals from 'globals';

import { reactNamingRuleConfig } from './share/naming-config.js';

Expand Down Expand Up @@ -63,6 +63,10 @@ export function prepareConfig({ a11y = false, nextjs = false } = {}) {
'jsx-quotes': ['error', 'prefer-double'],

'react/button-has-type': 'warn',
'react/display-name': ['error', {
checkContextObjects: true,
ignoreTranspilerName: true
}],
'react/hook-use-state': ['error', { allowDestructuredState: true }],
'react/iframe-missing-sandbox': 'error',
'react/jsx-boolean-value': 'error',
Expand All @@ -81,7 +85,7 @@ export function prepareConfig({ a11y = false, nextjs = false } = {}) {
children: { when: 'never' }
}],
'react/jsx-equals-spacing': 'error',
'react/jsx-first-prop-new-line': 'error',
'react/jsx-first-prop-new-line': ['error', 'multiprop'],
'react/jsx-fragments': ['error', 'syntax'],
'react/jsx-handler-names': ['error', { checkInlineFunction: true }],
'react/jsx-indent': ['error', 4, {
Expand Down Expand Up @@ -121,6 +125,7 @@ export function prepareConfig({ a11y = false, nextjs = false } = {}) {
'react/no-access-state-in-setstate': 'error',
'react/no-array-index-key': 'error',
'react/no-danger': 'error',
'react/no-deprecated': 'error',
'react/no-did-mount-set-state': 'error',
'react/no-did-update-set-state': 'error',
'react/no-object-type-as-default-prop': 'error',
Expand Down
32 changes: 10 additions & 22 deletions configs/testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,19 @@ const files = ['**/*.test.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];
// eslint-disable-next-line no-warning-comments
// TODO: move to FlatConfig once testing-library and jest-dom are upgraded
export async function prepareConfig() {
/** @type {import('eslint-define-config').FlatESLintConfig[]} */
const baseConfig = [{
// eslint-plugin-jest-dom depends on @testing-library/dom
const { default: jestDom } = await import('eslint-plugin-jest-dom');

return defineFlatConfig([{
files,
plugins: { 'testing-library': { rules: testingLibrary.rules } },
plugins: {
'jest-dom': { rules: jestDom.rules },
'testing-library': { rules: testingLibrary.rules }
},
rules: {
...jestDom.configs.all.rules,
...testingLibrary.configs.react.rules,
'testing-library/prefer-user-event': 'warn'
}
}];

// eslint-plugin-jest-dom depends on @testing-library/dom
try {
const { default: jestDom } = await import('eslint-plugin-jest-dom');
baseConfig.unshift({
files,
plugins: { 'jest-dom': { rules: jestDom.rules } },
rules: { ...jestDom.configs.all.rules }
});
} catch (e) {
// eslint-disable-next-line no-console
console.error(new Error(
'testing-library config has been requested, but some peer dependencies have not been found',
{ cause: e }
));
}

return defineFlatConfig(baseConfig);
}]);
}
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@
],
"license": "MIT",
"dependencies": {
"@next/eslint-plugin-next": "^13.4.7",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"eslint-define-config": "~1.20.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-cypress": "^2.13.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-jest-dom": "^5.0.1",
"@next/eslint-plugin-next": "^13.4.16",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint-define-config": "^1.23.0",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-cypress": "^2.14.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-jest-dom": "^5.0.2",
"eslint-plugin-jest-formatting": "^3.1.0",
"eslint-plugin-jsonc": "^2.9.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-lodash": "^7.4.0",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-security-node": "^1.1.1",
"eslint-plugin-testing-library": "^5.11.0",
"globals": "^13.20.0",
"eslint-plugin-testing-library": "^6.0.0",
"globals": "^13.21.0",
"husky": "^8.0.3",
"jsonc-eslint-parser": "^2.3.0"
},
"devDependencies": {
"@testing-library/dom": "^9.3.1",
"@types/eslint": "^8.40.2",
"@types/eslint": "^8.44.2",
"auto-changelog": "^2.4.0",
"eslint": "^8.43.0",
"eslint": "^8.47.0",
"eslint-plugin-mdx": "^2.2.0",
"exit-code": "^1.0.2",
"rimraf": "^5.0.1",
"typescript": "~5.1.6"
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "nodenext",
"moduleResolution": "node", // nodenext doesn't work with eslint-define-config
"allowJs": true,
"checkJs": true,
// "declaration": true,
Expand All @@ -11,8 +11,10 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"exactOptionalPropertyTypes": true,
"resolveJsonModule": true
"resolveJsonModule": true,

// "exactOptionalPropertyTypes": true,
"skipLibCheck": true
},
"exclude": []
}
Loading

0 comments on commit 543ee21

Please sign in to comment.