forked from eslint-community/eslint-plugin-eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsistent-output.js
52 lines (45 loc) · 1.51 KB
/
consistent-output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @fileoverview Enforce consistent use of output assertions in rule tests
* @author Teddy Katz
*/
'use strict';
const utils = require('../utils');
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'Enforce consistent use of output assertions in rule tests',
category: 'Tests',
recommended: false,
},
fixable: null, // or "code" or "whitespace"
schema: [],
},
create (context) {
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
return {
Program (ast) {
utils.getTestInfo(context, ast).forEach(testRun => {
if (!testRun.invalid) {
return;
}
const readableCases = testRun.invalid.filter(testCase => testCase.type === 'ObjectExpression');
const casesWithoutOutput = readableCases
.filter(testCase => testCase.properties.map(utils.getKeyName).indexOf('output') === -1);
if (casesWithoutOutput.length < readableCases.length) {
casesWithoutOutput.forEach(testCase => {
context.report({
node: testCase,
message: 'This test case should have an output assertion.',
});
});
}
});
},
};
},
};