Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Warn about .pull-right or .pull-left within a navbar #189

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions dist/browser/bootlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9227,6 +9227,9 @@ if (typeof module === 'object' && module.exports === exports)
// Not necessarily the package version of this code.
exports.SEMVER_SPEC_VERSION = '2.0.0';

var MAX_LENGTH = 256;
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;

// The actual regexps go on exports.re
var re = exports.re = [];
var src = exports.src = [];
Expand Down Expand Up @@ -9440,8 +9443,24 @@ for (var i = 0; i < R; i++) {

exports.parse = parse;
function parse(version, loose) {
if (version instanceof SemVer)
return version;

if (typeof version !== 'string')
return null;

if (version.length > MAX_LENGTH)
return null;

var r = loose ? re[LOOSE] : re[FULL];
return (r.test(version)) ? new SemVer(version, loose) : null;
if (!r.test(version))
return null;

try {
return new SemVer(version, loose);
} catch (er) {
return null;
}
}

exports.valid = valid;
Expand Down Expand Up @@ -9469,6 +9488,9 @@ function SemVer(version, loose) {
throw new TypeError('Invalid Version: ' + version);
}

if (version.length > MAX_LENGTH)
throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')

if (!(this instanceof SemVer))
return new SemVer(version, loose);

Expand All @@ -9486,12 +9508,26 @@ function SemVer(version, loose) {
this.minor = +m[2];
this.patch = +m[3];

if (this.major > MAX_SAFE_INTEGER || this.major < 0)
throw new TypeError('Invalid major version')

if (this.minor > MAX_SAFE_INTEGER || this.minor < 0)
throw new TypeError('Invalid minor version')

if (this.patch > MAX_SAFE_INTEGER || this.patch < 0)
throw new TypeError('Invalid patch version')

// numberify any prerelease numeric ids
if (!m[4])
this.prerelease = [];
else
this.prerelease = m[4].split('.').map(function(id) {
return (/^[0-9]+$/.test(id)) ? +id : id;
if (/^[0-9]+$/.test(id)) {
var num = +id
if (num >= 0 && num < MAX_SAFE_INTEGER)
return num
}
return id;
});

this.build = m[5] ? m[5].split('.') : [];
Expand Down Expand Up @@ -11311,6 +11347,35 @@ var LocationIndex = _location.LocationIndex;
reporter('`.carousel-inner` must have exactly one `.item.active` child.', innersWithWrongActiveItems);
}
});
addLinter("E042", function lintFormControlOnWrongControl($, reporter) {
var formControlsOnWrongTags = $('.form-control:not(input,textarea,select)');
if (formControlsOnWrongTags.length) {
reporter('`.form-control` should only be used on `<input>`s, `<textarea>`s, and `<select>`s.', formControlsOnWrongTags);
}

var formControlsOnWrongTypes = $('input.form-control:not(' + ([
'color',
'email',
'number',
'password',
'search',
'tel',
'text',
'url',
'datetime',
'datetime-local',
'date',
'month',
'week',
'time'
].map(function (type) {
return '[type="' + type + '"]';
}).join(',')
) + ')');
if (formControlsOnWrongTypes.length) {
reporter('`.form-control` cannot be used on non-textual `<input>`s, such as those whose `type` is: `file`, `checkbox`, `radio`, `range`, `button`', formControlsOnWrongTypes);
}
});
addLinter("W009", function lintEmptySpacerCols($, reporter) {
var selector = COL_CLASSES.map(function (colClass) {
return colClass + ':not(:last-child)';
Expand Down Expand Up @@ -11343,6 +11408,17 @@ var LocationIndex = _location.LocationIndex;
reporter('Using `.pull-left` or `.pull-right` as part of the media object component is deprecated as of Bootstrap v3.3.0. Use `.media-left` or `.media-right` instead.', mediaPulls);
}
});
addLinter("W011", function lintPullsInNavbar($, reporter) {
var navComponents = '.navbar-nav, .navbar-text, .navbar-btn, .navbar-link, .navbar-brand';
var pulls = ['pull-right', 'pull-left'];
$(navComponents).each(function () {
pulls.forEach(function (pull) {
if ($(this).hasClass(pull)) {
reporter('To align components in navbars with utility classes, use `.navbar-left` or `.navbar-right` instead.', $(this));
}
}, this);
});
});
addLinter("W012", function lintNavbarContainers($, reporter) {
var navBars = $('.navbar');
var containers = [
Expand Down
11 changes: 11 additions & 0 deletions src/bootlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,17 @@ var LocationIndex = _location.LocationIndex;
reporter('Using `.pull-left` or `.pull-right` as part of the media object component is deprecated as of Bootstrap v3.3.0. Use `.media-left` or `.media-right` instead.', mediaPulls);
}
});
addLinter("W011", function lintPullsInNavbar($, reporter) {
var navComponents = '.navbar-nav, .navbar-text, .navbar-btn, .navbar-link, .navbar-brand';
var pulls = ['pull-right', 'pull-left'];
$(navComponents).each(function () {
pulls.forEach(function (pull) {
if ($(this).hasClass(pull)) {
reporter('To align components in navbars with utility classes, use `.navbar-left` or `.navbar-right` instead.', $(this));
}
}, this);
});
});
addLinter("W012", function lintNavbarContainers($, reporter) {
var navBars = $('.navbar');
var containers = [
Expand Down
13 changes: 13 additions & 0 deletions test/bootlint_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,18 @@ exports.bootlint = {
'should not complain about usage of .form-control on valid elements and input types.'
);
test.done();
},

'pull classes inside navbar': function (test) {
test.expect(2);
test.deepEqual(lintHtml(utf8Fixture('navbar/pull-classes.html')),
['To align components in navbars with utility classes, use `.navbar-left` or `.navbar-right` instead.'],
'should complain about .pull-* classes in .navbar'
);
test.deepEqual(lintHtml(utf8Fixture('navbar/navbar-classes.html')),
[],
'should not complain about .navbar-left or .navbar-right classes'
);
test.done();
}
};
33 changes: 33 additions & 0 deletions test/fixtures/navbar/navbar-classes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Test</title>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="../../lib/jquery.min.js"></script>

<link rel="stylesheet" href="../../lib/qunit.css">
<script src="../../lib/qunit.js"></script>
<script src="../../../dist/browser/bootlint.js"></script>
<script src="../generic-qunit.js"></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<a class="navbar-brand navbar-left" href="#">Brand</a>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</nav>
<div id="qunit"></div>
<ol id="bootlint"> </ol>
</body>
</html>

34 changes: 34 additions & 0 deletions test/fixtures/navbar/pull-classes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Test</title>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="../../lib/jquery.min.js"></script>

<link rel="stylesheet" href="../../lib/qunit.css">
<script src="../../lib/qunit.js"></script>
<script src="../../../dist/browser/bootlint.js"></script>
<script src="../generic-qunit.js"></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand</a>
<ul class="nav navbar-nav pull-right">
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</nav>
<div id="qunit"></div>
<ol id="bootlint">
<li data-lint="To align components in navbars with utility classes, use `.navbar-left` or `.navbar-right` instead."></li>
</ol>
</body>
</html>