Skip to content

Commit

Permalink
fix(deps): update dependency eslint-plugin-testing-library to ~6.3.0 (#…
Browse files Browse the repository at this point in the history
…115)

* fix(deps): update dependency eslint-plugin-testing-library to ~6.3.0

* feat: Use testing-library flat config

* feat: Add extendFlatConfig

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Bartosz <burtekdotryw@gmail.com>
  • Loading branch information
renovate[bot] and burtek authored Aug 22, 2024
1 parent 2cd9ea2 commit 18f90e3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
23 changes: 23 additions & 0 deletions configs/share/extend-flat-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @import { type TSESLint } from '@typescript-eslint/utils'; */

/**
* @param {Partial<TSESLint.FlatConfig.Config>} baseConfig
* @param {Partial<TSESLint.FlatConfig.Config>} extendedConfig
* @returns {TSESLint.FlatConfig.Config}
*/
/**
* @param {...Partial<TSESLint.FlatConfig.Config>} configs
* @returns {TSESLint.FlatConfig.Config}
*/
export const extendFlatConfig = (...configs) => configs.reduce((current, next) => ({
...current,
...next,
plugins: {
...current.plugins,
...next.plugins
},
rules: {
...current.rules,
...next.rules
}
}));
35 changes: 19 additions & 16 deletions configs/testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@ import jestDom from 'eslint-plugin-jest-dom';
import testingLibrary from 'eslint-plugin-testing-library';
import tseslint from 'typescript-eslint';

import { extendFlatConfig } from './share/extend-flat-config.js';


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 function prepareConfig() {
return tseslint.config(
{
...jestDom.configs['flat/all'],
name: 'dtrw:testing-lib:jest-dom',
files
},
{
name: 'dtrw:testing-lib:react',
files,
plugins: { 'testing-library': { rules: testingLibrary.rules } },
rules: {
...testingLibrary.configs.react.rules,
'testing-library/prefer-explicit-assert': 'error',
'testing-library/prefer-user-event': 'warn'
extendFlatConfig(
jestDom.configs['flat/all'],
{
name: 'dtrw:testing-lib:jest-dom',
files
}
),
extendFlatConfig(
testingLibrary.configs['flat/react'],
{
name: 'dtrw:testing-lib:react',
files,
rules: {
'testing-library/prefer-explicit-assert': 'error',
'testing-library/prefer-user-event': 'warn'
}
}
}
)
);
}
4 changes: 3 additions & 1 deletion import-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ declare module 'eslint-plugin-testing-library' {


const plugin: {
configs: Record<'react' | 'vue' | 'marko' | 'dom' | 'angular', Required<Pick<TSESLint.ClassicConfig.Config, 'plugins' | 'rules'>>>;
configs:
& Record<'react' | 'vue' | 'marko' | 'dom' | 'angular', Required<Pick<TSESLint.ClassicConfig.Config, 'plugins' | 'rules'>>>
& Record<'flat/react' | 'flat/vue' | 'flat/marko' | 'flat/dom' | 'flat/angular', Required<Pick<TSESLint.FlatConfig.Config, 'plugins' | 'rules'>>>;
rules: Record<string, Rule.RuleModule>;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint-plugin-react": "~7.35.0",
"eslint-plugin-react-hooks": "~4.6.0",
"eslint-plugin-security-node": "~1.1.4",
"eslint-plugin-testing-library": "~6.2.2",
"eslint-plugin-testing-library": "~6.3.0",
"globals": "^15.0.0",
"jsonc-eslint-parser": "~2.4.0",
"typescript-eslint": "~8.0.0"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2647,10 +2647,10 @@ eslint-plugin-security-node@~1.1.4:
resolved "https://registry.yarnpkg.com/eslint-plugin-security-node/-/eslint-plugin-security-node-1.1.4.tgz#e78dbfa9d4852076d51ca512a28d6b4ead069792"
integrity sha512-8+agTMb2glNbP1zFhqo/Ixwtz16Hn0TvJW5KgpoHkAzGjDUhQf9iT+D6OgbhvZCMWRKMjc+5FbJ2Lh0UEUz7fQ==

eslint-plugin-testing-library@~6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-testing-library/-/eslint-plugin-testing-library-6.2.2.tgz#67e84ff891a2b3a8078ced0afa95ee6f343c00c1"
integrity sha512-1E94YOTUDnOjSLyvOwmbVDzQi/WkKm3WVrMXu6SmBr6DN95xTGZmI6HJ/eOkSXh/DlheRsxaPsJvZByDBhWLVQ==
eslint-plugin-testing-library@~6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-testing-library/-/eslint-plugin-testing-library-6.3.0.tgz#9c31a9941a860efdff3c06180151ab9c8142f685"
integrity sha512-GYcEErTt6EGwE0bPDY+4aehfEBpB2gDBFKohir8jlATSUvzStEyzCx8QWB/14xeKc/AwyXkzScSzMHnFojkWrA==
dependencies:
"@typescript-eslint/utils" "^5.58.0"

Expand Down

0 comments on commit 18f90e3

Please sign in to comment.