Skip to content

Commit 6e76a28

Browse files
Belco90nickservMateus Felixthebinaryfelixtimdeschryver
authored
v4 (#322)
* feat: recommend prefer-screen-queries (#169) BREAKING CHANGE: `prefer-screen-queries` rule is automatically enabled if recommended, angular, react or vue config enabled. If you have any of those enabled, you could get new ESLint errors related to this rule after upgrading this plugin. * feat: recommend no-wait-for-empty-callback (#168) BREAKING CHANGE: `no-wait-for-empty-callback` rule is automatically enabled if recommended, angular, react or vue config enabled. If you have any of those enabled, you could get new ESLint errors related to this rule after upgrading this plugin. * feat(no-container): setup new rule on index * refactor(no-container): set rules * test(no-container): define scenarios * refactor(no-debug): extract auxiliary functions to node-utils, to be used by no-container * refactor(no-container): add conditional for containerIndex | clean up method declaration * docs(no-container): add new and update README * refactor(no-container): allow custom render functions * test(no-container): add custom render function * docs(no-container): update further reading topics * docs(no-container): update | add description about testing library frameworks | add link to container docs | remove recommended badge * test(no-container): add scenarios * refactor(no-container): adjust to new scenarios | update error message * docs(no-container): add incorrect use cases * refactor(no-container): remove wrong use case scenario * refactor(no-container): add scenario | destructure method from container * refactor(no-container): rename function and change its scope * refactor(no-container): remove condition * refactor(no-container): update error message and incorrect use case * feat(no-promise-in-fire-event): add new no-promise-in-fire-event rule (#180) * feat(no-promise-in-fire-event): add new no-promise-in-fire-event rule * test: 100% code coverage * docs: add rule to readme * chore: review changes * chore: add rule to recommended config * refactor: rename recommended config to dom (#184) BREAKING CHANGE: `recommended` config preset has been renamed to `dom`, so make sure to update it in your ESLint config file if you were using `recommended` preset. * feat: add rule no-multiple-assertions-wait-for (#189) * feat: add initial files for no-multiple-expect-wait-for rule * fix: add expect fields in test * feat: add no-multiple-assertion-wait-for logic * feat: add findClosestCalleName in node-utils * feat: add check for expect and rename file * docs: add no-multiple-assertions-wait-for rule doc * docs: add link for no-multiple-assertions-wait-for doc * docs: insert function example in no-multiple-assertions-wait-for * refactor: remove find closest call node from node-utils * fix: check expect based in total * docs: better english in no-multiple-assertions-wait-for rule details Co-authored-by: Tim Deschryver <[email protected]> * fix: use correct rule name in no-multiple-assertions-wait-for Co-authored-by: Tim Deschryver <[email protected]> * docs: improve docs for no-multiple-assertions-wait-for * fix: typo in no-multiple-assertions-wait-for * fix: better english in no-multiple-assertions-wait-for Co-authored-by: Tim Deschryver <[email protected]> * feat: add no-node-access rule (#190) * refactor(utils): add properties and methods that returns another Node * test(no-node-access): add first scenarios * feat(no-node-access): add rule with few test cases * test(no-node-access): add scenarios * refactor(no-node-access): simplify conditions * refactor(no-node-access): add scenario when no variable is declared * refactor(no-node-access): remove conditional * refactor(utils): add DOM properties * refactor(no-node-access): add scenario for accessing document directly * docs(no-node-access): add readme * refactor(utils): export const containing all properties and methods that return a Node * docs(no-node-access): fix file location * docs(readme): add no-node-access * refactor(no-node-access): change highlight location * docs(no-node-access): fix typo * refactor(utils): add missing property that returns a Node * refactor(no-node-access): simplify checks triggering error for all methods with names matching the forbidden ones * test(no-node-access): add more scenarios with destructuring * docs(no-node-access): update examples * refactor(no-node-access): narrow error cases * refactor(no-node-access): check imports to validate whether is importing a testing-library package | update examples and testing scenarios * refactor(no-node-access): rename variable * feat: add prefer-user-event rule (#192) * feat: add render-result-naming-convention rule (#200) * feat: rule skeleton * test: first round * feat: rule implementation round 1 * refactor: move hasTestingLibraryImportModule * test: fix invalid lines * feat: check imported module * feat: check imported render renamed * feat: check custom render * test: add more valid tests for custom render functions * test: update tests for render wrapper functions * docs: add rule docs * test: increase coverage up to 100% * fix: add rule meta description * docs: update rule details to mention screen object * refactor: return as soon as conditions are not met * feat: check wildcard imports * refactor: rename default import * docs: include render result link * feat: add no-side-effects-wait-for rule (#196) * test: add scenarios for no-side-effects-wait-for * feat: add no-side-effects-wait-for rule * feat: add no-side-effects-wait-for in index * test: add more valid scenarios in no-side-effects-wait-for * docs: include no-side-effects-wait-for * fix: typo in no-side-effects-wait-for doc Co-authored-by: Gonzalo D'Elia <[email protected]> * fix: remove extra code in examples * refactor: use some instead filter in no-side-effects-wait-for * feat: check if no-side-effects-wait-for is called inside tests * refactor: use util for import check at no-side-effects-wait-for * test: valid scenario for no TL wait for import at no-side-effects * refactor: usage of correct user event methods Co-authored-by: Gonzalo D'Elia <[email protected]> * chore: lint and format on pre-commit and ci (#216) * chore: lint and format on pre-commit and ci * chore: changing stage name in travis ci conf * chore: merge master into v4 (#233) * feat(prefer-explicit-assert): add 'assertion' config option (#220) Closes #218 * docs: add skovy as a contributor (#221) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * feat: new no-wait-for-snapshot rule (#223) Closes: #214 * docs: add Gpx as a contributor [skip ci] (#224) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * docs(no-wait-for-snapshot): fix link to rule doc (#225) * docs: add jdanil as a contributor [skip ci] (#226) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * Update .travis.yml * feat: support ESLint 7.x (#139) Closes #138 * docs: add MichaelDeBoey as a contributor [skip ci] (#231) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * chore: update dependencies + run prettier on codebase (#232) * chore: update dependencies * chore: run Prettier on full codebase Co-authored-by: Spencer Miskoviak <[email protected]> Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> Co-authored-by: Giorgio Polvara <[email protected]> Co-authored-by: Josh David <[email protected]> Co-authored-by: Mario Beltrán Alarcón <[email protected]> * chore: update dependencies + run prettier on codebase (#234) BREAKING CHANGE: Minimum node version required is v10.22.1 BREAKING CHANGE: Minimum ESLint version required is 7.5.0. Support for ESLint between v5 and v7.4 has been dropped * style: apply prettier after merge * refactor(no-node-access): use new testing library rule maker (#237) * build: add npmrc file Adding .npmrc file to indicate we don't want to generate package-lock properly. * refactor: first approach for testing library detection * refactor: move testing library detection to high-order function * refactor: include create-testing-library-rule * refactor(no-node-access): use create-testing-library-rule * test: decrease coverage threshold for utils detection * test: decrease coverage threshold for utils detection branches * style: add missing return type on function * style: format with prettier properly Apparently the regexp for formatting the files within npm command must be passed with double quotes. More details here: https://dev.to/gruckion/comment/b665 * docs: copied types clarification * refactor: improve logic to detect if testing librar imported (#239) * refactor: check testing library imports automatically * feat: add new shared setting for testing library module * test: increase coverage for create testing library rule * refactor: extract common enhanced rule create types * docs: add jsdoc to detection helpers * docs: update old comments related to ImportDeclaration * test: check rule listener are combined properly * feat: new setting for reported filename pattern (#244) * feat: new setting for customizing file name pattern to report * test: add custom rule tester for testing library * refactor: use common rule tester config * refactor(no-dom-import): use createTestingLibraryRule (#247) * feat: new setting for customizing file name pattern to report * test: add custom rule tester for testing library * refactor: use common rule tester config * refactor(no-dom-import): use createTestingLibraryRule * feat(detection-helpers): check imports with require * test(no-dom-import): include test cases for custom module setting * test(no-dom-import): include test cases for custom module setting * chore: fix merge * refactor(no-dom-import): extract detection helpers for import nodes * test: increase coverage * refactor: rename setting for filename pattern * docs(consistent-data-testid): add clarification about rule creation (#248) * feat: new setting for customizing file name pattern to report * test: add custom rule tester for testing library * refactor: use common rule tester config * refactor(no-dom-import): use createTestingLibraryRule * feat(detection-helpers): check imports with require * test(no-dom-import): include test cases for custom module setting * test(no-dom-import): include test cases for custom module setting * chore: fix merge * refactor(no-dom-import): extract detection helpers for import nodes * test: increase coverage * refactor: rename setting for filename pattern * refactor: add new detection option to skip reporting checks * refactor(consistent-data-testid): use createTestingLibraryRule * revert: refactor consistent-data-testid * revert: detection options * docs(consistent-data-testid): add clarification about rule creation * refactor(no-manual-cleanup): use custom rule creator (#249) * refactor(no-manual-cleanup): use custom rule creator * refactor: extract detection utils for import module name * refactor(no-manual-cleanup): use detection helpers for imported modules * refactor(no-manual-cleanup): small improvements * test(no-manual-cleanup): include more variants * feat(no-manual-cleanup): report custom module * refactor: rename type for import module node * refactor: use node utils to know node type * refactor: remove unused imports * refactor: remove outdated comment line * refactor(prefer-user-event): use new custom rule creator (#251) * feat: add new settings for prefer-user-event pt1 * feat: part2 of refactoring user event. improved docs * test: improved coverage for prefer-user-event. applied feedback * refactor(prefer-presence-queries): use custom rule creator (#252) * test(prefer-presence-queries): improve existing invalid tests * refactor(prefer-presence-queries): use custom rule creator * feat(prefer-presence-queries): use aggressive query reporting * refactor(prefer-presence-queries): rename message ids * test: add fake rule tests for queries * refactor(extract helpers for detecting presence/absence assets): add fake rule tests for queries * refactor(prefer-presence-queries): use presence/absence helpers * refactor: simplify negated matcher condition * style: format files after rebase * refactor: detection helpers tweaks (#254) * refactor(extract helpers for detecting presence/absence assets): add fake rule tests for queries * refactor(prefer-presence-queries): use presence/absence helpers * refactor: rename boolean detection helpers * refactor: create helpers as separated functions * refactor(ast-utils): migrate custom node-utils to ASTUtils (#256) Closes #253 * refactor(ast-utils): remove isIdentifier * refactor(ast-utils): migrate isAwaitExpression * refactor(ast-utils): use optional chaining for consistency * chore: decrease node-utils coverage threshold * refactor(prefer-wait-for): use new custom rule creator (#255) * refactor: prefer-wait-for with the new settings * refactor: generalized util method * refactor: applied feedback from pr * test: improve coverage * refactor: use custom rule creator for promise-queries rules (#260) * refactor(no-await-sync-query): use custom rule creator * refactor(no-await-sync-query): improve error message * test(no-await-sync-query): check error location in invalid cases * refactor(no-await-sync-query): catch sync queries with detection helper * test(no-await-sync-query): use more realistic scenarios * test(no-await-sync-query): add more cases for custom queries and settings * refactor(await-async-query): use custom rule creator * refactor(await-async-query): improve error message * feat: new detection helpers for findBy queries * refactor(await-async-query): detection helpers + aggressive reporting * test(await-async-query): add cases for custom queries * test(await-async-query): add more cases for custom queries * test(await-async-query): check errors locations * test(await-async-query): mix built-in and custom queries * test(await-async-query): non-matching query case * feat(await-async-query): report query wrappers * refactor(await-async-query): extract ast utils for functions * test(await-async-query): cases for arrow functions * refactor(await-async-query): extract ast util for promise handled * test(await-async-query): increase coverage * refactor(await-async-query): rename isPromiseResolved to hasChainedThen * docs(await-async-query): update rule description and examples * docs(await-async-query): minor improvements * refactor: minor type fix * docs(await-async-query): more fixes * docs(await-async-query): wrong return type * refactor(await-async-query): check regex more efficiently * refactor(await-async-utils): use custom rule creator (#263) * refactor: extract utils for checking promise all methods * test(await-async-query): add cases for promise all and allSettled * docs(await-async-query): add cases for promise all and allSettled * refactor(await-async-utils): create rule with custom creator * refactor(await-async-utils): replace async utils regexp by method * refactor(await-async-utils): replace manual import checks by helper * refactor(await-async-utils): replace manual promise checks by util * refactor(await-async-utils): merge identifier and member expression nodes checks * test(await-async-query): check column on invalid cases * test(await-async-query): promise.allSettled cases * refactor(await-async-query): extract util to get innermost returning function name * feat(await-async-utils): report unhandled functions wrapping async utils * docs: minor improvements * test(await-async-utils): increase coverage * refactor: repurpose getInnermostReturningFunctionName to getInnermostReturningFunction * refactor(await-fire-event): use custom rule creator (#265) * refactor(await-async-utils): create rule with custom creator * docs(await-fire-event): update description * refactor(await-fire-event): create rule with custom creator * refactor(await-fire-event): replace manual promise checks by util * refactor: simplify isNodeComingFromTestingLibrary * fix: call findClosestCallExpressionNode recursively keeping args * refactor(prefer-user-event): extract fire event helpers * refactor(await-async-utils): remove unnecessary as expression * refactor(await-fire-event): reuse fire event detection helpers * feat(await-fire-event): detect functions wrapping fire event methods * fix(await-fire-event): detect more cases * test(await-fire-event): increase coverage * docs(await-fire-event): update rule details and examples * test(await-async-utils): remove outdated comment * docs(await-fire-event): update async note * style(await-fire-event): format rule doc * refactor(await-fire-event): remove unnecessary check * refactor(no-promise-in-fire-event): use custom rule creator (#266) * refactor(await-async-utils): create rule with custom creator * test(await-async-utils): remove outdated comment * docs(no-promise-in-fire-event): improve description and examples * docs(no-promise-in-fire-event): improve invalid errors checks * refactor(no-promise-in-fire-event): use custom rule creator and helpers * feat(no-promise-in-fire-event): detect promise in variable references * docs(no-promise-in-fire-event): update examples * test(no-promise-in-fire-event): increase coverage up to 100% * refactor(no-wait-for-snapshot) migrate to v4 (#271) * refactor: migrate no-wait-for-snapshot to v4 * refactor: apply pr suggestions * refactor(prefer-find-by) migrate to v4 (#270) * refactor: migrate prefer-find-by to v4 * refactor: applied pr suggestions * refactor(prefer-explicit-assert): use new utils and remove custom query option (#274) * refactor(prefer-explicit-assert): use new utils and remove custom query option * test: add custom query method * fix(no-await-sync-query): avoid reporting queries if not within callee (#278) Fixes #276 * refactor: remove duplicated param type * refactor: rename helpers for determining query variants * refactor(render-result-naming-convention): migrate to v4 (#280) * docs: add comments to main parts to be modified * refactor(render-result-naming-convention): first approach for new helper First implementation of isRenderUtil helper, and use it within this rule. * refactor(aggressive-render): update criteria to consider valid renders Before, it was checking if the name of the method started by "render". Now, it checks if the name of the method contains render. * feat(aggressive-render): keep aggressive module reporting in mind Depending on aggressive module reporting, isRenderUtil needs to check if node comes from valid Testing Library module or not. * test(render-result-naming-convention): move valid to invalid tests * docs(aggressive-reporting): improve jsdocs * test(create-testing-library-rule): cases for render * refactor: second round of tweaks (#281) * refactor(shared-settings): rename utils-module Rename testing-library/module to testing-library/utils-module * refactor(detection-helpers): improve fn type definitions * test(filename-pattern): simplify settings patterns * fix: check member expression properly within isRenderUtil helper * test: improve create-testing-library-rule test cases * refactor: check if coming from Testing Library within isAsyncUtil * refactor: extract common method for determining if node is TL util * refactor: improve TL util node detection from identifier * refactor: rename getIdentifierNode to clarify its behavior * fix: improve check for determining if node coming from TL * test: add async util test cases to fake rule * docs: format jsdoc * refactor(render-result-naming-convention): refine checks to decide if coming from Testing Library (#282) * feat(render-result-naming-convention): detect render calls from wrappers * fix: check imported node properly when specifiers are renamed ImportNamespaceSpecifier had to be checked properly in order to detect rename imports properly like: import { a as b } from 'foo' * refactor: split checks for import matching node name in different methods * test(render-result-naming-convention): add extra invalid case for wrapped function * fix(render-result-naming-convention): cover more renamed imports * ci: update pipeline with v4 changes (#289) * ci: migrate to GitHub Actions (#286) * ci: schedule github actions updates * ci: add github actions release workflow * ci: remove config related to travis * ci: split workflows * ci: use action for installing dependencies * ci: remove lint max warnings * ci: improve scripts * ci: remove format check * ci: install dependencies with npm * ci: revert - install dependencies with npm * ci: install dependencies manually on test step * ci: set ci env var on install step * ci: install peer deps in legacy mode * ci: revert manual deps install * ci: remove node 15 * ci: update badge in README.md Closes #275 * ci: github actions improvements (#288) * chore: fix scripts related to testing * ci: bump checkout action to v2 * ci: merge workflows files into single one * ci: add a step for canceling previous runs * ci: remove workflow run conditions * ci: rename workflow * ci: update github actions with v4 CI changes * chore: bump dependencies to last minor * chore: setting test environment to jest-environment-jsdom v25 I had to downgrade jsdom because of some errors jsdom v16 was causing when running tests in node v10. Apparently, jsdom v16 is compatible with node v10, so I'm not sure why is causing an issue. This can be removed when dropping support for node v10. * refactor(prefer-screen-queries): migrate to v4 (#285) * refactor(prefer-screen-queries): use new rule creator * refactor(prefer-screen-queries): detect render methods with helper * refactor(prefer-screen-queries): detect queries with helper * fix(prefer-screen-queries): detect queries coming from proper render * chore: update dependencies (#290) * refactor(no-wait-for-empty-callback): migrate to v4 (#284) * refactor(no-wait-for-empty-callback): use new rule creator and helpers * test(no-wait-for-empty-callback): improve invalid asserts * test(no-wait-for-empty-callback): increase rule coverage * refactor: improve valid names definition (PR suggestions) * refactor(refactor no-debug): migrate to v4 (#293) * refactor(no-debug): use new rule creator * test(no-debug): improve current invalid error assertions * docs(no-debug): fix typo * refactor(no-debug): report debug call expressions with detection helpers * refactor(no-debug): report debug from renders with detection helpers * refactor(no-debug): remove unnecessary checks * refactor(no-container): migrate to v4 (#295) * docs(no-container): remove custom render reference * test(no-container): improve errors asserts * refactor(no-container): use new rule creator * refactor(no-container): extract isRenderVariableDeclarator helper * refactor(no-container): improve node reported location * refactor(no-container): detect nodes coming from render wrapper * refactor(no-debug): detect nodes coming from render wrapper * refactor: remove mechanism to match files to be reported (#297) * refactor(no-render-in-setup): migrate to v4 (#299) * docs: update rule description - remove references "renderFunctions" rule option - improve examples * test: improve errors location asserts * refactor: use new rule creator * docs: update error message and description * refactor(no-debug): remove option schema leftover * refactor: remove custom render option in favor of helper * refactor: improve error reported location * feat: detect wrapper functions around render * refactor: improve utils types * refactor: remove unused node util * test: improve test cases * refacto(no-wait-for-side-effects): migrate to v4 (#300) * test: improve errors location asserts * refactor: use new rule creator * refactor: improve error reported location * refactor: use new helpers for detection * test: add more cases * feat: detect properly if fireEvent and userEvent should be reported * test: add cases for increasing coverage up to 100% * refactor: rename rule for consistency * docs: remove duplicated no-wait-for-snapshot row * fix: get identifier node simpler * refactor(no-wait-for-multiple-assertions): migrate to v4 (#301) * test: improve errors location asserts * refactor: use new rule creator * refactor: improve error reported location * refactor: use new helpers for detection * test: add more cases * feat: detect properly if fireEvent and userEvent should be reported * test: add cases for increasing coverage up to 100% * refactor: rename rule for consistency * docs: remove duplicated no-wait-for-snapshot row * refactor: rename rule * test: improve errors location asserts * refactor: use new rule creator * refactor: use new helpers for detection * refactor: improve error reported location * test: add more cases * refactor(no-await-sync-events): migrate to v4 (#302) * docs: update rule description * test: improve current cases * refactor: use new rule creator * feat: avoid reporting type and keyboard with 0 delay * refactor: use new helpers for detection * test: split fire and user events cases * test: improve errors location asserts * feat: detect user-event import properly * test: add cases for increasing coverage up to 100% * test: assert error message data * refactor: cleanup after migrating all rules to v4 (#303) * docs: update rule description * test: improve current cases * refactor: use new rule creator * feat: avoid reporting type and keyboard with 0 delay * refactor: use new helpers for detection * test: split fire and user events cases * test: improve errors location asserts * feat: detect user-event import properly * test: add cases for increasing coverage up to 100% * test: assert error message data * test: set final threshold for node-utils * chore: extract semantic release config to its own file * docs: including testing-library prefix in all rules * docs: including testing-library rule prefix in README * fix(await-async-utils): reference correct node name * fix(prefer-find-by): simplify error message * fix(no-await-sync-query): avoid false positive from parent func * test(no-await-sync-query): increase code coverage up to 100% * feat(no-wait-for-multiple-assertions): report assertions * test(no-wait-for-multiple-assertions): increase code coverage up to 100% * fix(no-wait-for-side-effects): report on each side effect node * test(no-await-sync-query): include extra case for disappearance * fix: guard against null deepest identifier node * fix: guard against null property identifier node * ci: decrease coverage threshold * fix: enable TS strict mode * fix: remove closing comment leftover * refactor: declare test cases typings as expected * fix: remove wrong boolean check for detection * fix(prefer-user-event): format list of userEvent methods correctly (#311) * fix(prefer-user-event): format list of userEvent methods correctly * test(prefer-user-event): check error data in all invalid cases Closes #310 * fix: second round of bugfixes for v4 (#314) * fix: handle require without assignment properly * fix: handle another require without assignment properly * fix: update rule levels on presets - remove prefer-user-event from presets - report no-debug as error on presets * docs: indicate prefer-user-event is not enabled in any preset Closes #313 * docs: add guide for migrating to v4 (#312) * docs: first steps for migrating to v4 guide * docs: extract Aggressive Reporting Query info to its own section * docs: explain Aggressive Reporting motivation and mechanism * docs: describe each aggressive reporting mechanism * docs: shared settings * docs: update info related to Shareable Configs updated * docs: fix typo * docs: fix more typos * docs: replace tho by though * docs: fix wrong new lines entered * ci: remove duplicated max-warnings param * docs: update README for v4 (#317) * docs: update README for v4 * docs: move detailed settings to migratuin guide * docs: format md files with prettier * chore: update dependencies (#319) * fix: third round of bug fixes (#320) * fix(prefer-screen-queries): improve error message * chore: update package keywords Closes #318 * docs: update contributing guidelines to v4 (#321) * docs: update contributing guidelines to v4 * docs: contributing guidelines PR suggestion Co-authored-by: Michaël De Boey <[email protected]> * docs: more contributing guidelines PR suggestions Co-authored-by: Michaël De Boey <[email protected]> Co-authored-by: Michaël De Boey <[email protected]> * ci: remove unnecessary quote marks for node versions Co-authored-by: Michaël De Boey <[email protected]> * Revert "ci: remove unnecessary quote marks for node versions" This reverts commit b150663 * chore: revert node 10.22.1 as minimum version Minimum node version required for using the plugin is still 10.12 but it was up to 10.22.1 because of a dev dependency. This won't affect usages of the plugin so I'm reverting it. More details here: #234 * ci: include 12.0 in node versions matrix * ci: wrap matrix values within quotes Co-authored-by: Nick McCurdy <[email protected]> Co-authored-by: Mateus Felix <[email protected]> Co-authored-by: Mateus Felix <[email protected]> Co-authored-by: Tim Deschryver <[email protected]> Co-authored-by: Gonzalo D'Elia <[email protected]> Co-authored-by: Renato Augusto Gama dos Santos <[email protected]> Co-authored-by: Michaël De Boey <[email protected]> Co-authored-by: Spencer Miskoviak <[email protected]> Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> Co-authored-by: Giorgio Polvara <[email protected]> Co-authored-by: Josh David <[email protected]> Co-authored-by: Thomas Lombart <[email protected]>
2 parents 4727c63 + 22387d5 commit 6e76a28

File tree

99 files changed

+12991
-2659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+12991
-2659
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
coverage/
2+
dist/

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"extends": [
99
"plugin:@typescript-eslint/eslint-recommended",
1010
"plugin:@typescript-eslint/recommended",
11-
"prettier/@typescript-eslint",
11+
"prettier",
1212
"plugin:jest/recommended",
1313
"plugin:jest-formatting/recommended"
1414
],

.github/dependabot.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
version: 2
22
updates:
3-
# Set update schedule for GitHub Actions
4-
- package-ecosystem: 'github-actions'
5-
directory: '/'
3+
- package-ecosystem: github-actions
4+
directory: /
65
schedule:
7-
interval: 'daily'
6+
interval: daily
7+
8+
- package-ecosystem: npm
9+
directory: /
10+
schedule:
11+
interval: daily

.github/workflows/pipeline.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
uses: styfle/[email protected]
2525
with:
2626
access_token: ${{ secrets.GITHUB_TOKEN }}
27+
2728
- name: Checkout
2829
uses: actions/checkout@v2
2930

@@ -37,12 +38,14 @@ jobs:
3738
with:
3839
useLockFile: false
3940

41+
- name: Check Types
42+
run: npm run type-check
43+
4044
- name: Lint code
4145
run: npm run lint
4246

43-
# TODO: reenable on v4 + run tsc
44-
# - name: Check format
45-
# run: npm run format:check
47+
- name: Check format
48+
run: npm run format:check
4649

4750
tests:
4851
name: Tests (Node v${{ matrix.node }} - ESLint v${{ matrix.eslint }})
@@ -51,7 +54,7 @@ jobs:
5154
strategy:
5255
matrix:
5356
node: [ '10.12', '10', '12.0', '12', '14' ]
54-
eslint: [ '5', '6', '7' ]
57+
eslint: [ '7.5', '7' ]
5558

5659
steps:
5760
- name: Cancel Previous Runs

.huskyrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hooks": {
3-
"pre-commit": "npm run test && lint-staged",
3+
"pre-commit": "lint-staged",
44
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
55
}
66
}

.lintstagedrc

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2-
"*.js": ["eslint --fix", "git add"],
3-
"*.md": ["prettier --write", "git add"]
2+
"*.{js,ts}": [
3+
"eslint --max-warnings 0 --fix",
4+
"prettier --write",
5+
"jest --findRelatedTests"
6+
],
7+
"*.md": ["prettier --write"]
48
}

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
singleQuote: true,
3+
};

.prettierrc.json

-4
This file was deleted.

.releaserc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"pkgRoot": "dist",
3+
"branches": [
4+
"+([0-9])?(.{+([0-9]),x}).x",
5+
"main",
6+
"next",
7+
"next-major",
8+
{
9+
"name": "beta",
10+
"prerelease": true
11+
},
12+
{
13+
"name": "alpha",
14+
"prerelease": true
15+
}
16+
]
17+
}

CODE_OF_CONDUCT.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
1414
Examples of behavior that contributes to creating a positive environment
1515
include:
1616

17-
* Using welcoming and inclusive language
18-
* Being respectful of differing viewpoints and experiences
19-
* Gracefully accepting constructive criticism
20-
* Focusing on what is best for the community
21-
* Showing empathy towards other community members
17+
- Using welcoming and inclusive language
18+
- Being respectful of differing viewpoints and experiences
19+
- Gracefully accepting constructive criticism
20+
- Focusing on what is best for the community
21+
- Showing empathy towards other community members
2222

2323
Examples of unacceptable behavior by participants include:
2424

25-
* The use of sexualized language or imagery and unwelcome sexual attention or
26-
advances
27-
* Trolling, insulting/derogatory comments, and personal or political attacks
28-
* Public or private harassment
29-
* Publishing others' private information, such as a physical or electronic
30-
address, without explicit permission
31-
* Other conduct which could reasonably be considered inappropriate in a
32-
professional setting
25+
- The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
- Trolling, insulting/derogatory comments, and personal or political attacks
28+
- Public or private harassment
29+
- Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
- Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
3333

3434
## Our Responsibilities
3535

CONTRIBUTING.md

+61-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,41 @@ Additionally, you need to do a couple of extra things:
7171
- Include your rule in the "Supported Rules" table within the [README.md](./README.md).
7272
Don't forget to include the proper badges if needed and to sort alphabetically the rules for readability.
7373
74-
## Modifying rules
74+
### Custom rule creator
75+
76+
In v4 we introduced several improvements for both the final users as for contributors. Now there is a custom Rule Creator available called `createTestingLibraryRule` which should be the default Rule Creator used in this plugin. This Testing Library Rule Creator extends TSESLint Rule Creator to enhance rules automatically, so it prevents rules to be reported if nothing related to Testing Library found, and injects a 3rd parameter within `create` function: `helpers`.
77+
78+
This new `helpers` available in the `create` of the rule gives you access to a bunch of utils to detect things related to Testing Library. You can find all of them in `detect-testing-library-utils.ts` file, but these are some helpers available:
79+
80+
- `isTestingLibraryImported`
81+
- `isGetQueryVariant`
82+
- `isQueryQueryVariant`
83+
- `isFindQueryVariant`
84+
- `isSyncQuery`
85+
- `isAsyncQuery`
86+
- `isQuery`
87+
- `isCustomQuery`
88+
- `isAsyncUtil`
89+
- `isFireEventUtil`
90+
- `isUserEventUtil`
91+
- `isFireEventMethod`
92+
- `isUserEventMethod`
93+
- `isRenderUtil`
94+
- `isRenderVariableDeclarator`
95+
- `isDebugUtil`
96+
- `isPresenceAssert`
97+
- `isAbsenceAssert`
98+
- `isNodeComingFromTestingLibrary`
99+
100+
Our custom Rule Creator will also take care of common checks like making sure Testing Library is imported, or verify Shared Settings. You don't need to implement anything to check if there is some import related to Testing Library or anything similar in your rule anymore, just stick to the `helpers` received as a 3rd parameter in your `create` function.
101+
102+
If you need some check related to Testing Library which is not available in any existing helper, feel free to implement a new one. You need to make sure to:
103+
104+
- add corresponding type
105+
- pass it through `helpers`
106+
- write some generic test within `fake-rule.ts`, which is a dumb rule to be able to test all enhanced behavior from our custom Rule Creator.
107+
108+
## Updating existing rules
75109
76110
A couple of things you need to remember when editing already existing rules:
77111
@@ -80,6 +114,32 @@ A couple of things you need to remember when editing already existing rules:
80114
- Try to add tests to cover the changes introduced, no matter if that's
81115
a bug fix or a new feature.
82116
117+
## Writing Tests
118+
119+
When writing tests for a new or existing rule, please make sure to follow these guidelines:
120+
121+
### Write real-ish scenarios
122+
123+
Since the plugin will report differently depending on which Testing Library package is imported and what Shared Settings are enabled, writing more realistic scenarios is pretty important. Ideally, you should:
124+
125+
- wrap the code for your rule with a real test file structure, something like
126+
127+
```javascript
128+
import { render } from '@testing-library/react';
129+
130+
test('should report invalid render usage', () => {
131+
// the following line is the actual code you needed to test your rule,
132+
// but everything else helps finding edge cases and makes it more robust.
133+
const wrapper = render(<Component />);
134+
});
135+
```
136+
137+
- add some extra valid and invalid cases for checking what's the result when some Shared Settings are enabled (so things may or may not be reported depending on the settings), or something named in the same way as a Testing Library util is found, but it's not coming from any Testing Library package (so it shouldn't be reported).
138+
139+
### Check as much as you can from error reported on invalid test cases
140+
141+
Please make sure you check `line`, `column`, `messageId` and `data` (if some) in your invalid test cases to check errors are reported as expected.
142+
83143
## Help needed
84144

85145
Please check the [the open issues](https://github.com/testing-library/eslint-plugin-testing-library/issues)

0 commit comments

Comments
 (0)