ruby_css_lint 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +71 -0
- data/VERSION +1 -0
- data/csslint/CHANGELOG +286 -0
- data/csslint/LICENSE +20 -0
- data/csslint/README.md +25 -0
- data/csslint/build.xml +242 -0
- data/csslint/demos/CSSLintDemo.htm +105 -0
- data/csslint/demos/demo.css +43 -0
- data/csslint/lib/js.jar +0 -0
- data/csslint/lib/jshint.js +3963 -0
- data/csslint/lib/parserlib.js +6295 -0
- data/csslint/lib/yuitest-rhino-cli.js +3955 -0
- data/csslint/lib/yuitest.js +4561 -0
- data/csslint/npm/package.json +30 -0
- data/csslint/release/csslint-node.js +9125 -0
- data/csslint/release/csslint-rhino.js +9390 -0
- data/csslint/release/csslint-tests.js +1921 -0
- data/csslint/release/csslint-worker.js +9148 -0
- data/csslint/release/csslint-wsh.js +9477 -0
- data/csslint/release/csslint.js +9127 -0
- data/csslint/release/npm/cli.js +307 -0
- data/csslint/release/npm/lib/csslint-node.js +9125 -0
- data/csslint/release/npm/package.json +30 -0
- data/csslint/src/cli/common.js +215 -0
- data/csslint/src/cli/node.js +87 -0
- data/csslint/src/cli/rhino.js +47 -0
- data/csslint/src/cli/wsh.js +134 -0
- data/csslint/src/core/CSSLint.js +181 -0
- data/csslint/src/core/Reporter.js +161 -0
- data/csslint/src/core/Util.js +62 -0
- data/csslint/src/formatters/checkstyle-xml.js +109 -0
- data/csslint/src/formatters/compact.js +59 -0
- data/csslint/src/formatters/csslint-xml.js +68 -0
- data/csslint/src/formatters/lint-xml.js +69 -0
- data/csslint/src/formatters/text.js +64 -0
- data/csslint/src/rules/adjoining-classes.js +45 -0
- data/csslint/src/rules/box-model.js +93 -0
- data/csslint/src/rules/box-sizing.js +28 -0
- data/csslint/src/rules/compatible-vendor-prefixes.js +171 -0
- data/csslint/src/rules/display-property-grouping.js +117 -0
- data/csslint/src/rules/duplicate-background-images.js +37 -0
- data/csslint/src/rules/duplicate-properties.js +46 -0
- data/csslint/src/rules/empty-rules.js +34 -0
- data/csslint/src/rules/errors.js +23 -0
- data/csslint/src/rules/fallback-colors.js +67 -0
- data/csslint/src/rules/floats.js +36 -0
- data/csslint/src/rules/font-faces.js +30 -0
- data/csslint/src/rules/font-sizes.js +35 -0
- data/csslint/src/rules/gradients.js +69 -0
- data/csslint/src/rules/ids.js +50 -0
- data/csslint/src/rules/import.js +23 -0
- data/csslint/src/rules/important.js +37 -0
- data/csslint/src/rules/known-properties.js +29 -0
- data/csslint/src/rules/outline-none.js +73 -0
- data/csslint/src/rules/overqualified-elements.js +63 -0
- data/csslint/src/rules/qualified-headings.js +38 -0
- data/csslint/src/rules/regex-selectors.js +44 -0
- data/csslint/src/rules/rules-count.js +28 -0
- data/csslint/src/rules/shorthand.js +87 -0
- data/csslint/src/rules/star-property-hack.js +27 -0
- data/csslint/src/rules/text-indent.js +53 -0
- data/csslint/src/rules/underscore-property-hack.js +27 -0
- data/csslint/src/rules/unique-headings.js +74 -0
- data/csslint/src/rules/universal-selector.js +35 -0
- data/csslint/src/rules/unqualified-attributes.js +42 -0
- data/csslint/src/rules/vendor-prefix.js +143 -0
- data/csslint/src/rules/zero-units.js +34 -0
- data/csslint/src/worker/Worker.js +26 -0
- data/csslint/tests/all-rules.js +64 -0
- data/csslint/tests/core/CSSLint.js +22 -0
- data/csslint/tests/core/Reporter.js +36 -0
- data/csslint/tests/css/width-100.html +76 -0
- data/csslint/tests/formatters/checkstyle-xml.js +44 -0
- data/csslint/tests/formatters/compact.js +47 -0
- data/csslint/tests/formatters/csslint-xml.js +42 -0
- data/csslint/tests/formatters/lint-xml.js +43 -0
- data/csslint/tests/formatters/text.js +36 -0
- data/csslint/tests/rules/adjoining-classes.js +31 -0
- data/csslint/tests/rules/box-model.js +211 -0
- data/csslint/tests/rules/box-sizing.js +23 -0
- data/csslint/tests/rules/compatible-vendor-prefixes.js +56 -0
- data/csslint/tests/rules/display-property-grouping.js +213 -0
- data/csslint/tests/rules/duplicate-background-images.js +25 -0
- data/csslint/tests/rules/duplicate-properties.js +54 -0
- data/csslint/tests/rules/empty-rules.js +18 -0
- data/csslint/tests/rules/errors.js +17 -0
- data/csslint/tests/rules/fallback-colors.js +162 -0
- data/csslint/tests/rules/floats.js +35 -0
- data/csslint/tests/rules/font-faces.js +28 -0
- data/csslint/tests/rules/font-sizes.js +30 -0
- data/csslint/tests/rules/gradients.js +60 -0
- data/csslint/tests/rules/ids.js +25 -0
- data/csslint/tests/rules/import.js +18 -0
- data/csslint/tests/rules/important.js +27 -0
- data/csslint/tests/rules/known-properties.js +44 -0
- data/csslint/tests/rules/outline-none.js +50 -0
- data/csslint/tests/rules/overqualified-elements.js +41 -0
- data/csslint/tests/rules/qualified-headings.js +19 -0
- data/csslint/tests/rules/regex-selectors.js +52 -0
- data/csslint/tests/rules/shorthand.js +36 -0
- data/csslint/tests/rules/star-property-hack.js +24 -0
- data/csslint/tests/rules/text-indent.js +55 -0
- data/csslint/tests/rules/underscore-property-hack.js +24 -0
- data/csslint/tests/rules/unique-headings.js +47 -0
- data/csslint/tests/rules/universal-selector.js +31 -0
- data/csslint/tests/rules/unqualified-attributes.js +37 -0
- data/csslint/tests/rules/vendor-prefix.js +76 -0
- data/csslint/tests/rules/zero-units.js +44 -0
- data/csslint/tests/testrunner.htm +138 -0
- data/js.jar +0 -0
- data/lib/ruby_css_lint.rb +168 -0
- data/test/helper.rb +17 -0
- data/test/test_ruby_css_lint.rb +7 -0
- metadata +240 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main CSSLint object.
|
|
3
|
+
* @class CSSLint
|
|
4
|
+
* @static
|
|
5
|
+
* @extends parserlib.util.EventTarget
|
|
6
|
+
*/
|
|
7
|
+
/*global parserlib, Reporter*/
|
|
8
|
+
var CSSLint = (function(){
|
|
9
|
+
|
|
10
|
+
var rules = [],
|
|
11
|
+
formatters = [],
|
|
12
|
+
api = new parserlib.util.EventTarget();
|
|
13
|
+
|
|
14
|
+
api.version = "@VERSION@";
|
|
15
|
+
|
|
16
|
+
//-------------------------------------------------------------------------
|
|
17
|
+
// Rule Management
|
|
18
|
+
//-------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Adds a new rule to the engine.
|
|
22
|
+
* @param {Object} rule The rule to add.
|
|
23
|
+
* @method addRule
|
|
24
|
+
*/
|
|
25
|
+
api.addRule = function(rule){
|
|
26
|
+
rules.push(rule);
|
|
27
|
+
rules[rule.id] = rule;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Clears all rule from the engine.
|
|
32
|
+
* @method clearRules
|
|
33
|
+
*/
|
|
34
|
+
api.clearRules = function(){
|
|
35
|
+
rules = [];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the rule objects.
|
|
40
|
+
* @return An array of rule objects.
|
|
41
|
+
* @method getRules
|
|
42
|
+
*/
|
|
43
|
+
api.getRules = function(){
|
|
44
|
+
return [].concat(rules).sort(function(a,b){
|
|
45
|
+
return a.id > b.id ? 1 : 0;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//-------------------------------------------------------------------------
|
|
50
|
+
// Formatters
|
|
51
|
+
//-------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Adds a new formatter to the engine.
|
|
55
|
+
* @param {Object} formatter The formatter to add.
|
|
56
|
+
* @method addFormatter
|
|
57
|
+
*/
|
|
58
|
+
api.addFormatter = function(formatter) {
|
|
59
|
+
// formatters.push(formatter);
|
|
60
|
+
formatters[formatter.id] = formatter;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves a formatter for use.
|
|
65
|
+
* @param {String} formatId The name of the format to retrieve.
|
|
66
|
+
* @return {Object} The formatter or undefined.
|
|
67
|
+
* @method getFormatter
|
|
68
|
+
*/
|
|
69
|
+
api.getFormatter = function(formatId){
|
|
70
|
+
return formatters[formatId];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Formats the results in a particular format for a single file.
|
|
75
|
+
* @param {Object} result The results returned from CSSLint.verify().
|
|
76
|
+
* @param {String} filename The filename for which the results apply.
|
|
77
|
+
* @param {String} formatId The name of the formatter to use.
|
|
78
|
+
* @param {Object} options (Optional) for special output handling.
|
|
79
|
+
* @return {String} A formatted string for the results.
|
|
80
|
+
* @method format
|
|
81
|
+
*/
|
|
82
|
+
api.format = function(results, filename, formatId, options) {
|
|
83
|
+
var formatter = this.getFormatter(formatId),
|
|
84
|
+
result = null;
|
|
85
|
+
|
|
86
|
+
if (formatter){
|
|
87
|
+
result = formatter.startFormat();
|
|
88
|
+
result += formatter.formatResults(results, filename, options || {});
|
|
89
|
+
result += formatter.endFormat();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Indicates if the given format is supported.
|
|
97
|
+
* @param {String} formatId The ID of the format to check.
|
|
98
|
+
* @return {Boolean} True if the format exists, false if not.
|
|
99
|
+
* @method hasFormat
|
|
100
|
+
*/
|
|
101
|
+
api.hasFormat = function(formatId){
|
|
102
|
+
return formatters.hasOwnProperty(formatId);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
//-------------------------------------------------------------------------
|
|
106
|
+
// Verification
|
|
107
|
+
//-------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Starts the verification process for the given CSS text.
|
|
111
|
+
* @param {String} text The CSS text to verify.
|
|
112
|
+
* @param {Object} ruleset (Optional) List of rules to apply. If null, then
|
|
113
|
+
* all rules are used. If a rule has a value of 1 then it's a warning,
|
|
114
|
+
* a value of 2 means it's an error.
|
|
115
|
+
* @return {Object} Results of the verification.
|
|
116
|
+
* @method verify
|
|
117
|
+
*/
|
|
118
|
+
api.verify = function(text, ruleset){
|
|
119
|
+
|
|
120
|
+
var i = 0,
|
|
121
|
+
len = rules.length,
|
|
122
|
+
reporter,
|
|
123
|
+
lines,
|
|
124
|
+
report,
|
|
125
|
+
parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
|
|
126
|
+
underscoreHack: true, strict: false });
|
|
127
|
+
|
|
128
|
+
lines = text.replace(/\n\r?/g, "$split$").split('$split$');
|
|
129
|
+
|
|
130
|
+
if (!ruleset){
|
|
131
|
+
ruleset = {};
|
|
132
|
+
while (i < len){
|
|
133
|
+
ruleset[rules[i++].id] = 1; //by default, everything is a warning
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
reporter = new Reporter(lines, ruleset);
|
|
138
|
+
|
|
139
|
+
ruleset.errors = 2; //always report parsing errors as errors
|
|
140
|
+
for (i in ruleset){
|
|
141
|
+
if(ruleset.hasOwnProperty(i)){
|
|
142
|
+
if (rules[i]){
|
|
143
|
+
rules[i].init(parser, reporter);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
//capture most horrible error type
|
|
150
|
+
try {
|
|
151
|
+
parser.parse(text);
|
|
152
|
+
} catch (ex) {
|
|
153
|
+
reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
report = {
|
|
157
|
+
messages : reporter.messages,
|
|
158
|
+
stats : reporter.stats
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//sort by line numbers, rollups at the bottom
|
|
162
|
+
report.messages.sort(function (a, b){
|
|
163
|
+
if (a.rollup && !b.rollup){
|
|
164
|
+
return 1;
|
|
165
|
+
} else if (!a.rollup && b.rollup){
|
|
166
|
+
return -1;
|
|
167
|
+
} else {
|
|
168
|
+
return a.line - b.line;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return report;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
//-------------------------------------------------------------------------
|
|
176
|
+
// Publish the API
|
|
177
|
+
//-------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
return api;
|
|
180
|
+
|
|
181
|
+
})();
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*global CSSLint*/
|
|
2
|
+
/**
|
|
3
|
+
* An instance of Report is used to report results of the
|
|
4
|
+
* verification back to the main API.
|
|
5
|
+
* @class Reporter
|
|
6
|
+
* @constructor
|
|
7
|
+
* @param {String[]} lines The text lines of the source.
|
|
8
|
+
* @param {Object} ruleset The set of rules to work with, including if
|
|
9
|
+
* they are errors or warnings.
|
|
10
|
+
*/
|
|
11
|
+
function Reporter(lines, ruleset){
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* List of messages being reported.
|
|
15
|
+
* @property messages
|
|
16
|
+
* @type String[]
|
|
17
|
+
*/
|
|
18
|
+
this.messages = [];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* List of statistics being reported.
|
|
22
|
+
* @property stats
|
|
23
|
+
* @type String[]
|
|
24
|
+
*/
|
|
25
|
+
this.stats = [];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Lines of code being reported on. Used to provide contextual information
|
|
29
|
+
* for messages.
|
|
30
|
+
* @property lines
|
|
31
|
+
* @type String[]
|
|
32
|
+
*/
|
|
33
|
+
this.lines = lines;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Information about the rules. Used to determine whether an issue is an
|
|
37
|
+
* error or warning.
|
|
38
|
+
* @property ruleset
|
|
39
|
+
* @type Object
|
|
40
|
+
*/
|
|
41
|
+
this.ruleset = ruleset;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Reporter.prototype = {
|
|
45
|
+
|
|
46
|
+
//restore constructor
|
|
47
|
+
constructor: Reporter,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Report an error.
|
|
51
|
+
* @param {String} message The message to store.
|
|
52
|
+
* @param {int} line The line number.
|
|
53
|
+
* @param {int} col The column number.
|
|
54
|
+
* @param {Object} rule The rule this message relates to.
|
|
55
|
+
* @method error
|
|
56
|
+
*/
|
|
57
|
+
error: function(message, line, col, rule){
|
|
58
|
+
this.messages.push({
|
|
59
|
+
type : "error",
|
|
60
|
+
line : line,
|
|
61
|
+
col : col,
|
|
62
|
+
message : message,
|
|
63
|
+
evidence: this.lines[line-1],
|
|
64
|
+
rule : rule || {}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Report an warning.
|
|
70
|
+
* @param {String} message The message to store.
|
|
71
|
+
* @param {int} line The line number.
|
|
72
|
+
* @param {int} col The column number.
|
|
73
|
+
* @param {Object} rule The rule this message relates to.
|
|
74
|
+
* @method warn
|
|
75
|
+
* @deprecated Use report instead.
|
|
76
|
+
*/
|
|
77
|
+
warn: function(message, line, col, rule){
|
|
78
|
+
this.report(message, line, col, rule);
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Report an issue.
|
|
83
|
+
* @param {String} message The message to store.
|
|
84
|
+
* @param {int} line The line number.
|
|
85
|
+
* @param {int} col The column number.
|
|
86
|
+
* @param {Object} rule The rule this message relates to.
|
|
87
|
+
* @method report
|
|
88
|
+
*/
|
|
89
|
+
report: function(message, line, col, rule){
|
|
90
|
+
this.messages.push({
|
|
91
|
+
type : this.ruleset[rule.id] == 2 ? "error" : "warning",
|
|
92
|
+
line : line,
|
|
93
|
+
col : col,
|
|
94
|
+
message : message,
|
|
95
|
+
evidence: this.lines[line-1],
|
|
96
|
+
rule : rule
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Report some informational text.
|
|
102
|
+
* @param {String} message The message to store.
|
|
103
|
+
* @param {int} line The line number.
|
|
104
|
+
* @param {int} col The column number.
|
|
105
|
+
* @param {Object} rule The rule this message relates to.
|
|
106
|
+
* @method info
|
|
107
|
+
*/
|
|
108
|
+
info: function(message, line, col, rule){
|
|
109
|
+
this.messages.push({
|
|
110
|
+
type : "info",
|
|
111
|
+
line : line,
|
|
112
|
+
col : col,
|
|
113
|
+
message : message,
|
|
114
|
+
evidence: this.lines[line-1],
|
|
115
|
+
rule : rule
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Report some rollup error information.
|
|
121
|
+
* @param {String} message The message to store.
|
|
122
|
+
* @param {Object} rule The rule this message relates to.
|
|
123
|
+
* @method rollupError
|
|
124
|
+
*/
|
|
125
|
+
rollupError: function(message, rule){
|
|
126
|
+
this.messages.push({
|
|
127
|
+
type : "error",
|
|
128
|
+
rollup : true,
|
|
129
|
+
message : message,
|
|
130
|
+
rule : rule
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Report some rollup warning information.
|
|
136
|
+
* @param {String} message The message to store.
|
|
137
|
+
* @param {Object} rule The rule this message relates to.
|
|
138
|
+
* @method rollupWarn
|
|
139
|
+
*/
|
|
140
|
+
rollupWarn: function(message, rule){
|
|
141
|
+
this.messages.push({
|
|
142
|
+
type : "warning",
|
|
143
|
+
rollup : true,
|
|
144
|
+
message : message,
|
|
145
|
+
rule : rule
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Report a statistic.
|
|
151
|
+
* @param {String} name The name of the stat to store.
|
|
152
|
+
* @param {Variant} value The value of the stat.
|
|
153
|
+
* @method stat
|
|
154
|
+
*/
|
|
155
|
+
stat: function(name, value){
|
|
156
|
+
this.stats[name] = value;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//expose for testing purposes
|
|
161
|
+
CSSLint._Reporter = Reporter;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
/*global CSSLint*/
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Utility functions that make life easier.
|
|
6
|
+
*/
|
|
7
|
+
CSSLint.Util = {
|
|
8
|
+
/*
|
|
9
|
+
* Adds all properties from supplier onto receiver,
|
|
10
|
+
* overwriting if the same name already exists on
|
|
11
|
+
* reciever.
|
|
12
|
+
* @param {Object} The object to receive the properties.
|
|
13
|
+
* @param {Object} The object to provide the properties.
|
|
14
|
+
* @return {Object} The receiver
|
|
15
|
+
*/
|
|
16
|
+
mix: function(receiver, supplier){
|
|
17
|
+
var prop;
|
|
18
|
+
|
|
19
|
+
for (prop in supplier){
|
|
20
|
+
if (supplier.hasOwnProperty(prop)){
|
|
21
|
+
receiver[prop] = supplier[prop];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return prop;
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Polyfill for array indexOf() method.
|
|
30
|
+
* @param {Array} values The array to search.
|
|
31
|
+
* @param {Variant} value The value to search for.
|
|
32
|
+
* @return {int} The index of the value if found, -1 if not.
|
|
33
|
+
*/
|
|
34
|
+
indexOf: function(values, value){
|
|
35
|
+
if (values.indexOf){
|
|
36
|
+
return values.indexOf(value);
|
|
37
|
+
} else {
|
|
38
|
+
for (var i=0, len=values.length; i < len; i++){
|
|
39
|
+
if (values[i] === value){
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* Polyfill for array forEach() method.
|
|
49
|
+
* @param {Array} values The array to operate on.
|
|
50
|
+
* @param {Function} func The function to call on each item.
|
|
51
|
+
* @return {void}
|
|
52
|
+
*/
|
|
53
|
+
forEach: function(values, func) {
|
|
54
|
+
if (values.forEach){
|
|
55
|
+
return values.forEach(func);
|
|
56
|
+
} else {
|
|
57
|
+
for (var i=0, len=values.length; i < len; i++){
|
|
58
|
+
func(values[i], i, values);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*global CSSLint*/
|
|
2
|
+
(function() {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Replace special characters before write to output.
|
|
6
|
+
*
|
|
7
|
+
* Rules:
|
|
8
|
+
* - single quotes is the escape sequence for double-quotes
|
|
9
|
+
* - & is the escape sequence for &
|
|
10
|
+
* - < is the escape sequence for <
|
|
11
|
+
* - > is the escape sequence for >
|
|
12
|
+
*
|
|
13
|
+
* @param {String} message to escape
|
|
14
|
+
* @return escaped message as {String}
|
|
15
|
+
*/
|
|
16
|
+
var xmlEscape = function(str) {
|
|
17
|
+
if (!str || str.constructor !== String) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return str.replace(/[\"&><]/g, function(match) {
|
|
22
|
+
switch (match) {
|
|
23
|
+
case "\"":
|
|
24
|
+
return """;
|
|
25
|
+
case "&":
|
|
26
|
+
return "&";
|
|
27
|
+
case "<":
|
|
28
|
+
return "<";
|
|
29
|
+
case ">":
|
|
30
|
+
return ">";
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
CSSLint.addFormatter({
|
|
36
|
+
//format information
|
|
37
|
+
id: "checkstyle-xml",
|
|
38
|
+
name: "Checkstyle XML format",
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Return opening root XML tag.
|
|
42
|
+
* @return {String} to prepend before all results
|
|
43
|
+
*/
|
|
44
|
+
startFormat: function(){
|
|
45
|
+
return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Return closing root XML tag.
|
|
50
|
+
* @return {String} to append after all results
|
|
51
|
+
*/
|
|
52
|
+
endFormat: function(){
|
|
53
|
+
return "</checkstyle>";
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns message when there is a file read error.
|
|
58
|
+
* @param {String} filename The name of the file that caused the error.
|
|
59
|
+
* @param {String} message The error message
|
|
60
|
+
* @return {String} The error message.
|
|
61
|
+
*/
|
|
62
|
+
readError: function(filename, message) {
|
|
63
|
+
return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Given CSS Lint results for a file, return output for this format.
|
|
68
|
+
* @param results {Object} with error and warning messages
|
|
69
|
+
* @param filename {String} relative file path
|
|
70
|
+
* @param options {Object} (UNUSED for now) specifies special handling of output
|
|
71
|
+
* @return {String} output for results
|
|
72
|
+
*/
|
|
73
|
+
formatResults: function(results, filename, options) {
|
|
74
|
+
var messages = results.messages,
|
|
75
|
+
output = [];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Generate a source string for a rule.
|
|
79
|
+
* Checkstyle source strings usually resemble Java class names e.g
|
|
80
|
+
* net.csslint.SomeRuleName
|
|
81
|
+
* @param {Object} rule
|
|
82
|
+
* @return rule source as {String}
|
|
83
|
+
*/
|
|
84
|
+
var generateSource = function(rule) {
|
|
85
|
+
if (!rule || !('name' in rule)) {
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
return 'net.csslint.' + rule.name.replace(/\s/g,'');
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if (messages.length > 0) {
|
|
94
|
+
output.push("<file name=\""+filename+"\">");
|
|
95
|
+
CSSLint.Util.forEach(messages, function (message, i) {
|
|
96
|
+
//ignore rollups for now
|
|
97
|
+
if (!message.rollup) {
|
|
98
|
+
output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
|
|
99
|
+
" message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
output.push("</file>");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return output.join("");
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
}());
|