Skip to content

Commit ed86653

Browse files
committed
Merge branch 'master' of github.com:stubbornella/csslint
2 parents 82bc624 + b2e2d0f commit ed86653

14 files changed

+400
-95
lines changed

build/csslint-node.js

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Build time: 22-June-2011 05:24:39 */
24+
/* Build time: 23-June-2011 03:44:41 */
2525
/*!
2626
Parser-Lib
2727
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
@@ -45,7 +45,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4545
THE SOFTWARE.
4646
4747
*/
48-
/* Build time: 22-June-2011 03:37:31 */
48+
/* Build time: 23-June-2011 03:36:49 */
4949
var parserlib = {};
5050
(function(){
5151

@@ -943,7 +943,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
943943
THE SOFTWARE.
944944
945945
*/
946-
/* Build time: 22-June-2011 03:37:31 */
946+
/* Build time: 23-June-2011 03:36:49 */
947947
(function(){
948948
var EventTarget = parserlib.util.EventTarget,
949949
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1556,10 +1556,12 @@ Parser.prototype = function(){
15561556
var tokenStream = this._tokenStream,
15571557
tt,
15581558
uri,
1559+
importToken,
15591560
mediaList = [];
15601561

15611562
//read import symbol
15621563
tokenStream.mustMatch(Tokens.IMPORT_SYM);
1564+
importToken = tokenStream.token();
15631565
this._readWhitespace();
15641566

15651567
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
@@ -1579,7 +1581,9 @@ Parser.prototype = function(){
15791581
this.fire({
15801582
type: "import",
15811583
uri: uri,
1582-
media: mediaList
1584+
media: mediaList,
1585+
line: importToken.startLine,
1586+
col: importToken.startCol
15831587
});
15841588
}
15851589

@@ -9661,7 +9665,7 @@ CSSLint.addRule({
96619665

96629666
if (heightProperties[name] || widthProperties[name]){
96639667
if (!/^0\S*$/.test(event.value) && !(name == "border" && event.value == "none")){
9664-
properties[name] = { line: name.line, col: name.col };
9668+
properties[name] = { line: event.property.line, col: event.property.col };
96659669
}
96669670
} else {
96679671
if (name == "width" || name == "height"){
@@ -9739,7 +9743,7 @@ CSSLint.addRule({
97399743
var name = event.property.text.toLowerCase();
97409744

97419745
if (propertiesToCheck[name]){
9742-
properties[name] = { value: event.value.text, line: name.line, col: name.col };
9746+
properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
97439747
}
97449748
});
97459749

@@ -10059,6 +10063,28 @@ CSSLint.addRule({
1005910063
});
1006010064
}
1006110065

10066+
});
10067+
/*
10068+
* Rule: Don't use @import, use <link> instead.
10069+
*/
10070+
CSSLint.addRule({
10071+
10072+
//rule information
10073+
id: "import",
10074+
name: "@import",
10075+
desc: "Don't use @import, use <link> instead.",
10076+
browsers: "All",
10077+
10078+
//initialization
10079+
init: function(parser, reporter){
10080+
var rule = this;
10081+
10082+
parser.addListener("import", function(event){
10083+
reporter.warn("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
10084+
});
10085+
10086+
}
10087+
1006210088
});
1006310089
/*
1006410090
* Rule: Make sure !important is not overused, this could lead to specificity
@@ -10110,7 +10136,9 @@ CSSLint.addRule({
1011010136

1011110137
//initialization
1011210138
init: function(parser, reporter){
10113-
var rule = this;
10139+
var rule = this,
10140+
classes = {};
10141+
1011410142
parser.addListener("startrule", function(event){
1011510143
var selectors = event.selectors,
1011610144
selector,
@@ -10124,19 +10152,36 @@ CSSLint.addRule({
1012410152
for (j=0; j < selector.parts.length; j++){
1012510153
part = selector.parts[j];
1012610154
if (part instanceof parserlib.css.SelectorPart){
10127-
if (part.elementName){
10128-
for (k=0; k < part.modifiers.length; k++){
10129-
modifier = part.modifiers[k];
10130-
if (modifier.type == "class" || modifier.type == "id"){
10131-
reporter.warn("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
10155+
for (k=0; k < part.modifiers.length; k++){
10156+
modifier = part.modifiers[k];
10157+
if (part.elementName && modifier.type == "id"){
10158+
reporter.warn("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
10159+
} else if (modifier.type == "class"){
10160+
10161+
if (!classes[modifier]){
10162+
classes[modifier] = [];
1013210163
}
10164+
classes[modifier].push({ modifier: modifier, part: part });
1013310165
}
10134-
1013510166
}
1013610167
}
1013710168
}
1013810169
}
1013910170
});
10171+
10172+
parser.addListener("endstylesheet", function(){
10173+
10174+
var prop;
10175+
for (prop in classes){
10176+
if (classes.hasOwnProperty(prop)){
10177+
10178+
//one use means that this is overqualified
10179+
if (classes[prop].length == 1 && classes[prop][0].part.elementName){
10180+
reporter.warn("Element (" + classes[prop][0].part + ") is overqualified, just use " + classes[prop][0].modifier + " without element name.", classes[prop][0].part.line, classes[prop][0].part.col, rule);
10181+
}
10182+
}
10183+
}
10184+
});
1014010185
}
1014110186

1014210187
});
@@ -10369,7 +10414,8 @@ CSSLint.addRule({
1036910414
* Rule: If an element has a width of 100%, be careful when placing within
1037010415
* an element that has padding. It may look strange.
1037110416
*/
10372-
CSSLint.addRule({
10417+
//Commented out pending further review.
10418+
/*CSSLint.addRule({
1037310419
1037410420
//rule information
1037510421
id: "width-100",
@@ -10406,7 +10452,7 @@ CSSLint.addRule({
1040610452
});
1040710453
}
1040810454
10409-
});
10455+
});*/
1041010456
/*
1041110457
* Rule: You don't need to specify units when a value is 0.
1041210458
*/

build/csslint-rhino.js

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Build time: 22-June-2011 05:24:39 */
24+
/* Build time: 23-June-2011 03:44:41 */
2525
var CSSLint = (function(){
2626
/*!
2727
Parser-Lib
@@ -46,7 +46,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4646
THE SOFTWARE.
4747
4848
*/
49-
/* Build time: 22-June-2011 03:37:31 */
49+
/* Build time: 23-June-2011 03:36:49 */
5050
var parserlib = {};
5151
(function(){
5252

@@ -944,7 +944,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
944944
THE SOFTWARE.
945945
946946
*/
947-
/* Build time: 22-June-2011 03:37:31 */
947+
/* Build time: 23-June-2011 03:36:49 */
948948
(function(){
949949
var EventTarget = parserlib.util.EventTarget,
950950
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1557,10 +1557,12 @@ Parser.prototype = function(){
15571557
var tokenStream = this._tokenStream,
15581558
tt,
15591559
uri,
1560+
importToken,
15601561
mediaList = [];
15611562

15621563
//read import symbol
15631564
tokenStream.mustMatch(Tokens.IMPORT_SYM);
1565+
importToken = tokenStream.token();
15641566
this._readWhitespace();
15651567

15661568
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
@@ -1580,7 +1582,9 @@ Parser.prototype = function(){
15801582
this.fire({
15811583
type: "import",
15821584
uri: uri,
1583-
media: mediaList
1585+
media: mediaList,
1586+
line: importToken.startLine,
1587+
col: importToken.startCol
15841588
});
15851589
}
15861590

@@ -9662,7 +9666,7 @@ CSSLint.addRule({
96629666

96639667
if (heightProperties[name] || widthProperties[name]){
96649668
if (!/^0\S*$/.test(event.value) && !(name == "border" && event.value == "none")){
9665-
properties[name] = { line: name.line, col: name.col };
9669+
properties[name] = { line: event.property.line, col: event.property.col };
96669670
}
96679671
} else {
96689672
if (name == "width" || name == "height"){
@@ -9740,7 +9744,7 @@ CSSLint.addRule({
97409744
var name = event.property.text.toLowerCase();
97419745

97429746
if (propertiesToCheck[name]){
9743-
properties[name] = { value: event.value.text, line: name.line, col: name.col };
9747+
properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
97449748
}
97459749
});
97469750

@@ -10060,6 +10064,28 @@ CSSLint.addRule({
1006010064
});
1006110065
}
1006210066

10067+
});
10068+
/*
10069+
* Rule: Don't use @import, use <link> instead.
10070+
*/
10071+
CSSLint.addRule({
10072+
10073+
//rule information
10074+
id: "import",
10075+
name: "@import",
10076+
desc: "Don't use @import, use <link> instead.",
10077+
browsers: "All",
10078+
10079+
//initialization
10080+
init: function(parser, reporter){
10081+
var rule = this;
10082+
10083+
parser.addListener("import", function(event){
10084+
reporter.warn("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
10085+
});
10086+
10087+
}
10088+
1006310089
});
1006410090
/*
1006510091
* Rule: Make sure !important is not overused, this could lead to specificity
@@ -10111,7 +10137,9 @@ CSSLint.addRule({
1011110137

1011210138
//initialization
1011310139
init: function(parser, reporter){
10114-
var rule = this;
10140+
var rule = this,
10141+
classes = {};
10142+
1011510143
parser.addListener("startrule", function(event){
1011610144
var selectors = event.selectors,
1011710145
selector,
@@ -10125,19 +10153,36 @@ CSSLint.addRule({
1012510153
for (j=0; j < selector.parts.length; j++){
1012610154
part = selector.parts[j];
1012710155
if (part instanceof parserlib.css.SelectorPart){
10128-
if (part.elementName){
10129-
for (k=0; k < part.modifiers.length; k++){
10130-
modifier = part.modifiers[k];
10131-
if (modifier.type == "class" || modifier.type == "id"){
10132-
reporter.warn("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
10156+
for (k=0; k < part.modifiers.length; k++){
10157+
modifier = part.modifiers[k];
10158+
if (part.elementName && modifier.type == "id"){
10159+
reporter.warn("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
10160+
} else if (modifier.type == "class"){
10161+
10162+
if (!classes[modifier]){
10163+
classes[modifier] = [];
1013310164
}
10165+
classes[modifier].push({ modifier: modifier, part: part });
1013410166
}
10135-
1013610167
}
1013710168
}
1013810169
}
1013910170
}
1014010171
});
10172+
10173+
parser.addListener("endstylesheet", function(){
10174+
10175+
var prop;
10176+
for (prop in classes){
10177+
if (classes.hasOwnProperty(prop)){
10178+
10179+
//one use means that this is overqualified
10180+
if (classes[prop].length == 1 && classes[prop][0].part.elementName){
10181+
reporter.warn("Element (" + classes[prop][0].part + ") is overqualified, just use " + classes[prop][0].modifier + " without element name.", classes[prop][0].part.line, classes[prop][0].part.col, rule);
10182+
}
10183+
}
10184+
}
10185+
});
1014110186
}
1014210187

1014310188
});
@@ -10370,7 +10415,8 @@ CSSLint.addRule({
1037010415
* Rule: If an element has a width of 100%, be careful when placing within
1037110416
* an element that has padding. It may look strange.
1037210417
*/
10373-
CSSLint.addRule({
10418+
//Commented out pending further review.
10419+
/*CSSLint.addRule({
1037410420
1037510421
//rule information
1037610422
id: "width-100",
@@ -10407,7 +10453,7 @@ CSSLint.addRule({
1040710453
});
1040810454
}
1040910455
10410-
});
10456+
});*/
1041110457
/*
1041210458
* Rule: You don't need to specify units when a value is 0.
1041310459
*/

0 commit comments

Comments
 (0)