lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css/csslint.js in gollum-2.4.4 vs lib/gollum/frontend/public/gollum/livepreview/js/ace/lib/ace/mode/css/csslint.js in gollum-2.4.5

- old
+ new

@@ -20,11 +20,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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: 12-September-2012 01:46:26 */ /*! Parser-Lib Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved. @@ -45,11 +45,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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.9, Build time: 23-July-2012 10:52:31 */ var parserlib = {}; (function(){ /** @@ -955,11 +955,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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.9, Build time: 23-July-2012 10:52:31 */ (function(){ var EventTarget = parserlib.util.EventTarget, TokenStreamBase = parserlib.util.TokenStreamBase, StringReader = parserlib.util.StringReader, SyntaxError = parserlib.util.SyntaxError, @@ -2169,11 +2169,11 @@ selector.push(combinator); nextSelector = this._simple_selector_sequence(); //there must be a next selector if (nextSelector === null){ - this._unexpectedToken(this.LT(1)); + this._unexpectedToken(tokenStream.LT(1)); } else { //nextSelector is an instance of SelectorPart selector.push(nextSelector); } @@ -2664,11 +2664,12 @@ var tokenStream = this._tokenStream, property = null, expr = null, prio = null, error = null, - invalid = null; + invalid = null, + propertyName= ""; property = this._property(); if (property !== null){ tokenStream.mustMatch(Tokens.COLON); @@ -2681,12 +2682,24 @@ this._unexpectedToken(tokenStream.LT(1)); } 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; } this.fire({ @@ -2726,11 +2739,11 @@ * ; */ var tokenStream = this._tokenStream, values = [], - //valueParts = [], + //valueParts = [], value = null, operator = null; value = this._term(); if (value !== null){ @@ -3010,24 +3023,31 @@ * ; */ var tokenStream = this._tokenStream, token, tt, - name; + name, + prefix = ""; tokenStream.mustMatch(Tokens.KEYFRAMES_SYM); + token = tokenStream.token(); + if (/^@\-([^\-]+)\-/.test(token.value)) { + prefix = RegExp.$1; + } + this._readWhitespace(); name = this._keyframe_name(); this._readWhitespace(); tokenStream.mustMatch(Tokens.LBRACE); this.fire({ type: "startkeyframes", name: name, - line: name.line, - col: name.col + prefix: prefix, + line: token.startLine, + col: token.startCol }); this._readWhitespace(); tt = tokenStream.peek(); @@ -3039,12 +3059,13 @@ } this.fire({ type: "endkeyframes", name: name, - line: name.line, - col: name.col + prefix: prefix, + line: token.startLine, + col: token.startCol }); this._readWhitespace(); tokenStream.mustMatch(Tokens.RBRACE); @@ -3523,10 +3544,11 @@ "background-origin" : { multi: "<box>", comma: true }, "background-position" : { multi: "<bg-position>", comma: true }, "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>", "bookmark-level" : "none | <integer>", "bookmark-state" : "open | closed", @@ -3821,10 +3843,11 @@ "perspective-origin" : 1, "phonemes" : 1, "pitch" : 1, "pitch-range" : 1, "play-during" : 1, + "pointer-events" : "auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | inherit", "position" : "static | relative | absolute | fixed | inherit", "presentation-level" : 1, "punctuation-trim" : 1, //Q @@ -3869,10 +3892,11 @@ "text-height" : 1, "text-indent" : "<length> | <percentage> | inherit", "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", "top" : "<margin-width> | inherit", "transform" : 1, @@ -5564,11 +5588,11 @@ { name: "NAMESPACE_SYM", text: "@namespace"}, { name: "UNKNOWN_SYM" }, //{ name: "ATKEYWORD"}, //CSS3 animations - { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] }, + { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] }, //important symbol { name: "IMPORTANT_SYM"}, //measurements @@ -5948,11 +5972,11 @@ var text = part.text.toString().toLowerCase(), args = literals.split(" | "), 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; } } return found; @@ -6040,11 +6064,11 @@ "<bg-image>": function(part){ return this["<image>"](part) || this["<gradient>"](part) || part == "none"; }, "<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){ return ValidationTypes.isLiteral(part, "padding-box | border-box | content-box"); }, @@ -6132,10 +6156,22 @@ xDir = "left | center | right", yDir = "top | center | bottom", 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; } else { @@ -6304,11 +6340,11 @@ var rules = [], formatters = [], api = new parserlib.util.EventTarget(); - api.version = "0.9.7"; + api.version = "0.9.9"; //------------------------------------------------------------------------- // Rule Management //------------------------------------------------------------------------- @@ -6338,10 +6374,27 @@ api.getRules = function(){ return [].concat(rules).sort(function(a,b){ return a.id > b.id ? 1 : 0; }); }; + + /** + * Returns a ruleset configuration object with all current rules. + * @return A ruleset object. + * @method getRuleset + */ + api.getRuleset = function() { + var ruleset = {}, + i = 0, + len = rules.length; + + while (i < len){ + ruleset[rules[i++].id] = 1; //by default, everything is a warning + } + + return ruleset; + }; //------------------------------------------------------------------------- // Formatters //------------------------------------------------------------------------- @@ -6418,17 +6471,15 @@ lines, report, parser = new parserlib.css.Parser({ starHack: true, ieFilters: true, underscoreHack: true, strict: false }); + // normalize line endings lines = text.replace(/\n\r?/g, "$split$").split('$split$'); if (!ruleset){ - ruleset = {}; - while (i < len){ - ruleset[rules[i++].id] = 1; //by default, everything is a warning - } + ruleset = this.getRuleset(); } reporter = new Reporter(lines, ruleset); ruleset.errors = 2; //always report parsing errors as errors @@ -6773,40 +6824,46 @@ "border-top": 1, padding: 1, "padding-bottom": 1, "padding-top": 1 }, - properties; + properties, + boxSizing = false; function startRule(){ properties = {}; + boxSizing = false; } function endRule(){ - var prop; - if (properties.height){ - for (prop in heightProperties){ - if (heightProperties.hasOwnProperty(prop) && properties[prop]){ - - //special case for padding - if (!(prop == "padding" && properties[prop].value.parts.length === 2 && properties[prop].value.parts[0].value === 0)){ - reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule); + var prop, value; + + if (!boxSizing) { + if (properties.height){ + for (prop in heightProperties){ + if (heightProperties.hasOwnProperty(prop) && properties[prop]){ + value = properties[prop].value; + //special case for padding + if (!(prop == "padding" && value.parts.length === 2 && value.parts[0].value === 0)){ + reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule); + } } } } - } - if (properties.width){ - for (prop in widthProperties){ - if (widthProperties.hasOwnProperty(prop) && properties[prop]){ - - if (!(prop == "padding" && properties[prop].value.parts.length === 2 && properties[prop].value.parts[1].value === 0)){ - reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule); + if (properties.width){ + for (prop in widthProperties){ + if (widthProperties.hasOwnProperty(prop) && properties[prop]){ + value = properties[prop].value; + + if (!(prop == "padding" && value.parts.length === 2 && value.parts[1].value === 0)){ + reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule); + } } } - } - } + } + } } parser.addListener("startrule", startRule); parser.addListener("startfontface", startRule); parser.addListener("startpage", startRule); @@ -6819,12 +6876,14 @@ if (heightProperties[name] || widthProperties[name]){ if (!/^0\S*$/.test(event.value) && !(name == "border" && event.value == "none")){ properties[name] = { line: event.property.line, col: event.property.col, value: event.value }; } } else { - if (name == "width" || name == "height"){ + if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)){ properties[name] = 1; + } else if (name == "box-sizing") { + boxSizing = true; } } }); @@ -6885,24 +6944,25 @@ prop, variations, prefixed, i, len, + inKeyFrame = false, arrayPush = Array.prototype.push, applyTo = []; // See http://peter.sh/experiments/vendor-prefixed-css-property-overview/ for details compatiblePrefixes = { - "animation" : "webkit moz ms", - "animation-delay" : "webkit moz ms", - "animation-direction" : "webkit moz ms", - "animation-duration" : "webkit moz ms", - "animation-fill-mode" : "webkit moz ms", - "animation-iteration-count" : "webkit moz ms", - "animation-name" : "webkit moz ms", - "animation-play-state" : "webkit moz ms", - "animation-timing-function" : "webkit moz ms", + "animation" : "webkit moz", + "animation-delay" : "webkit moz", + "animation-direction" : "webkit moz", + "animation-duration" : "webkit moz", + "animation-fill-mode" : "webkit moz", + "animation-iteration-count" : "webkit moz", + "animation-name" : "webkit moz", + "animation-play-state" : "webkit moz", + "animation-timing-function" : "webkit moz", "appearance" : "webkit moz", "border-end" : "webkit moz", "border-end-color" : "webkit moz", "border-end-style" : "webkit moz", "border-end-width" : "webkit moz", @@ -6938,15 +6998,15 @@ "padding-start" : "webkit moz", "tab-size" : "moz o", "text-size-adjust" : "webkit ms", "transform" : "webkit moz ms o", "transform-origin" : "webkit moz ms o", - "transition" : "webkit moz o ms", - "transition-delay" : "webkit moz o ms", - "transition-duration" : "webkit moz o ms", - "transition-property" : "webkit moz o ms", - "transition-timing-function" : "webkit moz o ms", + "transition" : "webkit moz o", + "transition-delay" : "webkit moz o", + "transition-duration" : "webkit moz o", + "transition-property" : "webkit moz o", + "transition-timing-function" : "webkit moz o", "user-modify" : "webkit moz", "user-select" : "webkit moz ms", "word-break" : "epub ms", "writing-mode" : "epub ms" }; @@ -6961,18 +7021,32 @@ } compatiblePrefixes[prop] = variations; arrayPush.apply(applyTo, variations); } } + parser.addListener("startrule", function () { properties = []; }); + parser.addListener("startkeyframes", function (event) { + inKeyFrame = event.prefix || true; + }); + + parser.addListener("endkeyframes", function (event) { + inKeyFrame = false; + }); + parser.addListener("property", function (event) { var name = event.property; if (CSSLint.Util.indexOf(applyTo, name.text) > -1) { - properties.push(name); + + // e.g., -moz-transform is okay to be alone in @-moz-keyframes + if (!inKeyFrame || typeof inKeyFrame != "string" || + name.text.indexOf("-" + inKeyFrame + "-") !== 0) { + properties.push(name); + } } }); parser.addListener("endrule", function (event) { if (!properties.length) { @@ -7631,11 +7705,11 @@ //if there are more than 10, show an error 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); } }); } }); @@ -7647,312 +7721,24 @@ CSSLint.addRule({ //rule information id: "known-properties", name: "Require use of known properties", - desc: "Properties should be known (listed in CSS specification) or be a vendor-prefixed property.", + desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.", browsers: "All", //initialization init: function(parser, reporter){ - var rule = this, - properties = { + var rule = this; - "alignment-adjust": 1, - "alignment-baseline": 1, - "animation": 1, - "animation-delay": 1, - "animation-direction": 1, - "animation-duration": 1, - "animation-fill-mode": 1, - "animation-iteration-count": 1, - "animation-name": 1, - "animation-play-state": 1, - "animation-timing-function": 1, - "appearance": 1, - "azimuth": 1, - "backface-visibility": 1, - "background": 1, - "background-attachment": 1, - "background-break": 1, - "background-clip": 1, - "background-color": 1, - "background-image": 1, - "background-origin": 1, - "background-position": 1, - "background-repeat": 1, - "background-size": 1, - "baseline-shift": 1, - "binding": 1, - "bleed": 1, - "bookmark-label": 1, - "bookmark-level": 1, - "bookmark-state": 1, - "bookmark-target": 1, - "border": 1, - "border-bottom": 1, - "border-bottom-color": 1, - "border-bottom-left-radius": 1, - "border-bottom-right-radius": 1, - "border-bottom-style": 1, - "border-bottom-width": 1, - "border-collapse": 1, - "border-color": 1, - "border-image": 1, - "border-image-outset": 1, - "border-image-repeat": 1, - "border-image-slice": 1, - "border-image-source": 1, - "border-image-width": 1, - "border-left": 1, - "border-left-color": 1, - "border-left-style": 1, - "border-left-width": 1, - "border-radius": 1, - "border-right": 1, - "border-right-color": 1, - "border-right-style": 1, - "border-right-width": 1, - "border-spacing": 1, - "border-style": 1, - "border-top": 1, - "border-top-color": 1, - "border-top-left-radius": 1, - "border-top-right-radius": 1, - "border-top-style": 1, - "border-top-width": 1, - "border-width": 1, - "bottom": 1, - "box-align": 1, - "box-decoration-break": 1, - "box-direction": 1, - "box-flex": 1, - "box-flex-group": 1, - "box-lines": 1, - "box-ordinal-group": 1, - "box-orient": 1, - "box-pack": 1, - "box-shadow": 1, - "box-sizing": 1, - "break-after": 1, - "break-before": 1, - "break-inside": 1, - "caption-side": 1, - "clear": 1, - "clip": 1, - "color": 1, - "color-profile": 1, - "column-count": 1, - "column-fill": 1, - "column-gap": 1, - "column-rule": 1, - "column-rule-color": 1, - "column-rule-style": 1, - "column-rule-width": 1, - "column-span": 1, - "column-width": 1, - "columns": 1, - "content": 1, - "counter-increment": 1, - "counter-reset": 1, - "crop": 1, - "cue": 1, - "cue-after": 1, - "cue-before": 1, - "cursor": 1, - "direction": 1, - "display": 1, - "dominant-baseline": 1, - "drop-initial-after-adjust": 1, - "drop-initial-after-align": 1, - "drop-initial-before-adjust": 1, - "drop-initial-before-align": 1, - "drop-initial-size": 1, - "drop-initial-value": 1, - "elevation": 1, - "empty-cells": 1, - "fit": 1, - "fit-position": 1, - "float": 1, - "float-offset": 1, - "font": 1, - "font-family": 1, - "font-size": 1, - "font-size-adjust": 1, - "font-stretch": 1, - "font-style": 1, - "font-variant": 1, - "font-weight": 1, - "grid-columns": 1, - "grid-rows": 1, - "hanging-punctuation": 1, - "height": 1, - "hyphenate-after": 1, - "hyphenate-before": 1, - "hyphenate-character": 1, - "hyphenate-lines": 1, - "hyphenate-resource": 1, - "hyphens": 1, - "icon": 1, - "image-orientation": 1, - "image-rendering": 1, - "image-resolution": 1, - "inline-box-align": 1, - "left": 1, - "letter-spacing": 1, - "line-height": 1, - "line-stacking": 1, - "line-stacking-ruby": 1, - "line-stacking-shift": 1, - "line-stacking-strategy": 1, - "list-style": 1, - "list-style-image": 1, - "list-style-position": 1, - "list-style-type": 1, - "margin": 1, - "margin-bottom": 1, - "margin-left": 1, - "margin-right": 1, - "margin-top": 1, - "mark": 1, - "mark-after": 1, - "mark-before": 1, - "marks": 1, - "marquee-direction": 1, - "marquee-play-count": 1, - "marquee-speed": 1, - "marquee-style": 1, - "max-height": 1, - "max-width": 1, - "min-height": 1, - "min-width": 1, - "move-to": 1, - "nav-down": 1, - "nav-index": 1, - "nav-left": 1, - "nav-right": 1, - "nav-up": 1, - "opacity": 1, - "orphans": 1, - "outline": 1, - "outline-color": 1, - "outline-offset": 1, - "outline-style": 1, - "outline-width": 1, - "overflow": 1, - "overflow-style": 1, - "overflow-x": 1, - "overflow-y": 1, - "padding": 1, - "padding-bottom": 1, - "padding-left": 1, - "padding-right": 1, - "padding-top": 1, - "page": 1, - "page-break-after": 1, - "page-break-before": 1, - "page-break-inside": 1, - "page-policy": 1, - "pause": 1, - "pause-after": 1, - "pause-before": 1, - "perspective": 1, - "perspective-origin": 1, - "phonemes": 1, - "pitch": 1, - "pitch-range": 1, - "play-during": 1, - "position": 1, - "presentation-level": 1, - "punctuation-trim": 1, - "quotes": 1, - "rendering-intent": 1, - "resize": 1, - "rest": 1, - "rest-after": 1, - "rest-before": 1, - "richness": 1, - "right": 1, - "rotation": 1, - "rotation-point": 1, - "ruby-align": 1, - "ruby-overhang": 1, - "ruby-position": 1, - "ruby-span": 1, - "size": 1, - "speak": 1, - "speak-header": 1, - "speak-numeral": 1, - "speak-punctuation": 1, - "speech-rate": 1, - "stress": 1, - "string-set": 1, - "table-layout": 1, - "target": 1, - "target-name": 1, - "target-new": 1, - "target-position": 1, - "text-align": 1, - "text-align-last": 1, - "text-decoration": 1, - "text-emphasis": 1, - "text-height": 1, - "text-indent": 1, - "text-justify": 1, - "text-outline": 1, - "text-shadow": 1, - "text-transform": 1, - "text-wrap": 1, - "top": 1, - "transform": 1, - "transform-origin": 1, - "transform-style": 1, - "transition": 1, - "transition-delay": 1, - "transition-duration": 1, - "transition-property": 1, - "transition-timing-function": 1, - "unicode-bidi": 1, - "user-modify": 1, - "user-select": 1, - "vertical-align": 1, - "visibility": 1, - "voice-balance": 1, - "voice-duration": 1, - "voice-family": 1, - "voice-pitch": 1, - "voice-pitch-range": 1, - "voice-rate": 1, - "voice-stress": 1, - "voice-volume": 1, - "volume": 1, - "white-space": 1, - "white-space-collapse": 1, - "widows": 1, - "width": 1, - "word-break": 1, - "word-spacing": 1, - "word-wrap": 1, - "z-index": 1, - - //IE - "filter": 1, - "zoom": 1, - - //@font-face - "src": 1 - }; - parser.addListener("property", function(event){ var name = event.property.text.toLowerCase(); + // the check is handled entirely by the parser-lib (https://github.com/nzakas/parser-lib) if (event.invalid) { reporter.report(event.invalid.message, event.line, event.col, rule); } - //if (!properties[name] && name.charAt(0) != "-"){ - // reporter.error("Unknown property '" + event.property + "'.", event.line, event.col, rule); - //} }); } }); @@ -8288,61 +8074,117 @@ } }); /* - * 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({ + + //rule information id: "text-indent", 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(), value = event.value; 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*/ CSSLint.addRule({ @@ -8667,348 +8509,11 @@ } }); /*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "checkstyle-xml", - name: "Checkstyle XML format", - /** - * Return opening root XML tag. - * @return {String} to prepend before all results - */ - startFormat: function(){ - return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>"; - }, - /** - * Return closing root XML tag. - * @return {String} to append after all results - */ - endFormat: function(){ - return "</checkstyle>"; - }, - - /** - * 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 = []; - - /** - * 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 ""; - } - return 'net.csslint.' + rule.name.replace(/\s/g,''); - }; - - /** - * 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} - */ - var escapeSpecialCharacters = function(str) { - if (!str || str.constructor !== String) { - return ""; - } - return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;"); - }; - - 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) +"\"/>"); - } - }); - output.push("</file>"); - } - - return output.join(""); - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "compact", - name: "Compact, 'porcelain' format", - - /** - * Return content to be printed before all file results. - * @return {String} to prepend before all results - */ - startFormat: function() { - return ""; - }, - - /** - * Return content to be printed after all file results. - * @return {String} to append after all results - */ - endFormat: function() { - return ""; - }, - - /** - * 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} (Optional) specifies special handling of output - * @return {String} output for results - */ - formatResults: function(results, filename, options) { - var messages = results.messages, - output = ""; - options = options || {}; - - /** - * Capitalize and return given string. - * @param str {String} to capitalize - * @return {String} capitalized - */ - var capitalize = function(str) { - return str.charAt(0).toUpperCase() + str.slice(1); - }; - - if (messages.length === 0) { - return options.quiet ? "" : filename + ": Lint Free!"; - } - - CSSLint.Util.forEach(messages, function(message, i) { - if (message.rollup) { - output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n"; - } else { - output += filename + ": " + "line " + message.line + - ", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + "\n"; - } - }); - - return output; - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "csslint-xml", - name: "CSSLint XML format", - - /** - * Return opening root XML tag. - * @return {String} to prepend before all results - */ - startFormat: function(){ - return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>"; - }, - - /** - * Return closing root XML tag. - * @return {String} to append after all results - */ - endFormat: function(){ - return "</csslint>"; - }, - - /** - * 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 = []; - - /** - * 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} - */ - var escapeSpecialCharacters = function(str) { - if (!str || str.constructor !== String) { - return ""; - } - return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;"); - }; - - if (messages.length > 0) { - output.push("<file name=\""+filename+"\">"); - CSSLint.Util.forEach(messages, function (message, i) { - if (message.rollup) { - output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>"); - } else { - output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" + - " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>"); - } - }); - output.push("</file>"); - } - - return output.join(""); - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "lint-xml", - name: "Lint XML format", - - /** - * Return opening root XML tag. - * @return {String} to prepend before all results - */ - startFormat: function(){ - return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>"; - }, - - /** - * Return closing root XML tag. - * @return {String} to append after all results - */ - endFormat: function(){ - return "</lint>"; - }, - - /** - * 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 = []; - - /** - * 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} - */ - var escapeSpecialCharacters = function(str) { - if (!str || str.constructor !== String) { - return ""; - } - return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;"); - }; - - if (messages.length > 0) { - - output.push("<file name=\""+filename+"\">"); - CSSLint.Util.forEach(messages, function (message, i) { - if (message.rollup) { - output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>"); - } else { - output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" + - " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>"); - } - }); - output.push("</file>"); - } - - return output.join(""); - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "text", - name: "Plain Text", - - /** - * Return content to be printed before all file results. - * @return {String} to prepend before all results - */ - startFormat: function() { - return ""; - }, - - /** - * Return content to be printed after all file results. - * @return {String} to append after all results - */ - endFormat: function() { - return ""; - }, - - /** - * 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} (Optional) specifies special handling of output - * @return {String} output for results - */ - formatResults: function(results, filename, options) { - var messages = results.messages, - output = ""; - options = options || {}; - - if (messages.length === 0) { - return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + "."; - } - - output = "\n\ncsslint: There are " + messages.length + " problems in " + filename + "."; - var pos = filename.lastIndexOf("/"), - shortFilename = filename; - - if (pos === -1){ - pos = filename.lastIndexOf("\\"); - } - if (pos > -1){ - shortFilename = filename.substring(pos+1); - } - - CSSLint.Util.forEach(messages, function (message, i) { - output = output + "\n\n" + shortFilename; - if (message.rollup) { - output += "\n" + (i+1) + ": " + message.type; - output += "\n" + message.message; - } else { - output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col; - output += "\n" + message.message; - output += "\n" + message.evidence; - } - }); - - return output; - } -}); - - exports.CSSLint = CSSLint; -}); \ No newline at end of file +});