@@ -16,22 +16,23 @@ var LocationIndex = _location.LocationIndex;
16
16
( function ( exports ) {
17
17
'use strict' ;
18
18
var NUM_COLS = 12 ;
19
- var COL_REGEX = / \b c o l - ( x s | s m | m d | l g ) - ( \d { 1 , 2 } ) \b / ;
20
- var COL_REGEX_G = / \b c o l - ( x s | s m | m d | l g ) - ( \d { 1 , 2 } ) \b / g;
19
+ var COL_REGEX = / \b c o l (?: - ( s m | m d | l g | x l ) ) ? (?: - ( a u t o | \d { 1 , 2 } ) ) ? \b / ;
20
+ var COL_REGEX_G = / \b c o l (?: - ( s m | m d | l g | x l ) ) ? (?: - ( a u t o | \d { 1 , 2 } ) ) ? \b / g;
21
21
var COL_CLASSES = [ ] ;
22
- var SCREENS = [ 'xs ' , 'sm' , 'md' , 'lg' ] ;
22
+ var SCREENS = [ '' , 'sm' , 'md' , 'lg' , 'xl '] ;
23
23
SCREENS . forEach ( function ( screen ) {
24
- for ( var n = 1 ; n <= NUM_COLS ; n ++ ) {
25
- COL_CLASSES . push ( '.col-' + screen + ' -' + n ) ;
24
+ for ( var n = - 1 ; n <= NUM_COLS ; n ++ ) {
25
+ COL_CLASSES . push ( '.col' + ( screen && ' -' + screen ) + ( n < 0 ? '' : ' -' + ( n || 'auto' ) ) ) ;
26
26
}
27
27
} ) ;
28
28
var SCREEN2NUM = {
29
- xs : 0 ,
30
- sm : 1 ,
31
- md : 2 ,
32
- lg : 3
29
+ '' : 0 ,
30
+ 'sm' : 1 ,
31
+ 'md' : 2 ,
32
+ 'lg' : 3 ,
33
+ 'xl' : 4
33
34
} ;
34
- var NUM2SCREEN = [ 'xs ' , 'sm' , 'md' , 'lg' ] ;
35
+ var NUM2SCREEN = [ '' , 'sm' , 'md' , 'lg' , 'xl '] ;
35
36
var IN_NODE_JS = Boolean ( cheerio . load ) ;
36
37
var MIN_JQUERY_VERSION = '1.9.1' ; // as of Bootstrap v3.3.0
37
38
var CURRENT_BOOTSTRAP_VERSION = '3.4.1' ;
@@ -131,11 +132,11 @@ var LocationIndex = _location.LocationIndex;
131
132
var width2screens = { } ;
132
133
while ( true ) {
133
134
var match = COL_REGEX_G . exec ( classes ) ;
134
- if ( ! match ) {
135
+ if ( ! match || ! match [ 1 ] && ! match [ 2 ] ) {
135
136
break ;
136
137
}
137
- var screen = match [ 1 ] ;
138
- width = match [ 2 ] ;
138
+ var screen = match [ 1 ] || '' ;
139
+ width = match [ 2 ] || '' ; // can also be 'auto'
139
140
var screens = width2screens [ width ] ;
140
141
if ( ! screens ) {
141
142
screens = width2screens [ width ] = [ ] ;
@@ -379,7 +380,7 @@ var LocationIndex = _location.LocationIndex;
379
380
// deliberately do nothing
380
381
// empty
381
382
}
382
- /* istanbul ignore if */
383
+ // istanbul ignore if
383
384
if (theWindow) {
384
385
// check browser global jQuery
385
386
var globaljQuery = theWindow.$ || theWindow.jQuery;
@@ -476,7 +477,6 @@ var LocationIndex = _location.LocationIndex;
476
477
}
477
478
});
478
479
*/
479
- /*
480
480
addLinter ( 'W009' , function lintEmptySpacerCols ( $ , reporter ) {
481
481
var selector = COL_CLASSES . map ( function ( colClass ) {
482
482
return colClass + ':not(:last-child)' ;
@@ -492,18 +492,9 @@ var LocationIndex = _location.LocationIndex;
492
492
return ;
493
493
}
494
494
495
- var colClasses = column.attr('class').split(/\s+/g).filter(function (klass) {
496
- return COL_REGEX.test(klass);
497
- });
498
- colClasses = sortedColumnClasses(colClasses.join(' ')).trim();
499
-
500
- var colRegex = new RegExp('\\b(col-)(' + SCREENS.join('|') + ')(-\\d+)\\b', 'g');
501
- var offsetClasses = colClasses.replace(colRegex, '$1$2-offset$3');
502
-
503
- reporter('Using empty spacer columns isn\'t necessary with Bootstrap\'s grid. So instead of having an empty grid column with `class="' + colClasses + '"` , just add `class="' + offsetClasses + '"` to the next grid column.', column);
495
+ reporter ( 'Using empty spacer columns isn\'t necessary with Bootstrap\'s grid.' , column ) ;
504
496
} ) ;
505
497
} ) ;
506
- */
507
498
/*
508
499
addLinter('W010', function lintMediaPulls($, reporter) {
509
500
var mediaPulls = $('.media>.pull-left, .media>.pull-right');
@@ -534,7 +525,7 @@ var LocationIndex = _location.LocationIndex;
534
525
var OUTDATED_BOOTSTRAP = 'Bootstrap version might be outdated. Latest version is at least ' + CURRENT_BOOTSTRAP_VERSION + ' ; saw what appears to be usage of Bootstrap ';
535
526
var theWindow = getBrowserWindowObject();
536
527
var globaljQuery = theWindow && (theWindow.$ || theWindow.jQuery);
537
- /* istanbul ignore if */
528
+ // istanbul ignore if
538
529
if (globaljQuery) {
539
530
var versions = jqueryPluginVersions(globaljQuery);
540
531
if (versions.length) {
@@ -578,7 +569,7 @@ var LocationIndex = _location.LocationIndex;
578
569
var theWindow = getBrowserWindowObject();
579
570
580
571
var globaljQuery = theWindow && (theWindow.$ || theWindow.jQuery);
581
- /* istanbul ignore if */
572
+ // istanbul ignore if
582
573
if (globaljQuery) {
583
574
var versions = jqueryPluginVersions(globaljQuery);
584
575
if (versions.length) {
@@ -695,18 +686,16 @@ var LocationIndex = _location.LocationIndex;
695
686
}
696
687
});
697
688
*/
698
- /*
699
689
addLinter ( 'E005' , function lintRowAndColOnSameElem ( $ , reporter ) {
700
690
var selector = COL_CLASSES . map ( function ( col ) {
701
691
return '.row' + col ;
702
692
} ) . join ( ',' ) ;
703
693
704
694
var rowCols = $ ( selector ) ;
705
695
if ( rowCols . length ) {
706
- reporter('Found both `.row` and `.col-*- *` used on the same element', rowCols);
696
+ reporter ( 'Found both `.row` and `.col*` used on the same element' , rowCols ) ;
707
697
}
708
698
} ) ;
709
- */
710
699
/*
711
700
addLinter('E006', function lintInputGroupFormControlTypes($, reporter) {
712
701
var selectInputGroups = $('.input-group select');
@@ -759,43 +748,38 @@ var LocationIndex = _location.LocationIndex;
759
748
}
760
749
});
761
750
*/
762
- /*
763
751
addLinter ( 'E012' , function lintGridClassMixedWithInputGroup ( $ , reporter ) {
764
752
var selector = COL_CLASSES . map ( function ( colClass ) {
765
753
return '.input-group' + colClass ;
766
754
} ) . join ( ',' ) ;
767
755
768
756
var badMixes = $ ( selector ) ;
769
757
if ( badMixes . length ) {
770
- reporter('`.input-group` and `.col-*-* ` cannot be used directly on the same element. Instead, nest the `.input-group` within the `.col-*- *`', badMixes);
758
+ reporter ( '`.input-group` and `.col* ` cannot be used directly on the same element. Instead, nest the `.input-group` within the `.col*`' , badMixes ) ;
771
759
}
772
760
} ) ;
773
- */
774
- /*
775
761
addLinter ( 'E013' , function lintRowChildrenAreCols ( $ , reporter ) {
776
- var ALLOWED_CHILDREN = COL_CLASSES.concat(['script', '.clearfix', '.bs-customizer-input' ]);
777
- var selector = '.row>*' + ALLOWED_CHILDREN.map(function (colClass) {
762
+ var ALLOWED_CHILDREN = COL_CLASSES . concat ( [ 'script' , '.clearfix' ] ) ;
763
+ var disallowedChildren = ALLOWED_CHILDREN . map ( function ( colClass ) {
778
764
return ':not(' + colClass + ')' ;
779
765
} ) . join ( '' ) ;
766
+ var selector = '.row>*' + disallowedChildren + ',.form-row>*' + disallowedChildren ;
780
767
781
768
var nonColRowChildren = $ ( selector ) ;
782
769
if ( nonColRowChildren . length ) {
783
- reporter('Only columns (`.col-*-* `) may be children of `.row`s', nonColRowChildren);
770
+ reporter ( 'Only columns (`.col* `) or `.clearfix` may be children of `.row`s or `.form- row`s' , nonColRowChildren ) ;
784
771
}
785
772
} ) ;
786
- */
787
- /*
788
773
addLinter ( 'E014' , function lintColParentsAreRowsOrFormGroups ( $ , reporter ) {
789
774
var selector = COL_CLASSES . map ( function ( colClass ) {
790
- return '*:not(.row):not(.form-group )>' + colClass + ':not(col):not(th):not(td)';
775
+ return '*:not(.row):not(.form-row )>' + colClass + ':not(col):not(th):not(td)' ;
791
776
} ) . join ( ',' ) ;
792
777
793
778
var colsOutsideRowsAndFormGroups = $ ( selector ) ;
794
779
if ( colsOutsideRowsAndFormGroups . length ) {
795
- reporter('Columns (`.col-*-* `) can only be children of `.row`s or `.form-group `s', colsOutsideRowsAndFormGroups);
780
+ reporter ( 'Columns (`.col* `) can only be children of `.row`s or `.form-row `s' , colsOutsideRowsAndFormGroups ) ;
796
781
}
797
782
} ) ;
798
- */
799
783
/*
800
784
addLinter('E015', function lintInputGroupsWithMultipleAddOnsPerSide($, reporter) {
801
785
var addOnClasses = ['.input-group-addon', '.input-group-btn'];
@@ -944,7 +928,6 @@ var LocationIndex = _location.LocationIndex;
944
928
}
945
929
});
946
930
*/
947
- /*
948
931
addLinter ( 'E029' , function lintRedundantColumnClasses ( $ , reporter ) {
949
932
var columns = $ ( COL_CLASSES . join ( ',' ) ) ;
950
933
columns . each ( function ( _index , col ) {
@@ -953,27 +936,26 @@ var LocationIndex = _location.LocationIndex;
953
936
var simplifiedClasses = classes ;
954
937
var width2screens = width2screensFor ( classes ) ;
955
938
var isRedundant = false ;
956
- for (var width = 1; width <= NUM_COLS; width++) {
957
- var screens = width2screens[width];
958
- if (!screens) {
959
- continue;
960
- }
961
- var runs = incrementingRunsFrom(screens);
962
- if (!runs.length) {
963
- continue;
964
- }
939
+ for ( var width in width2screens ) {
940
+ if ( Object . prototype . hasOwnProperty . call ( width2screens , width ) ) {
941
+ var screens = width2screens [ width ] ;
942
+ var runs = incrementingRunsFrom ( screens ) ;
943
+ if ( ! runs . length ) {
944
+ continue ;
945
+ }
965
946
966
- isRedundant = true;
947
+ isRedundant = true ;
967
948
968
- for (var i = 0; i < runs.length; i++) {
969
- var run = runs[i];
970
- var min = run[0];
971
- var max = run[1];
949
+ for ( var i = 0 ; i < runs . length ; i ++ ) {
950
+ var run = runs [ i ] ;
951
+ var min = run [ 0 ] ;
952
+ var max = run [ 1 ] ;
972
953
973
- // remove redundant classes
974
- for (var screenNum = min + 1; screenNum <= max; screenNum++) {
975
- var colClass = 'col-' + NUM2SCREEN[screenNum] + '-' + width;
976
- simplifiedClasses = withoutClass(simplifiedClasses, colClass);
954
+ // remove redundant classes
955
+ for ( var screenNum = min + 1 ; screenNum <= max ; screenNum ++ ) {
956
+ var colClass = 'col' + ( NUM2SCREEN [ screenNum ] && '-' + NUM2SCREEN [ screenNum ] ) + ( width && '-' + width ) ;
957
+ simplifiedClasses = withoutClass ( simplifiedClasses , colClass ) ;
958
+ }
977
959
}
978
960
}
979
961
}
@@ -992,7 +974,6 @@ var LocationIndex = _location.LocationIndex;
992
974
) ;
993
975
} ) ;
994
976
} ) ;
995
- */
996
977
/*
997
978
addLinter('E030', function lintSoloGlyphiconClasses($, reporter) {
998
979
var missingGlyphiconClass = $('[class*="glyphicon-"]:not(.glyphicon):not(.glyphicon-class)').filter(function () {
@@ -1076,17 +1057,15 @@ var LocationIndex = _location.LocationIndex;
1076
1057
}
1077
1058
});
1078
1059
*/
1079
- /*
1080
1060
addLinter ( 'E037' , function lintColZeros ( $ , reporter ) {
1081
1061
var selector = SCREENS . map ( function ( screen ) {
1082
- return '.col-' + screen + '-0';
1062
+ return '.col' + ( screen && ' -' + screen ) + '-0' ;
1083
1063
} ) . join ( ',' ) ;
1084
1064
var elements = $ ( selector ) ;
1085
1065
if ( elements . length ) {
1086
- reporter('Column widths must be positive integers (and <= 12 by default). Found usage(s) of invalid nonexistent `.col- *-0` classes.', elements);
1066
+ reporter ( 'Column widths must be positive integers (and <= 12 by default). Found usage(s) of invalid nonexistent `.col*-0` classes.' , elements ) ;
1087
1067
}
1088
1068
} ) ;
1089
- */
1090
1069
/*
1091
1070
addLinter('E038', function lintMediaPulls($, reporter) {
1092
1071
var mediaPullsOutsideMedia = $('.media-left, .media-right').filter(function () {
@@ -1227,14 +1206,13 @@ var LocationIndex = _location.LocationIndex;
1227
1206
}
1228
1207
});
1229
1208
*/
1230
- /*
1231
1209
addLinter ( 'E051' , function lintColumnsNoFloats ( $ , reporter ) {
1232
1210
var pullSelector = COL_CLASSES . map ( function ( col ) {
1233
- return '.pull -left' + col + ',.pull -right' + col;
1211
+ return '.float -left' + col + ',.float -right' + col ;
1234
1212
} ) . join ( ',' ) ;
1235
1213
var pulledCols = $ ( pullSelector ) ;
1236
1214
if ( pulledCols . length ) {
1237
- reporter('`.pull -right` and `.pull -left` must not be used on `.col-*- *` elements', pulledCols);
1215
+ reporter ( '`.float -right` and `.float -left` must not be used on `.col*` elements' , pulledCols ) ;
1238
1216
}
1239
1217
var styledSelector = COL_CLASSES . map ( function ( col ) {
1240
1218
return col + '[style]' ;
@@ -1244,15 +1222,13 @@ var LocationIndex = _location.LocationIndex;
1244
1222
return / f l o a t \s * : \s * [ a - z ] + / i. test ( $ ( el ) . attr ( 'style' ) ) ;
1245
1223
} ) ;
1246
1224
if ( styledCols . length ) {
1247
- reporter('Manually added `float` styles must not be added on `.col-*- *` elements', styledCols);
1225
+ reporter ( 'Manually added `float` styles must not be added on `.col*` elements' , styledCols ) ;
1248
1226
}
1249
1227
} ) ;
1250
- */
1251
- /*
1252
1228
addLinter ( 'E052' , function lintRowsNoFloats ( $ , reporter ) {
1253
- var pulledRows = $('.row.pull -right, .row.pull -left');
1229
+ var pulledRows = $ ( '.row.float -right, .row.float -left' ) ;
1254
1230
if ( pulledRows . length ) {
1255
- reporter('`.pull -right` and `.pull -left` must not be used on `.row` elements', pulledRows);
1231
+ reporter ( '`.float -right` and `.float -left` must not be used on `.row` elements' , pulledRows ) ;
1256
1232
}
1257
1233
var styledRows = $ ( '.row[style]' ) . filter ( function ( i , el ) {
1258
1234
//test for `float:*` in the style attribute
@@ -1262,7 +1238,6 @@ var LocationIndex = _location.LocationIndex;
1262
1238
reporter ( 'Manually added `float` styles must not be added on `.row` elements' , styledRows ) ;
1263
1239
}
1264
1240
} ) ;
1265
- */
1266
1241
exports . _lint = function ( $ , reporter , disabledIdList , html ) {
1267
1242
var locationIndex = IN_NODE_JS ? new LocationIndex ( html ) : null ;
1268
1243
var reporterWrapper = IN_NODE_JS ?
0 commit comments