eslint-plugin-jest-formatting 0.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +5 -5
- package/CHANGELOG.md +28 -6
- package/README.md +29 -9
- package/docs/rules/padding-around-after-all-blocks.md +25 -0
- package/docs/rules/padding-around-after-each-blocks.md +29 -0
- package/docs/rules/padding-around-all.md +13 -0
- package/docs/rules/padding-around-before-all-blocks.md +29 -0
- package/docs/rules/padding-around-before-each-blocks.md +29 -0
- package/docs/rules/padding-around-describe-blocks.md +33 -0
- package/docs/rules/padding-around-expect-groups.md +35 -0
- package/docs/rules/padding-around-test-blocks.md +39 -0
- package/lib/ast-utils.js +40 -0
- package/lib/index.js +238 -38
- package/lib/rules/padding.js +130 -158
- package/package.json +4 -2
- package/src/ast-utils.ts +78 -0
- package/src/index.ts +282 -43
- package/src/rules/padding.ts +261 -252
- package/tests/catfood.js +39 -0
- package/tests/dogfood.spec.js +16 -1
- package/tests/lib/ast-utils.spec.ts +94 -0
- package/tests/lib/rules/padding-around-after-all-blocks.spec.js +114 -0
- package/tests/lib/rules/padding-around-after-each-blocks.spec.js +112 -0
- package/tests/lib/rules/padding-around-before-all-blocks.spec.js +114 -0
- package/tests/lib/rules/padding-around-before-each-blocks.spec.js +114 -0
- package/tests/lib/rules/padding-around-describe-blocks.spec.js +152 -0
- package/tests/lib/rules/padding-around-expect-groups.spec.js +154 -0
- package/tests/lib/rules/padding-around-test-blocks.spec.js +161 -0
- package/tests/lib/rules/padding-before-after-all-blocks.spec.js +1 -7
- package/tests/lib/rules/padding-before-after-each-blocks.spec.js +1 -7
- package/tests/lib/rules/padding-before-before-all-blocks.spec.js +1 -7
- package/tests/lib/rules/padding-before-before-each-blocks.spec.js +1 -7
- package/tests/lib/rules/padding-before-describe-blocks.spec.js +1 -7
- package/tests/lib/rules/padding-before-expect-statements.spec.js +1 -7
- package/tests/lib/rules/padding-before-test-blocks.spec.js +1 -7
- package/tsconfig.json +1 -1
- package/yarn.lock +12 -10
- package/lib/utils.js +0 -15
- package/src/utils.ts +0 -40
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enforces single line padding around groups of expect statements
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
//------------------------------------------------------------------------------
|
|
6
|
+
// Requirements
|
|
7
|
+
//------------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
const { RuleTester } = require('eslint');
|
|
10
|
+
const rule = require('../../../lib').rules['padding-around-expect-groups'];
|
|
11
|
+
|
|
12
|
+
const ruleTester = new RuleTester({
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaVersion: 6,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//------------------------------------------------------------------------------
|
|
19
|
+
// Tests
|
|
20
|
+
//------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
const valid = `
|
|
23
|
+
foo();
|
|
24
|
+
bar();
|
|
25
|
+
|
|
26
|
+
const someText = 'abc';
|
|
27
|
+
const someObject = {
|
|
28
|
+
one: 1,
|
|
29
|
+
two: 2,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
test('thing one', () => {
|
|
33
|
+
let abc = 123;
|
|
34
|
+
|
|
35
|
+
expect(abc).toEqual(123);
|
|
36
|
+
expect(123).toEqual(abc); // Line comment
|
|
37
|
+
|
|
38
|
+
abc = 456;
|
|
39
|
+
|
|
40
|
+
expect(abc).toEqual(456);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('thing one', () => {
|
|
44
|
+
const abc = 123;
|
|
45
|
+
|
|
46
|
+
expect(abc).toEqual(123);
|
|
47
|
+
|
|
48
|
+
const xyz = 987;
|
|
49
|
+
|
|
50
|
+
expect(123).toEqual(abc); // Line comment
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('someText', () => {
|
|
54
|
+
describe('some condition', () => {
|
|
55
|
+
test('foo', () => {
|
|
56
|
+
const xyz = 987;
|
|
57
|
+
|
|
58
|
+
// Comment
|
|
59
|
+
expect(xyz).toEqual(987);
|
|
60
|
+
expect(1)
|
|
61
|
+
.toEqual(1);
|
|
62
|
+
expect(true).toEqual(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
const invalid = `
|
|
69
|
+
foo();
|
|
70
|
+
bar();
|
|
71
|
+
|
|
72
|
+
const someText = 'abc';
|
|
73
|
+
const someObject = {
|
|
74
|
+
one: 1,
|
|
75
|
+
two: 2,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
test('thing one', () => {
|
|
79
|
+
let abc = 123;
|
|
80
|
+
expect(abc).toEqual(123);
|
|
81
|
+
expect(123).toEqual(abc); // Line comment
|
|
82
|
+
abc = 456;
|
|
83
|
+
expect(abc).toEqual(456);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('thing one', () => {
|
|
87
|
+
const abc = 123;
|
|
88
|
+
expect(abc).toEqual(123);
|
|
89
|
+
|
|
90
|
+
const xyz = 987;
|
|
91
|
+
expect(123).toEqual(abc); // Line comment
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('someText', () => {
|
|
95
|
+
describe('some condition', () => {
|
|
96
|
+
test('foo', () => {
|
|
97
|
+
const xyz = 987;
|
|
98
|
+
// Comment
|
|
99
|
+
expect(xyz).toEqual(987);
|
|
100
|
+
expect(1)
|
|
101
|
+
.toEqual(1);
|
|
102
|
+
expect(true).toEqual(true);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
ruleTester.run('padding-around-expect-groups', rule, {
|
|
109
|
+
valid: [valid],
|
|
110
|
+
invalid: [
|
|
111
|
+
{
|
|
112
|
+
code: invalid,
|
|
113
|
+
filename: 'src/component.test.jsx',
|
|
114
|
+
errors: 6,
|
|
115
|
+
output: valid,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
code: invalid,
|
|
119
|
+
filename: 'src/component.test.js',
|
|
120
|
+
errors: [
|
|
121
|
+
{
|
|
122
|
+
message: 'Expected blank line before this statement.',
|
|
123
|
+
line: 13,
|
|
124
|
+
column: 3
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
message: 'Expected blank line before this statement.',
|
|
128
|
+
line: 15,
|
|
129
|
+
column: 3
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
message: 'Expected blank line before this statement.',
|
|
133
|
+
line: 16,
|
|
134
|
+
column: 3
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
message: 'Expected blank line before this statement.',
|
|
138
|
+
line: 21,
|
|
139
|
+
column: 3
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
message: 'Expected blank line before this statement.',
|
|
143
|
+
line: 24,
|
|
144
|
+
column: 3
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
message: 'Expected blank line before this statement.',
|
|
148
|
+
line: 32,
|
|
149
|
+
column: 7
|
|
150
|
+
},
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
]
|
|
154
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enforces padding line around test/it blocks
|
|
3
|
+
* @author Dan Green-Leipciger
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
//------------------------------------------------------------------------------
|
|
7
|
+
// Requirements
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
const { RuleTester } = require('eslint');
|
|
10
|
+
const rule = require('../../../lib').rules['padding-around-test-blocks'];
|
|
11
|
+
|
|
12
|
+
const ruleTester = new RuleTester({
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaVersion: 6,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//------------------------------------------------------------------------------
|
|
19
|
+
// Tests
|
|
20
|
+
//------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
const valid = `
|
|
23
|
+
const foo = 'bar';
|
|
24
|
+
const bar = 'baz';
|
|
25
|
+
|
|
26
|
+
it('foo', () => {
|
|
27
|
+
// stuff
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
fit('bar', () => {
|
|
31
|
+
// stuff
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('foo foo', () => {});
|
|
35
|
+
|
|
36
|
+
test('bar bar', () => {});
|
|
37
|
+
|
|
38
|
+
// Nesting
|
|
39
|
+
describe('other bar', () => {
|
|
40
|
+
const thing = 123;
|
|
41
|
+
|
|
42
|
+
test('is another bar w/ test', () => {
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// With a comment
|
|
46
|
+
it('is another bar w/ it', () => {
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test.skip('skipping', () => {}); // Another comment
|
|
50
|
+
|
|
51
|
+
it.skip('skipping too', () => {});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
xtest('weird', () => {});
|
|
55
|
+
|
|
56
|
+
test
|
|
57
|
+
.skip('skippy skip', () => {});
|
|
58
|
+
|
|
59
|
+
xit('bar foo', () => {});
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const invalid = `
|
|
63
|
+
const foo = 'bar';
|
|
64
|
+
const bar = 'baz';
|
|
65
|
+
it('foo', () => {
|
|
66
|
+
// stuff
|
|
67
|
+
});
|
|
68
|
+
fit('bar', () => {
|
|
69
|
+
// stuff
|
|
70
|
+
});
|
|
71
|
+
test('foo foo', () => {});
|
|
72
|
+
test('bar bar', () => {});
|
|
73
|
+
|
|
74
|
+
// Nesting
|
|
75
|
+
describe('other bar', () => {
|
|
76
|
+
const thing = 123;
|
|
77
|
+
test('is another bar w/ test', () => {
|
|
78
|
+
});
|
|
79
|
+
// With a comment
|
|
80
|
+
it('is another bar w/ it', () => {
|
|
81
|
+
});
|
|
82
|
+
test.skip('skipping', () => {}); // Another comment
|
|
83
|
+
it.skip('skipping too', () => {});
|
|
84
|
+
});xtest('weird', () => {});
|
|
85
|
+
test
|
|
86
|
+
.skip('skippy skip', () => {});
|
|
87
|
+
xit('bar foo', () => {});
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
ruleTester.run('padding-around-test-blocks', rule, {
|
|
91
|
+
valid: [valid],
|
|
92
|
+
invalid: [
|
|
93
|
+
{
|
|
94
|
+
code: invalid,
|
|
95
|
+
filename: 'src/component.test.jsx',
|
|
96
|
+
errors: 11,
|
|
97
|
+
output: valid,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
code: invalid,
|
|
101
|
+
filename: 'src/component.test.js',
|
|
102
|
+
errors: [
|
|
103
|
+
{
|
|
104
|
+
message: 'Expected blank line before this statement.',
|
|
105
|
+
line: 4,
|
|
106
|
+
column: 1
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
message: 'Expected blank line before this statement.',
|
|
110
|
+
line: 7,
|
|
111
|
+
column: 1
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
message: 'Expected blank line before this statement.',
|
|
115
|
+
line: 10,
|
|
116
|
+
column: 1
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
message: 'Expected blank line before this statement.',
|
|
120
|
+
line: 11,
|
|
121
|
+
column: 1
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
message: 'Expected blank line before this statement.',
|
|
125
|
+
line: 16,
|
|
126
|
+
column: 3
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
message: 'Expected blank line before this statement.',
|
|
130
|
+
line: 19,
|
|
131
|
+
column: 3
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
message: 'Expected blank line before this statement.',
|
|
135
|
+
line: 21,
|
|
136
|
+
column: 3
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
message: 'Expected blank line before this statement.',
|
|
140
|
+
line: 22,
|
|
141
|
+
column: 3
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
message: 'Expected blank line before this statement.',
|
|
145
|
+
line: 23,
|
|
146
|
+
column: 4
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
message: 'Expected blank line before this statement.',
|
|
150
|
+
line: 24,
|
|
151
|
+
column: 1
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
message: 'Expected blank line before this statement.',
|
|
155
|
+
line: 26,
|
|
156
|
+
column: 1
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
@@ -100,13 +100,7 @@ describe('someText', () => {
|
|
|
100
100
|
`;
|
|
101
101
|
|
|
102
102
|
ruleTester.run('padding-before-expect-statements', rule, {
|
|
103
|
-
valid: [
|
|
104
|
-
valid,
|
|
105
|
-
{
|
|
106
|
-
code: invalid,
|
|
107
|
-
filename: 'src/component.jsx',
|
|
108
|
-
}
|
|
109
|
-
],
|
|
103
|
+
valid: [valid],
|
|
110
104
|
invalid: [
|
|
111
105
|
{
|
|
112
106
|
code: invalid,
|
package/tsconfig.json
CHANGED
package/yarn.lock
CHANGED
|
@@ -1152,7 +1152,7 @@ eslint-plugin-import@2.14.0:
|
|
|
1152
1152
|
resolve "^1.6.0"
|
|
1153
1153
|
|
|
1154
1154
|
"eslint-plugin-jest-formatting@file:./.":
|
|
1155
|
-
version "
|
|
1155
|
+
version "1.1.0"
|
|
1156
1156
|
|
|
1157
1157
|
eslint-plugin-jest@22.7.0:
|
|
1158
1158
|
version "22.7.0"
|
|
@@ -1180,14 +1180,16 @@ eslint-scope@^4.0.0, eslint-scope@^4.0.3:
|
|
|
1180
1180
|
estraverse "^4.1.1"
|
|
1181
1181
|
|
|
1182
1182
|
eslint-utils@^1.3.1:
|
|
1183
|
-
version "1.
|
|
1184
|
-
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.
|
|
1185
|
-
integrity sha512-
|
|
1183
|
+
version "1.4.2"
|
|
1184
|
+
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.2.tgz#166a5180ef6ab7eb462f162fd0e6f2463d7309ab"
|
|
1185
|
+
integrity sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==
|
|
1186
|
+
dependencies:
|
|
1187
|
+
eslint-visitor-keys "^1.0.0"
|
|
1186
1188
|
|
|
1187
1189
|
eslint-visitor-keys@^1.0.0:
|
|
1188
|
-
version "1.
|
|
1189
|
-
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.
|
|
1190
|
-
integrity sha512-
|
|
1190
|
+
version "1.1.0"
|
|
1191
|
+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
|
|
1192
|
+
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==
|
|
1191
1193
|
|
|
1192
1194
|
eslint@5.16.0:
|
|
1193
1195
|
version "5.16.0"
|
|
@@ -2689,9 +2691,9 @@ minizlib@^1.2.1:
|
|
|
2689
2691
|
minipass "^2.2.1"
|
|
2690
2692
|
|
|
2691
2693
|
mixin-deep@^1.2.0:
|
|
2692
|
-
version "1.3.
|
|
2693
|
-
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.
|
|
2694
|
-
integrity sha512-
|
|
2694
|
+
version "1.3.2"
|
|
2695
|
+
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.2.tgz#1120b43dc359a785dce65b55b82e257ccf479566"
|
|
2696
|
+
integrity sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==
|
|
2695
2697
|
dependencies:
|
|
2696
2698
|
for-in "^1.0.2"
|
|
2697
2699
|
is-extendable "^1.0.1"
|
package/lib/utils.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const padding_1 = require("./rules/padding");
|
|
4
|
-
exports.makeRule = (options) => {
|
|
5
|
-
return {
|
|
6
|
-
meta: {
|
|
7
|
-
fixable: 'whitespace',
|
|
8
|
-
},
|
|
9
|
-
create(context) {
|
|
10
|
-
const ctx = Object.create(context, { options: { value: options } });
|
|
11
|
-
Object.freeze(ctx);
|
|
12
|
-
return padding_1.default.create(ctx);
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
};
|
package/src/utils.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Rule } from 'eslint';
|
|
2
|
-
import padding from './rules/padding';
|
|
3
|
-
|
|
4
|
-
type TokenIdentifier =
|
|
5
|
-
| '*'
|
|
6
|
-
| 'afterAll'
|
|
7
|
-
| 'afterEach'
|
|
8
|
-
| 'beforeAll'
|
|
9
|
-
| 'beforeEach'
|
|
10
|
-
| 'describe'
|
|
11
|
-
| 'expect'
|
|
12
|
-
| 'it'
|
|
13
|
-
| 'test';
|
|
14
|
-
|
|
15
|
-
interface RuleOption {
|
|
16
|
-
blankLine: 'always' | 'any' | 'never';
|
|
17
|
-
prev: TokenIdentifier | TokenIdentifier[];
|
|
18
|
-
next: TokenIdentifier | TokenIdentifier[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Returns a rule that wraps a call to padding.create and adds the given options
|
|
22
|
-
// to the RuleContext so users don't have to.
|
|
23
|
-
export const makeRule = (options: RuleOption[]): Rule.RuleModule => {
|
|
24
|
-
return {
|
|
25
|
-
meta: {
|
|
26
|
-
fixable: 'whitespace',
|
|
27
|
-
},
|
|
28
|
-
create(context: Rule.RuleContext) {
|
|
29
|
-
// Copy the RuleContext and overwrite options; it's frozen and
|
|
30
|
-
// we can't set them directly.
|
|
31
|
-
const ctx = Object.create(context, { options: { value: options } });
|
|
32
|
-
|
|
33
|
-
// Freeze it again
|
|
34
|
-
Object.freeze(ctx);
|
|
35
|
-
|
|
36
|
-
// Call the original create method with new context
|
|
37
|
-
return padding.create(ctx);
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
};
|