Skip to content

Commit

Permalink
Minor docs tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 19, 2021
1 parent 34ead70 commit dee1802
Show file tree
Hide file tree
Showing 30 changed files with 21 additions and 83 deletions.
4 changes: 1 addition & 3 deletions docs/new-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)<br>
- [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.
Expand Down
14 changes: 6 additions & 8 deletions docs/rules/assertion-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/hooks-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,7 +44,6 @@ test.before(t => {
});
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/max-asserts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +25,6 @@ test('getSomeObject should define the players\' names', t => {
});
```


## Pass

```js
Expand Down
6 changes: 2 additions & 4 deletions docs/rules/no-async-fn-without-await.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
```
2 changes: 0 additions & 2 deletions docs/rules/no-cb-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +15,6 @@ test.cb('some test', t => {
});
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-duplicate-modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +16,6 @@ test.beforeEach.beforeEach(t => {});
test.only.only.cb(t => {});
```


## Pass

```js
Expand Down
6 changes: 0 additions & 6 deletions docs/rules/no-identical-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,16 +18,11 @@ test('foo', t => {
});
```


## Pass

```js
const test = require('ava');

test(t => {
t.pass();
});

test('foo', t => {
t.pass();
});
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-ignored-test-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +24,6 @@ test('foo', t => {
});
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-import-test-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +22,6 @@ test('foo', t => {
});
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-incorrect-deep-equal.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ The `deepEqual` and `notDeepEqual` assertions are unnecessary when comparing pri

This rule is fixable.


## Fail

```js
Expand All @@ -18,7 +17,6 @@ t.deepEqual(expression, undefined);
t.notDeepEqual(expression, undefined);
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-inline-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +14,6 @@ const test = require('ava');
test('foo', t => t.true(fn()));
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-invalid-end.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +15,6 @@ test('some test', t => {
});
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-nested-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +19,6 @@ test('foo', t => {
});
```


## Pass

```js
Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-only-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ test('test 2', t => {
});
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-skip-assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +14,6 @@ test('some title', t => {
});
```


## Pass

```js
Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-skip-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ test.skip('bar', t => {
});
```


## Pass

```js
Expand Down
1 change: 0 additions & 1 deletion docs/rules/no-statement-after-end.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test.cb(t => {
});
```


## Pass

```js
Expand Down
8 changes: 1 addition & 7 deletions docs/rules/no-todo-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,21 +12,16 @@ const test = require('ava');
test.todo('title', t => {
// ...
});

test.todo(t => {
// ...
});
```


## Pass

```js
const test = require('ava');

test.todo('title');

test(t => {
test('title2', t => {
// ...
});
```
2 changes: 0 additions & 2 deletions docs/rules/no-todo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +12,6 @@ const test = require('ava');
test.todo('some test');
```


## Pass

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/rules/no-unknown-modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +16,6 @@ test.beforeeach(t => {});
test.unknown(t => {});
```


## Pass

```js
Expand Down
Loading

0 comments on commit dee1802

Please sign in to comment.