Skip to content

Commit

Permalink
Add testing-library (react-only) config
Browse files Browse the repository at this point in the history
  • Loading branch information
burtek committed Jun 22, 2023
1 parent 10c58f8 commit dce98fe
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The configuration object can contain following keys:
- node
- react
- cypress
- testing-library

### TODO: Docs

Expand Down
2 changes: 2 additions & 0 deletions configs/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import globals from 'globals';

const files = ['**/*.cy.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];

// eslint-disable-next-line no-warning-comments
// TODO: move to FlatConfig once cypress is upgraded
export function prepareConfig() {
return defineFlatConfig([
{
Expand Down
4 changes: 3 additions & 1 deletion configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { prepareConfig as json } from './json.js';
import { prepareConfig as lodash } from './lodash.js';
import { prepareConfig as node } from './node.js';
import { prepareConfig as react } from './react.js';
import { prepareConfig as testingLibrary } from './testing-library.js';

/** @satisfies {Record<string, (config?: any) => import('eslint-define-config').FlatESLintConfig[]>} */
export const configs = {
Expand All @@ -16,7 +17,8 @@ export const configs = {
json,
lodash,
node,
react
react,
testingLibrary
};

/**
Expand Down
2 changes: 2 additions & 0 deletions configs/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const testFiles = ['**/*.test.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];
const tsFiles = ['**/*.{ts,cts,mts,tsx}'];
const jsxFiles = ['**/*.{jsx,tsx}'];

// eslint-disable-next-line no-warning-comments
// TODO: move to FlatConfig once react-hooks is upgraded
/**
* @param {Object} [config]
* @param {boolean} [config.a11y] Include config for a11y
Expand Down
28 changes: 28 additions & 0 deletions configs/testing-library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineFlatConfig } from 'eslint-define-config';
import testingLibrary from 'eslint-plugin-testing-library';


const files = ['**/*.test.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];
const cyFiles = ['**/*.cy.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'];

// eslint-disable-next-line no-warning-comments
// TODO: move to FlatConfig once testing-library is upgraded
/**
* @param {Object} [config]
* @param {boolean} [config.enableCypress]
*/
export function prepareConfig({ enableCypress = false } = {}) {
return defineFlatConfig([
{
files: [
...files,
...(enableCypress ? cyFiles : [])
],
plugins: { 'testing-library': { rules: testingLibrary.rules } },
rules: {
...testingLibrary.configs.react.rules,
'testing-library/prefer-user-event': 'warn'
}
}
]);
}
28 changes: 28 additions & 0 deletions import-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,31 @@ declare module 'eslint-plugin-cypress' {

export default plugin;
}

declare module 'eslint-plugin-testing-library' {
import type { Rule } from 'eslint';
import type { Severity } from 'eslint-define-config/src/rules/rule-severity.js';


const plugin: {
configs: Record<'react' | 'vue' | 'marko' | 'dom' | 'angular', {
plugins: [string];
rules: Record<string, Severity>;
}>;
rules: Record<string, Rule.RuleModule>;
};

export default plugin;
}

declare module 'eslint-plugin-testing-library/configs/*.js' {
import type { Severity } from 'eslint-define-config/src/rules/rule-severity.js';


const config: {
plugins: [string];
rules: Record<string, Severity>;
};

export default config;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-security-node": "^1.1.1",
"eslint-plugin-testing-library": "^5.11.0",
"globals": "^13.20.0",
"husky": "^8.0.3",
"jsonc-eslint-parser": "^2.3.0"
Expand Down
57 changes: 56 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@
"@typescript-eslint/types" "5.59.6"
"@typescript-eslint/visitor-keys" "5.59.6"

"@typescript-eslint/scope-manager@5.60.0":
version "5.60.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.60.0.tgz#ae511967b4bd84f1d5e179bb2c82857334941c1c"
integrity sha512-hakuzcxPwXi2ihf9WQu1BbRj1e/Pd8ZZwVTG9kfbxAMZstKz8/9OoexIwnmLzShtsdap5U/CoQGRCWlSuPbYxQ==
dependencies:
"@typescript-eslint/types" "5.60.0"
"@typescript-eslint/visitor-keys" "5.60.0"

"@typescript-eslint/type-utils@5.59.6":
version "5.59.6"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.59.6.tgz#37c51d2ae36127d8b81f32a0a4d2efae19277c48"
Expand All @@ -177,6 +185,11 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.59.6.tgz#5a6557a772af044afe890d77c6a07e8c23c2460b"
integrity sha512-tH5lBXZI7T2MOUgOWFdVNUILsI02shyQvfzG9EJkoONWugCG77NDDa1EeDGw7oJ5IvsTAAGVV8I3Tk2PNu9QfA==

"@typescript-eslint/types@5.60.0":
version "5.60.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.60.0.tgz#3179962b28b4790de70e2344465ec97582ce2558"
integrity sha512-ascOuoCpNZBccFVNJRSC6rPq4EmJ2NkuoKnd6LDNyAQmdDnziAtxbCGWCbefG1CNzmDvd05zO36AmB7H8RzKPA==

"@typescript-eslint/typescript-estree@5.59.6":
version "5.59.6"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.6.tgz#2fb80522687bd3825504925ea7e1b8de7bb6251b"
Expand All @@ -190,7 +203,20 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/utils@5.59.6", "@typescript-eslint/utils@^5.10.0":
"@typescript-eslint/typescript-estree@5.60.0":
version "5.60.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.60.0.tgz#4ddf1a81d32a850de66642d9b3ad1e3254fb1600"
integrity sha512-R43thAuwarC99SnvrBmh26tc7F6sPa2B3evkXp/8q954kYL6Ro56AwASYWtEEi+4j09GbiNAHqYwNNZuNlARGQ==
dependencies:
"@typescript-eslint/types" "5.60.0"
"@typescript-eslint/visitor-keys" "5.60.0"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/utils@5.59.6":
version "5.59.6"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.59.6.tgz#82960fe23788113fc3b1f9d4663d6773b7907839"
integrity sha512-vzaaD6EXbTS29cVH0JjXBdzMt6VBlv+hE31XktDRMX1j3462wZCJa7VzO2AxXEXcIl8GQqZPcOPuW/Z1tZVogg==
Expand All @@ -204,6 +230,20 @@
eslint-scope "^5.1.1"
semver "^7.3.7"

"@typescript-eslint/utils@^5.10.0", "@typescript-eslint/utils@^5.58.0":
version "5.60.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.60.0.tgz#4667c5aece82f9d4f24a667602f0f300864b554c"
integrity sha512-ba51uMqDtfLQ5+xHtwlO84vkdjrqNzOnqrnwbMHMRY8Tqeme8C2Q8Fc7LajfGR+e3/4LoYiWXUM6BpIIbHJ4hQ==
dependencies:
"@eslint-community/eslint-utils" "^4.2.0"
"@types/json-schema" "^7.0.9"
"@types/semver" "^7.3.12"
"@typescript-eslint/scope-manager" "5.60.0"
"@typescript-eslint/types" "5.60.0"
"@typescript-eslint/typescript-estree" "5.60.0"
eslint-scope "^5.1.1"
semver "^7.3.7"

"@typescript-eslint/visitor-keys@5.59.6":
version "5.59.6"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.6.tgz#673fccabf28943847d0c8e9e8d008e3ada7be6bb"
Expand All @@ -212,6 +252,14 @@
"@typescript-eslint/types" "5.59.6"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/visitor-keys@5.60.0":
version "5.60.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.60.0.tgz#b48b29da3f5f31dd1656281727004589d2722a66"
integrity sha512-wm9Uz71SbCyhUKgcaPRauBdTegUyY/ZWl8gLwD/i/ybJqscrrdVSFImpvUz16BLPChIeKBK5Fa9s6KDQjsjyWw==
dependencies:
"@typescript-eslint/types" "5.60.0"
eslint-visitor-keys "^3.3.0"

acorn-jsx@^5.3.2:
version "5.3.2"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"
Expand Down Expand Up @@ -811,6 +859,13 @@ eslint-plugin-security-node@^1.1.1:
resolved "https://registry.yarnpkg.com/eslint-plugin-security-node/-/eslint-plugin-security-node-1.1.1.tgz#97c334632665d0f861389d798340323024c368f2"
integrity sha512-PXl5uKQOglpIpU13YIwWhhXK9Sw14KHbzCdVthDWoIsUPOuMYbrGOCWJSEVVuZ1uJK2ciN+45ogPeErrKtNm0Q==

eslint-plugin-testing-library@^5.11.0:
version "5.11.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-testing-library/-/eslint-plugin-testing-library-5.11.0.tgz#0bad7668e216e20dd12f8c3652ca353009163121"
integrity sha512-ELY7Gefo+61OfXKlQeXNIDVVLPcvKTeiQOoMZG9TeuWa7Ln4dUNRv8JdRWBQI9Mbb427XGlVB1aa1QPZxBJM8Q==
dependencies:
"@typescript-eslint/utils" "^5.58.0"

eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
Expand Down

0 comments on commit dce98fe

Please sign in to comment.