Skip to content

Commit

Permalink
[reword] implement rules for remaining functions
Browse files Browse the repository at this point in the history
  • Loading branch information
benkimpel committed Jul 19, 2019
1 parent 27a7c51 commit 8d0618c
Show file tree
Hide file tree
Showing 13 changed files with 745 additions and 3 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,30 @@ Then configure the rules you want to use under the rules section.
```json
{
"rules": {
"jest-formatting/padding-before-test-blocks": 2,
"jest-formatting/padding-before-describe-blocks": 2
"jest-formatting/padding-before-all": 2
}
}
```

_or_

```json
{
"rules": {
"jest-formatting/padding-before-describe-blocks": 2,
"jest-formatting/padding-before-test-blocks": 2
}
}
```

## Rule Documentation

- [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md)
- [padding-before-all](docs/rules/padding-before-all.md)

- [padding-before-after-all-blocks](docs/rules/padding-before-after-all-blocks.md)
- [padding-before-after-each-blocks](docs/rules/padding-before-after-each-blocks.md)
- [padding-before-before-all-blocks](docs/rules/padding-before-before-all-blocks.md)
- [padding-before-before-each-blocks](docs/rules/padding-before-before-each-blocks.md)
- [padding-before-describe-blocks](docs/rules/padding-before-describe-blocks.md)
- [padding-before-expect-statements](docs/rules/padding-before-expect-statements.md)
- [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md)
24 changes: 24 additions & 0 deletions docs/rules/padding-before-after-all-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# padding-before-after-all-blocks

## Rule Details

This rule enforces a line of padding before afterAll blocks

Examples of **incorrect** code for this rule:

```js
const something = 123;
afterAll(() => {
// more stuff
});
```

Examples of **correct** code for this rule:

```js
const something = 123;

afterAll(() => {
// more stuff
});
```
24 changes: 24 additions & 0 deletions docs/rules/padding-before-after-each-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# padding-before-after-each-blocks

## Rule Details

This rule enforces a line of padding before afterEach blocks

Examples of **incorrect** code for this rule:

```js
const something = 123;
afterEach(() => {
// more stuff
});
```

Examples of **correct** code for this rule:

```js
const something = 123;

afterEach(() => {
// more stuff
});
```
15 changes: 15 additions & 0 deletions docs/rules/padding-before-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# padding-before-after-all-blocks

## Rule Details

This rule enforces a line of padding before all Jest tokens.

See each individual rules for examples.

- [padding-before-after-all-blocks](docs/rules/padding-before-after-all-blocks.md)
- [padding-before-after-each-blocks](docs/rules/padding-before-after-each-blocks.md)
- [padding-before-before-all-blocks](docs/rules/padding-before-before-all-blocks.md)
- [padding-before-before-each-blocks](docs/rules/padding-before-before-each-blocks.md)
- [padding-before-describe-blocks](docs/rules/padding-before-describe-blocks.md)
- [padding-before-expect-statements](docs/rules/padding-before-expect-statements.md)
- [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md)
24 changes: 24 additions & 0 deletions docs/rules/padding-before-before-all-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# padding-before-before-all-blocks

## Rule Details

This rule enforces a line of padding before beforeAll blocks

Examples of **incorrect** code for this rule:

```js
const something = 123;
beforeAll(() => {
// more stuff
});
```

Examples of **correct** code for this rule:

```js
const something = 123;

beforeAll(() => {
// more stuff
});
```
24 changes: 24 additions & 0 deletions docs/rules/padding-before-before-each-blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# padding-before-before-each-blocks

## Rule Details

This rule enforces a line of padding before beforeEach blocks

Examples of **incorrect** code for this rule:

```js
const something = 123;
beforeEach(() => {
// more stuff
});
```

Examples of **correct** code for this rule:

```js
const something = 123;

beforeEach(() => {
// more stuff
});
```
22 changes: 22 additions & 0 deletions docs/rules/padding-before-expect-statements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# padding-before-expect-statements

## Rule Details

This rule enforces a line of padding before non-consecutive expect statements

Examples of **incorrect** code for this rule:

```js
const something = 123;
expect(something).toEqual(123);
expect(something).toBeGreaterThan(0);
```

Examples of **correct** code for this rule:

```js
const something = 123;

expect(something).toEqual(123);
expect(something).toBeGreaterThan(0);
```
33 changes: 33 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,43 @@ import { makeRule } from './utils';
//------------------------------------------------------------------------------

export const rules = {
'padding-before-after-all-blocks': makeRule([
{ blankLine: 'always', prev: '*', next: 'afterAll' },
]),
'padding-before-after-each-blocks': makeRule([
{ blankLine: 'always', prev: '*', next: 'afterEach' },
]),
'padding-before-before-all-blocks': makeRule([
{ blankLine: 'always', prev: '*', next: 'beforeAll' },
]),
'padding-before-before-each-blocks': makeRule([
{ blankLine: 'always', prev: '*', next: 'beforeEach' },
]),
'padding-before-describe-blocks': makeRule([
{ blankLine: 'always', prev: '*', next: 'describe' },
]),
'padding-before-expect-statements': makeRule([
{ blankLine: 'always', prev: '*', next: 'expect' },
{ blankLine: 'any', prev: 'expect', next: 'expect' },
]),
'padding-before-test-blocks': makeRule([
{ blankLine: 'always', prev: '*', next: ['test', 'it'] },
]),
'padding-before-all': makeRule([
{
blankLine: 'always',
prev: '*',
next: [
'afterAll',
'afterEach',
'beforeAll',
'beforeEach',
'describe',
'expect',
'it',
'test',
],
},
{ blankLine: 'any', prev: 'expect', next: 'expect' },
]),
};
104 changes: 104 additions & 0 deletions tests/lib/rules/padding-before-after-all-blocks.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @fileoverview Enforces single line padding before afterAll blocks
*/

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const { RuleTester } = require('eslint');
const rule = require('../../../lib').rules['padding-before-after-all-blocks'];

const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6,
},
});

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const invalid = `
const someText = 'abc';
afterAll(() => {
});
describe('someText', () => {
const something = 'abc';
// A comment
afterAll(() => {
// stuff
});
});
describe('someText', () => {
const something = 'abc';
afterAll(() => {
// stuff
});
});
`;

const valid = `
const someText = 'abc';
afterAll(() => {
});
describe('someText', () => {
const something = 'abc';
// A comment
afterAll(() => {
// stuff
});
});
describe('someText', () => {
const something = 'abc';
afterAll(() => {
// stuff
});
});
`;

ruleTester.run('padding-before-after-all-blocks', rule, {
valid: [
valid,
{
code: invalid,
filename: 'src/component.jsx'
}
],
invalid: [
{
code: invalid,
filename: 'src/component.test.jsx',
errors: 3,
output: valid,
},
{
code: invalid,
filename: 'src/component.test.js',
errors: [
{
message: 'Expected blank line before this statement.',
line: 3,
column: 1
},
{
message: 'Expected blank line before this statement.',
line: 9,
column: 3
},
{
message: 'Expected blank line before this statement.',
line: 16,
column: 3
},
]
},
]
});
Loading

0 comments on commit 8d0618c

Please sign in to comment.