Merge pull request #232 from twbs/fix-224

Complain about .media-left/right outside of .media
This commit is contained in:
Chris Rebert 2015-02-20 12:46:44 -08:00
Родитель 7d97ff5290 b004381e16
Коммит fd0bfad391
6 изменённых файлов: 119 добавлений и 2 удалений

Просмотреть файл

@ -789,6 +789,14 @@ var LocationIndex = _location.LocationIndex;
reporter("Column widths must be positive integers (and <= 12 by default). Found usage(s) of invalid nonexistent `.col-*-0` classes.", elements);
}
});
addLinter("E038", function lintMediaPulls($, reporter) {
var mediaPullsOutsideMedia = $('.media-left, .media-right').filter(function () {
return !($(this).parent().closest('.media').length);
});
if (mediaPullsOutsideMedia.length) {
reporter('`.media-left` and `.media-right` should not be used outside of `.media` objects.', mediaPullsOutsideMedia);
}
});
addLinter("W009", function lintEmptySpacerCols($, reporter) {
var selector = COL_CLASSES.map(function (colClass) {
return colClass + ':not(col):not(:last-child)';

Просмотреть файл

@ -612,7 +612,7 @@ exports.bootlint = {
'pull classes inside media': function (test) {
test.expect(2);
test.deepEqual(lintHtml(utf8Fixture('media/pull-classes.html')),
test.deepEqual(lintHtml(utf8Fixture('media/deprecated-pull-classes.html')),
['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.'],
'should complain about .pull-* classes in .media'
);
@ -690,7 +690,29 @@ exports.bootlint = {
'should complain about incorrect indicator control targets.'
);
test.deepEqual(lintHtml(utf8Fixture('carousel/valid.html')),
[], 'should not complain about correct indicator control targets.'
[],
'should not complain about correct indicator control targets.'
);
test.done();
},
'media pulls outside of media objects': function (test) {
test.expect(4);
test.deepEqual(lintHtml(utf8Fixture('media/media-classes.html')),
[],
'should not complain about media pulls inside media objects.'
);
test.deepEqual(lintHtml(utf8Fixture('media/misplaced-media-left.html')),
['`.media-left` and `.media-right` should not be used outside of `.media` objects.'],
'should complain about .media-left outside of a media object.'
);
test.deepEqual(lintHtml(utf8Fixture('media/misplaced-media-right.html')),
['`.media-left` and `.media-right` should not be used outside of `.media` objects.'],
'should complain about .media-right outside of a media object.'
);
test.deepEqual(lintHtml(utf8Fixture('media/media-pull-on-media.html')),
['`.media-left` and `.media-right` should not be used outside of `.media` objects.'],
'should complain about media pulls on .media itself.'
);
test.done();
}

Просмотреть файл

35
test/fixtures/media/media-pull-on-media.html поставляемый Normal file
Просмотреть файл

@ -0,0 +1,35 @@
<!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>
<div class="media media-left">
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
</div>
</div>
<div class="media media-right">
<div class="media-body">
<h4 class="media-heading">Media heading</h4>
</div>
</div>
<div id="qunit"></div>
<ol id="bootlint">
<li data-lint="`.media-left` and `.media-right` should not be used outside of `.media` objects."></li>
</ol>
</body>
</html>

26
test/fixtures/media/misplaced-media-left.html поставляемый Normal file
Просмотреть файл

@ -0,0 +1,26 @@
<!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>
<a class="media-left" href="#">Where is my media object?</a>
<div id="qunit"></div>
<ol id="bootlint">
<li data-lint="`.media-left` and `.media-right` should not be used outside of `.media` objects."></li>
</ol>
</body>
</html>

26
test/fixtures/media/misplaced-media-right.html поставляемый Normal file
Просмотреть файл

@ -0,0 +1,26 @@
<!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>
<a class="media-right" href="#">Where is my media object?</a>
<div id="qunit"></div>
<ol id="bootlint">
<li data-lint="`.media-left` and `.media-right` should not be used outside of `.media` objects."></li>
</ol>
</body>
</html>