eslint-plugin-jest-formatting 1.2.0 → 3.1.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.
Files changed (30) hide show
  1. package/.circleci/config.yml +2 -2
  2. package/.eslintrc +17 -4
  3. package/.github/workflows/codeql-analysis.yml +71 -0
  4. package/CHANGELOG.md +6 -0
  5. package/README.md +10 -11
  6. package/lib/ast-utils.js +16 -8
  7. package/lib/index.js +9 -83
  8. package/lib/rules/padding.js +15 -8
  9. package/package.json +21 -20
  10. package/src/ast-utils.ts +5 -1
  11. package/src/index.ts +1 -110
  12. package/src/rules/padding.ts +61 -53
  13. package/tests/catfood.js +2 -0
  14. package/tests/dogfood.spec.js +2 -0
  15. package/tests/lib/rules/padding-around-after-all-blocks.spec.js +2 -1
  16. package/tests/lib/rules/padding-around-after-each-blocks.spec.js +2 -1
  17. package/tests/lib/rules/padding-around-before-all-blocks.spec.js +2 -1
  18. package/tests/lib/rules/padding-around-before-each-blocks.spec.js +2 -1
  19. package/tests/lib/rules/padding-around-describe-blocks.spec.js +2 -1
  20. package/tests/lib/rules/padding-around-expect-groups.spec.js +66 -3
  21. package/tests/lib/rules/padding-around-test-blocks.spec.js +1 -0
  22. package/.nvmrc +0 -1
  23. package/tests/lib/rules/padding-before-after-all-blocks.spec.js +0 -98
  24. package/tests/lib/rules/padding-before-after-each-blocks.spec.js +0 -98
  25. package/tests/lib/rules/padding-before-before-all-blocks.spec.js +0 -98
  26. package/tests/lib/rules/padding-before-before-each-blocks.spec.js +0 -98
  27. package/tests/lib/rules/padding-before-describe-blocks.spec.js +0 -144
  28. package/tests/lib/rules/padding-before-expect-statements.spec.js +0 -138
  29. package/tests/lib/rules/padding-before-test-blocks.spec.js +0 -153
  30. package/yarn.lock +0 -4234
@@ -1,98 +0,0 @@
1
- /**
2
- * @fileoverview Enforces single line padding before beforeEach blocks
3
- */
4
-
5
- //------------------------------------------------------------------------------
6
- // Requirements
7
- //------------------------------------------------------------------------------
8
-
9
- const { RuleTester } = require('eslint');
10
- const rule = require('../../../lib').rules['padding-before-before-each-blocks'];
11
-
12
- const ruleTester = new RuleTester({
13
- parserOptions: {
14
- ecmaVersion: 6,
15
- },
16
- });
17
-
18
- //------------------------------------------------------------------------------
19
- // Tests
20
- //------------------------------------------------------------------------------
21
-
22
- const invalid = `
23
- const someText = 'abc';
24
- beforeEach(() => {
25
- });
26
-
27
- describe('someText', () => {
28
- const something = 'abc';
29
- // A comment
30
- beforeEach(() => {
31
- // stuff
32
- });
33
- });
34
-
35
- describe('someText', () => {
36
- const something = 'abc';
37
- beforeEach(() => {
38
- // stuff
39
- });
40
- });
41
- `;
42
-
43
- const valid = `
44
- const someText = 'abc';
45
-
46
- beforeEach(() => {
47
- });
48
-
49
- describe('someText', () => {
50
- const something = 'abc';
51
-
52
- // A comment
53
- beforeEach(() => {
54
- // stuff
55
- });
56
- });
57
-
58
- describe('someText', () => {
59
- const something = 'abc';
60
-
61
- beforeEach(() => {
62
- // stuff
63
- });
64
- });
65
- `;
66
-
67
- ruleTester.run('padding-before-before-each-blocks', rule, {
68
- valid: [valid],
69
- invalid: [
70
- {
71
- code: invalid,
72
- filename: 'src/component.test.jsx',
73
- errors: 3,
74
- output: valid,
75
- },
76
- {
77
- code: invalid,
78
- filename: 'src/component.test.js',
79
- errors: [
80
- {
81
- message: 'Expected blank line before this statement.',
82
- line: 3,
83
- column: 1
84
- },
85
- {
86
- message: 'Expected blank line before this statement.',
87
- line: 9,
88
- column: 3
89
- },
90
- {
91
- message: 'Expected blank line before this statement.',
92
- line: 16,
93
- column: 3
94
- },
95
- ]
96
- },
97
- ]
98
- });
@@ -1,144 +0,0 @@
1
- /**
2
- * @fileoverview Enforces single line padding around describe blocks
3
- * @author Dan Green-Leipciger
4
- */
5
-
6
- //------------------------------------------------------------------------------
7
- // Requirements
8
- //------------------------------------------------------------------------------
9
-
10
- const { RuleTester } = require('eslint');
11
- const rule = require('../../../lib').rules['padding-before-describe-blocks'];
12
-
13
- const ruleTester = new RuleTester({
14
- parserOptions: {
15
- ecmaVersion: 6,
16
- },
17
- });
18
-
19
- //------------------------------------------------------------------------------
20
- // Tests
21
- //------------------------------------------------------------------------------
22
-
23
- const valid = `
24
- foo();
25
- bar();
26
-
27
- const someText = 'abc';
28
- const someObject = {
29
- one: 1,
30
- two: 2,
31
- };
32
-
33
- // A comment before describe
34
- describe('someText', () => {
35
- describe('some condition', () => {
36
- });
37
-
38
- describe('some other condition', () => {
39
- });
40
- });
41
-
42
- describe('someObject', () => {
43
- // Another comment
44
- describe('some condition', () => {
45
- const anotherThing = 500;
46
-
47
- describe('yet another condition', () => { // A comment over here!
48
- });
49
- });
50
- });
51
-
52
- describe('weird', () => {});
53
-
54
- describe.skip('skip me', () => {});
55
-
56
- describe
57
- .skip('skip me too', () => {
58
- // stuff
59
- });
60
- `;
61
-
62
- const invalid = `
63
- foo();
64
- bar();
65
-
66
- const someText = 'abc';
67
- const someObject = {
68
- one: 1,
69
- two: 2,
70
- };
71
- // A comment before describe
72
- describe('someText', () => {
73
- describe('some condition', () => {
74
- });
75
- describe('some other condition', () => {
76
- });
77
- });
78
- describe('someObject', () => {
79
- // Another comment
80
- describe('some condition', () => {
81
- const anotherThing = 500;
82
- describe('yet another condition', () => { // A comment over here!
83
- });
84
- });
85
- });describe('weird', () => {});
86
- describe.skip('skip me', () => {});
87
- describe
88
- .skip('skip me too', () => {
89
- // stuff
90
- });
91
- `;
92
-
93
- ruleTester.run('padding-before-describe-blocks', rule, {
94
- valid: [valid],
95
- invalid: [
96
- {
97
- code: invalid,
98
- filename: 'src/component.test.jsx',
99
- errors: 7,
100
- output: valid,
101
- },
102
- {
103
- code: invalid,
104
- filename: 'src/component.test.js',
105
- errors: [
106
- {
107
- message: 'Expected blank line before this statement.',
108
- line: 11,
109
- column: 1
110
- },
111
- {
112
- message: 'Expected blank line before this statement.',
113
- line: 14,
114
- column: 3
115
- },
116
- {
117
- message: 'Expected blank line before this statement.',
118
- line: 17,
119
- column: 1
120
- },
121
- {
122
- message: 'Expected blank line before this statement.',
123
- line: 21,
124
- column: 5
125
- },
126
- {
127
- message: 'Expected blank line before this statement.',
128
- line: 24,
129
- column: 4
130
- },
131
- {
132
- message: 'Expected blank line before this statement.',
133
- line: 25,
134
- column: 1
135
- },
136
- {
137
- message: 'Expected blank line before this statement.',
138
- line: 26,
139
- column: 1
140
- },
141
- ]
142
- },
143
- ]
144
- });
@@ -1,138 +0,0 @@
1
- /**
2
- * @fileoverview Enforces single line padding before expect statements
3
- */
4
-
5
- //------------------------------------------------------------------------------
6
- // Requirements
7
- //------------------------------------------------------------------------------
8
-
9
- const { RuleTester } = require('eslint');
10
- const rule = require('../../../lib').rules['padding-before-expect-statements'];
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
- const abc = 123;
34
-
35
- expect(abc).toEqual(123);
36
- expect(123).toEqual(abc); // Line comment
37
- });
38
-
39
- test('thing one', () => {
40
- const abc = 123;
41
-
42
- expect(abc).toEqual(123);
43
-
44
- const xyz = 987;
45
-
46
- expect(123).toEqual(abc); // Line comment
47
- });
48
-
49
- describe('someText', () => {
50
- describe('some condition', () => {
51
- test('foo', () => {
52
- const xyz = 987;
53
-
54
- // Comment
55
- expect(xyz).toEqual(987);
56
- expect(1)
57
- .toEqual(1);
58
- expect(true).toEqual(true);
59
- });
60
- });
61
- });
62
- `;
63
-
64
- const invalid = `
65
- foo();
66
- bar();
67
-
68
- const someText = 'abc';
69
- const someObject = {
70
- one: 1,
71
- two: 2,
72
- };
73
-
74
- test('thing one', () => {
75
- const abc = 123;
76
- expect(abc).toEqual(123);
77
- expect(123).toEqual(abc); // Line comment
78
- });
79
-
80
- test('thing one', () => {
81
- const abc = 123;
82
- expect(abc).toEqual(123);
83
-
84
- const xyz = 987;
85
- expect(123).toEqual(abc); // Line comment
86
- });
87
-
88
- describe('someText', () => {
89
- describe('some condition', () => {
90
- test('foo', () => {
91
- const xyz = 987;
92
- // Comment
93
- expect(xyz).toEqual(987);
94
- expect(1)
95
- .toEqual(1);
96
- expect(true).toEqual(true);
97
- });
98
- });
99
- });
100
- `;
101
-
102
- ruleTester.run('padding-before-expect-statements', rule, {
103
- valid: [valid],
104
- invalid: [
105
- {
106
- code: invalid,
107
- filename: 'src/component.test.jsx',
108
- errors: 4,
109
- output: valid,
110
- },
111
- {
112
- code: invalid,
113
- filename: 'src/component.test.js',
114
- errors: [
115
- {
116
- message: 'Expected blank line before this statement.',
117
- line: 13,
118
- column: 3
119
- },
120
- {
121
- message: 'Expected blank line before this statement.',
122
- line: 19,
123
- column: 3
124
- },
125
- {
126
- message: 'Expected blank line before this statement.',
127
- line: 22,
128
- column: 3
129
- },
130
- {
131
- message: 'Expected blank line before this statement.',
132
- line: 30,
133
- column: 7
134
- },
135
- ]
136
- },
137
- ]
138
- });
@@ -1,153 +0,0 @@
1
- /**
2
- * @fileoverview Enforces a single line of padding between test blocks with a describe
3
- * @author Dan Green-Leipciger
4
- */
5
-
6
- //------------------------------------------------------------------------------
7
- // Requirements
8
- //------------------------------------------------------------------------------
9
- const { RuleTester } = require('eslint');
10
- const rule = require('../../../lib').rules['padding-before-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
- it('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
- test('weird', () => {});
55
-
56
- test
57
- .skip('skippy skip', () => {});
58
- `;
59
-
60
- const invalid = `
61
- const foo = 'bar';
62
- const bar = 'baz';
63
- it('foo', () => {
64
- // stuff
65
- });
66
- it('bar', () => {
67
- // stuff
68
- });
69
- test('foo foo', () => {});
70
- test('bar bar', () => {});
71
-
72
- // Nesting
73
- describe('other bar', () => {
74
- const thing = 123;
75
- test('is another bar w/ test', () => {
76
- });
77
- // With a comment
78
- it('is another bar w/ it', () => {
79
- });
80
- test.skip('skipping', () => {}); // Another comment
81
- it.skip('skipping too', () => {});
82
- });test('weird', () => {});
83
- test
84
- .skip('skippy skip', () => {});
85
- `;
86
-
87
- ruleTester.run('padding-before-test-blocks', rule, {
88
- valid: [valid],
89
- invalid: [
90
- {
91
- code: invalid,
92
- filename: 'src/component.test.jsx',
93
- errors: 10,
94
- output: valid,
95
- },
96
- {
97
- code: invalid,
98
- filename: 'src/component.test.js',
99
- errors: [
100
- {
101
- message: 'Expected blank line before this statement.',
102
- line: 4,
103
- column: 1
104
- },
105
- {
106
- message: 'Expected blank line before this statement.',
107
- line: 7,
108
- column: 1
109
- },
110
- {
111
- message: 'Expected blank line before this statement.',
112
- line: 10,
113
- column: 1
114
- },
115
- {
116
- message: 'Expected blank line before this statement.',
117
- line: 11,
118
- column: 1
119
- },
120
- {
121
- message: 'Expected blank line before this statement.',
122
- line: 16,
123
- column: 3
124
- },
125
- {
126
- message: 'Expected blank line before this statement.',
127
- line: 19,
128
- column: 3
129
- },
130
- {
131
- message: 'Expected blank line before this statement.',
132
- line: 21,
133
- column: 3
134
- },
135
- {
136
- message: 'Expected blank line before this statement.',
137
- line: 22,
138
- column: 3
139
- },
140
- {
141
- message: 'Expected blank line before this statement.',
142
- line: 23,
143
- column: 4
144
- },
145
- {
146
- message: 'Expected blank line before this statement.',
147
- line: 24,
148
- column: 1
149
- },
150
- ],
151
- },
152
- ],
153
- });