From b5561e4cfea6fec09e57096cf3f56628c799551d Mon Sep 17 00:00:00 2001 From: Tyler Vigario Date: Fri, 3 May 2024 00:51:18 -0700 Subject: [PATCH] Target ESLint 9 (#357) Co-authored-by: Sindre Sorhus --- .github/workflows/ci.yml | 2 +- docs/rules/assertion-arguments.md | 2 +- docs/rules/hooks-order.md | 2 +- docs/rules/max-asserts.md | 2 +- docs/rules/no-async-fn-without-await.md | 2 +- docs/rules/no-duplicate-modifiers.md | 2 +- docs/rules/no-identical-title.md | 2 +- docs/rules/no-ignored-test-files.md | 2 +- docs/rules/no-import-test-files.md | 2 +- docs/rules/no-incorrect-deep-equal.md | 2 +- docs/rules/no-inline-assertions.md | 2 +- docs/rules/no-nested-tests.md | 2 +- docs/rules/no-only-test.md | 4 +- docs/rules/no-skip-assert.md | 2 +- docs/rules/no-skip-test.md | 4 +- docs/rules/no-todo-implementation.md | 2 +- docs/rules/no-todo-test.md | 2 +- docs/rules/no-unknown-modifiers.md | 2 +- docs/rules/prefer-async-await.md | 2 +- docs/rules/prefer-power-assert.md | 2 +- docs/rules/prefer-t-regex.md | 2 +- docs/rules/test-title-format.md | 2 +- docs/rules/test-title.md | 2 +- docs/rules/use-t-throws-async-well.md | 2 +- docs/rules/use-t-well.md | 2 +- docs/rules/use-t.md | 2 +- docs/rules/use-test.md | 2 +- docs/rules/use-true-false.md | 2 +- index.js | 72 ++++++++++++++----------- package.json | 4 +- readme.md | 62 ++++++++++----------- rules/assertion-arguments.js | 2 +- rules/prefer-t-regex.js | 9 ++-- 33 files changed, 111 insertions(+), 98 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c0efd2..869d4f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^14.17, ^16.4] + node-version: [^18.18] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/docs/rules/assertion-arguments.md b/docs/rules/assertion-arguments.md index 3794e45..a5e5d53 100644 --- a/docs/rules/assertion-arguments.md +++ b/docs/rules/assertion-arguments.md @@ -1,6 +1,6 @@ # Enforce passing correct arguments to assertions (`ava/assertion-arguments`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/hooks-order.md b/docs/rules/hooks-order.md index 26c67dc..06e6611 100644 --- a/docs/rules/hooks-order.md +++ b/docs/rules/hooks-order.md @@ -1,6 +1,6 @@ # Enforce test hook ordering (`ava/hooks-order`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/max-asserts.md b/docs/rules/max-asserts.md index 52c4793..04244ae 100644 --- a/docs/rules/max-asserts.md +++ b/docs/rules/max-asserts.md @@ -1,6 +1,6 @@ # Enforce a limit on the number of assertions in a test (`ava/max-asserts`) -🚫 This rule is _disabled_ in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +🚫 This rule is _disabled_ in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-async-fn-without-await.md b/docs/rules/no-async-fn-without-await.md index 4f5b249..325ab0d 100644 --- a/docs/rules/no-async-fn-without-await.md +++ b/docs/rules/no-async-fn-without-await.md @@ -1,6 +1,6 @@ # Ensure that async tests use `await` (`ava/no-async-fn-without-await`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-duplicate-modifiers.md b/docs/rules/no-duplicate-modifiers.md index 6ddd0b5..a0842f8 100644 --- a/docs/rules/no-duplicate-modifiers.md +++ b/docs/rules/no-duplicate-modifiers.md @@ -1,6 +1,6 @@ # Ensure tests do not have duplicate modifiers (`ava/no-duplicate-modifiers`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-identical-title.md b/docs/rules/no-identical-title.md index 3b69185..2da828d 100644 --- a/docs/rules/no-identical-title.md +++ b/docs/rules/no-identical-title.md @@ -1,6 +1,6 @@ # Ensure no tests have the same title (`ava/no-identical-title`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-ignored-test-files.md b/docs/rules/no-ignored-test-files.md index ff358c3..89256b0 100644 --- a/docs/rules/no-ignored-test-files.md +++ b/docs/rules/no-ignored-test-files.md @@ -1,6 +1,6 @@ # Ensure no tests are written in ignored files (`ava/no-ignored-test-files`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-import-test-files.md b/docs/rules/no-import-test-files.md index 57bfd36..32ca1cb 100644 --- a/docs/rules/no-import-test-files.md +++ b/docs/rules/no-import-test-files.md @@ -1,6 +1,6 @@ # Ensure no test files are imported anywhere (`ava/no-import-test-files`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-incorrect-deep-equal.md b/docs/rules/no-incorrect-deep-equal.md index 1aefeb0..6343f0e 100644 --- a/docs/rules/no-incorrect-deep-equal.md +++ b/docs/rules/no-incorrect-deep-equal.md @@ -1,6 +1,6 @@ # Disallow using `deepEqual` with primitives (`ava/no-incorrect-deep-equal`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/no-inline-assertions.md b/docs/rules/no-inline-assertions.md index da142b6..84039de 100644 --- a/docs/rules/no-inline-assertions.md +++ b/docs/rules/no-inline-assertions.md @@ -1,6 +1,6 @@ # Ensure assertions are not called from inline arrow functions (`ava/no-inline-assertions`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/no-nested-tests.md b/docs/rules/no-nested-tests.md index 8f5195a..12751e7 100644 --- a/docs/rules/no-nested-tests.md +++ b/docs/rules/no-nested-tests.md @@ -1,6 +1,6 @@ # Ensure no tests are nested (`ava/no-nested-tests`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-only-test.md b/docs/rules/no-only-test.md index b575249..8b46bbc 100644 --- a/docs/rules/no-only-test.md +++ b/docs/rules/no-only-test.md @@ -1,8 +1,8 @@ # Ensure no `test.only()` are present (`ava/no-only-test`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. -πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). diff --git a/docs/rules/no-skip-assert.md b/docs/rules/no-skip-assert.md index aaf239d..315b27f 100644 --- a/docs/rules/no-skip-assert.md +++ b/docs/rules/no-skip-assert.md @@ -1,6 +1,6 @@ # Ensure no assertions are skipped (`ava/no-skip-assert`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-skip-test.md b/docs/rules/no-skip-test.md index 471c78d..035cf14 100644 --- a/docs/rules/no-skip-test.md +++ b/docs/rules/no-skip-test.md @@ -1,8 +1,8 @@ # Ensure no tests are skipped (`ava/no-skip-test`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. -πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). diff --git a/docs/rules/no-todo-implementation.md b/docs/rules/no-todo-implementation.md index 4bbf236..7ebf457 100644 --- a/docs/rules/no-todo-implementation.md +++ b/docs/rules/no-todo-implementation.md @@ -1,6 +1,6 @@ # Ensure `test.todo()` is not given an implementation function (`ava/no-todo-implementation`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-todo-test.md b/docs/rules/no-todo-test.md index 0b5cd1b..da8deca 100644 --- a/docs/rules/no-todo-test.md +++ b/docs/rules/no-todo-test.md @@ -1,6 +1,6 @@ # Ensure no `test.todo()` is used (`ava/no-todo-test`) -⚠️ This rule _warns_ in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +⚠️ This rule _warns_ in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/no-unknown-modifiers.md b/docs/rules/no-unknown-modifiers.md index fba9e90..7cb6d0e 100644 --- a/docs/rules/no-unknown-modifiers.md +++ b/docs/rules/no-unknown-modifiers.md @@ -1,6 +1,6 @@ # Disallow the use of unknown test modifiers (`ava/no-unknown-modifiers`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/prefer-async-await.md b/docs/rules/prefer-async-await.md index da96b20..ef12b37 100644 --- a/docs/rules/prefer-async-await.md +++ b/docs/rules/prefer-async-await.md @@ -1,6 +1,6 @@ # Prefer using async/await instead of returning a Promise (`ava/prefer-async-await`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/prefer-power-assert.md b/docs/rules/prefer-power-assert.md index aeddaf2..df33c5e 100644 --- a/docs/rules/prefer-power-assert.md +++ b/docs/rules/prefer-power-assert.md @@ -1,6 +1,6 @@ # Enforce the use of the asserts that have no [power-assert](https://github.com/power-assert-js/power-assert) alternative (`ava/prefer-power-assert`) -🚫 This rule is _disabled_ in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +🚫 This rule is _disabled_ in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/prefer-t-regex.md b/docs/rules/prefer-t-regex.md index f04a186..2fa41d7 100644 --- a/docs/rules/prefer-t-regex.md +++ b/docs/rules/prefer-t-regex.md @@ -1,6 +1,6 @@ # Prefer using `t.regex()` to test regular expressions (`ava/prefer-t-regex`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/test-title-format.md b/docs/rules/test-title-format.md index 7953453..d3b9150 100644 --- a/docs/rules/test-title-format.md +++ b/docs/rules/test-title-format.md @@ -1,6 +1,6 @@ # Ensure test titles have a certain format (`ava/test-title-format`) -🚫 This rule is _disabled_ in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +🚫 This rule is _disabled_ in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/test-title.md b/docs/rules/test-title.md index 7fa8c02..ee06e61 100644 --- a/docs/rules/test-title.md +++ b/docs/rules/test-title.md @@ -1,6 +1,6 @@ # Ensure tests have a title (`ava/test-title`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/use-t-throws-async-well.md b/docs/rules/use-t-throws-async-well.md index 1c72763..108b743 100644 --- a/docs/rules/use-t-throws-async-well.md +++ b/docs/rules/use-t-throws-async-well.md @@ -1,6 +1,6 @@ # Ensure that `t.throwsAsync()` and `t.notThrowsAsync()` are awaited (`ava/use-t-throws-async-well`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/use-t-well.md b/docs/rules/use-t-well.md index 220ba35..8383844 100644 --- a/docs/rules/use-t-well.md +++ b/docs/rules/use-t-well.md @@ -1,6 +1,6 @@ # Disallow the incorrect use of `t` (`ava/use-t-well`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). diff --git a/docs/rules/use-t.md b/docs/rules/use-t.md index 5467cea..d47e451 100644 --- a/docs/rules/use-t.md +++ b/docs/rules/use-t.md @@ -1,6 +1,6 @@ # Ensure test functions use `t` as their parameter (`ava/use-t`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/use-test.md b/docs/rules/use-test.md index d8b1108..42f4e5a 100644 --- a/docs/rules/use-test.md +++ b/docs/rules/use-test.md @@ -1,6 +1,6 @@ # Ensure that AVA is imported with `test` as the variable name (`ava/use-test`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/docs/rules/use-true-false.md b/docs/rules/use-true-false.md index 5b41ed0..5ef3602 100644 --- a/docs/rules/use-true-false.md +++ b/docs/rules/use-true-false.md @@ -1,6 +1,6 @@ # Ensure that `t.true()`/`t.false()` are used instead of `t.truthy()`/`t.falsy()` (`ava/use-true-false`) -πŸ’Ό This rule is enabled in the βœ… `recommended` [config](https://github.com/avajs/eslint-plugin-ava#recommended-config). +πŸ’Ό This rule is enabled in the following [configs](https://github.com/avajs/eslint-plugin-ava#recommended-config): `flat/recommended`, βœ… `recommended`. diff --git a/index.js b/index.js index f671c8f..b6a54fb 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,39 @@ const path = require('path'); const importModules = require('import-modules'); +const rules = { + 'ava/assertion-arguments': 'error', + 'ava/hooks-order': 'error', + 'ava/max-asserts': [ + 'off', + 5, + ], + 'ava/no-async-fn-without-await': 'error', + 'ava/no-duplicate-modifiers': 'error', + 'ava/no-identical-title': 'error', + 'ava/no-ignored-test-files': 'error', + 'ava/no-import-test-files': 'error', + 'ava/no-incorrect-deep-equal': 'error', + 'ava/no-inline-assertions': 'error', + 'ava/no-nested-tests': 'error', + 'ava/no-only-test': 'error', + 'ava/no-skip-assert': 'error', + 'ava/no-skip-test': 'error', + 'ava/no-todo-implementation': 'error', + 'ava/no-todo-test': 'warn', + 'ava/no-unknown-modifiers': 'error', + 'ava/prefer-async-await': 'error', + 'ava/prefer-power-assert': 'off', + 'ava/prefer-t-regex': 'error', + 'ava/test-title': 'error', + 'ava/test-title-format': 'off', + 'ava/use-t-well': 'error', + 'ava/use-t': 'error', + 'ava/use-t-throws-async-well': 'error', + 'ava/use-test': 'error', + 'ava/use-true-false': 'error', +}; + module.exports = { rules: importModules(path.resolve(__dirname, 'rules'), {camelize: false}), configs: { @@ -18,37 +51,16 @@ module.exports = { 'ava', ], rules: { - 'ava/assertion-arguments': 'error', - 'ava/hooks-order': 'error', - 'ava/max-asserts': [ - 'off', - 5, - ], - 'ava/no-async-fn-without-await': 'error', - 'ava/no-duplicate-modifiers': 'error', - 'ava/no-identical-title': 'error', - 'ava/no-ignored-test-files': 'error', - 'ava/no-import-test-files': 'error', - 'ava/no-incorrect-deep-equal': 'error', - 'ava/no-inline-assertions': 'error', - 'ava/no-nested-tests': 'error', - 'ava/no-only-test': 'error', - 'ava/no-skip-assert': 'error', - 'ava/no-skip-test': 'error', - 'ava/no-todo-implementation': 'error', - 'ava/no-todo-test': 'warn', - 'ava/no-unknown-modifiers': 'error', - 'ava/prefer-async-await': 'error', - 'ava/prefer-power-assert': 'off', - 'ava/prefer-t-regex': 'error', - 'ava/test-title': 'error', - 'ava/test-title-format': 'off', - 'ava/use-t-well': 'error', - 'ava/use-t': 'error', - 'ava/use-t-throws-async-well': 'error', - 'ava/use-test': 'error', - 'ava/use-true-false': 'error', + ...rules, }, }, + "flat/recommended": { + plugins: { + 'ava': 'ava' + }, + rules: { + ...rules + } + } }, }; diff --git a/package.json b/package.json index abd1da9..9144460 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "MIT", "repository": "avajs/eslint-plugin-ava", "engines": { - "node": ">=14.17 <15 || >=16.4" + "node": "^18.18 || >=20" }, "scripts": { "integration": "node ./test/integration/test.js", @@ -63,7 +63,7 @@ "xo": "^0.52.4" }, "peerDependencies": { - "eslint": ">=8.26.0" + "eslint": ">=9" }, "ava": { "files": [ diff --git a/readme.md b/readme.md index cbc2721..4985d37 100644 --- a/readme.md +++ b/readme.md @@ -51,37 +51,37 @@ The rules will only activate in test files. 🚫 [Configurations](https://github.com/avajs/eslint-plugin-ava#recommended-config) disabled in.\ βœ… Set in the `recommended` [configuration](https://github.com/avajs/eslint-plugin-ava#recommended-config).\ πŸ”§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\ -πŸ’‘ Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). - -| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  | Description | πŸ’Ό | ⚠️ | 🚫 | πŸ”§ | πŸ’‘ | -| :------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- | :- | :- | :- | :- | :- | -| [assertion-arguments](docs/rules/assertion-arguments.md) | Enforce passing correct arguments to assertions. | βœ… | | | πŸ”§ | | -| [hooks-order](docs/rules/hooks-order.md) | Enforce test hook ordering. | βœ… | | | πŸ”§ | | -| [max-asserts](docs/rules/max-asserts.md) | Enforce a limit on the number of assertions in a test. | | | βœ… | | | -| [no-async-fn-without-await](docs/rules/no-async-fn-without-await.md) | Ensure that async tests use `await`. | βœ… | | | | | -| [no-duplicate-modifiers](docs/rules/no-duplicate-modifiers.md) | Ensure tests do not have duplicate modifiers. | βœ… | | | | | -| [no-identical-title](docs/rules/no-identical-title.md) | Ensure no tests have the same title. | βœ… | | | | | -| [no-ignored-test-files](docs/rules/no-ignored-test-files.md) | Ensure no tests are written in ignored files. | βœ… | | | | | -| [no-import-test-files](docs/rules/no-import-test-files.md) | Ensure no test files are imported anywhere. | βœ… | | | | | -| [no-incorrect-deep-equal](docs/rules/no-incorrect-deep-equal.md) | Disallow using `deepEqual` with primitives. | βœ… | | | πŸ”§ | | -| [no-inline-assertions](docs/rules/no-inline-assertions.md) | Ensure assertions are not called from inline arrow functions. | βœ… | | | πŸ”§ | | -| [no-nested-tests](docs/rules/no-nested-tests.md) | Ensure no tests are nested. | βœ… | | | | | -| [no-only-test](docs/rules/no-only-test.md) | Ensure no `test.only()` are present. | βœ… | | | πŸ”§ | πŸ’‘ | -| [no-skip-assert](docs/rules/no-skip-assert.md) | Ensure no assertions are skipped. | βœ… | | | | | -| [no-skip-test](docs/rules/no-skip-test.md) | Ensure no tests are skipped. | βœ… | | | πŸ”§ | πŸ’‘ | -| [no-todo-implementation](docs/rules/no-todo-implementation.md) | Ensure `test.todo()` is not given an implementation function. | βœ… | | | | | -| [no-todo-test](docs/rules/no-todo-test.md) | Ensure no `test.todo()` is used. | | βœ… | | | | -| [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) | Disallow the use of unknown test modifiers. | βœ… | | | | | -| [prefer-async-await](docs/rules/prefer-async-await.md) | Prefer using async/await instead of returning a Promise. | βœ… | | | | | -| [prefer-power-assert](docs/rules/prefer-power-assert.md) | Enforce the use of the asserts that have no [power-assert](https://github.com/power-assert-js/power-assert) alternative. | | | βœ… | | | -| [prefer-t-regex](docs/rules/prefer-t-regex.md) | Prefer using `t.regex()` to test regular expressions. | βœ… | | | πŸ”§ | | -| [test-title](docs/rules/test-title.md) | Ensure tests have a title. | βœ… | | | | | -| [test-title-format](docs/rules/test-title-format.md) | Ensure test titles have a certain format. | | | βœ… | | | -| [use-t](docs/rules/use-t.md) | Ensure test functions use `t` as their parameter. | βœ… | | | | | -| [use-t-throws-async-well](docs/rules/use-t-throws-async-well.md) | Ensure that `t.throwsAsync()` and `t.notThrowsAsync()` are awaited. | βœ… | | | πŸ”§ | | -| [use-t-well](docs/rules/use-t-well.md) | Disallow the incorrect use of `t`. | βœ… | | | πŸ”§ | | -| [use-test](docs/rules/use-test.md) | Ensure that AVA is imported with `test` as the variable name. | βœ… | | | | | -| [use-true-false](docs/rules/use-true-false.md) | Ensure that `t.true()`/`t.false()` are used instead of `t.truthy()`/`t.falsy()`. | βœ… | | | | | +πŸ’‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). + +| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  | Description | πŸ’Ό | ⚠️ | 🚫 | πŸ”§ | πŸ’‘ | +| :------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- | :---------------------------- | :---------------------------- | :---------------------------- | :- | :- | +| [assertion-arguments](docs/rules/assertion-arguments.md) | Enforce passing correct arguments to assertions. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [hooks-order](docs/rules/hooks-order.md) | Enforce test hook ordering. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [max-asserts](docs/rules/max-asserts.md) | Enforce a limit on the number of assertions in a test. | | | βœ… ![badge-flat/recommended][] | | | +| [no-async-fn-without-await](docs/rules/no-async-fn-without-await.md) | Ensure that async tests use `await`. | βœ… ![badge-flat/recommended][] | | | | | +| [no-duplicate-modifiers](docs/rules/no-duplicate-modifiers.md) | Ensure tests do not have duplicate modifiers. | βœ… ![badge-flat/recommended][] | | | | | +| [no-identical-title](docs/rules/no-identical-title.md) | Ensure no tests have the same title. | βœ… ![badge-flat/recommended][] | | | | | +| [no-ignored-test-files](docs/rules/no-ignored-test-files.md) | Ensure no tests are written in ignored files. | βœ… ![badge-flat/recommended][] | | | | | +| [no-import-test-files](docs/rules/no-import-test-files.md) | Ensure no test files are imported anywhere. | βœ… ![badge-flat/recommended][] | | | | | +| [no-incorrect-deep-equal](docs/rules/no-incorrect-deep-equal.md) | Disallow using `deepEqual` with primitives. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [no-inline-assertions](docs/rules/no-inline-assertions.md) | Ensure assertions are not called from inline arrow functions. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [no-nested-tests](docs/rules/no-nested-tests.md) | Ensure no tests are nested. | βœ… ![badge-flat/recommended][] | | | | | +| [no-only-test](docs/rules/no-only-test.md) | Ensure no `test.only()` are present. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | πŸ’‘ | +| [no-skip-assert](docs/rules/no-skip-assert.md) | Ensure no assertions are skipped. | βœ… ![badge-flat/recommended][] | | | | | +| [no-skip-test](docs/rules/no-skip-test.md) | Ensure no tests are skipped. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | πŸ’‘ | +| [no-todo-implementation](docs/rules/no-todo-implementation.md) | Ensure `test.todo()` is not given an implementation function. | βœ… ![badge-flat/recommended][] | | | | | +| [no-todo-test](docs/rules/no-todo-test.md) | Ensure no `test.todo()` is used. | | βœ… ![badge-flat/recommended][] | | | | +| [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) | Disallow the use of unknown test modifiers. | βœ… ![badge-flat/recommended][] | | | | | +| [prefer-async-await](docs/rules/prefer-async-await.md) | Prefer using async/await instead of returning a Promise. | βœ… ![badge-flat/recommended][] | | | | | +| [prefer-power-assert](docs/rules/prefer-power-assert.md) | Enforce the use of the asserts that have no [power-assert](https://github.com/power-assert-js/power-assert) alternative. | | | βœ… ![badge-flat/recommended][] | | | +| [prefer-t-regex](docs/rules/prefer-t-regex.md) | Prefer using `t.regex()` to test regular expressions. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [test-title](docs/rules/test-title.md) | Ensure tests have a title. | βœ… ![badge-flat/recommended][] | | | | | +| [test-title-format](docs/rules/test-title-format.md) | Ensure test titles have a certain format. | | | βœ… ![badge-flat/recommended][] | | | +| [use-t](docs/rules/use-t.md) | Ensure test functions use `t` as their parameter. | βœ… ![badge-flat/recommended][] | | | | | +| [use-t-throws-async-well](docs/rules/use-t-throws-async-well.md) | Ensure that `t.throwsAsync()` and `t.notThrowsAsync()` are awaited. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [use-t-well](docs/rules/use-t-well.md) | Disallow the incorrect use of `t`. | βœ… ![badge-flat/recommended][] | | | πŸ”§ | | +| [use-test](docs/rules/use-test.md) | Ensure that AVA is imported with `test` as the variable name. | βœ… ![badge-flat/recommended][] | | | | | +| [use-true-false](docs/rules/use-true-false.md) | Ensure that `t.true()`/`t.false()` are used instead of `t.truthy()`/`t.falsy()`. | βœ… ![badge-flat/recommended][] | | | | | diff --git a/rules/assertion-arguments.js b/rules/assertion-arguments.js index 6afcf17..0bf5117 100644 --- a/rules/assertion-arguments.js +++ b/rules/assertion-arguments.js @@ -282,7 +282,7 @@ const create = context => { let lastArg = node.arguments[node.arguments.length - 1]; if (lastArg.type === 'Identifier') { - const variable = findVariable(context.getScope(), lastArg); + const variable = findVariable(context.sourceCode.getScope(node), lastArg); let value; for (const ref of variable.references) { value = ref.writeExpr ?? value; diff --git a/rules/prefer-t-regex.js b/rules/prefer-t-regex.js index 6d103cf..6464f59 100644 --- a/rules/prefer-t-regex.js +++ b/rules/prefer-t-regex.js @@ -20,8 +20,9 @@ const create = context => { ]); // Find the latest reference to the given identifier's name. - const findReference = name => { - const reference = context.getScope().references.find(reference => reference.identifier.name === name); + const findReference = node => { + const sourceCode = context.sourceCode; + const reference = sourceCode.getScope(node).references.find(reference => reference.identifier.name === node.name); if (reference?.resolved) { const definitions = reference.resolved.defs; @@ -37,7 +38,7 @@ const create = context => { /* Recursively find the "origin" node of the given node. - Note: `context.getScope()` doesn't contain information about the outer scope so in most cases this function will only find the reference directly above the current scope. So the following code will only find the reference in this order: y -> x, and it will have no knowledge of the number `0`. (assuming we run this function on the identifier `y`) + Note: `sourceCode.getScope()` doesn't contain information about the outer scope so in most cases this function will only find the reference directly above the current scope. So the following code will only find the reference in this order: y -> x, and it will have no knowledge of the number `0`. (assuming we run this function on the identifier `y`) ``` const test = require('ava'); @@ -56,7 +57,7 @@ const create = context => { } if (node.type === 'Identifier') { - const reference = findReference(node.name); + const reference = findReference(node); if (reference?.init) { return findRootReference(reference.init);