Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.9.8

  • Loading branch information...
commit 2a2cac5748d4371a1b3a05883e89bcf311e0ef25 1 parent ee1af4e
@nzakas nzakas authored
View
27 CHANGELOG
@@ -1,3 +1,28 @@
+May 14, 2012 - v0.9.8
+
+* Merge pull request #272 from mahonnaise/text-indent (Nicholas C. Zakas)
+* Changed the -98px test to -99px (the exact threshold value). Added -99em and -100em tests in order to increase test coverage and to document the current (actually desired) behavior (see #133). (Jos Hirth)
+* Ensure proper output flushing for Node.js (Nicholas C. Zakas)
+* Fix output for checkstyle when a file can't be read (fixes #253) (Nicholas C. Zakas)
+* Merge branch 'master' of github.com:stubbornella/csslint (Nicholas C. Zakas)
+* Updated parser (fixes #261, fixes #259, fixes #242) (Nicholas C. Zakas)
+* Merge pull request #269 from mahonnaise/master (Nicholas C. Zakas)
+* Merge pull request #270 from huangyingjie/master (Nicholas C. Zakas)
+* cannot find csslint.js (huangyingjie)
+* use the parser's "hack" property instead of redoing this step again (Jos Hirth)
+* +2 rules which detected star (IE6/7) and underscore (IE6) property hacks (Jos Hirth)
+* Merge pull request #268 from frvge/patch-1 (Nicholas C. Zakas)
+* Fix typo (Frank van Gemeren)
+* Merge pull request #265 from frvge/patch-1 (Nicholas C. Zakas)
+* Fix typo (Frank van Gemeren)
+* Merge pull request #252 from aaronpowell/master (Nicholas C. Zakas)
+* Merge pull request #260 from mahonnaise/master (Nicholas C. Zakas)
+* use separate flags for text-indent and direction. fixes #249 (Jos Hirth)
+* Merge pull request #256 from khoomeister/master (Nicholas C. Zakas)
+* updated xml formatters to escape ampersand character, updated tests to check ampersand and fixed other tests to check angled brackets as well (Jenkins)
+* Update npm/package.json (Aaron Powell)
+
+
March 2, 2012 - v0.9.7
* Fix unqualified attribute issue (fixes #237) (Nicholas C. Zakas)
@@ -257,3 +282,5 @@ June 15, 2011 - v0.1.0
+
+
View
2  build.xml
@@ -1,7 +1,7 @@
<project name="csslint" default="build.all">
<!-- version number -->
- <property name="csslint.version" value="0.9.7" />
+ <property name="csslint.version" value="0.9.8" />
<!-- the directories containing the source files -->
<property name="src.dir" value="./src" />
View
290 release/csslint-node.js
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Build time: 2-March-2012 02:47:11 */
+/* Build time: 14-May-2012 10:24:48 */
/*!
Parser-Lib
@@ -46,7 +46,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
var parserlib = {};
(function(){
@@ -956,7 +956,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2665,7 +2665,8 @@ Parser.prototype = function(){
expr = null,
prio = null,
error = null,
- invalid = null;
+ invalid = null,
+ propertyName= "";
property = this._property();
if (property !== null){
@@ -2682,8 +2683,20 @@ Parser.prototype = function(){
prio = this._prio();
+ /*
+ * If hacks should be allowed, then only check the root
+ * property. If hacks should not be allowed, treat
+ * _property or *property as invalid properties.
+ */
+ propertyName = property.toString();
+ if (this.options.starHack && property.hack == "*" ||
+ this.options.underscoreHack && property.hack == "_") {
+
+ propertyName = property.text;
+ }
+
try {
- this._validateProperty(property, expr);
+ this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
@@ -3524,6 +3537,7 @@ var Properties = {
"background-repeat" : { multi: "<repeat-style>" },
"background-size" : { multi: "<bg-size>", comma: true },
"baseline-shift" : "baseline | sub | super | <percentage> | <length>",
+ "behavior" : 1,
"binding" : 1,
"bleed" : "<length>",
"bookmark-label" : "<content> | <attr> | <string>",
@@ -3870,6 +3884,7 @@ var Properties = {
"text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
"text-outline" : 1,
"text-overflow" : 1,
+ "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
"text-shadow" : 1,
"text-transform" : "capitalize | uppercase | lowercase | none | inherit",
"text-wrap" : "normal | none | avoid",
@@ -5949,7 +5964,7 @@ var ValidationTypes = {
i, len, found = false;
for (i=0,len=args.length; i < len && !found; i++){
- if (text == args[i]){
+ if (text == args[i].toLowerCase()){
found = true;
}
}
@@ -6041,7 +6056,7 @@ var ValidationTypes = {
},
"<gradient>": function(part) {
- return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial|linear)\-gradient/i.test(part);
+ return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
},
"<box>": function(part){
@@ -6133,6 +6148,18 @@ var ValidationTypes = {
part,
i, len;
+/*
+<position> = [
+ [ left | center | right | top | bottom | <percentage> | <length> ]
+|
+ [ left | center | right | <percentage> | <length> ]
+ [ top | center | bottom | <percentage> | <length> ]
+|
+ [ center | [ left | right ] [ <percentage> | <length> ]? ] &&
+ [ center | [ top | bottom ] [ <percentage> | <length> ]? ]
+]
+
+*/
if (ValidationTypes.isAny(expression, "top | bottom")) {
result = true;
@@ -6305,7 +6332,7 @@ var CSSLint = (function(){
formatters = [],
api = new parserlib.util.EventTarget();
- api.version = "0.9.7";
+ api.version = "0.9.8";
//-------------------------------------------------------------------------
// Rule Management
@@ -7632,7 +7659,7 @@ CSSLint.addRule({
parser.addListener("endstylesheet", function(){
reporter.stat("important", count);
if (count >= 10){
- reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specifity issues.", rule);
+ reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
@@ -8289,8 +8316,35 @@ CSSLint.addRule({
});
/*
- * Rule: Don't use text-indent for image replacement if you need to support rtl.
- *
+ * Rule: Don't use properties with a star prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "star-property-hack",
+ name: "Disallow properties with a star prefix",
+ desc: "Checks for the star property hack (targets IE6/7)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "*"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "*") {
+ reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
+ * Rule: Don't use text-indent for image replacement if you need to support rtl.
+ *
*/
/*global CSSLint*/
CSSLint.addRule({
@@ -8300,27 +8354,29 @@ CSSLint.addRule({
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
-
+
//initialization
init: function(parser, reporter){
var rule = this,
- textIndent = false;
-
-
+ textIndent,
+ direction;
+
+
function startRule(event){
textIndent = false;
+ direction = "inherit";
}
-
+
//event handler for end of rules
function endRule(event){
- if (textIndent){
+ if (textIndent && direction != "ltr"){
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
- }
-
+ }
+
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
-
+
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
@@ -8329,17 +8385,44 @@ CSSLint.addRule({
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
- textIndent = false;
+ direction = "ltr";
}
});
parser.addListener("endrule", endRule);
- parser.addListener("endfontface", endRule);
+ parser.addListener("endfontface", endRule);
}
});
/*
+ * Rule: Don't use properties with a underscore prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "underscore-property-hack",
+ name: "Disallow properties with an underscore prefix",
+ desc: "Checks for the underscore property hack (targets IE6)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "_"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "_") {
+ reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
* Rule: Headings (h1-h6) should be defined only once.
*/
/*global CSSLint*/
@@ -8668,85 +8751,114 @@ CSSLint.addRule({
});
/*global CSSLint*/
-CSSLint.addFormatter({
- //format information
- id: "checkstyle-xml",
- name: "Checkstyle XML format",
+(function() {
/**
- * Return opening root XML tag.
- * @return {String} to prepend before all results
+ * Replace special characters before write to output.
+ *
+ * Rules:
+ * - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
+ * - &lt; is the escape sequence for <
+ * - &gt; is the escape sequence for >
+ *
+ * @param {String} message to escape
+ * @return escaped message as {String}
*/
- startFormat: function(){
- return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
- },
+ var xmlEscape = function(str) {
+ if (!str || str.constructor !== String) {
+ return "";
+ }
+
+ return str.replace(/[\"&><]/g, function(match) {
+ switch (match) {
+ case "\"":
+ return "&quot;";
+ case "&":
+ return "&amp;";
+ case "<":
+ return "&lt;";
+ case ">":
+ return "&gt;";
+ }
+ });
+ };
- /**
- * Return closing root XML tag.
- * @return {String} to append after all results
- */
- endFormat: function(){
- return "</checkstyle>";
- },
+ CSSLint.addFormatter({
+ //format information
+ id: "checkstyle-xml",
+ name: "Checkstyle XML format",
- /**
- * Given CSS Lint results for a file, return output for this format.
- * @param results {Object} with error and warning messages
- * @param filename {String} relative file path
- * @param options {Object} (UNUSED for now) specifies special handling of output
- * @return {String} output for results
- */
- formatResults: function(results, filename, options) {
- var messages = results.messages,
- output = [];
+ /**
+ * Return opening root XML tag.
+ * @return {String} to prepend before all results
+ */
+ startFormat: function(){
+ return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
+ },
/**
- * Generate a source string for a rule.
- * Checkstyle source strings usually resemble Java class names e.g
- * net.csslint.SomeRuleName
- * @param {Object} rule
- * @return rule source as {String}
+ * Return closing root XML tag.
+ * @return {String} to append after all results
*/
- var generateSource = function(rule) {
- if (!rule || !('name' in rule)) {
- return "";
- }
- return 'net.csslint.' + rule.name.replace(/\s/g,'');
- };
+ endFormat: function(){
+ return "</checkstyle>";
+ },
+
+ /**
+ * Returns message when there is a file read error.
+ * @param {String} filename The name of the file that caused the error.
+ * @param {String} message The error message
+ * @return {String} The error message.
+ */
+ readError: function(filename, message) {
+ return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
+ },
/**
- * Replace special characters before write to output.
- *
- * Rules:
- * - single quotes is the escape sequence for double-quotes
- * - &lt; is the escape sequence for <
- * - &gt; is the escape sequence for >
- *
- * @param {String} message to escape
- * @return escaped message as {String}
+ * Given CSS Lint results for a file, return output for this format.
+ * @param results {Object} with error and warning messages
+ * @param filename {String} relative file path
+ * @param options {Object} (UNUSED for now) specifies special handling of output
+ * @return {String} output for results
*/
- var escapeSpecialCharacters = function(str) {
- if (!str || str.constructor !== String) {
- return "";
- }
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
- };
+ formatResults: function(results, filename, options) {
+ var messages = results.messages,
+ output = [];
- if (messages.length > 0) {
- output.push("<file name=\""+filename+"\">");
- CSSLint.Util.forEach(messages, function (message, i) {
- //ignore rollups for now
- if (!message.rollup) {
- output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
- " message=\"" + escapeSpecialCharacters(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ /**
+ * Generate a source string for a rule.
+ * Checkstyle source strings usually resemble Java class names e.g
+ * net.csslint.SomeRuleName
+ * @param {Object} rule
+ * @return rule source as {String}
+ */
+ var generateSource = function(rule) {
+ if (!rule || !('name' in rule)) {
+ return "";
}
- });
- output.push("</file>");
+ return 'net.csslint.' + rule.name.replace(/\s/g,'');
+ };
+
+
+
+ if (messages.length > 0) {
+ output.push("<file name=\""+filename+"\">");
+ CSSLint.Util.forEach(messages, function (message, i) {
+ //ignore rollups for now
+ if (!message.rollup) {
+ output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
+ " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ }
+ });
+ output.push("</file>");
+ }
+
+ return output.join("");
}
+ });
- return output.join("");
- }
-});
+}());
/*global CSSLint*/
CSSLint.addFormatter({
//format information
@@ -8844,6 +8956,7 @@ CSSLint.addFormatter({
*
* Rules:
* - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
@@ -8854,7 +8967,7 @@ CSSLint.addFormatter({
if (!str || str.constructor !== String) {
return "";
}
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
@@ -8911,6 +9024,7 @@ CSSLint.addFormatter({
*
* Rules:
* - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
@@ -8921,7 +9035,7 @@ CSSLint.addFormatter({
if (!str || str.constructor !== String) {
return "";
}
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
View
296 release/csslint-rhino.js
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Build time: 2-March-2012 02:47:11 */
+/* Build time: 14-May-2012 10:24:48 */
var CSSLint = (function(){
/*!
@@ -47,7 +47,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
var parserlib = {};
(function(){
@@ -957,7 +957,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2666,7 +2666,8 @@ Parser.prototype = function(){
expr = null,
prio = null,
error = null,
- invalid = null;
+ invalid = null,
+ propertyName= "";
property = this._property();
if (property !== null){
@@ -2683,8 +2684,20 @@ Parser.prototype = function(){
prio = this._prio();
+ /*
+ * If hacks should be allowed, then only check the root
+ * property. If hacks should not be allowed, treat
+ * _property or *property as invalid properties.
+ */
+ propertyName = property.toString();
+ if (this.options.starHack && property.hack == "*" ||
+ this.options.underscoreHack && property.hack == "_") {
+
+ propertyName = property.text;
+ }
+
try {
- this._validateProperty(property, expr);
+ this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
@@ -3525,6 +3538,7 @@ var Properties = {
"background-repeat" : { multi: "<repeat-style>" },
"background-size" : { multi: "<bg-size>", comma: true },
"baseline-shift" : "baseline | sub | super | <percentage> | <length>",
+ "behavior" : 1,
"binding" : 1,
"bleed" : "<length>",
"bookmark-label" : "<content> | <attr> | <string>",
@@ -3871,6 +3885,7 @@ var Properties = {
"text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
"text-outline" : 1,
"text-overflow" : 1,
+ "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
"text-shadow" : 1,
"text-transform" : "capitalize | uppercase | lowercase | none | inherit",
"text-wrap" : "normal | none | avoid",
@@ -5950,7 +5965,7 @@ var ValidationTypes = {
i, len, found = false;
for (i=0,len=args.length; i < len && !found; i++){
- if (text == args[i]){
+ if (text == args[i].toLowerCase()){
found = true;
}
}
@@ -6042,7 +6057,7 @@ var ValidationTypes = {
},
"<gradient>": function(part) {
- return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial|linear)\-gradient/i.test(part);
+ return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
},
"<box>": function(part){
@@ -6134,6 +6149,18 @@ var ValidationTypes = {
part,
i, len;
+/*
+<position> = [
+ [ left | center | right | top | bottom | <percentage> | <length> ]
+|
+ [ left | center | right | <percentage> | <length> ]
+ [ top | center | bottom | <percentage> | <length> ]
+|
+ [ center | [ left | right ] [ <percentage> | <length> ]? ] &&
+ [ center | [ top | bottom ] [ <percentage> | <length> ]? ]
+]
+
+*/
if (ValidationTypes.isAny(expression, "top | bottom")) {
result = true;
@@ -6306,7 +6333,7 @@ var CSSLint = (function(){
formatters = [],
api = new parserlib.util.EventTarget();
- api.version = "0.9.7";
+ api.version = "0.9.8";
//-------------------------------------------------------------------------
// Rule Management
@@ -7633,7 +7660,7 @@ CSSLint.addRule({
parser.addListener("endstylesheet", function(){
reporter.stat("important", count);
if (count >= 10){
- reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specifity issues.", rule);
+ reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
@@ -8290,8 +8317,35 @@ CSSLint.addRule({
});
/*
- * Rule: Don't use text-indent for image replacement if you need to support rtl.
- *
+ * Rule: Don't use properties with a star prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "star-property-hack",
+ name: "Disallow properties with a star prefix",
+ desc: "Checks for the star property hack (targets IE6/7)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "*"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "*") {
+ reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
+ * Rule: Don't use text-indent for image replacement if you need to support rtl.
+ *
*/
/*global CSSLint*/
CSSLint.addRule({
@@ -8301,27 +8355,29 @@ CSSLint.addRule({
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
-
+
//initialization
init: function(parser, reporter){
var rule = this,
- textIndent = false;
-
-
+ textIndent,
+ direction;
+
+
function startRule(event){
textIndent = false;
+ direction = "inherit";
}
-
+
//event handler for end of rules
function endRule(event){
- if (textIndent){
+ if (textIndent && direction != "ltr"){
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
- }
-
+ }
+
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
-
+
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
@@ -8330,17 +8386,44 @@ CSSLint.addRule({
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
- textIndent = false;
+ direction = "ltr";
}
});
parser.addListener("endrule", endRule);
- parser.addListener("endfontface", endRule);
+ parser.addListener("endfontface", endRule);
}
});
/*
+ * Rule: Don't use properties with a underscore prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "underscore-property-hack",
+ name: "Disallow properties with an underscore prefix",
+ desc: "Checks for the underscore property hack (targets IE6)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "_"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "_") {
+ reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
* Rule: Headings (h1-h6) should be defined only once.
*/
/*global CSSLint*/
@@ -8669,85 +8752,114 @@ CSSLint.addRule({
});
/*global CSSLint*/
-CSSLint.addFormatter({
- //format information
- id: "checkstyle-xml",
- name: "Checkstyle XML format",
+(function() {
/**
- * Return opening root XML tag.
- * @return {String} to prepend before all results
+ * Replace special characters before write to output.
+ *
+ * Rules:
+ * - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
+ * - &lt; is the escape sequence for <
+ * - &gt; is the escape sequence for >
+ *
+ * @param {String} message to escape
+ * @return escaped message as {String}
*/
- startFormat: function(){
- return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
- },
+ var xmlEscape = function(str) {
+ if (!str || str.constructor !== String) {
+ return "";
+ }
+
+ return str.replace(/[\"&><]/g, function(match) {
+ switch (match) {
+ case "\"":
+ return "&quot;";
+ case "&":
+ return "&amp;";
+ case "<":
+ return "&lt;";
+ case ">":
+ return "&gt;";
+ }
+ });
+ };
- /**
- * Return closing root XML tag.
- * @return {String} to append after all results
- */
- endFormat: function(){
- return "</checkstyle>";
- },
+ CSSLint.addFormatter({
+ //format information
+ id: "checkstyle-xml",
+ name: "Checkstyle XML format",
- /**
- * Given CSS Lint results for a file, return output for this format.
- * @param results {Object} with error and warning messages
- * @param filename {String} relative file path
- * @param options {Object} (UNUSED for now) specifies special handling of output
- * @return {String} output for results
- */
- formatResults: function(results, filename, options) {
- var messages = results.messages,
- output = [];
+ /**
+ * Return opening root XML tag.
+ * @return {String} to prepend before all results
+ */
+ startFormat: function(){
+ return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
+ },
/**
- * Generate a source string for a rule.
- * Checkstyle source strings usually resemble Java class names e.g
- * net.csslint.SomeRuleName
- * @param {Object} rule
- * @return rule source as {String}
+ * Return closing root XML tag.
+ * @return {String} to append after all results
*/
- var generateSource = function(rule) {
- if (!rule || !('name' in rule)) {
- return "";
- }
- return 'net.csslint.' + rule.name.replace(/\s/g,'');
- };
+ endFormat: function(){
+ return "</checkstyle>";
+ },
+
+ /**
+ * Returns message when there is a file read error.
+ * @param {String} filename The name of the file that caused the error.
+ * @param {String} message The error message
+ * @return {String} The error message.
+ */
+ readError: function(filename, message) {
+ return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
+ },
/**
- * Replace special characters before write to output.
- *
- * Rules:
- * - single quotes is the escape sequence for double-quotes
- * - &lt; is the escape sequence for <
- * - &gt; is the escape sequence for >
- *
- * @param {String} message to escape
- * @return escaped message as {String}
+ * Given CSS Lint results for a file, return output for this format.
+ * @param results {Object} with error and warning messages
+ * @param filename {String} relative file path
+ * @param options {Object} (UNUSED for now) specifies special handling of output
+ * @return {String} output for results
*/
- var escapeSpecialCharacters = function(str) {
- if (!str || str.constructor !== String) {
- return "";
- }
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
- };
+ formatResults: function(results, filename, options) {
+ var messages = results.messages,
+ output = [];
- if (messages.length > 0) {
- output.push("<file name=\""+filename+"\">");
- CSSLint.Util.forEach(messages, function (message, i) {
- //ignore rollups for now
- if (!message.rollup) {
- output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
- " message=\"" + escapeSpecialCharacters(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ /**
+ * Generate a source string for a rule.
+ * Checkstyle source strings usually resemble Java class names e.g
+ * net.csslint.SomeRuleName
+ * @param {Object} rule
+ * @return rule source as {String}
+ */
+ var generateSource = function(rule) {
+ if (!rule || !('name' in rule)) {
+ return "";
}
- });
- output.push("</file>");
+ return 'net.csslint.' + rule.name.replace(/\s/g,'');
+ };
+
+
+
+ if (messages.length > 0) {
+ output.push("<file name=\""+filename+"\">");
+ CSSLint.Util.forEach(messages, function (message, i) {
+ //ignore rollups for now
+ if (!message.rollup) {
+ output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
+ " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ }
+ });
+ output.push("</file>");
+ }
+
+ return output.join("");
}
+ });
- return output.join("");
- }
-});
+}());
/*global CSSLint*/
CSSLint.addFormatter({
//format information
@@ -8845,6 +8957,7 @@ CSSLint.addFormatter({
*
* Rules:
* - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
@@ -8855,7 +8968,7 @@ CSSLint.addFormatter({
if (!str || str.constructor !== String) {
return "";
}
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
@@ -8912,6 +9025,7 @@ CSSLint.addFormatter({
*
* Rules:
* - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
@@ -8922,7 +9036,7 @@ CSSLint.addFormatter({
if (!str || str.constructor !== String) {
return "";
}
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
@@ -9089,7 +9203,11 @@ function cli(api){
exitCode = 0;
if (!input) {
- api.print("csslint: Could not read file data in " + relativeFilePath + ". Is the file empty?");
+ if (formatter.readError) {
+ api.print(formatter.readError(relativeFilePath, "Could not read file data. Is the file empty?"));
+ } else {
+ api.print("csslint: Could not read file data in " + relativeFilePath + ". Is the file empty?");
+ }
exitCode = 1;
} else {
//var relativeFilePath = getRelativePath(api.getWorkingDirectory(), fullFilePath);
View
101 release/csslint-tests.js
@@ -87,14 +87,14 @@
},
"Formatter should escape special characters": function() {
- var specialCharsSting = 'sneaky, "sneaky", <sneaky>',
+ var specialCharsSting = 'sneaky, "sneaky", <sneaky>, sneak & sneaky',
result = { messages: [
{ type: "warning", line: 1, col: 1, message: specialCharsSting, evidence: "ALSO BOGUS", rule: [] },
{ type: "error", line: 2, col: 1, message: specialCharsSting, evidence: "ALSO BOGUS", rule: [] }
], stats: [] },
file = "<file name=\"FILE\">",
- error1 = "<error line=\"1\" column=\"1\" severity=\"warning\" message=\"sneaky, 'sneaky', &lt;sneaky&gt;\" source=\"\"/>",
- error2 = "<error line=\"2\" column=\"1\" severity=\"error\" message=\"sneaky, 'sneaky', &lt;sneaky&gt;\" source=\"\"/>",
+ error1 = "<error line=\"1\" column=\"1\" severity=\"warning\" message=\"sneaky, &quot;sneaky&quot;, &lt;sneaky&gt;, sneak &amp; sneaky\" source=\"\"/>",
+ error2 = "<error line=\"2\" column=\"1\" severity=\"error\" message=\"sneaky, &quot;sneaky&quot;, &lt;sneaky&gt;, sneak &amp; sneaky\" source=\"\"/>",
expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>" + file + error1 + error2 + "</file></checkstyle>",
actual = CSSLint.format(result, "FILE", "checkstyle-xml");
Assert.areEqual(expected, actual);
@@ -179,14 +179,14 @@
},
"Formatter should escape double quotes": function() {
- var doubleQuotedEvidence = 'sneaky, "sneaky"',
+ var doubleQuotedEvidence = 'sneaky, "sneaky", <sneaky>, sneak & sneaky',
result = { messages: [
{ type: "warning", line: 1, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] },
{ type: "error", line: 2, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] }
], stats: [] },
file = "<file name=\"FILE\">",
- error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
- error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
+ error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
+ error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>" + file + error1 + error2 + "</file></csslint>",
actual = CSSLint.format(result, "FILE", "csslint-xml");
Assert.areEqual(expected, actual);
@@ -223,14 +223,14 @@
},
"Formatter should escape double quotes": function() {
- var doubleQuotedEvidence = 'sneaky, "sneaky"',
+ var doubleQuotedEvidence = 'sneaky, "sneaky", <sneaky>, sneak & sneaky',
result = { messages: [
{ type: "warning", line: 1, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] },
{ type: "error", line: 2, col: 1, message: "BOGUS", evidence: doubleQuotedEvidence, rule: [] }
], stats: [] },
file = "<file name=\"FILE\">",
- error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
- error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky'\"/>",
+ error1 = "<issue line=\"1\" char=\"1\" severity=\"warning\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
+ error2 = "<issue line=\"2\" char=\"1\" severity=\"error\" reason=\"BOGUS\" evidence=\"sneaky, 'sneaky', &lt;sneaky&gt;, sneak &amp; sneaky\"/>",
expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>" + file + error1 + error2 + "</file></lint>",
actual = CSSLint.format(result, "FILE", "lint-xml");
Assert.areEqual(expected, actual);
@@ -1318,7 +1318,7 @@ background: -ms-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
var result = CSSLint.verify(css, { "important": 1 });
Assert.areEqual(11, result.messages.length);
Assert.areEqual("warning", result.messages[10].type);
- Assert.areEqual("Too many !important declarations (10), try to use less than 10 to avoid specifity issues.", result.messages[10].message);
+ Assert.areEqual("Too many !important declarations (10), try to use less than 10 to avoid specificity issues.", result.messages[10].message);
}
}));
@@ -1346,6 +1346,16 @@ background: -ms-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
Assert.areEqual(0, result.messages.length);
},
+ "Using a known property with the star hack should not result in a warning": function(){
+ var result = CSSLint.verify("h1 { *color: red;}", { "known-properties": 1 });
+ Assert.areEqual(0, result.messages.length);
+ },
+
+ "Using a known property with the underscore hack should not result in a warning": function(){
+ var result = CSSLint.verify("h1 { _color: red;}", { "known-properties": 1 });
+ Assert.areEqual(0, result.messages.length);
+ },
+
"Using a vendor-prefix property should not result in a warning": function(){
var result = CSSLint.verify("h2 { -moz-border-radius: 5px; }", { "known-properties": 1 });
Assert.areEqual(0, result.messages.length);
@@ -1569,7 +1579,32 @@ background: -ms-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
var Assert = YUITest.Assert;
YUITest.TestRunner.add(new YUITest.TestCase({
-
+
+ name: "star-property-hack Rule Errors",
+
+ "a property with a star prefix should result in a warning": function(){
+ var result = CSSLint.verify(".foo{*width: 100px;}", {"star-property-hack": 1 });
+ Assert.areEqual(1, result.messages.length);
+ Assert.areEqual("warning", result.messages[0].type);
+ Assert.areEqual("Property with star prefix found.", result.messages[0].message);
+ },
+
+ "a property without a star prefix should not result in a warning": function(){
+ var result = CSSLint.verify(".foo{width: 100px;}", {"star-property-hack": 1 });
+ Assert.areEqual(0, result.messages.length);
+ }
+
+ }));
+
+})();
+
+(function(){
+
+ /*global YUITest, CSSLint*/
+ var Assert = YUITest.Assert;
+
+ YUITest.TestRunner.add(new YUITest.TestCase({
+
name: "text-indent Rule Errors",
"-100px text-indent should result in a warning": function(){
@@ -1579,18 +1614,25 @@ background: -ms-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
Assert.areEqual("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", result.messages[0].message);
},
- "-98px text-indent should not result in a warning": function(){
- var result = CSSLint.verify(".foo{text-indent: -98px;} ", {"text-indent": 1 });
+ "-99px text-indent should not result in a warning": function(){
+ var result = CSSLint.verify(".foo{text-indent: -99px;} ", {"text-indent": 1 });
+ Assert.areEqual(0, result.messages.length);
+ },
+
+ "-99em text-indent should not result in a warning": function(){
+ var result = CSSLint.verify(".foo{text-indent: -99em;} ", {"text-indent": 1 });
Assert.areEqual(0, result.messages.length);
},
"-100px text-indent with LTR should not result in a warning": function(){
var result = CSSLint.verify(".foo{text-indent: -100px; direction: ltr; }", {"text-indent": 1 });
Assert.areEqual(0, result.messages.length);
+ result = CSSLint.verify(".foo{direction: ltr; text-indent: -100px; }", {"text-indent": 1 });
+ Assert.areEqual(0, result.messages.length);
},
- "-100px text-indent with RTL should result in a warning": function(){
- var result = CSSLint.verify(".foo{text-indent: -100px; direction: rtl; }", {"text-indent": 1 });
+ "-100em text-indent with RTL should result in a warning": function(){
+ var result = CSSLint.verify(".foo{text-indent: -100em; direction: rtl; }", {"text-indent": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", result.messages[0].message);
@@ -1600,14 +1642,39 @@ background: -ms-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
var result = CSSLint.verify(".foo{text-indent: 5px;}", {"text-indent": 1 });
Assert.areEqual(0, result.messages.length);
},
-
+
"This should cause a warning, not an error": function(){
var result = CSSLint.verify(".top h1 a { background: url(../images/background/logo.png) no-repeat; display: block; height: 44px; position: relative; text-indent: -9999px; width: 250px; }", { "text-indent": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", result.messages[0].message);
}
-
+
+ }));
+
+})();
+
+(function(){
+
+ /*global YUITest, CSSLint*/
+ var Assert = YUITest.Assert;
+
+ YUITest.TestRunner.add(new YUITest.TestCase({
+
+ name: "underscore-property-hack Rule Errors",
+
+ "a property with an underscore prefix should result in a warning": function(){
+ var result = CSSLint.verify(".foo{_width: 100px;}", {"underscore-property-hack": 1 });
+ Assert.areEqual(1, result.messages.length);
+ Assert.areEqual("warning", result.messages[0].type);
+ Assert.areEqual("Property with underscore prefix found.", result.messages[0].message);
+ },
+
+ "a property without an underscore prefix should not result in a warning": function(){
+ var result = CSSLint.verify(".foo{width: 100px;}", {"underscore-property-hack": 1 });
+ Assert.areEqual(0, result.messages.length);
+ }
+
}));
})();
View
290 release/csslint-worker.js
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Build time: 2-March-2012 02:47:11 */
+/* Build time: 14-May-2012 10:24:48 */
/*!
Parser-Lib
@@ -46,7 +46,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
var parserlib = {};
(function(){
@@ -956,7 +956,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2665,7 +2665,8 @@ Parser.prototype = function(){
expr = null,
prio = null,
error = null,
- invalid = null;
+ invalid = null,
+ propertyName= "";
property = this._property();
if (property !== null){
@@ -2682,8 +2683,20 @@ Parser.prototype = function(){
prio = this._prio();
+ /*
+ * If hacks should be allowed, then only check the root
+ * property. If hacks should not be allowed, treat
+ * _property or *property as invalid properties.
+ */
+ propertyName = property.toString();
+ if (this.options.starHack && property.hack == "*" ||
+ this.options.underscoreHack && property.hack == "_") {
+
+ propertyName = property.text;
+ }
+
try {
- this._validateProperty(property, expr);
+ this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
@@ -3524,6 +3537,7 @@ var Properties = {
"background-repeat" : { multi: "<repeat-style>" },
"background-size" : { multi: "<bg-size>", comma: true },
"baseline-shift" : "baseline | sub | super | <percentage> | <length>",
+ "behavior" : 1,
"binding" : 1,
"bleed" : "<length>",
"bookmark-label" : "<content> | <attr> | <string>",
@@ -3870,6 +3884,7 @@ var Properties = {
"text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
"text-outline" : 1,
"text-overflow" : 1,
+ "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
"text-shadow" : 1,
"text-transform" : "capitalize | uppercase | lowercase | none | inherit",
"text-wrap" : "normal | none | avoid",
@@ -5949,7 +5964,7 @@ var ValidationTypes = {
i, len, found = false;
for (i=0,len=args.length; i < len && !found; i++){
- if (text == args[i]){
+ if (text == args[i].toLowerCase()){
found = true;
}
}
@@ -6041,7 +6056,7 @@ var ValidationTypes = {
},
"<gradient>": function(part) {
- return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial|linear)\-gradient/i.test(part);
+ return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
},
"<box>": function(part){
@@ -6133,6 +6148,18 @@ var ValidationTypes = {
part,
i, len;
+/*
+<position> = [
+ [ left | center | right | top | bottom | <percentage> | <length> ]
+|
+ [ left | center | right | <percentage> | <length> ]
+ [ top | center | bottom | <percentage> | <length> ]
+|
+ [ center | [ left | right ] [ <percentage> | <length> ]? ] &&
+ [ center | [ top | bottom ] [ <percentage> | <length> ]? ]
+]
+
+*/
if (ValidationTypes.isAny(expression, "top | bottom")) {
result = true;
@@ -6305,7 +6332,7 @@ var CSSLint = (function(){
formatters = [],
api = new parserlib.util.EventTarget();
- api.version = "0.9.7";
+ api.version = "0.9.8";
//-------------------------------------------------------------------------
// Rule Management
@@ -7632,7 +7659,7 @@ CSSLint.addRule({
parser.addListener("endstylesheet", function(){
reporter.stat("important", count);
if (count >= 10){
- reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specifity issues.", rule);
+ reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
@@ -8289,8 +8316,35 @@ CSSLint.addRule({
});
/*
- * Rule: Don't use text-indent for image replacement if you need to support rtl.
- *
+ * Rule: Don't use properties with a star prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "star-property-hack",
+ name: "Disallow properties with a star prefix",
+ desc: "Checks for the star property hack (targets IE6/7)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "*"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "*") {
+ reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
+ * Rule: Don't use text-indent for image replacement if you need to support rtl.
+ *
*/
/*global CSSLint*/
CSSLint.addRule({
@@ -8300,27 +8354,29 @@ CSSLint.addRule({
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
-
+
//initialization
init: function(parser, reporter){
var rule = this,
- textIndent = false;
-
-
+ textIndent,
+ direction;
+
+
function startRule(event){
textIndent = false;
+ direction = "inherit";
}
-
+
//event handler for end of rules
function endRule(event){
- if (textIndent){
+ if (textIndent && direction != "ltr"){
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
- }
-
+ }
+
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
-
+
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
@@ -8329,17 +8385,44 @@ CSSLint.addRule({
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
- textIndent = false;
+ direction = "ltr";
}
});
parser.addListener("endrule", endRule);
- parser.addListener("endfontface", endRule);
+ parser.addListener("endfontface", endRule);
}
});
/*
+ * Rule: Don't use properties with a underscore prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "underscore-property-hack",
+ name: "Disallow properties with an underscore prefix",
+ desc: "Checks for the underscore property hack (targets IE6)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "_"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "_") {
+ reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
* Rule: Headings (h1-h6) should be defined only once.
*/
/*global CSSLint*/
@@ -8668,85 +8751,114 @@ CSSLint.addRule({
});
/*global CSSLint*/
-CSSLint.addFormatter({
- //format information
- id: "checkstyle-xml",
- name: "Checkstyle XML format",
+(function() {
/**
- * Return opening root XML tag.
- * @return {String} to prepend before all results
+ * Replace special characters before write to output.
+ *
+ * Rules:
+ * - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
+ * - &lt; is the escape sequence for <
+ * - &gt; is the escape sequence for >
+ *
+ * @param {String} message to escape
+ * @return escaped message as {String}
*/
- startFormat: function(){
- return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
- },
+ var xmlEscape = function(str) {
+ if (!str || str.constructor !== String) {
+ return "";
+ }
+
+ return str.replace(/[\"&><]/g, function(match) {
+ switch (match) {
+ case "\"":
+ return "&quot;";
+ case "&":
+ return "&amp;";
+ case "<":
+ return "&lt;";
+ case ">":
+ return "&gt;";
+ }
+ });
+ };
- /**
- * Return closing root XML tag.
- * @return {String} to append after all results
- */
- endFormat: function(){
- return "</checkstyle>";
- },
+ CSSLint.addFormatter({
+ //format information
+ id: "checkstyle-xml",
+ name: "Checkstyle XML format",
- /**
- * Given CSS Lint results for a file, return output for this format.
- * @param results {Object} with error and warning messages
- * @param filename {String} relative file path
- * @param options {Object} (UNUSED for now) specifies special handling of output
- * @return {String} output for results
- */
- formatResults: function(results, filename, options) {
- var messages = results.messages,
- output = [];
+ /**
+ * Return opening root XML tag.
+ * @return {String} to prepend before all results
+ */
+ startFormat: function(){
+ return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
+ },
/**
- * Generate a source string for a rule.
- * Checkstyle source strings usually resemble Java class names e.g
- * net.csslint.SomeRuleName
- * @param {Object} rule
- * @return rule source as {String}
+ * Return closing root XML tag.
+ * @return {String} to append after all results
*/
- var generateSource = function(rule) {
- if (!rule || !('name' in rule)) {
- return "";
- }
- return 'net.csslint.' + rule.name.replace(/\s/g,'');
- };
+ endFormat: function(){
+ return "</checkstyle>";
+ },
+
+ /**
+ * Returns message when there is a file read error.
+ * @param {String} filename The name of the file that caused the error.
+ * @param {String} message The error message
+ * @return {String} The error message.
+ */
+ readError: function(filename, message) {
+ return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
+ },
/**
- * Replace special characters before write to output.
- *
- * Rules:
- * - single quotes is the escape sequence for double-quotes
- * - &lt; is the escape sequence for <
- * - &gt; is the escape sequence for >
- *
- * @param {String} message to escape
- * @return escaped message as {String}
+ * Given CSS Lint results for a file, return output for this format.
+ * @param results {Object} with error and warning messages
+ * @param filename {String} relative file path
+ * @param options {Object} (UNUSED for now) specifies special handling of output
+ * @return {String} output for results
*/
- var escapeSpecialCharacters = function(str) {
- if (!str || str.constructor !== String) {
- return "";
- }
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
- };
+ formatResults: function(results, filename, options) {
+ var messages = results.messages,
+ output = [];
- if (messages.length > 0) {
- output.push("<file name=\""+filename+"\">");
- CSSLint.Util.forEach(messages, function (message, i) {
- //ignore rollups for now
- if (!message.rollup) {
- output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
- " message=\"" + escapeSpecialCharacters(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ /**
+ * Generate a source string for a rule.
+ * Checkstyle source strings usually resemble Java class names e.g
+ * net.csslint.SomeRuleName
+ * @param {Object} rule
+ * @return rule source as {String}
+ */
+ var generateSource = function(rule) {
+ if (!rule || !('name' in rule)) {
+ return "";
}
- });
- output.push("</file>");
+ return 'net.csslint.' + rule.name.replace(/\s/g,'');
+ };
+
+
+
+ if (messages.length > 0) {
+ output.push("<file name=\""+filename+"\">");
+ CSSLint.Util.forEach(messages, function (message, i) {
+ //ignore rollups for now
+ if (!message.rollup) {
+ output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
+ " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ }
+ });
+ output.push("</file>");
+ }
+
+ return output.join("");
}
+ });
- return output.join("");
- }
-});
+}());
/*global CSSLint*/
CSSLint.addFormatter({
//format information
@@ -8844,6 +8956,7 @@ CSSLint.addFormatter({
*
* Rules:
* - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
@@ -8854,7 +8967,7 @@ CSSLint.addFormatter({
if (!str || str.constructor !== String) {
return "";
}
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
@@ -8911,6 +9024,7 @@ CSSLint.addFormatter({
*
* Rules:
* - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
* - &lt; is the escape sequence for <
* - &gt; is the escape sequence for >
*
@@ -8921,7 +9035,7 @@ CSSLint.addFormatter({
if (!str || str.constructor !== String) {
return "";
}
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};
if (messages.length > 0) {
View
296 release/csslint-wsh.js
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Build time: 2-March-2012 02:47:11 */
+/* Build time: 14-May-2012 10:24:48 */
var CSSLint = (function(){
/*!
@@ -47,7 +47,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
var parserlib = {};
(function(){
@@ -957,7 +957,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v0.1.6, Build time: 2-March-2012 02:44:32 */
+/* Version v0.1.7, Build time: 4-May-2012 03:57:04 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2666,7 +2666,8 @@ Parser.prototype = function(){
expr = null,
prio = null,
error = null,
- invalid = null;
+ invalid = null,
+ propertyName= "";
property = this._property();
if (property !== null){
@@ -2683,8 +2684,20 @@ Parser.prototype = function(){
prio = this._prio();
+ /*
+ * If hacks should be allowed, then only check the root
+ * property. If hacks should not be allowed, treat
+ * _property or *property as invalid properties.
+ */
+ propertyName = property.toString();
+ if (this.options.starHack && property.hack == "*" ||
+ this.options.underscoreHack && property.hack == "_") {
+
+ propertyName = property.text;
+ }
+
try {
- this._validateProperty(property, expr);
+ this._validateProperty(propertyName, expr);
} catch (ex) {
invalid = ex;
}
@@ -3525,6 +3538,7 @@ var Properties = {
"background-repeat" : { multi: "<repeat-style>" },
"background-size" : { multi: "<bg-size>", comma: true },
"baseline-shift" : "baseline | sub | super | <percentage> | <length>",
+ "behavior" : 1,
"binding" : 1,
"bleed" : "<length>",
"bookmark-label" : "<content> | <attr> | <string>",
@@ -3871,6 +3885,7 @@ var Properties = {
"text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
"text-outline" : 1,
"text-overflow" : 1,
+ "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
"text-shadow" : 1,
"text-transform" : "capitalize | uppercase | lowercase | none | inherit",
"text-wrap" : "normal | none | avoid",
@@ -5950,7 +5965,7 @@ var ValidationTypes = {
i, len, found = false;
for (i=0,len=args.length; i < len && !found; i++){
- if (text == args[i]){
+ if (text == args[i].toLowerCase()){
found = true;
}
}
@@ -6042,7 +6057,7 @@ var ValidationTypes = {
},
"<gradient>": function(part) {
- return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial|linear)\-gradient/i.test(part);
+ return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
},
"<box>": function(part){
@@ -6134,6 +6149,18 @@ var ValidationTypes = {
part,
i, len;
+/*
+<position> = [
+ [ left | center | right | top | bottom | <percentage> | <length> ]
+|
+ [ left | center | right | <percentage> | <length> ]
+ [ top | center | bottom | <percentage> | <length> ]
+|
+ [ center | [ left | right ] [ <percentage> | <length> ]? ] &&
+ [ center | [ top | bottom ] [ <percentage> | <length> ]? ]
+]
+
+*/
if (ValidationTypes.isAny(expression, "top | bottom")) {
result = true;
@@ -6306,7 +6333,7 @@ var CSSLint = (function(){
formatters = [],
api = new parserlib.util.EventTarget();
- api.version = "0.9.7";
+ api.version = "0.9.8";
//-------------------------------------------------------------------------
// Rule Management
@@ -7633,7 +7660,7 @@ CSSLint.addRule({
parser.addListener("endstylesheet", function(){
reporter.stat("important", count);
if (count >= 10){
- reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specifity issues.", rule);
+ reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
}
});
}
@@ -8290,8 +8317,35 @@ CSSLint.addRule({
});
/*
- * Rule: Don't use text-indent for image replacement if you need to support rtl.
- *
+ * Rule: Don't use properties with a star prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "star-property-hack",
+ name: "Disallow properties with a star prefix",
+ desc: "Checks for the star property hack (targets IE6/7)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "*"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "*") {
+ reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
+ * Rule: Don't use text-indent for image replacement if you need to support rtl.
+ *
*/
/*global CSSLint*/
CSSLint.addRule({
@@ -8301,27 +8355,29 @@ CSSLint.addRule({
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
-
+
//initialization
init: function(parser, reporter){
var rule = this,
- textIndent = false;
-
-
+ textIndent,
+ direction;
+
+
function startRule(event){
textIndent = false;
+ direction = "inherit";
}
-
+
//event handler for end of rules
function endRule(event){
- if (textIndent){
+ if (textIndent && direction != "ltr"){
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
}
- }
-
+ }
+
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
-
+
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
@@ -8330,17 +8386,44 @@ CSSLint.addRule({
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
- textIndent = false;
+ direction = "ltr";
}
});
parser.addListener("endrule", endRule);
- parser.addListener("endfontface", endRule);
+ parser.addListener("endfontface", endRule);
}
});
/*
+ * Rule: Don't use properties with a underscore prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "underscore-property-hack",
+ name: "Disallow properties with an underscore prefix",
+ desc: "Checks for the underscore property hack (targets IE6)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "_"
+ parser.addListener("property", function(event){
+ var property = event.property;
+
+ if (property.hack == "_") {
+ reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
+/*
* Rule: Headings (h1-h6) should be defined only once.
*/
/*global CSSLint*/
@@ -8669,85 +8752,114 @@ CSSLint.addRule({
});
/*global CSSLint*/
-CSSLint.addFormatter({
- //format information
- id: "checkstyle-xml",
- name: "Checkstyle XML format",
+(function() {
/**
- * Return opening root XML tag.
- * @return {String} to prepend before all results
+ * Replace special characters before write to output.
+ *
+ * Rules:
+ * - single quotes is the escape sequence for double-quotes
+ * - &amp; is the escape sequence for &
+ * - &lt; is the escape sequence for <
+ * - &gt; is the escape sequence for >
+ *
+ * @param {String} message to escape
+ * @return escaped message as {String}
*/
- startFormat: function(){
- return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
- },
+ var xmlEscape = function(str) {
+ if (!str || str.constructor !== String) {
+ return "";
+ }
+
+ return str.replace(/[\"&><]/g, function(match) {
+ switch (match) {
+ case "\"":
+ return "&quot;";
+ case "&":
+ return "&amp;";
+ case "<":
+ return "&lt;";
+ case ">":
+ return "&gt;";
+ }
+ });
+ };
- /**
- * Return closing root XML tag.
- * @return {String} to append after all results
- */
- endFormat: function(){
- return "</checkstyle>";
- },
+ CSSLint.addFormatter({
+ //format information
+ id: "checkstyle-xml",
+ name: "Checkstyle XML format",
- /**
- * Given CSS Lint results for a file, return output for this format.
- * @param results {Object} with error and warning messages
- * @param filename {String} relative file path
- * @param options {Object} (UNUSED for now) specifies special handling of output
- * @return {String} output for results
- */
- formatResults: function(results, filename, options) {
- var messages = results.messages,
- output = [];
+ /**
+ * Return opening root XML tag.
+ * @return {String} to prepend before all results
+ */
+ startFormat: function(){
+ return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
+ },
/**
- * Generate a source string for a rule.
- * Checkstyle source strings usually resemble Java class names e.g
- * net.csslint.SomeRuleName
- * @param {Object} rule
- * @return rule source as {String}
+ * Return closing root XML tag.
+ * @return {String} to append after all results
*/
- var generateSource = function(rule) {
- if (!rule || !('name' in rule)) {
- return "";
- }
- return 'net.csslint.' + rule.name.replace(/\s/g,'');
- };
+ endFormat: function(){
+ return "</checkstyle>";
+ },
+
+ /**
+ * Returns message when there is a file read error.
+ * @param {String} filename The name of the file that caused the error.
+ * @param {String} message The error message
+ * @return {String} The error message.
+ */
+ readError: function(filename, message) {
+ return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
+ },
/**
- * Replace special characters before write to output.
- *
- * Rules:
- * - single quotes is the escape sequence for double-quotes
- * - &lt; is the escape sequence for <
- * - &gt; is the escape sequence for >
- *
- * @param {String} message to escape
- * @return escaped message as {String}
+ * Given CSS Lint results for a file, return output for this format.
+ * @param results {Object} with error and warning messages
+ * @param filename {String} relative file path
+ * @param options {Object} (UNUSED for now) specifies special handling of output
+ * @return {String} output for results
*/
- var escapeSpecialCharacters = function(str) {
- if (!str || str.constructor !== String) {
- return "";
- }
- return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
- };
+ formatResults: function(results, filename, options) {
+ var messages = results.messages,
+ output = [];
- if (messages.length > 0) {
- output.push("<file name=\""+filename+"\">");
- CSSLint.Util.forEach(messages, function (message, i) {
- //ignore rollups for now
- if (!message.rollup) {
- output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
- " message=\"" + escapeSpecialCharacters(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
+ /**
+ * Generate a source string for a rule.
+ * Checkstyle source strings usually resemble Java class names e.g
+ * net.csslint.SomeRuleName