diff --git a/src/bootlint.js b/src/bootlint.js index 0e6af22..69ad2d6 100644 --- a/src/bootlint.js +++ b/src/bootlint.js @@ -797,6 +797,14 @@ var LocationIndex = _location.LocationIndex; reporter('`.media-left` and `.media-right` should not be used outside of `.media` objects.', mediaPullsOutsideMedia); } }); + addLinter("E039", function lintNavbarPulls($, reporter) { + var navbarPullsOutsideNavbars = $('.navbar-left, .navbar-right').filter(function () { + return !($(this).parent().closest('.navbar').length); + }); + if (navbarPullsOutsideNavbars.length) { + reporter('`.navbar-left` and `.navbar-right` should not be used outside of navbars.', navbarPullsOutsideNavbars); + } + }); addLinter("W009", function lintEmptySpacerCols($, reporter) { var selector = COL_CLASSES.map(function (colClass) { return colClass + ':not(col):not(:last-child)'; diff --git a/test/bootlint_test.js b/test/bootlint_test.js index a5c9a5b..75678aa 100644 --- a/test/bootlint_test.js +++ b/test/bootlint_test.js @@ -715,5 +715,26 @@ exports.bootlint = { 'should complain about media pulls on .media itself.' ); test.done(); + }, + + 'navbar pulls outside of navbars': function (test) { + test.expect(4); + test.deepEqual(lintHtml(utf8Fixture('navbar/navbar-left-bad.html')), + ['`.navbar-left` and `.navbar-right` should not be used outside of navbars.'], + 'should complain about .navbar-left outside of .navbar.' + ); + test.deepEqual(lintHtml(utf8Fixture('navbar/navbar-right-bad.html')), + ['`.navbar-left` and `.navbar-right` should not be used outside of navbars.'], + 'should complain about .navbar-right outside of .navbar.' + ); + test.deepEqual(lintHtml(utf8Fixture('navbar/navbar-left-right-on-navbar.html')), + ['`.navbar-left` and `.navbar-right` should not be used outside of navbars.'], + 'should complain about .navbar-left/right directly on a .navbar.' + ); + test.deepEqual(lintHtml(utf8Fixture('navbar/navbar-left-right-valid.html')), + [], + 'should not complain about .navbar-left or .navbar-right inside of .navbar.' + ); + test.done(); } }; diff --git a/test/fixtures/navbar/navbar-left-bad.html b/test/fixtures/navbar/navbar-left-bad.html new file mode 100644 index 0000000..56b5cb1 --- /dev/null +++ b/test/fixtures/navbar/navbar-left-bad.html @@ -0,0 +1,27 @@ + + +
+ + + +