Skip to content

Commit d064cb6

Browse files
author
薛定谔的猫
committed
Fix: some rules crash if tests array has missing elements (fixes #35).
rules: no-identical-tests, test-case-property-ordering, test-case-shorthand-string.
1 parent 7cabcdc commit d064cb6

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

lib/rules/no-identical-tests.js

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ module.exports = {
3737
*@returns {boolean} if eq, return true, else return false.
3838
*/
3939
function eq (testA, testB) {
40+
// https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/35
41+
if (!testA || !testB) {
42+
return testA === testB;
43+
}
44+
4045
if (testA.type !== testB.type) {
4146
return false;
4247
}

lib/rules/test-case-property-ordering.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = {
3838
utils.getTestInfo(context, ast).forEach(testRun => {
3939
[testRun.valid, testRun.invalid].forEach(tests => {
4040
(tests || []).forEach(test => {
41-
const properties = test.properties || [];
41+
const properties = (test && test.properties) || [];
4242
const keyNames = properties.map(utils.getKeyName);
4343

4444
for (let i = 0, lastChecked; i < keyNames.length; i++) {

lib/rules/test-case-shorthand-strings.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ module.exports = {
3737
*/
3838
function reportTestCases (cases) {
3939
const caseInfoList = cases.map(testCase => {
40-
if (testCase.type === 'Literal' || testCase.type === 'TemplateLiteral') {
41-
return { node: testCase, shorthand: true, needsLongform: false };
42-
}
43-
if (testCase.type === 'ObjectExpression') {
44-
return {
45-
node: testCase,
46-
shorthand: false,
47-
needsLongform: !(testCase.properties.length === 1 && utils.getKeyName(testCase.properties[0]) === 'code'),
48-
};
40+
if (testCase) {
41+
if (testCase.type === 'Literal' || testCase.type === 'TemplateLiteral') {
42+
return { node: testCase, shorthand: true, needsLongform: false };
43+
}
44+
if (testCase.type === 'ObjectExpression') {
45+
return {
46+
node: testCase,
47+
shorthand: false,
48+
needsLongform: !(testCase.properties.length === 1 && utils.getKeyName(testCase.properties[0]) === 'code'),
49+
};
50+
}
4951
}
5052
return null;
5153
}).filter(Boolean);

0 commit comments

Comments
 (0)