diff --git a/lib/rules/consistent-output.js b/lib/rules/consistent-output.js index 47e546e7..0f990210 100644 --- a/lib/rules/consistent-output.js +++ b/lib/rules/consistent-output.js @@ -30,9 +30,6 @@ module.exports = { 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); diff --git a/lib/rules/no-identical-tests.js b/lib/rules/no-identical-tests.js index d278b3de..f5a9ca28 100644 --- a/lib/rules/no-identical-tests.js +++ b/lib/rules/no-identical-tests.js @@ -37,11 +37,6 @@ module.exports = { *@returns {boolean} if eq, return true, else return false. */ function eq (testA, testB) { - // https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/35 - if (!testA || !testB) { - return testA === testB; - } - if (testA.type !== testB.type) { return false; } @@ -78,8 +73,7 @@ module.exports = { utils.getTestInfo(context, ast).forEach(testRun => { [testRun.valid, testRun.invalid].forEach(tests => { const cache = []; - // to avoid tests being null - (tests || []).forEach(test => { + tests.forEach(test => { if (cache.some(item => eq(item, test))) { context.report({ node: test, diff --git a/lib/rules/prefer-output-null.js b/lib/rules/prefer-output-null.js index 5d033d3f..22fd7f1a 100644 --- a/lib/rules/prefer-output-null.js +++ b/lib/rules/prefer-output-null.js @@ -33,7 +33,7 @@ module.exports = { return { Program (ast) { utils.getTestInfo(context, ast).forEach(testRun => { - (testRun.invalid || []).forEach(test => { + testRun.invalid.forEach(test => { /** * Get a test case's giving keyname node. * @param {string} the keyname to find. diff --git a/lib/rules/test-case-property-ordering.js b/lib/rules/test-case-property-ordering.js index c1f60f02..273001f7 100644 --- a/lib/rules/test-case-property-ordering.js +++ b/lib/rules/test-case-property-ordering.js @@ -37,7 +37,7 @@ module.exports = { Program (ast) { utils.getTestInfo(context, ast).forEach(testRun => { [testRun.valid, testRun.invalid].forEach(tests => { - (tests || []).forEach(test => { + tests.forEach(test => { const properties = (test && test.properties) || []; const keyNames = properties.map(utils.getKeyName); diff --git a/lib/rules/test-case-shorthand-strings.js b/lib/rules/test-case-shorthand-strings.js index f20a8c2f..863f86ad 100644 --- a/lib/rules/test-case-shorthand-strings.js +++ b/lib/rules/test-case-shorthand-strings.js @@ -37,17 +37,15 @@ module.exports = { */ function reportTestCases (cases) { const caseInfoList = cases.map(testCase => { - if (testCase) { - if (testCase.type === 'Literal' || testCase.type === 'TemplateLiteral') { - return { node: testCase, shorthand: true, needsLongform: false }; - } - if (testCase.type === 'ObjectExpression') { - return { - node: testCase, - shorthand: false, - needsLongform: !(testCase.properties.length === 1 && utils.getKeyName(testCase.properties[0]) === 'code'), - }; - } + if (testCase.type === 'Literal' || testCase.type === 'TemplateLiteral') { + return { node: testCase, shorthand: true, needsLongform: false }; + } + if (testCase.type === 'ObjectExpression') { + return { + node: testCase, + shorthand: false, + needsLongform: !(testCase.properties.length === 1 && utils.getKeyName(testCase.properties[0]) === 'code'), + }; } return null; }).filter(Boolean); diff --git a/lib/utils.js b/lib/utils.js index 7faac419..92a1d13b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -179,8 +179,8 @@ module.exports = { const invalidProperty = run.properties.find(prop => module.exports.getKeyName(prop) === 'invalid'); return { - valid: validProperty && validProperty.value.type === 'ArrayExpression' ? validProperty.value.elements : null, - invalid: invalidProperty && invalidProperty.value.type === 'ArrayExpression' ? invalidProperty.value.elements : null, + valid: validProperty && validProperty.value.type === 'ArrayExpression' ? validProperty.value.elements.filter(Boolean) : [], + invalid: invalidProperty && invalidProperty.value.type === 'ArrayExpression' ? invalidProperty.value.elements.filter(Boolean) : [], }; }); }, diff --git a/tests/lib/utils.js b/tests/lib/utils.js index 9d60acca..fbe78bfc 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -213,6 +213,7 @@ describe('utils', () => { 'var foo = new RuleTester(); foo.run(bar, baz, { valid: [foo], invalid: [bar] })': { valid: 1, invalid: 1 }, 'var foo = new (require("eslint")).RuleTester; foo.run(bar, baz, { valid: [], invalid: [] })': { valid: 0, invalid: 0 }, 'var foo = new bar.RuleTester; foo.run(bar, baz, { valid: [], invalid: [bar, baz] })': { valid: 0, invalid: 2 }, + 'var foo = new bar.RuleTester; foo.run(bar, baz, { valid: [,], invalid: [bar, , baz] })': { valid: 0, invalid: 2 }, }; Object.keys(CASES).forEach(testSource => {