forked from eslint-community/eslint-plugin-eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-identical-tests.js
53 lines (47 loc) · 1.43 KB
/
no-identical-tests.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
53
/**
* @fileoverview disallow identical tests
* @author 薛定谔的猫<[email protected]>
*/
'use strict';
const utils = require('../utils');
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'disallow identical tests',
category: 'Tests',
recommended: true,
},
fixable: null, // or "code" or "whitespace"
schema: [],
},
create (context) {
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
const message = 'This test case should not be identical to someone else.';
const sourceCode = context.getSourceCode();
return {
Program (ast) {
utils.getTestInfo(context, ast).forEach(testRun => {
[testRun.valid, testRun.invalid].forEach(tests => {
const cache = Object.create(null);
(tests || []).forEach(test => {
const testCode = sourceCode.getText(test);
if (cache[testCode]) {
context.report({
node: test,
message,
});
} else {
cache[testCode] = true;
}
});
});
});
},
};
},
};