eslint-plugin-jest 23.5.0 → 23.8.1

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,47 @@
1
+ ## [23.8.1](https://github.com/jest-community/eslint-plugin-jest/compare/v23.8.0...v23.8.1) (2020-02-29)
2
+
3
+ ### Bug Fixes
4
+
5
+ - remove tests from published package
6
+ ([#541](https://github.com/jest-community/eslint-plugin-jest/issues/541))
7
+ ([099a150](https://github.com/jest-community/eslint-plugin-jest/commit/099a150b87fa693ccf1c512ee501aed1457ba656))
8
+
9
+ # [23.8.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.7.0...v23.8.0) (2020-02-23)
10
+
11
+ ### Bug Fixes
12
+
13
+ - **valid-title:** ensure argument node is defined before accessing props
14
+ ([#538](https://github.com/jest-community/eslint-plugin-jest/issues/538))
15
+ ([7730f75](https://github.com/jest-community/eslint-plugin-jest/commit/7730f757561100559509b756fd362ca33b9ab1d4))
16
+
17
+ ### Features
18
+
19
+ - **no-large-snapshots:** add setting to define maxSize by snapshot type
20
+ ([#524](https://github.com/jest-community/eslint-plugin-jest/issues/524))
21
+ ([0d77300](https://github.com/jest-community/eslint-plugin-jest/commit/0d77300e61adc7a5aa84f34ff4ccc164075d5f41))
22
+
23
+ # [23.7.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.6.0...v23.7.0) (2020-02-07)
24
+
25
+ ### Bug Fixes
26
+
27
+ - **expect-expect:** use `u` flag in regex
28
+ ([#532](https://github.com/jest-community/eslint-plugin-jest/issues/532))
29
+ ([c12b725](https://github.com/jest-community/eslint-plugin-jest/commit/c12b7251ef1506073d268973b93c7fc9fbcf50af))
30
+
31
+ ### Features
32
+
33
+ - **valid-title:** support `disallowedWords` option
34
+ ([#522](https://github.com/jest-community/eslint-plugin-jest/issues/522))
35
+ ([38bbe93](https://github.com/jest-community/eslint-plugin-jest/commit/38bbe93794ed456c6e9e5d7be848b2aeb55ce0ba))
36
+
37
+ # [23.6.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.5.0...v23.6.0) (2020-01-12)
38
+
39
+ ### Features
40
+
41
+ - **no-if:** support `switch` statements
42
+ ([#515](https://github.com/jest-community/eslint-plugin-jest/issues/515))
43
+ ([be4e49d](https://github.com/jest-community/eslint-plugin-jest/commit/be4e49dcecd64711e743f5e09d1ff24e4c6e1648))
44
+
1
45
  # [23.5.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.4.0...v23.5.0) (2020-01-12)
2
46
 
3
47
  ### Features
package/README.md CHANGED
@@ -1,6 +1,3 @@
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
-
4
1
  <div align="center">
5
2
  <a href="https://eslint.org/">
6
3
  <img width="150" height="150" src="https://eslint.org/assets/img/logo.svg">
@@ -12,6 +9,9 @@
12
9
  <p>ESLint plugin for Jest</p>
13
10
  </div>
14
11
 
12
+ [![Actions Status](https://github.com/jest-community/eslint-plugin-jest/workflows/Unit%20tests/badge.svg?branch=master)](https://github.com/jest-community/eslint-plugin-jest/actions)
13
+ [![Renovate badge](https://badges.renovateapi.com/github/jest-community/eslint-plugin-jest)](https://renovatebot.com/)
14
+
15
15
  ## Installation
16
16
 
17
17
  ```
@@ -43,8 +43,8 @@ it('should work with callbacks/async', () => {
43
43
  ### `assertFunctionNames`
44
44
 
45
45
  This array option whitelists the assertion function names to look for. Function
46
- names can be a glob pattern like `request.*.expect` (see
47
- [micromatch](https://github.com/micromatch/micromatch) for syntax)
46
+ names can use wildcards like `request.*.expect`, `request.**.expect`,
47
+ `request.*.expect*`
48
48
 
49
49
  Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }`
50
50
  option:
@@ -98,7 +98,7 @@ line 4
98
98
 
99
99
  ## Options
100
100
 
101
- This rule has an option for modifying the max number of lines allowed for a
101
+ This rule has options for modifying the max number of lines allowed for a
102
102
  snapshot:
103
103
 
104
104
  In an `eslintrc` file:
@@ -106,11 +106,19 @@ In an `eslintrc` file:
106
106
  ```json
107
107
  ...
108
108
  "rules": {
109
- "jest/no-large-snapshots": ["warn", { "maxSize": 12 }]
109
+ "jest/no-large-snapshots": ["warn", { "maxSize": 12, "inlineMaxSize": 6 }]
110
110
  }
111
111
  ...
112
112
  ```
113
113
 
114
+ Max number of lines allowed could be defined by snapshot type (Inline and
115
+ External). Use `inlineMaxSize` for
116
+ [Inline Snapshots](https://jestjs.io/docs/en/snapshot-testing#inline-snapshots)
117
+ size and `maxSize` for
118
+ [External Snapshots](https://jestjs.io/docs/en/snapshot-testing#snapshot-testing-with-jest).
119
+ If only `maxSize` is provided on options, the value of `maxSize` will be used to
120
+ both snapshot types (Inline and External).
121
+
114
122
  In addition there is an option for whitelisting large snapshot files. Since
115
123
  `//eslint` comments will be removed when a `.snap` file is updated, this option
116
124
  provides a way of whitelisting large snapshots. The list of whitelistedSnapshots
@@ -45,7 +45,7 @@ xtest('foo', () => {});
45
45
 
46
46
  Titles for test blocks should always be a string literal or expression.
47
47
 
48
- This is also applied to describe blocks by default, but can be turned off via
48
+ This is also applied to `describe` blocks by default, but can be turned off via
49
49
  the `ignoreTypeOfDescribeName` option:
50
50
 
51
51
  Examples of **incorrect** code for this rule:
@@ -87,7 +87,7 @@ describe(6, function() {});
87
87
 
88
88
  **duplicatePrefix**
89
89
 
90
- A describe/ test block should not start with duplicatePrefix
90
+ A `describe` / `test` block should not start with `duplicatePrefix`
91
91
 
92
92
  Examples of **incorrect** code for this rule
93
93
 
@@ -117,7 +117,7 @@ describe('foo', () => {
117
117
 
118
118
  **accidentalSpace**
119
119
 
120
- A describe/ test block should not contain accidentalSpace
120
+ A `describe` / `test` block should not contain accidentalSpace
121
121
 
122
122
  Examples of **incorrect** code for this rule
123
123
 
@@ -148,3 +148,45 @@ describe('foo', () => {
148
148
  test('bar', () => {});
149
149
  });
150
150
  ```
151
+
152
+ ## Options
153
+
154
+ ```ts
155
+ interface {
156
+ ignoreTypeOfDescribeName?: boolean;
157
+ disallowedWords?: string[];
158
+ }
159
+ ```
160
+
161
+ #### `ignoreTypeOfDescribeName`
162
+
163
+ Default: `false`
164
+
165
+ When enabled, the type of the first argument to `describe` blocks won't be
166
+ checked.
167
+
168
+ #### `disallowedWords`
169
+
170
+ Default: `[]`
171
+
172
+ A string array of words that are not allowed to be used in test titles. Matching
173
+ is not case-sensitive, and looks for complete words:
174
+
175
+ Examples of **incorrect** code using `disallowedWords`:
176
+
177
+ ```js
178
+ // with disallowedWords: ['correct', 'all', 'every', 'properly']
179
+ describe('the correct way to do things', () => {});
180
+ it('has ALL the things', () => {});
181
+ xdescribe('every single one of them', () => {});
182
+ test(`that the value is set properly`, () => {});
183
+ ```
184
+
185
+ Examples of **correct** code when using `disallowedWords`:
186
+
187
+ ```js
188
+ // with disallowedWords: ['correct', 'all', 'every', 'properly']
189
+ it('correctly sets the value', () => {});
190
+ test('that everything is as it should be', () => {});
191
+ describe('the proper way to handle things', () => {});
192
+ ```
@@ -7,16 +7,27 @@ exports.default = void 0;
7
7
 
8
8
  var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
9
 
10
- var _micromatch = _interopRequireDefault(require("micromatch"));
11
-
12
10
  var _utils = require("./utils");
13
11
 
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
12
  /*
17
13
  * This implementation is adapted from eslint-plugin-jasmine.
18
14
  * MIT license, Remco Haszing.
19
15
  */
16
+
17
+ /**
18
+ * Checks if node names returned by getNodeName matches any of the given star patterns
19
+ * Pattern examples:
20
+ * request.*.expect
21
+ * request.**.expect
22
+ * request.**.expect*
23
+ */
24
+ function matchesAssertFunctionName(nodeName, patterns) {
25
+ return patterns.some(p => new RegExp(`^${p.split('.').map(x => {
26
+ if (x === '**') return '[a-z\\.]*';
27
+ return x.replace(/\*/gu, '[a-z]*');
28
+ }).join('\\.')}(\\.|$)`, 'ui').test(nodeName));
29
+ }
30
+
20
31
  var _default = (0, _utils.createRule)({
21
32
  name: __filename,
22
33
  meta: {
@@ -74,7 +85,7 @@ var _default = (0, _utils.createRule)({
74
85
 
75
86
  if (name === _utils.TestCaseName.it || name === _utils.TestCaseName.test) {
76
87
  unchecked.push(node);
77
- } else if (name && _micromatch.default.isMatch(name, assertFunctionNames)) {
88
+ } else if (name && matchesAssertFunctionName(name, assertFunctionNames)) {
78
89
  // Return early in case of nested `it` statements.
79
90
  checkCallExpressionUsed(context.getAncestors());
80
91
  }
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _utils = require("./utils");
9
9
 
10
10
  function hasTests(node) {
11
- return /^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/m.test(node.value);
11
+ return /^\s*[xf]?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/mu.test(node.value);
12
12
  }
13
13
 
14
14
  var _default = (0, _utils.createRule)({
@@ -63,7 +63,7 @@ var _default = (0, _utils.createRule)({
63
63
  } = object);
64
64
  }
65
65
 
66
- if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports?$/.test(property.name)) {
66
+ if ('name' in object && object.name === 'module' && property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && /^exports?$/u.test(property.name)) {
67
67
  exportNodes.push(node);
68
68
  }
69
69
  }
@@ -13,6 +13,12 @@ const testCaseNames = new Set([...Object.keys(_utils.TestCaseName), 'it.only', '
13
13
 
14
14
  const isTestArrowFunction = node => node.parent !== undefined && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils.getNodeName)(node.parent.callee));
15
15
 
16
+ const conditionName = {
17
+ [_experimentalUtils.AST_NODE_TYPES.ConditionalExpression]: 'conditional',
18
+ [_experimentalUtils.AST_NODE_TYPES.SwitchStatement]: 'switch',
19
+ [_experimentalUtils.AST_NODE_TYPES.IfStatement]: 'if'
20
+ };
21
+
16
22
  var _default = (0, _utils.createRule)({
17
23
  name: __filename,
18
24
  meta: {
@@ -22,8 +28,7 @@ var _default = (0, _utils.createRule)({
22
28
  recommended: false
23
29
  },
24
30
  messages: {
25
- noIf: 'Tests should not contain if statements.',
26
- noConditional: 'Tests should not contain conditional statements.'
31
+ noConditionalExpect: 'Test should not contain { condition } statements.'
27
32
  },
28
33
  schema: [],
29
34
  type: 'suggestion'
@@ -36,13 +41,15 @@ var _default = (0, _utils.createRule)({
36
41
  function validate(node) {
37
42
  const lastElementInStack = stack[stack.length - 1];
38
43
 
39
- if (stack.length === 0 || lastElementInStack === false) {
44
+ if (stack.length === 0 || !lastElementInStack) {
40
45
  return;
41
46
  }
42
47
 
43
- const messageId = node.type === _experimentalUtils.AST_NODE_TYPES.ConditionalExpression ? 'noConditional' : 'noIf';
44
48
  context.report({
45
- messageId,
49
+ data: {
50
+ condition: conditionName[node.type]
51
+ },
52
+ messageId: 'noConditionalExpect',
46
53
  node
47
54
  });
48
55
  }
@@ -67,6 +74,7 @@ var _default = (0, _utils.createRule)({
67
74
  },
68
75
 
69
76
  IfStatement: validate,
77
+ SwitchStatement: validate,
70
78
  ConditionalExpression: validate,
71
79
 
72
80
  'CallExpression:exit'() {
@@ -11,6 +11,12 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
11
11
 
12
12
  var _utils = require("./utils");
13
13
 
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
14
20
  const reportOnViolation = (context, node, {
15
21
  maxSize: lineLimit = 50,
16
22
  whitelistedSnapshots = {}
@@ -73,6 +79,9 @@ var _default = (0, _utils.createRule)({
73
79
  maxSize: {
74
80
  type: 'number'
75
81
  },
82
+ inlineMaxSize: {
83
+ type: 'number'
84
+ },
76
85
  whitelistedSnapshots: {
77
86
  type: 'object',
78
87
  patternProperties: {
@@ -99,7 +108,11 @@ var _default = (0, _utils.createRule)({
99
108
  return {
100
109
  CallExpression(node) {
101
110
  if ('property' in node.callee && ((0, _utils.isSupportedAccessor)(node.callee.property, 'toMatchInlineSnapshot') || (0, _utils.isSupportedAccessor)(node.callee.property, 'toThrowErrorMatchingInlineSnapshot'))) {
102
- reportOnViolation(context, node, options);
111
+ var _options$inlineMaxSiz;
112
+
113
+ reportOnViolation(context, node, _objectSpread({}, options, {
114
+ maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
115
+ }));
103
116
  }
104
117
  }
105
118
 
@@ -360,28 +360,18 @@ exports.TestCaseProperty = TestCaseProperty;
360
360
  TestCaseProperty["todo"] = "todo";
361
361
  })(TestCaseProperty || (exports.TestCaseProperty = TestCaseProperty = {}));
362
362
 
363
+ const joinNames = (a, b) => a && b ? `${a}.${b}` : null;
364
+
363
365
  function getNodeName(node) {
364
- function joinNames(a, b) {
365
- return a && b ? `${a}.${b}` : null;
366
+ if (isSupportedAccessor(node)) {
367
+ return getAccessorValue(node);
366
368
  }
367
369
 
368
370
  switch (node.type) {
369
- case _experimentalUtils.AST_NODE_TYPES.Identifier:
370
- return node.name;
371
-
372
- case _experimentalUtils.AST_NODE_TYPES.Literal:
373
- return `${node.value}`;
374
-
375
- case _experimentalUtils.AST_NODE_TYPES.TemplateLiteral:
376
- if (node.expressions.length === 0) return node.quasis[0].value.cooked;
377
- break;
378
-
379
371
  case _experimentalUtils.AST_NODE_TYPES.MemberExpression:
380
372
  return joinNames(getNodeName(node.object), getNodeName(node.property));
381
373
 
382
374
  case _experimentalUtils.AST_NODE_TYPES.NewExpression:
383
- return getNodeName(node.callee);
384
-
385
375
  case _experimentalUtils.AST_NODE_TYPES.CallExpression:
386
376
  return getNodeName(node.callee);
387
377
  }
@@ -397,8 +387,8 @@ const isHook = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.Id
397
387
 
398
388
  exports.isHook = isHook;
399
389
 
400
- const getTestCallExpressionsFromDeclaredVariables = declaredVaiables => {
401
- return declaredVaiables.reduce((acc, {
390
+ const getTestCallExpressionsFromDeclaredVariables = declaredVariables => {
391
+ return declaredVariables.reduce((acc, {
402
392
  references
403
393
  }) => acc.concat(references.map(({
404
394
  identifier
@@ -23,6 +23,8 @@ const doesBinaryExpressionContainStringNode = binaryExp => {
23
23
  return (0, _utils.isStringNode)(binaryExp.left);
24
24
  };
25
25
 
26
+ const quoteStringValue = node => node.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
27
+
26
28
  var _default = (0, _utils.createRule)({
27
29
  name: __filename,
28
30
  meta: {
@@ -35,7 +37,8 @@ var _default = (0, _utils.createRule)({
35
37
  titleMustBeString: 'Title must be a string',
36
38
  emptyTitle: '{{ jestFunctionName }} should not have an empty title',
37
39
  duplicatePrefix: 'should not have duplicate prefix',
38
- accidentalSpace: 'should not have leading or trailing spaces'
40
+ accidentalSpace: 'should not have leading or trailing spaces',
41
+ disallowedWord: '"{{ word }}" is not allowed in test titles.'
39
42
  },
40
43
  type: 'suggestion',
41
44
  schema: [{
@@ -44,6 +47,13 @@ var _default = (0, _utils.createRule)({
44
47
  ignoreTypeOfDescribeName: {
45
48
  type: 'boolean',
46
49
  default: false
50
+ },
51
+ disallowedWords: {
52
+ type: 'array',
53
+ items: {
54
+ type: 'string'
55
+ },
56
+ default: []
47
57
  }
48
58
  },
49
59
  additionalProperties: false
@@ -51,20 +61,27 @@ var _default = (0, _utils.createRule)({
51
61
  fixable: 'code'
52
62
  },
53
63
  defaultOptions: [{
54
- ignoreTypeOfDescribeName: false
64
+ ignoreTypeOfDescribeName: false,
65
+ disallowedWords: []
55
66
  }],
56
67
 
57
68
  create(context, [{
58
- ignoreTypeOfDescribeName
69
+ ignoreTypeOfDescribeName,
70
+ disallowedWords
59
71
  }]) {
72
+ const disallowedWordsRegexp = new RegExp(`\\b(${disallowedWords.join('|')})\\b`, 'iu');
60
73
  return {
61
74
  CallExpression(node) {
62
- if (!((0, _utils.isDescribe)(node) || (0, _utils.isTestCase)(node)) || !node.arguments.length) {
75
+ if (!(0, _utils.isDescribe)(node) && !(0, _utils.isTestCase)(node)) {
63
76
  return;
64
77
  }
65
78
 
66
79
  const [argument] = (0, _utils.getJestFunctionArguments)(node);
67
80
 
81
+ if (!argument) {
82
+ return;
83
+ }
84
+
68
85
  if (!(0, _utils.isStringNode)(argument)) {
69
86
  if (argument.type === _experimentalUtils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
70
87
  return;
@@ -93,16 +110,26 @@ var _default = (0, _utils.createRule)({
93
110
  return;
94
111
  }
95
112
 
113
+ if (disallowedWords.length > 0) {
114
+ const disallowedMatch = disallowedWordsRegexp.exec(title);
115
+
116
+ if (disallowedMatch) {
117
+ context.report({
118
+ data: {
119
+ word: disallowedMatch[1]
120
+ },
121
+ messageId: 'disallowedWord',
122
+ node: argument
123
+ });
124
+ return;
125
+ }
126
+ }
127
+
96
128
  if (title.trim().length !== title.length) {
97
129
  context.report({
98
130
  messageId: 'accidentalSpace',
99
131
  node: argument,
100
-
101
- fix(fixer) {
102
- const stringValue = argument.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${argument.quasis[0].value.raw}\`` : argument.raw;
103
- return [fixer.replaceTextRange(argument.range, stringValue.replace(/^([`'"]) +?/, '$1').replace(/ +?([`'"])$/, '$1'))];
104
- }
105
-
132
+ fix: fixer => [fixer.replaceTextRange(argument.range, quoteStringValue(argument).replace(/^([`'"]) +?/u, '$1').replace(/ +?([`'"])$/u, '$1'))]
106
133
  });
107
134
  }
108
135
 
@@ -113,12 +140,7 @@ var _default = (0, _utils.createRule)({
113
140
  context.report({
114
141
  messageId: 'duplicatePrefix',
115
142
  node: argument,
116
-
117
- fix(fixer) {
118
- const stringValue = argument.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${argument.quasis[0].value.raw}\`` : argument.raw;
119
- return [fixer.replaceTextRange(argument.range, stringValue.replace(/^([`'"]).+? /, '$1'))];
120
- }
121
-
143
+ fix: fixer => [fixer.replaceTextRange(argument.range, quoteStringValue(argument).replace(/^([`'"]).+? /u, '$1'))]
122
144
  });
123
145
  }
124
146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "23.5.0",
3
+ "version": "23.8.1",
4
4
  "description": "Eslint rules for Jest",
5
5
  "repository": "jest-community/eslint-plugin-jest",
6
6
  "license": "MIT",
@@ -33,12 +33,11 @@
33
33
  "pretest": "yarn build",
34
34
  "test": "jest",
35
35
  "build": "babel --extensions .js,.ts src --out-dir lib --copy-files",
36
- "postbuild": "rimraf lib/**/__tests__/**",
36
+ "postbuild": "rimraf lib/__tests__ lib/**/__tests__",
37
37
  "typecheck": "tsc -p ."
38
38
  },
39
39
  "dependencies": {
40
- "@typescript-eslint/experimental-utils": "^2.5.0",
41
- "micromatch": "^4.0.2"
40
+ "@typescript-eslint/experimental-utils": "^2.5.0"
42
41
  },
43
42
  "devDependencies": {
44
43
  "@babel/cli": "^7.4.4",
@@ -51,7 +50,6 @@
51
50
  "@semantic-release/git": "^7.0.17",
52
51
  "@types/eslint": "^6.1.3",
53
52
  "@types/jest": "^24.0.15",
54
- "@types/micromatch": "^4.0.0",
55
53
  "@types/node": "^12.6.6",
56
54
  "@typescript-eslint/eslint-plugin": "^2.5.0",
57
55
  "@typescript-eslint/parser": "^2.5.0",
@@ -1,94 +0,0 @@
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
- `;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- var _fs = require("fs");
4
-
5
- var _path = require("path");
6
-
7
- var _ = _interopRequireDefault(require("../"));
8
-
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
-
11
- const ruleNames = Object.keys(_.default.rules);
12
- const numberOfRules = 40;
13
- describe('rules', () => {
14
- it('should have a corresponding doc for each rule', () => {
15
- ruleNames.forEach(rule => {
16
- const docPath = (0, _path.resolve)(__dirname, '../../docs/rules', `${rule}.md`);
17
-
18
- if (!(0, _fs.existsSync)(docPath)) {
19
- throw new Error(`Could not find documentation file for rule "${rule}" in path "${docPath}"`);
20
- }
21
- });
22
- });
23
- it('should have the correct amount of rules', () => {
24
- const {
25
- length
26
- } = ruleNames;
27
-
28
- if (length !== numberOfRules) {
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.`);
30
- }
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
- });
47
- });