Repository: rwjblue/ember-template-lint (js)

Issue:
Changes for table-group rule.
Per [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) the allowed contents of a `<table>` are:

> In this order:
> 1. an optional `<caption>` element,
> 2. zero or more `<colgroup>` elements,
> 3. an optional `<thead>` element,
> 4. either one of the following:
>   i) zero or more `<tbody>` elements
>   ii) one or more `<tr>` elements
> 5. an optional `<tfoot>` element

We are intentionally disallowing the option in 4 above (e.g. we require `<tr>` to be in `<tbody>`), but we still need to account for:

- [ ] `<caption>`
- [ ] `<colgroup`>

Pull request description:
Allow colgroup and caption in tables
Fixes #285 

Basically only `thead`, `tbody`, `tfoot`, `caption` and `colgroup` are allowed children for tables.

Patch:
diff --git a/lib/rules/lint-table-groups.js b/lib/rules/lint-table-groups.js
index db0f675..20a17d2 100644
--- a/lib/rules/lint-table-groups.js
+++ b/lib/rules/lint-table-groups.js
@@ -3,24 +3,16 @@
 const Rule = require('./base');
 const message = 'Tables must have a table group (thead, tbody or tfoot).';
 
-const TABLE_GROUPS = ['thead', 'tbody', 'tfoot'];
+const ALLOWED_TABLE_CHILDREN = ['thead', 'tbody', 'tfoot', 'caption', 'colgroup'];
 
-function hasTableGroup(tableNode) {
+function hasDisallowedChildren(tableNode) {
   const tableGroup = tableNode.children.find((child) => {
-    return child.type === 'ElementNode' && TABLE_GROUPS.indexOf(child.tag) > -1;
+    return !(child.type === 'ElementNode' && ALLOWED_TABLE_CHILDREN.indexOf(child.tag) > -1);
   });
 
   return !!tableGroup;
 }
 
-function hasTableRows(tableNode) {
-  const tableRow = tableNode.children.find((child) => {
-    return child.type === 'ElementNode' && child.tag === 'tr';
-  });
-
-  return !!tableRow;
-}
-
 function hasChildTags(tableNode) {
   const contentNodes = tableNode.children.filter((child) => {
     return child.type !== 'TextNode';
@@ -38,7 +30,7 @@ module.exports = class TableGroups extends Rule {
             return;
           }
 
-          if (!hasTableGroup(node) || hasTableRows(node)) {
+          if (hasDisallowedChildren(node)) {
             this.log({
               message: message,
               line: node.loc && node.loc.start.line,


Test patch:
diff --git a/test/unit/rules/lint-table-groups-test.js b/test/unit/rules/lint-table-groups-test.js
index 92ae2ee..24f9ad2 100644
--- a/test/unit/rules/lint-table-groups-test.js
+++ b/test/unit/rules/lint-table-groups-test.js
@@ -10,6 +10,8 @@ generateRuleTests({
 
   good: [
     '<table> </table>',
+    '<table><caption>Foo</caption></table>',
+    '<table><colgroup><col style="background-color: red"></colgroup></table>',
     '<table><thead><tr><td>Header</td></tr></thead></table>',
     '<table><tbody><tr><td>Body</td></tr></tbody></table>',
     '<table><tfoot><tr><td>Footer</td></tr></tfoot></table>',