ruby_css_lint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.document +5 -0
  2. data/Gemfile +13 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +19 -0
  5. data/Rakefile +71 -0
  6. data/VERSION +1 -0
  7. data/csslint/CHANGELOG +286 -0
  8. data/csslint/LICENSE +20 -0
  9. data/csslint/README.md +25 -0
  10. data/csslint/build.xml +242 -0
  11. data/csslint/demos/CSSLintDemo.htm +105 -0
  12. data/csslint/demos/demo.css +43 -0
  13. data/csslint/lib/js.jar +0 -0
  14. data/csslint/lib/jshint.js +3963 -0
  15. data/csslint/lib/parserlib.js +6295 -0
  16. data/csslint/lib/yuitest-rhino-cli.js +3955 -0
  17. data/csslint/lib/yuitest.js +4561 -0
  18. data/csslint/npm/package.json +30 -0
  19. data/csslint/release/csslint-node.js +9125 -0
  20. data/csslint/release/csslint-rhino.js +9390 -0
  21. data/csslint/release/csslint-tests.js +1921 -0
  22. data/csslint/release/csslint-worker.js +9148 -0
  23. data/csslint/release/csslint-wsh.js +9477 -0
  24. data/csslint/release/csslint.js +9127 -0
  25. data/csslint/release/npm/cli.js +307 -0
  26. data/csslint/release/npm/lib/csslint-node.js +9125 -0
  27. data/csslint/release/npm/package.json +30 -0
  28. data/csslint/src/cli/common.js +215 -0
  29. data/csslint/src/cli/node.js +87 -0
  30. data/csslint/src/cli/rhino.js +47 -0
  31. data/csslint/src/cli/wsh.js +134 -0
  32. data/csslint/src/core/CSSLint.js +181 -0
  33. data/csslint/src/core/Reporter.js +161 -0
  34. data/csslint/src/core/Util.js +62 -0
  35. data/csslint/src/formatters/checkstyle-xml.js +109 -0
  36. data/csslint/src/formatters/compact.js +59 -0
  37. data/csslint/src/formatters/csslint-xml.js +68 -0
  38. data/csslint/src/formatters/lint-xml.js +69 -0
  39. data/csslint/src/formatters/text.js +64 -0
  40. data/csslint/src/rules/adjoining-classes.js +45 -0
  41. data/csslint/src/rules/box-model.js +93 -0
  42. data/csslint/src/rules/box-sizing.js +28 -0
  43. data/csslint/src/rules/compatible-vendor-prefixes.js +171 -0
  44. data/csslint/src/rules/display-property-grouping.js +117 -0
  45. data/csslint/src/rules/duplicate-background-images.js +37 -0
  46. data/csslint/src/rules/duplicate-properties.js +46 -0
  47. data/csslint/src/rules/empty-rules.js +34 -0
  48. data/csslint/src/rules/errors.js +23 -0
  49. data/csslint/src/rules/fallback-colors.js +67 -0
  50. data/csslint/src/rules/floats.js +36 -0
  51. data/csslint/src/rules/font-faces.js +30 -0
  52. data/csslint/src/rules/font-sizes.js +35 -0
  53. data/csslint/src/rules/gradients.js +69 -0
  54. data/csslint/src/rules/ids.js +50 -0
  55. data/csslint/src/rules/import.js +23 -0
  56. data/csslint/src/rules/important.js +37 -0
  57. data/csslint/src/rules/known-properties.js +29 -0
  58. data/csslint/src/rules/outline-none.js +73 -0
  59. data/csslint/src/rules/overqualified-elements.js +63 -0
  60. data/csslint/src/rules/qualified-headings.js +38 -0
  61. data/csslint/src/rules/regex-selectors.js +44 -0
  62. data/csslint/src/rules/rules-count.js +28 -0
  63. data/csslint/src/rules/shorthand.js +87 -0
  64. data/csslint/src/rules/star-property-hack.js +27 -0
  65. data/csslint/src/rules/text-indent.js +53 -0
  66. data/csslint/src/rules/underscore-property-hack.js +27 -0
  67. data/csslint/src/rules/unique-headings.js +74 -0
  68. data/csslint/src/rules/universal-selector.js +35 -0
  69. data/csslint/src/rules/unqualified-attributes.js +42 -0
  70. data/csslint/src/rules/vendor-prefix.js +143 -0
  71. data/csslint/src/rules/zero-units.js +34 -0
  72. data/csslint/src/worker/Worker.js +26 -0
  73. data/csslint/tests/all-rules.js +64 -0
  74. data/csslint/tests/core/CSSLint.js +22 -0
  75. data/csslint/tests/core/Reporter.js +36 -0
  76. data/csslint/tests/css/width-100.html +76 -0
  77. data/csslint/tests/formatters/checkstyle-xml.js +44 -0
  78. data/csslint/tests/formatters/compact.js +47 -0
  79. data/csslint/tests/formatters/csslint-xml.js +42 -0
  80. data/csslint/tests/formatters/lint-xml.js +43 -0
  81. data/csslint/tests/formatters/text.js +36 -0
  82. data/csslint/tests/rules/adjoining-classes.js +31 -0
  83. data/csslint/tests/rules/box-model.js +211 -0
  84. data/csslint/tests/rules/box-sizing.js +23 -0
  85. data/csslint/tests/rules/compatible-vendor-prefixes.js +56 -0
  86. data/csslint/tests/rules/display-property-grouping.js +213 -0
  87. data/csslint/tests/rules/duplicate-background-images.js +25 -0
  88. data/csslint/tests/rules/duplicate-properties.js +54 -0
  89. data/csslint/tests/rules/empty-rules.js +18 -0
  90. data/csslint/tests/rules/errors.js +17 -0
  91. data/csslint/tests/rules/fallback-colors.js +162 -0
  92. data/csslint/tests/rules/floats.js +35 -0
  93. data/csslint/tests/rules/font-faces.js +28 -0
  94. data/csslint/tests/rules/font-sizes.js +30 -0
  95. data/csslint/tests/rules/gradients.js +60 -0
  96. data/csslint/tests/rules/ids.js +25 -0
  97. data/csslint/tests/rules/import.js +18 -0
  98. data/csslint/tests/rules/important.js +27 -0
  99. data/csslint/tests/rules/known-properties.js +44 -0
  100. data/csslint/tests/rules/outline-none.js +50 -0
  101. data/csslint/tests/rules/overqualified-elements.js +41 -0
  102. data/csslint/tests/rules/qualified-headings.js +19 -0
  103. data/csslint/tests/rules/regex-selectors.js +52 -0
  104. data/csslint/tests/rules/shorthand.js +36 -0
  105. data/csslint/tests/rules/star-property-hack.js +24 -0
  106. data/csslint/tests/rules/text-indent.js +55 -0
  107. data/csslint/tests/rules/underscore-property-hack.js +24 -0
  108. data/csslint/tests/rules/unique-headings.js +47 -0
  109. data/csslint/tests/rules/universal-selector.js +31 -0
  110. data/csslint/tests/rules/unqualified-attributes.js +37 -0
  111. data/csslint/tests/rules/vendor-prefix.js +76 -0
  112. data/csslint/tests/rules/zero-units.js +44 -0
  113. data/csslint/tests/testrunner.htm +138 -0
  114. data/js.jar +0 -0
  115. data/lib/ruby_css_lint.rb +168 -0
  116. data/test/helper.rb +17 -0
  117. data/test/test_ruby_css_lint.rb +7 -0
  118. 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
+ * - &amp; is the escape sequence for &
10
+ * - &lt; is the escape sequence for <
11
+ * - &gt; 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 "&quot;";
25
+ case "&":
26
+ return "&amp;";
27
+ case "<":
28
+ return "&lt;";
29
+ case ">":
30
+ return "&gt;";
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
+ }());