-
Notifications
You must be signed in to change notification settings - Fork 480
un-anchored :hover issue #387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
niallmur
wants to merge
17
commits into
CSSLint:master
Choose a base branch
from
niallmur:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0485042
Add duplicate property-value pairs rule
brettstimmerman e456ed8
separator changed to "|" and divided Prop from value
stubbornella ecd91b6
Find duplicate property counts
stubbornella b5cb040
Add test and rollupwarn for rules-count
stubbornella fd53a96
instructions for running the dev version
stubbornella c9ce606
Create non-link-hover
niallmur 8a72ca4
Create non-link-hover
niallmur a8b39b3
Create non-link-hover
niallmur e543a32
Update non-link-hover
niallmur 98a6b6f
Update non-link-hover
niallmur 96f1375
Merge branch 'duplicate-property-value-pairs-experimental' of https:/…
niallmur 22745fb
deleted extra non-link-hover file.
niallmur 8e6e033
Added a more complicated test case
niallmur 4da270b
added the .js to file as it was missing
niallmur f1a88ed
Signed-off-by: niallmur <[email protected]>
niallmur 0048664
update
niallmur 151b7fe
Added the ability to deal with an upper case 'A' anchor. Even though …
niallmur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Steps to run dev version of csslint from the command line (not the current release): | ||
|
||
1. command line: "ant" | ||
1. edit /build/npm/package.json give it a version number like 1.0.0 | ||
1. command line: "npm link" (in the build/npm dir, possibly sudo) | ||
1. command line: "csslint <options> <file-name>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Rule: Be aware of duplicate property-value pairs. | ||
*/ | ||
/*global CSSLint*/ | ||
CSSLint.addRule({ | ||
|
||
//rule information | ||
id: "duplicate-property-count", | ||
name: "Duplicate properties", | ||
desc: "Be aware of duplicate properties. Many duplicates may indicate the need for abstratcion.", | ||
browsers: "All", | ||
|
||
//initialization | ||
init: function(parser, reporter){ | ||
var rule = this; | ||
var count = {}; | ||
|
||
//count how many times "float" is used | ||
parser.addListener("property", function(event){ | ||
var prop = event.property.text.toLowerCase(), | ||
val = event.value.text.toLowerCase(), | ||
key = prop + ':' + val; | ||
|
||
if (!count[prop]) { | ||
count[prop] = 0; | ||
} | ||
|
||
count[prop] += 1; | ||
}); | ||
|
||
//report the results | ||
parser.addListener("endstylesheet", function(){ | ||
var data = [], | ||
msg = []; // remove | ||
|
||
for (var prop in count) { | ||
if (count.hasOwnProperty(prop)) { | ||
data.push([prop, count[prop]]); | ||
} | ||
} | ||
|
||
data.sort(function (a, b) { | ||
return b[1] - a[1]; | ||
}); | ||
|
||
data = data.map(function (item) { | ||
return item[1] + ',' + item[0]; | ||
}).join('\n'); | ||
|
||
reporter.rollupWarn('Duplicate property count:\n\n' + data); | ||
}); | ||
} | ||
|
||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Rule: Be aware of duplicate property-value pairs. | ||
*/ | ||
/*global CSSLint*/ | ||
CSSLint.addRule({ | ||
|
||
//rule information | ||
id: "duplicate-property-value-pairs", | ||
name: "Duplicate property-value pairs", | ||
desc: "Be aware of duplicate property-value pairs. Many duplicates may indicate the need for abstratcion.", | ||
browsers: "All", | ||
|
||
//initialization | ||
init: function(parser, reporter){ | ||
var rule = this; | ||
var count = {}; | ||
|
||
//count how many times "float" is used | ||
parser.addListener("property", function(event){ | ||
var prop = event.property.text.toLowerCase(), | ||
val = event.value.text.toLowerCase(), | ||
key = prop + '|' + val; | ||
|
||
if (!count[key]) { | ||
count[key] = 0; | ||
} | ||
|
||
count[key] += 1; | ||
}); | ||
|
||
//report the results | ||
parser.addListener("endstylesheet", function(){ | ||
var data = [], | ||
msg = []; | ||
|
||
for (var prop in count) { | ||
if (count.hasOwnProperty(prop)) { | ||
data.push([prop, count[prop]]); | ||
} | ||
} | ||
|
||
data.sort(function (a, b) { | ||
return b[1] - a[1]; | ||
}); | ||
|
||
data = data.map(function (item) { | ||
return item[1] + '|' + item[0]; | ||
}).join('\n'); | ||
|
||
reporter.rollupWarn('Duplicate property-value-pairs:\n\n' + data); | ||
}); | ||
} | ||
|
||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Rule: When using a :hover selector ensure that it has been anchored with the <a> tag. | ||
*/ | ||
/*global CSSLint*/ | ||
CSSLint.addRule({ | ||
|
||
//rule information | ||
id: "non-link-hover", | ||
name: "Non-Link Hover", | ||
desc: "Using :hover pseudo-selector to non-link elements is known to be slow.", | ||
browsers: "IE7, IE8", | ||
|
||
//initialization | ||
init: function(parser, reporter){ | ||
var rule = this; | ||
|
||
|
||
parser.addListener("startrule", function(event){ | ||
var selectors = event.selectors, | ||
selector, | ||
part, | ||
modifier, | ||
i, j, k; | ||
|
||
for (i=0; i < selectors.length; i++){ | ||
selector = selectors[i]; | ||
|
||
part = selector.parts[selector.parts.length-1]; | ||
|
||
if (part.modifiers.length-1 !== -1){ | ||
if (part.modifiers[part.modifiers.length-1].text === ":hover" && (part.elementName == null || (part.elementName != "a" && part.elementName != "A"))){ | ||
reporter.warn(rule.desc, part.line, part.col, rule); | ||
} | ||
} | ||
|
||
} | ||
}); | ||
} | ||
|
||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(function(){ | ||
|
||
/*global YUITest, CSSLint*/ | ||
var Assert = YUITest.Assert; | ||
|
||
YUITest.TestRunner.add(new YUITest.TestCase({ | ||
|
||
name: "Duplicate Property-Value Pair Rule Errors", | ||
|
||
"Duplicate property count should result in a warning": function () { | ||
var result = CSSLint.verify(".foo { color: #f00; } .bar { color: #f00; }", {"duplicate-property-count": 1}); | ||
Assert.areEqual(1, result.messages.length); | ||
Assert.areEqual("warning", result.messages[0].type); | ||
Assert.areEqual("Duplicate property count:\n\n2,color", result.messages[0].message); | ||
} | ||
})); | ||
|
||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(function(){ | ||
|
||
/*global YUITest, CSSLint*/ | ||
var Assert = YUITest.Assert; | ||
|
||
YUITest.TestRunner.add(new YUITest.TestCase({ | ||
|
||
name: "Duplicate Property-Value Pair Rule Errors", | ||
|
||
"Duplicate property-value pairs should result in a warning": function () { | ||
var result = CSSLint.verify(".foo { color: #f00; } .bar { color: #f00; }", {"duplicate-property-value-pairs": 1}); | ||
Assert.areEqual(1, result.messages.length); | ||
Assert.areEqual("warning", result.messages[0].type); | ||
Assert.areEqual("Duplicate property-value-pairs:\n\n2|color|#f00", result.messages[0].message); | ||
} | ||
})); | ||
|
||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function(){ | ||
|
||
/*global YUITest, CSSLint*/ | ||
var Assert = YUITest.Assert; | ||
|
||
YUITest.TestRunner.add(new YUITest.TestCase({ | ||
name: ":hover; Warning", | ||
"using :hover on non-link ements should result in an warning": function(){ | ||
var result = CSSLint.verify("li:hover {color:blue;} .foo:hover {float:left;} #foo:hover {clear:both;} div.faa :hover {font-size:1px;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image :hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage .test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image :hover {font-size:1px;}, body .test-eligibility-result .test-eligibility-result-triage .test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 4 }); | ||
Assert.areEqual(4, result.messages.length); | ||
Assert.areEqual("warn", result.messages[0].type); | ||
Assert.areEqual("Using :hover pseudo-selector to non-link elements is known to be slow.", result.messages[0].message); | ||
}, | ||
"using :hover on link ements should not result in any remark": function(){ | ||
var result = CSSLint.verify("a:hover {color:red;} li a:hover, div a:hover {color:red;}, body .test-result .tmp-program .test-program-left .test-program-title .test-program-help-image a:hover, body .test-eligibility-result.cw-collapsed-map .test-eligibility-triage a.test-top-panel-left-image:hover, body .test-eligibility-result .test-eligibility-result-triage .test-panel-right-image a:hover {font-size:1px;}, body .test-eligibility-result .test-eligibility-result-triage a.test-panel-image:hover {background-position: 100% 49%;}", { "non-link-hover": 0 }); | ||
Assert.areEqual(0, result.messages.length); | ||
} | ||
})); | ||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(function(){ | ||
|
||
/*global YUITest, CSSLint*/ | ||
var Assert = YUITest.Assert; | ||
|
||
YUITest.TestRunner.add(new YUITest.TestCase({ | ||
|
||
name: "Rule Count Errors", | ||
|
||
"Rules should be counted": function(){ | ||
var result = CSSLint.verify("h1 { color:#fff; }.foo{color: red;}", { "rules-count": 1}); | ||
// console.dir(result); | ||
Assert.areEqual(1, result.messages.length); | ||
Assert.areEqual("warning", result.messages[0].type); | ||
Assert.areEqual("This CSS contains 2 rules.", result.messages[0].message); | ||
} | ||
|
||
})); | ||
|
||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file in two places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have removed the extra non-link-hover which was at root of csslint-1. Sorry i am very new to Git Hub so I am making a lot of newbie mistakes