From 1ae21a4fdb1458c012d86a83fba14a3fd241f527 Mon Sep 17 00:00:00 2001 From: Chris Barr Date: Fri, 11 Aug 2017 07:50:36 -0400 Subject: [PATCH] #366 - 2 new lint checks: disallow pull-left/right on .row and .col-*-* classes (#367) * Add 2 new errors - A fix for issue #366: disallow pull-left/right on .row and .col-*-* classes * Fixing to make this report for each occurrence in a file * Removing unneeded loops * Now also disallowing `style="float:left;"` and `style="float:right;"` on grid rows and columns. --- src/bootlint.js | 32 ++++++++++++++++++++ test/bootlint_test.js | 22 ++++++++++++++ test/fixtures/grid/col-no-float.html | 38 ++++++++++++++++++++++++ test/fixtures/grid/row-no-float.html | 44 ++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 test/fixtures/grid/col-no-float.html create mode 100644 test/fixtures/grid/row-no-float.html diff --git a/src/bootlint.js b/src/bootlint.js index fa64d28..260fe2c 100644 --- a/src/bootlint.js +++ b/src/bootlint.js @@ -1105,6 +1105,38 @@ var LocationIndex = _location.LocationIndex; reporter('`.form-group`s should not be nested.', nestedFormGroups); } }); + addLinter('E051', function lintColumnsNoFloats($, reporter) { + var pullSelector = COL_CLASSES.map(function (col) { + return '.pull-left' + col + ',.pull-right' + col; + }).join(','); + var pulledCols = $(pullSelector); + if (pulledCols.length) { + reporter('`.pull-right` and `.pull-left` must not be used on `.col-*-*` elements', pulledCols); + } + var styledSelector = COL_CLASSES.map(function (col) { + return col + '[style]'; + }).join(','); + var styledCols = $(styledSelector).filter(function (i, el) { + //test for `float:*` in the style attribute + return /float\s*:\s*[a-z]+/i.test($(el).attr('style')); + }); + if (styledCols.length) { + reporter('Manually added `float` styles must not be added on `.col-*-*` elements', styledCols); + } + }); + addLinter('E052', function lintRowsNoFloats($, reporter) { + var pulledRows = $('.row.pull-right, .row.pull-left'); + if (pulledRows.length) { + reporter('`.pull-right` and `.pull-left` must not be used on `.row` elements', pulledRows); + } + var styledRows = $('.row[style]').filter(function (i, el) { + //test for `float:*` in the style attribute + return /float\s*:\s*[a-z]+/i.test($(el).attr('style')); + }); + if (styledRows.length) { + reporter('Manually added `float` styles must not be added on `.row` elements', styledRows); + } + }); exports._lint = function ($, reporter, disabledIdList, html) { var locationIndex = IN_NODE_JS ? new LocationIndex(html) : null; var reporterWrapper = IN_NODE_JS ? function (problem) { diff --git a/test/bootlint_test.js b/test/bootlint_test.js index 31ffbb1..2900aef 100644 --- a/test/bootlint_test.js +++ b/test/bootlint_test.js @@ -955,5 +955,27 @@ exports.bootlint = { 'should complain when form-groups are nested' ); test.done(); + }, + '.pull-right/left classes and manual float styles not allowed on .col-*-*': function (test) { + test.expect(1); + test.deepEqual(lintHtml(utf8Fixture('grid/col-no-float.html')), + [ + '`.pull-right` and `.pull-left` must not be used on `.col-*-*` elements', + 'Manually added `float` styles must not be added on `.col-*-*` elements' + ], + 'should complain about a `.pull-right/.pull-left` classes on `.col-*-*` AND manual `style="float:left;"/style="float:right;"` on a `.col-*-*`' + ); + test.done(); + }, + '.pull-right/left classes and manual float styles not allowed on .row': function (test) { + test.expect(1); + test.deepEqual(lintHtml(utf8Fixture('grid/row-no-float.html')), + [ + '`.pull-right` and `.pull-left` must not be used on `.row` elements', + 'Manually added `float` styles must not be added on `.row` elements' + ], + 'should complain about a `.pull-right/.pull-left` classes on `.row` AND manual `style="float:left;"/style="float:right;"` on a `.row`' + ); + test.done(); } }; diff --git a/test/fixtures/grid/col-no-float.html b/test/fixtures/grid/col-no-float.html new file mode 100644 index 0000000..95c0fdf --- /dev/null +++ b/test/fixtures/grid/col-no-float.html @@ -0,0 +1,38 @@ + + + + + + + Test + + + + + + + + + +
+
+
Content
+
Content
+
+ +
+
Content
+
Content
+
+
+ +
+
    +
  1. +
  2. +
+ + diff --git a/test/fixtures/grid/row-no-float.html b/test/fixtures/grid/row-no-float.html new file mode 100644 index 0000000..c209031 --- /dev/null +++ b/test/fixtures/grid/row-no-float.html @@ -0,0 +1,44 @@ + + + + + + + Test + + + + + + + + + +
+
+
Content
+
+ +
+
Content
+
+ +
+
Content
+
+ +
+
Content
+
+
+ +
+
    +
  1. +
  2. +
+ +