From dee1802d39e22aec0915d5067062356f5abfbd84 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 20 Apr 2021 01:35:55 +0700 Subject: [PATCH] Minor docs tweaks --- docs/new-rule.md | 4 +--- docs/rules/assertion-arguments.md | 14 ++++++-------- docs/rules/hooks-order.md | 2 -- docs/rules/max-asserts.md | 2 -- docs/rules/no-async-fn-without-await.md | 6 ++---- docs/rules/no-cb-test.md | 2 -- docs/rules/no-duplicate-modifiers.md | 2 -- docs/rules/no-identical-title.md | 6 ------ 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-invalid-end.md | 2 -- docs/rules/no-nested-tests.md | 2 -- docs/rules/no-only-test.md | 1 - docs/rules/no-skip-assert.md | 2 -- docs/rules/no-skip-test.md | 1 - docs/rules/no-statement-after-end.md | 1 - docs/rules/no-todo-implementation.md | 8 +------- docs/rules/no-todo-test.md | 2 -- docs/rules/no-unknown-modifiers.md | 2 -- docs/rules/prefer-async-await.md | 6 ++---- docs/rules/prefer-power-assert.md | 6 ++---- docs/rules/prefer-t-regex.md | 2 -- docs/rules/test-ended.md | 2 -- docs/rules/test-title-format.md | 3 --- docs/rules/test-title.md | 2 -- docs/rules/use-t-well.md | 2 -- docs/rules/use-t.md | 10 +++++----- docs/rules/use-true-false.md | 4 ++-- 30 files changed, 21 insertions(+), 83 deletions(-) diff --git a/docs/new-rule.md b/docs/new-rule.md index 8cc5aa5..85e57a4 100644 --- a/docs/new-rule.md +++ b/docs/new-rule.md @@ -7,12 +7,10 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela - [Read the ESLint docs on creating a new rule.](https://eslint.org/docs/developer-guide/working-with-rules) - Look at the commit for how previous rules were added as inspiration. For example, the [`no-async-fn-without-await` rule](https://github.com/avajs/eslint-plugin-ava/commit/a443d7a9c94165f42749938e6b491a7c10749b6c). - ## Tip Use the [`astexplorer` site](https://astexplorer.net) with the `espree` parser and `ESLint v4` transform to interactively create the initial rule implementation. It lets you inspect the full AST as you would get from ESLint and you can even see the result of your auto-fixer implementation. - ## Steps - Go to the `test` directory and duplicate the `no-todo-test.js` file and rename it to the name of your rule. Then write some tests before starting to implement the rule. @@ -22,7 +20,7 @@ Use the [`astexplorer` site](https://astexplorer.net) with the `espree` parser a - Add the rule in alphabetically sorted order to: - [The recommended config](https://github.com/avajs/eslint-plugin-ava/blob/0ded4b5c3cd09504e846309760566c9499a24196/index.js#L19) - [The recommended config in the readme](https://github.com/avajs/eslint-plugin-ava/blame/0ded4b5c3cd09504e846309760566c9499a24196/readme.md#L35) - - [The rule listing in the readme](https://github.com/avajs/eslint-plugin-ava/blame/0ded4b5c3cd09504e846309760566c9499a24196/readme.md#L73)
+ - [The rule listing in the readme](https://github.com/avajs/eslint-plugin-ava/blame/0ded4b5c3cd09504e846309760566c9499a24196/readme.md#L73)\ *(The description should be the same as the heading of the documentation file).* - Run `$ npm test` to ensure the tests pass. - Run `$ npm run integration` to run the rules against real projects to ensure your rule does not fail on real-world code. diff --git a/docs/rules/assertion-arguments.md b/docs/rules/assertion-arguments.md index 3942c4b..98c1503 100644 --- a/docs/rules/assertion-arguments.md +++ b/docs/rules/assertion-arguments.md @@ -13,46 +13,44 @@ This rule also attempts to enforce passing actual values before expected values. ```js const test = require('ava'); -test(t => { +test('1', t => { t.is(value); // Not enough arguments t.is(value, expected, message, extra); // Too many arguments t.is(value, expected, false); // Assertion message is not a string }); /* eslint ava/assertion-arguments: ["error", {"message": "always"}] */ -test(t => { +test('2', t => { t.true(array.includes(value)); }); /* eslint ava/assertion-arguments: ["error", {"message": "never"}] */ -test(t => { +test('3', t => { t.true(array.includes(value), 'value is not in array'); }); ``` - ## Pass ```js const test = require('ava'); -test(t => { +test('1', t => { t.is(value, expected); t.is(value, expected, message); }); /* eslint ava/assertion-arguments: ["error", {"message": "always"}] */ -test(t => { +test('2', t => { t.true(array.includes(value), 'value is not in array'); }); /* eslint ava/assertion-arguments: ["error", {"message": "never"}] */ -test(t => { +test('3', t => { t.true(array.includes(value)); }); ``` - ## Options This rule supports the following options: diff --git a/docs/rules/hooks-order.md b/docs/rules/hooks-order.md index 3213b9c..bcb5a29 100644 --- a/docs/rules/hooks-order.md +++ b/docs/rules/hooks-order.md @@ -14,7 +14,6 @@ Hooks should be placed before any tests and in the proper semantic order: This rule is fixable as long as no other code is between the hooks that need to be reordered. - ## Fail ```js @@ -45,7 +44,6 @@ test.before(t => { }); ``` - ## Pass ```js diff --git a/docs/rules/max-asserts.md b/docs/rules/max-asserts.md index 756d5a8..a048f8f 100644 --- a/docs/rules/max-asserts.md +++ b/docs/rules/max-asserts.md @@ -6,7 +6,6 @@ Limit the amount of assertions in a test to enforce splitting up large tests int Skipped assertions are counted. - ## Fail ```js @@ -26,7 +25,6 @@ test('getSomeObject should define the players\' names', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-async-fn-without-await.md b/docs/rules/no-async-fn-without-await.md index cad70e3..dc5a5fb 100644 --- a/docs/rules/no-async-fn-without-await.md +++ b/docs/rules/no-async-fn-without-await.md @@ -8,26 +8,24 @@ Declaring an async test without using the `await` keyword means that either a Pr This rule will report an error when it finds an async test which does not use the `await` keyword. - ## Fail ```js const test = require('ava'); -test(async t => { +test('foo', async t => { return foo().then(res => { t.is(res, 1); }); }); ``` - ## Pass ```js const test = require('ava'); -test(async t => { +test('foo', async t => { t.is(await foo(), 1); }); ``` diff --git a/docs/rules/no-cb-test.md b/docs/rules/no-cb-test.md index 5f64050..7ff8a38 100644 --- a/docs/rules/no-cb-test.md +++ b/docs/rules/no-cb-test.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Disallow the use of `test.cb()`. We instead recommend using `test()` with an async function or a function returning a promise. - ## Fail ```js @@ -16,7 +15,6 @@ test.cb('some test', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-duplicate-modifiers.md b/docs/rules/no-duplicate-modifiers.md index 517f6f3..e4bd251 100644 --- a/docs/rules/no-duplicate-modifiers.md +++ b/docs/rules/no-duplicate-modifiers.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Prevent the use of duplicate [test modifiers](https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md). - ## Fail ```js @@ -17,7 +16,6 @@ test.beforeEach.beforeEach(t => {}); test.only.only.cb(t => {}); ``` - ## Pass ```js diff --git a/docs/rules/no-identical-title.md b/docs/rules/no-identical-title.md index 5ba9fe3..269ef2a 100644 --- a/docs/rules/no-identical-title.md +++ b/docs/rules/no-identical-title.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Disallow tests with identical titles as it makes it hard to differentiate them. - ## Fail ```js @@ -19,16 +18,11 @@ test('foo', t => { }); ``` - ## Pass ```js const test = require('ava'); -test(t => { - t.pass(); -}); - test('foo', t => { t.pass(); }); diff --git a/docs/rules/no-ignored-test-files.md b/docs/rules/no-ignored-test-files.md index 17f440c..061f393 100644 --- a/docs/rules/no-ignored-test-files.md +++ b/docs/rules/no-ignored-test-files.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela This rule will verify that files which create tests are treated as test files by AVA. It will consider the root of the project to be the closest folder containing a `package.json` file, and will not do anything if it can't find one. Test files in `node_modules` will not be linted as they are ignored by ESLint. - ## Fail ```js @@ -25,7 +24,6 @@ test('foo', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-import-test-files.md b/docs/rules/no-import-test-files.md index 2d2941f..ff0ab9c 100644 --- a/docs/rules/no-import-test-files.md +++ b/docs/rules/no-import-test-files.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela This rule will verify that you don't import any test files. It will consider the root of the project to be the closest folder containing a `package.json` file, and will not do anything if it can't find one. Test files in `node_modules` will not be linted as they are ignored by ESLint. - ## Fail ```js @@ -23,7 +22,6 @@ test('foo', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-incorrect-deep-equal.md b/docs/rules/no-incorrect-deep-equal.md index 1eb3526..f98033e 100644 --- a/docs/rules/no-incorrect-deep-equal.md +++ b/docs/rules/no-incorrect-deep-equal.md @@ -6,7 +6,6 @@ The `deepEqual` and `notDeepEqual` assertions are unnecessary when comparing pri This rule is fixable. - ## Fail ```js @@ -18,7 +17,6 @@ t.deepEqual(expression, undefined); t.notDeepEqual(expression, undefined); ``` - ## Pass ```js diff --git a/docs/rules/no-inline-assertions.md b/docs/rules/no-inline-assertions.md index 72bd70f..23b07d2 100644 --- a/docs/rules/no-inline-assertions.md +++ b/docs/rules/no-inline-assertions.md @@ -6,7 +6,6 @@ The test implementation should not purely consist of an inline assertion as asse This rule is fixable. It will wrap the assertion in braces `{}`. It will not do any whitespace or style changes. - ## Fail ```js @@ -15,7 +14,6 @@ const test = require('ava'); test('foo', t => t.true(fn())); ``` - ## Pass ```js diff --git a/docs/rules/no-invalid-end.md b/docs/rules/no-invalid-end.md index 89902ad..f1eb29a 100644 --- a/docs/rules/no-invalid-end.md +++ b/docs/rules/no-invalid-end.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela AVA will fail if `t.end()` is called in a non-`.cb` test function. - ## Fail ```js @@ -16,7 +15,6 @@ test('some test', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-nested-tests.md b/docs/rules/no-nested-tests.md index 467d5a6..a40c90d 100644 --- a/docs/rules/no-nested-tests.md +++ b/docs/rules/no-nested-tests.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela In AVA, you cannot nest tests, for example, create tests inside of other tests. Doing so will lead to odd behavior. - ## Fail ```js @@ -20,7 +19,6 @@ test('foo', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-only-test.md b/docs/rules/no-only-test.md index 92201c3..454baee 100644 --- a/docs/rules/no-only-test.md +++ b/docs/rules/no-only-test.md @@ -19,7 +19,6 @@ test('test 2', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-skip-assert.md b/docs/rules/no-skip-assert.md index 8bfe570..fc886ee 100644 --- a/docs/rules/no-skip-assert.md +++ b/docs/rules/no-skip-assert.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela It's easy to make an assertion skipped with `t.skip.xyz()` and then forget about it. - ## Fail ```js @@ -15,7 +14,6 @@ test('some title', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-skip-test.md b/docs/rules/no-skip-test.md index a770752..d8ecc81 100644 --- a/docs/rules/no-skip-test.md +++ b/docs/rules/no-skip-test.md @@ -18,7 +18,6 @@ test.skip('bar', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-statement-after-end.md b/docs/rules/no-statement-after-end.md index eda431c..3583e14 100644 --- a/docs/rules/no-statement-after-end.md +++ b/docs/rules/no-statement-after-end.md @@ -20,7 +20,6 @@ test.cb(t => { }); ``` - ## Pass ```js diff --git a/docs/rules/no-todo-implementation.md b/docs/rules/no-todo-implementation.md index fd706e4..cf9cfc6 100644 --- a/docs/rules/no-todo-implementation.md +++ b/docs/rules/no-todo-implementation.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela [`test.todo()`](https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#test-placeholders-todo) is intended for planning tests. It's not meant to be passed a function to implement the test, and if given one, AVA will throw an error. If you added an implementation, you probably meant to remove the `.todo` modifier. - ## Fail ```js @@ -13,13 +12,8 @@ const test = require('ava'); test.todo('title', t => { // ... }); - -test.todo(t => { - // ... -}); ``` - ## Pass ```js @@ -27,7 +21,7 @@ const test = require('ava'); test.todo('title'); -test(t => { +test('title2', t => { // ... }); ``` diff --git a/docs/rules/no-todo-test.md b/docs/rules/no-todo-test.md index 72a72c4..462d03e 100644 --- a/docs/rules/no-todo-test.md +++ b/docs/rules/no-todo-test.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Disallow the use of `test.todo()`. You might want to do this to only ship features with specs fully written and passing. - ## Fail ```js @@ -13,7 +12,6 @@ const test = require('ava'); test.todo('some test'); ``` - ## Pass ```js diff --git a/docs/rules/no-unknown-modifiers.md b/docs/rules/no-unknown-modifiers.md index de736c1..c4a5f7e 100644 --- a/docs/rules/no-unknown-modifiers.md +++ b/docs/rules/no-unknown-modifiers.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Prevent the use of unknown [test modifiers](https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md). - ## Fail ```js @@ -17,7 +16,6 @@ test.beforeeach(t => {}); test.unknown(t => {}); ``` - ## Pass ```js diff --git a/docs/rules/prefer-async-await.md b/docs/rules/prefer-async-await.md index 570b5aa..428ab30 100644 --- a/docs/rules/prefer-async-await.md +++ b/docs/rules/prefer-async-await.md @@ -6,26 +6,24 @@ AVA comes with built-in support for async functions (async/await). This allows y This rule will report an error when it finds a test that returns an expression that looks like a Promise (containing a `.then()` call), which could be simplified by using the async/await syntax. - ## Fail ```js const test = require('ava'); -test(t => { +test('foo', t => { return foo().then(res => { t.is(res, 1); }); }); ``` - ## Pass ```js const test = require('ava'); -test(async t => { +test('foo', async t => { t.is(await foo(), 1); }); ``` diff --git a/docs/rules/prefer-power-assert.md b/docs/rules/prefer-power-assert.md index 5513ede..48222f4 100644 --- a/docs/rules/prefer-power-assert.md +++ b/docs/rules/prefer-power-assert.md @@ -13,13 +13,12 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Useful for people wanting to fully embrace the power of [power-assert](https://github.com/power-assert-js/power-assert). - ## Fail ```js const test = require('ava'); -test(t => { +test('foo', t => { t.truthy(foo); t.falsy(foo); t.true(foo === bar); @@ -31,13 +30,12 @@ test(t => { }); ``` - ## Pass ```js const test = require('ava'); -test(t => { +test('foo', t => { t.assert(foo === bar); t.deepEqual(foo, bar); t.notDeepEqual(foo, bar); diff --git a/docs/rules/prefer-t-regex.md b/docs/rules/prefer-t-regex.md index 4a561ef..3b7842c 100644 --- a/docs/rules/prefer-t-regex.md +++ b/docs/rules/prefer-t-regex.md @@ -8,7 +8,6 @@ This rule will enforce the use of `t.regex()` instead of manually using `RegExp# This rule is fixable. It will replace the use of `RegExp#test()`, `String#match()`, or `String#search()` with `t.regex()`. - ## Fail ```js @@ -27,7 +26,6 @@ test('main', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/test-ended.md b/docs/rules/test-ended.md index 96f1738..f2252f4 100644 --- a/docs/rules/test-ended.md +++ b/docs/rules/test-ended.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela If you forget a `t.end();` in `test.cb()` the test will hang indefinitely. - ## Fail ```js @@ -15,7 +14,6 @@ test.cb(t => { }); ``` - ## Pass ```js diff --git a/docs/rules/test-title-format.md b/docs/rules/test-title-format.md index bdf6f2c..1bfc322 100644 --- a/docs/rules/test-title-format.md +++ b/docs/rules/test-title-format.md @@ -6,7 +6,6 @@ This rule is useful when you want to make sure all test titles match a common pa For example, titles like `'Should throw when invalid.'`, `'Should fail when called.'` or `'Should pass when using any number.'` could be enforced with the following pattern `'^Should (pass|fail|throw) when [\\w ]+\\.$'` (Note the escaped `\`). - ## Fail ```js @@ -27,7 +26,6 @@ test('Doesn\'t end with a dot', t => { }); ``` - ## Pass ```js @@ -52,7 +50,6 @@ test('End with a dot.', t => { }); ``` - ## Options This rule supports the following options: diff --git a/docs/rules/test-title.md b/docs/rules/test-title.md index 00f13e5..022eca9 100644 --- a/docs/rules/test-title.md +++ b/docs/rules/test-title.md @@ -4,7 +4,6 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/rela Tests should have a title. AVA [v1.0.1](https://github.com/avajs/ava/releases/tag/v1.0.1) and later enforces this at runtime. - ## Fail ```js @@ -15,7 +14,6 @@ test(t => { }); ``` - ## Pass ```js diff --git a/docs/rules/use-t-well.md b/docs/rules/use-t-well.md index e9ec334..1c4bf81 100644 --- a/docs/rules/use-t-well.md +++ b/docs/rules/use-t-well.md @@ -6,7 +6,6 @@ Prevent the use of unknown assertion methods and the access to members other tha This rule is partly fixable. It can fix most misspelled assertion method names and incorrect usages of `.skip`. - ## Fail ```js @@ -24,7 +23,6 @@ test('main', t => { }); ``` - ## Pass ```js diff --git a/docs/rules/use-t.md b/docs/rules/use-t.md index 3d17ddd..22d4ddf 100644 --- a/docs/rules/use-t.md +++ b/docs/rules/use-t.md @@ -9,15 +9,15 @@ The convention is to have the parameter in AVA's test function be named `t`. Mos ```js const test = require('ava'); -test(foo => { // Incorrect name +test('foo', foo => { // Incorrect name t.pass(); }); -test((t, bar) => { // too many arguments +test('bar', (t, bar) => { // too many arguments t.pass(); }); -test((bar, t) => { // too many arguments +test('baz', (bar, t) => { // too many arguments t.pass(); }); ``` @@ -27,11 +27,11 @@ test((bar, t) => { // too many arguments ```js const test = require('ava'); -test(() => { +test('foo', () => { // ... }); -test(t => { +test('bar', t => { t.pass(); }); ``` diff --git a/docs/rules/use-true-false.md b/docs/rules/use-true-false.md index b9d2a49..9dab3bc 100644 --- a/docs/rules/use-true-false.md +++ b/docs/rules/use-true-false.md @@ -11,7 +11,7 @@ This rule enforces the use of the former when the tested expression is known to ```js const ava = require('ava'); -test(t => { +test('foo', t => { t.truthy(value < 2); t.truthy(value === 1); t.truthy([1, 2, 3].includes(value)); @@ -26,7 +26,7 @@ test(t => { ```js const ava = require('ava'); -test(t => { +test('foo', t => { t.true(value < 2); t.true(value === 1); t.true([1, 2, 3].includes(value));