Repository: not-an-aardvark/eslint-plugin-eslint-plugin (js)

Issue:
rule consistent-output crashing when invalid tests array has missing element.
test case:
```js
// invalid
invalid: [
  {code:"foo"},
  ,
  {code: "bar"}
]
```

error:
```bash
TypeError: Cannot read property 'type' of null
    at testRun.invalid.filter.testCase (C:\repo\eslint\node_modules\eslint-plugin-eslint-plugin\lib\rules\consistent-output.js:36:7
6)
    at Array.filter (native)
    at Program.utils.getTestInfo.forEach.testRun (C:\repo\eslint\node_modules\eslint-plugin-eslint-plugin\lib\rules\consistent-outp
ut.js:36:49)
    at Array.forEach (native)
    at EventEmitter.Program (C:\repo\eslint\node_modules\eslint-plugin-eslint-plugin\lib\rules\consistent-output.js:32:41)
    at emitOne (events.js:120:20)
    at EventEmitter.emit (events.js:210:7)
    at NodeEventGenerator.applySelector (C:\repo\eslint\lib\util\node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (C:\repo\eslint\lib\util\node-event-generator.js:294:22)
    at NodeEventGenerator.enterNode (C:\repo\eslint\lib\util\node-event-generator.js:308:14)
```

Pull request description:
Update: utils.getTestInfo filter elements equal to null (fixes #37).

Patch:
diff --git a/lib/rules/consistent-output.js b/lib/rules/consistent-output.js
index 47e546e..0f99021 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/prefer-output-null.js b/lib/rules/prefer-output-null.js
index 5d033d3..22fd7f1 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/utils.js b/lib/utils.js
index 7faac41..92a1d13 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) : [],
         };
       });
   },


Test patch:
diff --git a/lib/rules/no-identical-tests.js b/lib/rules/no-identical-tests.js
index d278b3d..f5a9ca2 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/test-case-property-ordering.js b/lib/rules/test-case-property-ordering.js
index c1f60f0..273001f 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 f20a8c2..863f86a 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/tests/lib/utils.js b/tests/lib/utils.js
index 9d60acc..fbe78bf 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 => {