eslint-plugin-jest 22.21.0 → 23.0.3

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 (37) hide show
  1. package/CHANGELOG.md +29 -2
  2. package/README.md +12 -14
  3. package/docs/rules/{require-tothrow-message.md → require-to-throw-message.md} +0 -0
  4. package/docs/rules/valid-title.md +78 -0
  5. package/lib/__tests__/__snapshots__/rules.test.ts.snap +94 -0
  6. package/lib/__tests__/rules.test.js +19 -2
  7. package/lib/index.js +9 -3
  8. package/lib/rules/expect-expect.js +5 -25
  9. package/lib/rules/lowercase-name.js +4 -12
  10. package/lib/rules/no-alias-methods.js +3 -2
  11. package/lib/rules/no-export.js +13 -30
  12. package/lib/rules/no-focused-tests.js +3 -1
  13. package/lib/rules/no-identical-title.js +1 -10
  14. package/lib/rules/no-jasmine-globals.js +10 -4
  15. package/lib/rules/no-mocks-import.js +1 -10
  16. package/lib/rules/no-test-callback.js +16 -15
  17. package/lib/rules/no-test-return-statement.js +1 -10
  18. package/lib/rules/no-truthy-falsy.js +3 -2
  19. package/lib/rules/prefer-called-with.js +4 -4
  20. package/lib/rules/prefer-expect-assertions.js +1 -11
  21. package/lib/rules/prefer-inline-snapshots.js +3 -1
  22. package/lib/rules/prefer-spy-on.js +5 -14
  23. package/lib/rules/prefer-strict-equal.js +3 -2
  24. package/lib/rules/prefer-to-be-null.js +3 -2
  25. package/lib/rules/prefer-to-be-undefined.js +3 -2
  26. package/lib/rules/prefer-to-contain.js +10 -23
  27. package/lib/rules/prefer-to-have-length.js +6 -12
  28. package/lib/rules/prefer-todo.js +3 -15
  29. package/lib/rules/{require-tothrow-message.js → require-to-throw-message.js} +7 -8
  30. package/lib/rules/utils.js +36 -50
  31. package/lib/rules/valid-describe.js +9 -29
  32. package/lib/rules/valid-expect-in-promise.js +4 -14
  33. package/lib/rules/valid-expect.js +5 -4
  34. package/lib/rules/valid-title.js +48 -15
  35. package/package.json +27 -13
  36. package/docs/rules/no-empty-title.md +0 -36
  37. package/lib/rules/no-empty-title.js +0 -60
package/CHANGELOG.md CHANGED
@@ -1,6 +1,33 @@
1
- # [22.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v22.1.3...v22.2.0) (2019-01-29)
1
+ ## [23.0.3](https://github.com/jest-community/eslint-plugin-jest/compare/v23.0.2...v23.0.3) (2019-11-08)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **no-test-callback:** don't provide fix for `async` functions
6
+ ([#469](https://github.com/jest-community/eslint-plugin-jest/issues/469))
7
+ ([09111e0](https://github.com/jest-community/eslint-plugin-jest/commit/09111e0c951aaa930c9a2c8e0ca84251b3196e94)),
8
+ closes [#466](https://github.com/jest-community/eslint-plugin-jest/issues/466)
9
+
10
+ ## [23.0.2](https://github.com/jest-community/eslint-plugin-jest/compare/v23.0.1...v23.0.2) (2019-10-28)
11
+
12
+ ### Bug Fixes
2
13
 
14
+ - **prefer-todo:** ensure argument exists before trying to access it
15
+ ([#462](https://github.com/jest-community/eslint-plugin-jest/issues/462))
16
+ ([a87c8c2](https://github.com/jest-community/eslint-plugin-jest/commit/a87c8c29e1faf9d5364c9074d988aa95ef6cc987))
17
+
18
+ ## [23.0.1](https://github.com/jest-community/eslint-plugin-jest/compare/v23.0.0...v23.0.1) (2019-10-28)
19
+
20
+ ### Bug Fixes
21
+
22
+ - **valid-title:** ignore string addition
23
+ ([#461](https://github.com/jest-community/eslint-plugin-jest/issues/461))
24
+ ([b7c1be2](https://github.com/jest-community/eslint-plugin-jest/commit/b7c1be2f279b87366332fb2d3a3e49a71aa75711))
25
+
26
+ # [22.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v22.1.3...v22.2.0) (2019-01-29)
3
27
 
4
28
  ### Features
5
29
 
6
- * **rules:** add prefer-todo rule ([#218](https://github.com/jest-community/eslint-plugin-jest/issues/218)) ([0933d82](https://github.com/jest-community/eslint-plugin-jest/commit/0933d82)), closes [#217](https://github.com/jest-community/eslint-plugin-jest/issues/217)
30
+ - **rules:** add prefer-todo rule
31
+ ([#218](https://github.com/jest-community/eslint-plugin-jest/issues/218))
32
+ ([0933d82](https://github.com/jest-community/eslint-plugin-jest/commit/0933d82)),
33
+ closes [#217](https://github.com/jest-community/eslint-plugin-jest/issues/217)
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Build Status](https://travis-ci.org/jest-community/eslint-plugin-jest.svg?branch=master)](https://travis-ci.org/jest-community/eslint-plugin-jest)
2
- [![Greenkeeper badge](https://badges.greenkeeper.io/jest-community/eslint-plugin-jest.svg)](https://greenkeeper.io/)
1
+ [![Actions Status](https://github.com/jest-community/eslint-plugin-jest/workflows/Unit%20tests/badge.svg)](https://github.com/jest-community/eslint-plugin-jest/actions)
2
+ [![Renovate badge](https://badges.renovateapi.com/github/jest-community/eslint-plugin-jest)](https://renovatebot.com/)
3
3
 
4
4
  <div align="center">
5
5
  <a href="https://eslint.org/">
@@ -111,15 +111,14 @@ installations requiring long-term consistency.
111
111
  | Rule | Description | Configurations | Fixable |
112
112
  | ------------------------------ | ----------------------------------------------------------------- | ---------------- | ------------------- |
113
113
  | [consistent-test-it][] | Enforce consistent test or it keyword | | ![fixable-green][] |
114
- | [expect-expect][] | Enforce assertion to be made in a test body | | |
114
+ | [expect-expect][] | Enforce assertion to be made in a test body | ![recommended][] | |
115
115
  | [lowercase-name][] | Disallow capitalized test names | | ![fixable-green][] |
116
- | [no-alias-methods][] | Disallow alias methods | ![recommended][] | ![fixable-green][] |
117
- | [no-commented-out-tests][] | Disallow commented out tests | | |
116
+ | [no-alias-methods][] | Disallow alias methods | ![style][] | ![fixable-green][] |
117
+ | [no-commented-out-tests][] | Disallow commented out tests | ![recommended][] | |
118
118
  | [no-disabled-tests][] | Disallow disabled tests | ![recommended][] | |
119
119
  | [no-duplicate-hooks][] | Disallow duplicate hooks within a `describe` block | | |
120
- | [no-empty-title][] | Disallow empty titles | | |
121
120
  | [no-expect-resolves][] | Disallow using `expect().resolves` | | |
122
- | [no-export][] | Disallow export from test files | | |
121
+ | [no-export][] | Disallow export from test files | ![recommended][] | |
123
122
  | [no-focused-tests][] | Disallow focused tests | ![recommended][] | |
124
123
  | [no-hooks][] | Disallow setup and teardown hooks | | |
125
124
  | [no-identical-title][] | Disallow identical titles | ![recommended][] | |
@@ -127,13 +126,13 @@ installations requiring long-term consistency.
127
126
  | [no-jasmine-globals][] | Disallow Jasmine globals | ![recommended][] | ![fixable-yellow][] |
128
127
  | [no-jest-import][] | Disallow importing `jest` | ![recommended][] | |
129
128
  | [no-large-snapshots][] | Disallow large snapshots | | |
130
- | [no-mocks-import][] | Disallow manually importing from `__mocks__` | | |
131
- | [no-standalone-expect][] | Prevents `expect` statements outside of a `test` or `it` block | | |
132
- | [no-test-callback][] | Using a callback in asynchronous tests | | ![fixable-green][] |
129
+ | [no-mocks-import][] | Disallow manually importing from `__mocks__` | ![recommended][] | |
130
+ | [no-standalone-expect][] | Prevents `expect` statements outside of a `test` or `it` block | ![recommended][] | |
131
+ | [no-test-callback][] | Using a callback in asynchronous tests | ![recommended][] | ![fixable-green][] |
133
132
  | [no-test-prefixes][] | Disallow using `f` & `x` prefixes to define focused/skipped tests | ![recommended][] | ![fixable-green][] |
134
133
  | [no-test-return-statement][] | Disallow explicitly returning from tests | | |
135
134
  | [no-truthy-falsy][] | Disallow using `toBeTruthy()` & `toBeFalsy()` | | |
136
- | [no-try-expect][] | Prevent `catch` assertions in tests | | |
135
+ | [no-try-expect][] | Prevent `catch` assertions in tests | ![recommended][] | |
137
136
  | [prefer-called-with][] | Suggest using `toBeCalledWith()` OR `toHaveBeenCalledWith()` | | |
138
137
  | [prefer-expect-assertions][] | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | |
139
138
  | [prefer-hooks-on-top][] | Suggest to have all hooks at top-level before tests | | |
@@ -146,7 +145,7 @@ installations requiring long-term consistency.
146
145
  | [prefer-to-have-length][] | Suggest using `toHaveLength()` | ![style][] | ![fixable-green][] |
147
146
  | [prefer-todo][] | Suggest using `test.todo()` | | ![fixable-green][] |
148
147
  | [require-top-level-describe][] | Require a top-level `describe` block | | |
149
- | [require-tothrow-message][] | Require that `toThrow()` and `toThrowError` includes a message | | |
148
+ | [require-to-throw-message][] | Require that `toThrow()` and `toThrowError` includes a message | | |
150
149
  | [valid-describe][] | Enforce valid `describe()` callback | ![recommended][] | |
151
150
  | [valid-expect-in-promise][] | Enforce having return statement when testing with promises | ![recommended][] | |
152
151
  | [valid-expect][] | Enforce valid `expect()` usage | ![recommended][] | |
@@ -173,7 +172,6 @@ https://github.com/dangreenisrael/eslint-plugin-jest-formatting
173
172
  [no-commented-out-tests]: docs/rules/no-commented-out-tests.md
174
173
  [no-disabled-tests]: docs/rules/no-disabled-tests.md
175
174
  [no-duplicate-hooks]: docs/rules/no-duplicate-hooks.md
176
- [no-empty-title]: docs/rules/no-empty-title.md
177
175
  [no-expect-resolves]: docs/rules/no-expect-resolves.md
178
176
  [no-export]: docs/rules/no-export.md
179
177
  [no-focused-tests]: docs/rules/no-focused-tests.md
@@ -202,7 +200,7 @@ https://github.com/dangreenisrael/eslint-plugin-jest-formatting
202
200
  [prefer-to-have-length]: docs/rules/prefer-to-have-length.md
203
201
  [prefer-todo]: docs/rules/prefer-todo.md
204
202
  [require-top-level-describe]: docs/rules/require-top-level-describe.md
205
- [require-tothrow-message]: docs/rules/require-tothrow-message.md
203
+ [require-to-throw-message]: docs/rules/require-to-throw-message.md
206
204
  [valid-describe]: docs/rules/valid-describe.md
207
205
  [valid-expect-in-promise]: docs/rules/valid-expect-in-promise.md
208
206
  [valid-expect]: docs/rules/valid-expect.md
@@ -2,11 +2,89 @@
2
2
 
3
3
  Checks that the title of Jest blocks are valid by ensuring that titles are:
4
4
 
5
+ - not empty,
6
+ - is a string,
5
7
  - not prefixed with their block name,
6
8
  - have no leading or trailing spaces
7
9
 
8
10
  ## Rule Details
9
11
 
12
+ **emptyTitle**
13
+
14
+ An empty title is not informative, and serves little purpose.
15
+
16
+ Examples of **incorrect** code for this rule:
17
+
18
+ ```js
19
+ describe('', () => {});
20
+ describe('foo', () => {
21
+ it('', () => {});
22
+ });
23
+ it('', () => {});
24
+ test('', () => {});
25
+ xdescribe('', () => {});
26
+ xit('', () => {});
27
+ xtest('', () => {});
28
+ ```
29
+
30
+ Examples of **correct** code for this rule:
31
+
32
+ ```js
33
+ describe('foo', () => {});
34
+ describe('foo', () => {
35
+ it('bar', () => {});
36
+ });
37
+ test('foo', () => {});
38
+ it('foo', () => {});
39
+ xdescribe('foo', () => {});
40
+ xit('foo', () => {});
41
+ xtest('foo', () => {});
42
+ ```
43
+
44
+ **titleMustBeString**
45
+
46
+ Titles for test blocks should always be a string literal or expression.
47
+
48
+ This is also applied to describe blocks by default, but can be turned off via
49
+ the `ignoreTypeOfDescribeName` option:
50
+
51
+ Examples of **incorrect** code for this rule:
52
+
53
+ ```js
54
+ it(123, () => {});
55
+ describe(String(/.+/), () => {});
56
+ describe(myFunction, () => {});
57
+ xdescribe(myFunction, () => {});
58
+ describe(6, function() {});
59
+ ```
60
+
61
+ Examples of **correct** code for this rule:
62
+
63
+ ```js
64
+ it('is a string', () => {});
65
+ test('is a string', () => {});
66
+ xtest('is a string', () => {});
67
+ describe('is a string', () => {});
68
+ describe.skip('is a string', () => {});
69
+ fdescribe('is a string', () => {});
70
+ ```
71
+
72
+ Examples of **correct** code when `ignoreTypeOfDescribeName` is `true`:
73
+
74
+ ```js
75
+ it('is a string', () => {});
76
+ test('is a string', () => {});
77
+ xtest('is a string', () => {});
78
+ describe('is a string', () => {});
79
+ describe.skip('is a string', () => {});
80
+ fdescribe('is a string', () => {});
81
+
82
+ describe(String(/.+/), () => {});
83
+ describe(myFunction, () => {});
84
+ xdescribe(myFunction, () => {});
85
+ describe(6, function() {});
86
+ ```
87
+
10
88
  **duplicatePrefix**
11
89
 
12
90
  A describe/ test block should not start with duplicatePrefix
@@ -0,0 +1,94 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`rules should export configs that refer to actual rules 1`] = `
4
+ Object {
5
+ "all": Object {
6
+ "env": Object {
7
+ "jest/globals": true,
8
+ },
9
+ "plugins": Array [
10
+ "jest",
11
+ ],
12
+ "rules": Object {
13
+ "jest/consistent-test-it": "error",
14
+ "jest/expect-expect": "error",
15
+ "jest/lowercase-name": "error",
16
+ "jest/no-alias-methods": "error",
17
+ "jest/no-commented-out-tests": "error",
18
+ "jest/no-disabled-tests": "error",
19
+ "jest/no-duplicate-hooks": "error",
20
+ "jest/no-expect-resolves": "error",
21
+ "jest/no-export": "error",
22
+ "jest/no-focused-tests": "error",
23
+ "jest/no-hooks": "error",
24
+ "jest/no-identical-title": "error",
25
+ "jest/no-if": "error",
26
+ "jest/no-jasmine-globals": "error",
27
+ "jest/no-jest-import": "error",
28
+ "jest/no-large-snapshots": "error",
29
+ "jest/no-mocks-import": "error",
30
+ "jest/no-standalone-expect": "error",
31
+ "jest/no-test-callback": "error",
32
+ "jest/no-test-prefixes": "error",
33
+ "jest/no-test-return-statement": "error",
34
+ "jest/no-truthy-falsy": "error",
35
+ "jest/no-try-expect": "error",
36
+ "jest/prefer-called-with": "error",
37
+ "jest/prefer-expect-assertions": "error",
38
+ "jest/prefer-hooks-on-top": "error",
39
+ "jest/prefer-inline-snapshots": "error",
40
+ "jest/prefer-spy-on": "error",
41
+ "jest/prefer-strict-equal": "error",
42
+ "jest/prefer-to-be-null": "error",
43
+ "jest/prefer-to-be-undefined": "error",
44
+ "jest/prefer-to-contain": "error",
45
+ "jest/prefer-to-have-length": "error",
46
+ "jest/prefer-todo": "error",
47
+ "jest/require-to-throw-message": "error",
48
+ "jest/require-top-level-describe": "error",
49
+ "jest/valid-describe": "error",
50
+ "jest/valid-expect": "error",
51
+ "jest/valid-expect-in-promise": "error",
52
+ "jest/valid-title": "error",
53
+ },
54
+ },
55
+ "recommended": Object {
56
+ "env": Object {
57
+ "jest/globals": true,
58
+ },
59
+ "plugins": Array [
60
+ "jest",
61
+ ],
62
+ "rules": Object {
63
+ "jest/expect-expect": "warn",
64
+ "jest/no-commented-out-tests": "warn",
65
+ "jest/no-disabled-tests": "warn",
66
+ "jest/no-export": "error",
67
+ "jest/no-focused-tests": "error",
68
+ "jest/no-identical-title": "error",
69
+ "jest/no-jasmine-globals": "warn",
70
+ "jest/no-jest-import": "error",
71
+ "jest/no-mocks-import": "error",
72
+ "jest/no-standalone-expect": "error",
73
+ "jest/no-test-callback": "error",
74
+ "jest/no-test-prefixes": "error",
75
+ "jest/no-try-expect": "error",
76
+ "jest/valid-describe": "error",
77
+ "jest/valid-expect": "error",
78
+ "jest/valid-expect-in-promise": "error",
79
+ },
80
+ },
81
+ "style": Object {
82
+ "plugins": Array [
83
+ "jest",
84
+ ],
85
+ "rules": Object {
86
+ "jest/no-alias-methods": "warn",
87
+ "jest/prefer-to-be-null": "error",
88
+ "jest/prefer-to-be-undefined": "error",
89
+ "jest/prefer-to-contain": "error",
90
+ "jest/prefer-to-have-length": "error",
91
+ },
92
+ },
93
+ }
94
+ `;
@@ -9,7 +9,7 @@ var _ = _interopRequireDefault(require("../"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
 
11
11
  const ruleNames = Object.keys(_.default.rules);
12
- const numberOfRules = 41;
12
+ const numberOfRules = 40;
13
13
  describe('rules', () => {
14
14
  it('should have a corresponding doc for each rule', () => {
15
15
  ruleNames.forEach(rule => {
@@ -21,10 +21,27 @@ describe('rules', () => {
21
21
  });
22
22
  });
23
23
  it('should have the correct amount of rules', () => {
24
- const length = ruleNames.length;
24
+ const {
25
+ length
26
+ } = ruleNames;
25
27
 
26
28
  if (length !== numberOfRules) {
27
29
  throw new Error(`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`);
28
30
  }
29
31
  });
32
+ it('should export configs that refer to actual rules', () => {
33
+ const recommendedConfigs = _.default.configs;
34
+ expect(recommendedConfigs).toMatchSnapshot();
35
+ expect(Object.keys(recommendedConfigs)).toEqual(['all', 'recommended', 'style']);
36
+ expect(Object.keys(recommendedConfigs.all.rules)).toHaveLength(ruleNames.length);
37
+ const allConfigRules = Object.values(recommendedConfigs).map(config => Object.keys(config.rules)).reduce((previousValue, currentValue) => [...previousValue, ...currentValue]);
38
+ allConfigRules.forEach(rule => {
39
+ const ruleNamePrefix = 'jest/';
40
+ const ruleName = rule.slice(ruleNamePrefix.length);
41
+ expect(rule.startsWith(ruleNamePrefix)).toBe(true);
42
+ expect(ruleNames).toContain(ruleName); // eslint-disable-next-line @typescript-eslint/no-require-imports
43
+
44
+ expect(() => require(`../rules/${ruleName}`)).not.toThrow();
45
+ });
46
+ });
30
47
  });
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@ var _globals = _interopRequireDefault(require("./globals.json"));
8
8
 
9
9
  var snapshotProcessor = _interopRequireWildcard(require("./processors/snapshot-processor"));
10
10
 
11
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
11
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
12
12
 
13
13
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
14
 
@@ -53,14 +53,19 @@ module.exports = {
53
53
  'jest/globals': true
54
54
  },
55
55
  rules: {
56
- 'jest/no-alias-methods': 'warn',
56
+ 'jest/expect-expect': 'warn',
57
+ 'jest/no-commented-out-tests': 'warn',
57
58
  'jest/no-disabled-tests': 'warn',
59
+ 'jest/no-export': 'error',
58
60
  'jest/no-focused-tests': 'error',
59
61
  'jest/no-identical-title': 'error',
60
62
  'jest/no-jest-import': 'error',
61
- // 'jest/no-mocks-import': 'error',
63
+ 'jest/no-mocks-import': 'error',
62
64
  'jest/no-jasmine-globals': 'warn',
65
+ 'jest/no-standalone-expect': 'error',
66
+ 'jest/no-test-callback': 'error',
63
67
  'jest/no-test-prefixes': 'error',
68
+ 'jest/no-try-expect': 'error',
64
69
  'jest/valid-describe': 'error',
65
70
  'jest/valid-expect': 'error',
66
71
  'jest/valid-expect-in-promise': 'error'
@@ -69,6 +74,7 @@ module.exports = {
69
74
  style: {
70
75
  plugins: ['jest'],
71
76
  rules: {
77
+ 'jest/no-alias-methods': 'warn',
72
78
  'jest/prefer-to-be-null': 'error',
73
79
  'jest/prefer-to-be-undefined': 'error',
74
80
  'jest/prefer-to-contain': 'error',
@@ -54,32 +54,12 @@ var _default = (0, _utils.createRule)({
54
54
  unchecked.push(node);
55
55
  } else if (name && assertFunctionNames.includes(name)) {
56
56
  // Return early in case of nested `it` statements.
57
- var _iteratorNormalCompletion = true;
58
- var _didIteratorError = false;
59
- var _iteratorError = undefined;
57
+ for (const ancestor of context.getAncestors()) {
58
+ const index = ancestor.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? unchecked.indexOf(ancestor) : -1;
60
59
 
61
- try {
62
- for (var _iterator = context.getAncestors()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
63
- const ancestor = _step.value;
64
- const index = ancestor.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? unchecked.indexOf(ancestor) : -1;
65
-
66
- if (index !== -1) {
67
- unchecked.splice(index, 1);
68
- break;
69
- }
70
- }
71
- } catch (err) {
72
- _didIteratorError = true;
73
- _iteratorError = err;
74
- } finally {
75
- try {
76
- if (!_iteratorNormalCompletion && _iterator.return != null) {
77
- _iterator.return();
78
- }
79
- } finally {
80
- if (_didIteratorError) {
81
- throw _iteratorError;
82
- }
60
+ if (index !== -1) {
61
+ unchecked.splice(index, 1);
62
+ break;
83
63
  }
84
64
  }
85
65
  }
@@ -9,21 +9,15 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
9
 
10
10
  var _utils = require("./utils");
11
11
 
12
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
13
-
14
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
15
-
16
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
-
18
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
-
20
12
  const hasStringAsFirstArgument = node => node.arguments && node.arguments[0] && (node.arguments[0].type === _experimentalUtils.AST_NODE_TYPES.Literal || node.arguments[0].type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral);
21
13
 
22
14
  const isJestFunctionWithLiteralArg = node => ((0, _utils.isTestCase)(node) || (0, _utils.isDescribe)(node)) && node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && hasStringAsFirstArgument(node);
23
15
 
24
16
  const testDescription = argument => {
25
17
  if (argument.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
26
- const value = argument.value;
18
+ const {
19
+ value
20
+ } = argument;
27
21
 
28
22
  if (typeof value === 'string') {
29
23
  return value;
@@ -115,9 +109,7 @@ var _default = (0, _utils.createRule)({
115
109
  node,
116
110
 
117
111
  fix(fixer) {
118
- const _node$arguments = _slicedToArray(node.arguments, 1),
119
- firstArg = _node$arguments[0]; // guaranteed by jestFunctionName
120
-
112
+ const [firstArg] = node.arguments; // guaranteed by jestFunctionName
121
113
 
122
114
  const description = testDescription(firstArg);
123
115
  const rangeIgnoringQuotes = [firstArg.range[0] + 1, firstArg.range[1] - 1];
@@ -35,8 +35,9 @@ var _default = (0, _utils.createRule)({
35
35
  return;
36
36
  }
37
37
 
38
- const _parseExpectCall = (0, _utils.parseExpectCall)(node),
39
- matcher = _parseExpectCall.matcher;
38
+ const {
39
+ matcher
40
+ } = (0, _utils.parseExpectCall)(node);
40
41
 
41
42
  if (!matcher) {
42
43
  return;
@@ -31,31 +31,11 @@ var _default = (0, _utils.createRule)({
31
31
  return {
32
32
  'Program:exit'() {
33
33
  if (hasTestCase && exportNodes.length > 0) {
34
- var _iteratorNormalCompletion = true;
35
- var _didIteratorError = false;
36
- var _iteratorError = undefined;
37
-
38
- try {
39
- for (var _iterator = exportNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
40
- const node = _step.value;
41
- context.report({
42
- node,
43
- messageId: 'unexpectedExport'
44
- });
45
- }
46
- } catch (err) {
47
- _didIteratorError = true;
48
- _iteratorError = err;
49
- } finally {
50
- try {
51
- if (!_iteratorNormalCompletion && _iterator.return != null) {
52
- _iterator.return();
53
- }
54
- } finally {
55
- if (_didIteratorError) {
56
- throw _iteratorError;
57
- }
58
- }
34
+ for (const node of exportNodes) {
35
+ context.report({
36
+ node,
37
+ messageId: 'unexpectedExport'
38
+ });
59
39
  }
60
40
  }
61
41
  },
@@ -71,13 +51,16 @@ var _default = (0, _utils.createRule)({
71
51
  },
72
52
 
73
53
  'AssignmentExpression > MemberExpression'(node) {
74
- let object = node.object,
75
- property = node.property;
54
+ let {
55
+ object,
56
+ property
57
+ } = node;
76
58
 
77
59
  if (object.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
78
- var _object = object;
79
- object = _object.object;
80
- property = _object.property;
60
+ ({
61
+ object,
62
+ property
63
+ } = object);
81
64
  }
82
65
 
83
66
  if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports?$/.test(property.name)) {
@@ -37,7 +37,9 @@ var _default = (0, _utils.createRule)({
37
37
  defaultOptions: [],
38
38
  create: context => ({
39
39
  CallExpression(node) {
40
- const callee = node.callee;
40
+ const {
41
+ callee
42
+ } = node;
41
43
 
42
44
  if (callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
43
45
  if (callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && isCallToFocusedTestFunction(callee.object)) {
@@ -7,14 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("./utils");
9
9
 
10
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
11
-
12
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
13
-
14
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
15
-
16
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
-
18
10
  const newDescribeContext = () => ({
19
11
  describeTitles: [],
20
12
  testTitles: []
@@ -47,8 +39,7 @@ var _default = (0, _utils.createRule)({
47
39
  contexts.push(newDescribeContext());
48
40
  }
49
41
 
50
- const _node$arguments = _slicedToArray(node.arguments, 1),
51
- argument = _node$arguments[0];
42
+ const [argument] = node.arguments;
52
43
 
53
44
  if (!argument || !(0, _utils.isStringNode)(argument)) {
54
45
  return;
@@ -33,7 +33,9 @@ var _default = (0, _utils.createRule)({
33
33
  create(context) {
34
34
  return {
35
35
  CallExpression(node) {
36
- const callee = node.callee;
36
+ const {
37
+ callee
38
+ } = node;
37
39
  const calleeName = (0, _utils.getNodeName)(callee);
38
40
 
39
41
  if (!calleeName) {
@@ -126,12 +128,16 @@ var _default = (0, _utils.createRule)({
126
128
 
127
129
  MemberExpression(node) {
128
130
  if ('name' in node.object && node.object.name === 'jasmine') {
129
- const parent = node.parent,
130
- property = node.property;
131
+ const {
132
+ parent,
133
+ property
134
+ } = node;
131
135
 
132
136
  if (parent && parent.type === _experimentalUtils.AST_NODE_TYPES.AssignmentExpression) {
133
137
  if ('name' in property && property.name === 'DEFAULT_TIMEOUT_INTERVAL') {
134
- const right = parent.right;
138
+ const {
139
+ right
140
+ } = parent;
135
141
 
136
142
  if (right.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
137
143
  context.report({
@@ -9,14 +9,6 @@ var _path = require("path");
9
9
 
10
10
  var _utils = require("./utils");
11
11
 
12
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
13
-
14
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
15
-
16
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
-
18
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
-
20
12
  const mocksDirName = '__mocks__';
21
13
 
22
14
  const isMockPath = path => path.split(_path.posix.sep).includes(mocksDirName);
@@ -51,8 +43,7 @@ var _default = (0, _utils.createRule)({
51
43
  },
52
44
 
53
45
  'CallExpression[callee.name="require"]'(node) {
54
- const _node$arguments = _slicedToArray(node.arguments, 1),
55
- arg = _node$arguments[0];
46
+ const [arg] = node.arguments;
56
47
 
57
48
  if (arg && isMockImportLiteral(arg)) {
58
49
  context.report({