eslint-plugin-jest 24.3.7 → 24.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [24.4.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.7...v24.4.0) (2021-07-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * create `max-nested-describe` rule ([#845](https://github.com/jest-community/eslint-plugin-jest/issues/845)) ([8067405](https://github.com/jest-community/eslint-plugin-jest/commit/8067405deb609cc1800bce596e929c1840d290ab))
7
+
1
8
  ## [24.3.7](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.6...v24.3.7) (2021-07-21)
2
9
 
3
10
 
package/README.md CHANGED
@@ -135,6 +135,7 @@ installations requiring long-term consistency.
135
135
  | [consistent-test-it](docs/rules/consistent-test-it.md) | Have control over `test` and `it` usages | | ![fixable][] |
136
136
  | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | ![recommended][] | |
137
137
  | [lowercase-name](docs/rules/lowercase-name.md) | Enforce lowercase test names | | ![fixable][] |
138
+ | [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | |
138
139
  | [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![style][] | ![fixable][] |
139
140
  | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
140
141
  | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | |
@@ -0,0 +1,131 @@
1
+ # Enforces a maximum depth to nested describe calls (`max-nested-describe`)
2
+
3
+ While it's useful to be able to group your tests together within the same file
4
+ using `describe()`, having too many levels of nesting throughout your tests make
5
+ them difficult to read.
6
+
7
+ ## Rule Details
8
+
9
+ This rule enforces a maximum depth to nested `describe()` calls to improve code
10
+ clarity in your tests.
11
+
12
+ The following patterns are considered warnings (with the default option of
13
+ `{ "max": 5 } `):
14
+
15
+ ```js
16
+ describe('foo', () => {
17
+ describe('bar', () => {
18
+ describe('baz', () => {
19
+ describe('qux', () => {
20
+ describe('quxx', () => {
21
+ describe('too many', () => {
22
+ it('should get something', () => {
23
+ expect(getSomething()).toBe('Something');
24
+ });
25
+ });
26
+ });
27
+ });
28
+ });
29
+ });
30
+ });
31
+
32
+ describe('foo', function () {
33
+ describe('bar', function () {
34
+ describe('baz', function () {
35
+ describe('qux', function () {
36
+ describe('quxx', function () {
37
+ describe('too many', function () {
38
+ it('should get something', () => {
39
+ expect(getSomething()).toBe('Something');
40
+ });
41
+ });
42
+ });
43
+ });
44
+ });
45
+ });
46
+ });
47
+ ```
48
+
49
+ The following patterns are **not** considered warnings (with the default option
50
+ of `{ "max": 5 } `):
51
+
52
+ ```js
53
+ describe('foo', () => {
54
+ describe('bar', () => {
55
+ it('should get something', () => {
56
+ expect(getSomething()).toBe('Something');
57
+ });
58
+ });
59
+
60
+ describe('qux', () => {
61
+ it('should get something', () => {
62
+ expect(getSomething()).toBe('Something');
63
+ });
64
+ });
65
+ });
66
+
67
+ describe('foo2', function () {
68
+ it('should get something', () => {
69
+ expect(getSomething()).toBe('Something');
70
+ });
71
+ });
72
+
73
+ describe('foo', function () {
74
+ describe('bar', function () {
75
+ describe('baz', function () {
76
+ describe('qux', function () {
77
+ describe('this is the limit', function () {
78
+ it('should get something', () => {
79
+ expect(getSomething()).toBe('Something');
80
+ });
81
+ });
82
+ });
83
+ });
84
+ });
85
+ });
86
+ ```
87
+
88
+ ## Options
89
+
90
+ ```json
91
+ {
92
+ "jest/max-nested-describe": [
93
+ "error",
94
+ {
95
+ "max": 5
96
+ }
97
+ ]
98
+ }
99
+ ```
100
+
101
+ ### `max`
102
+
103
+ Enforces a maximum depth for nested `describe()`.
104
+
105
+ This has a default value of `5`.
106
+
107
+ Examples of patterns **not** considered warnings with options set to
108
+ `{ "max": 2 }`:
109
+
110
+ ```js
111
+ describe('foo', () => {
112
+ describe('bar', () => {
113
+ it('should get something', () => {
114
+ expect(getSomething()).toBe('Something');
115
+ });
116
+ });
117
+ });
118
+
119
+ describe('foo2', function()) {
120
+ describe('bar2', function() {
121
+ it('should get something', function() {
122
+ expect(getSomething()).toBe('Something');
123
+ });
124
+
125
+ it('should get else', function() {
126
+ expect(getSomething()).toBe('Something');
127
+ });
128
+ });
129
+ });
130
+
131
+ ```
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
+
10
+ var _utils = require("./utils");
11
+
12
+ var _default = (0, _utils.createRule)({
13
+ name: __filename,
14
+ meta: {
15
+ docs: {
16
+ category: 'Best Practices',
17
+ description: 'Enforces a maximum depth to nested describe calls',
18
+ recommended: false
19
+ },
20
+ messages: {
21
+ exceededMaxDepth: 'Too many nested describe calls ({{ depth }}). Maximum allowed is {{ max }}.'
22
+ },
23
+ type: 'suggestion',
24
+ schema: [{
25
+ type: 'object',
26
+ properties: {
27
+ max: {
28
+ type: 'integer',
29
+ minimum: 0
30
+ }
31
+ },
32
+ additionalProperties: false
33
+ }]
34
+ },
35
+ defaultOptions: [{
36
+ max: 5
37
+ }],
38
+
39
+ create(context, [{
40
+ max
41
+ }]) {
42
+ const describeCallbackStack = [];
43
+
44
+ function pushDescribeCallback(node) {
45
+ const {
46
+ parent
47
+ } = node;
48
+
49
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression || !(0, _utils.isDescribeCall)(parent)) {
50
+ return;
51
+ }
52
+
53
+ describeCallbackStack.push(0);
54
+
55
+ if (describeCallbackStack.length > max) {
56
+ context.report({
57
+ node: parent,
58
+ messageId: 'exceededMaxDepth',
59
+ data: {
60
+ depth: describeCallbackStack.length,
61
+ max
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ function popDescribeCallback(node) {
68
+ const {
69
+ parent
70
+ } = node;
71
+
72
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isDescribeCall)(parent)) {
73
+ describeCallbackStack.pop();
74
+ }
75
+ }
76
+
77
+ return {
78
+ FunctionExpression: pushDescribeCallback,
79
+ 'FunctionExpression:exit': popDescribeCallback,
80
+ ArrowFunctionExpression: pushDescribeCallback,
81
+ 'ArrowFunctionExpression:exit': popDescribeCallback
82
+ };
83
+ }
84
+
85
+ });
86
+
87
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "24.3.7",
3
+ "version": "24.4.0",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",