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,117 @@
1
+ /*
2
+ * Rule: Certain properties don't play well with certain display values.
3
+ * - float should not be used with inline-block
4
+ * - height, width, margin-top, margin-bottom, float should not be used with inline
5
+ * - vertical-align should not be used with block
6
+ * - margin, float should not be used with table-*
7
+ */
8
+ /*global CSSLint*/
9
+ CSSLint.addRule({
10
+
11
+ //rule information
12
+ id: "display-property-grouping",
13
+ name: "Require properties appropriate for display",
14
+ desc: "Certain properties shouldn't be used with certain display property values.",
15
+ browsers: "All",
16
+
17
+ //initialization
18
+ init: function(parser, reporter){
19
+ var rule = this;
20
+
21
+ var propertiesToCheck = {
22
+ display: 1,
23
+ "float": "none",
24
+ height: 1,
25
+ width: 1,
26
+ margin: 1,
27
+ "margin-left": 1,
28
+ "margin-right": 1,
29
+ "margin-bottom": 1,
30
+ "margin-top": 1,
31
+ padding: 1,
32
+ "padding-left": 1,
33
+ "padding-right": 1,
34
+ "padding-bottom": 1,
35
+ "padding-top": 1,
36
+ "vertical-align": 1
37
+ },
38
+ properties;
39
+
40
+ function reportProperty(name, display, msg){
41
+ if (properties[name]){
42
+ if (typeof propertiesToCheck[name] != "string" || properties[name].value.toLowerCase() != propertiesToCheck[name]){
43
+ reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
44
+ }
45
+ }
46
+ }
47
+
48
+ function startRule(){
49
+ properties = {};
50
+ }
51
+
52
+ function endRule(){
53
+
54
+ var display = properties.display ? properties.display.value : null;
55
+ if (display){
56
+ switch(display){
57
+
58
+ case "inline":
59
+ //height, width, margin-top, margin-bottom, float should not be used with inline
60
+ reportProperty("height", display);
61
+ reportProperty("width", display);
62
+ reportProperty("margin", display);
63
+ reportProperty("margin-top", display);
64
+ reportProperty("margin-bottom", display);
65
+ reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
66
+ break;
67
+
68
+ case "block":
69
+ //vertical-align should not be used with block
70
+ reportProperty("vertical-align", display);
71
+ break;
72
+
73
+ case "inline-block":
74
+ //float should not be used with inline-block
75
+ reportProperty("float", display);
76
+ break;
77
+
78
+ default:
79
+ //margin, float should not be used with table
80
+ if (display.indexOf("table-") === 0){
81
+ reportProperty("margin", display);
82
+ reportProperty("margin-left", display);
83
+ reportProperty("margin-right", display);
84
+ reportProperty("margin-top", display);
85
+ reportProperty("margin-bottom", display);
86
+ reportProperty("float", display);
87
+ }
88
+
89
+ //otherwise do nothing
90
+ }
91
+ }
92
+
93
+ }
94
+
95
+ parser.addListener("startrule", startRule);
96
+ parser.addListener("startfontface", startRule);
97
+ parser.addListener("startkeyframerule", startRule);
98
+ parser.addListener("startpagemargin", startRule);
99
+ parser.addListener("startpage", startRule);
100
+
101
+ parser.addListener("property", function(event){
102
+ var name = event.property.text.toLowerCase();
103
+
104
+ if (propertiesToCheck[name]){
105
+ properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
106
+ }
107
+ });
108
+
109
+ parser.addListener("endrule", endRule);
110
+ parser.addListener("endfontface", endRule);
111
+ parser.addListener("endkeyframerule", endRule);
112
+ parser.addListener("endpagemargin", endRule);
113
+ parser.addListener("endpage", endRule);
114
+
115
+ }
116
+
117
+ });
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Rule: Disallow duplicate background-images (using url).
3
+ */
4
+ /*global CSSLint*/
5
+ CSSLint.addRule({
6
+
7
+ //rule information
8
+ id: "duplicate-background-images",
9
+ name: "Disallow duplicate background images",
10
+ desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
11
+ browsers: "All",
12
+
13
+ //initialization
14
+ init: function(parser, reporter){
15
+ var rule = this,
16
+ stack = {};
17
+
18
+ parser.addListener("property", function(event){
19
+ var name = event.property.text,
20
+ value = event.value,
21
+ i, len;
22
+
23
+ if (name.match(/background/i)) {
24
+ for (i=0, len=value.parts.length; i < len; i++) {
25
+ if (value.parts[i].type == 'uri') {
26
+ if (typeof stack[value.parts[i].uri] === 'undefined') {
27
+ stack[value.parts[i].uri] = event;
28
+ }
29
+ else {
30
+ reporter.report("Background image '" + value.parts[i].uri + "' was used multiple times, first declared at line " + stack[value.parts[i].uri].line + ", col " + stack[value.parts[i].uri].col + ".", event.line, event.col, rule);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ });
36
+ }
37
+ });
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Rule: Duplicate properties must appear one after the other. If an already-defined
3
+ * property appears somewhere else in the rule, then it's likely an error.
4
+ */
5
+ /*global CSSLint*/
6
+ CSSLint.addRule({
7
+
8
+ //rule information
9
+ id: "duplicate-properties",
10
+ name: "Disallow duplicate properties",
11
+ desc: "Duplicate properties must appear one after the other.",
12
+ browsers: "All",
13
+
14
+ //initialization
15
+ init: function(parser, reporter){
16
+ var rule = this,
17
+ properties,
18
+ lastProperty;
19
+
20
+ function startRule(event){
21
+ properties = {};
22
+ }
23
+
24
+ parser.addListener("startrule", startRule);
25
+ parser.addListener("startfontface", startRule);
26
+ parser.addListener("startpage", startRule);
27
+ parser.addListener("startpagemargin", startRule);
28
+ parser.addListener("startkeyframerule", startRule);
29
+
30
+ parser.addListener("property", function(event){
31
+ var property = event.property,
32
+ name = property.text.toLowerCase();
33
+
34
+ if (properties[name] && (lastProperty != name || properties[name] == event.value.text)){
35
+ reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
36
+ }
37
+
38
+ properties[name] = event.value.text;
39
+ lastProperty = name;
40
+
41
+ });
42
+
43
+
44
+ }
45
+
46
+ });
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Rule: Style rules without any properties defined should be removed.
3
+ */
4
+ /*global CSSLint*/
5
+ CSSLint.addRule({
6
+
7
+ //rule information
8
+ id: "empty-rules",
9
+ name: "Disallow empty rules",
10
+ desc: "Rules without any properties specified should be removed.",
11
+ browsers: "All",
12
+
13
+ //initialization
14
+ init: function(parser, reporter){
15
+ var rule = this,
16
+ count = 0;
17
+
18
+ parser.addListener("startrule", function(){
19
+ count=0;
20
+ });
21
+
22
+ parser.addListener("property", function(){
23
+ count++;
24
+ });
25
+
26
+ parser.addListener("endrule", function(event){
27
+ var selectors = event.selectors;
28
+ if (count === 0){
29
+ reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
30
+ }
31
+ });
32
+ }
33
+
34
+ });
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Rule: There should be no syntax errors. (Duh.)
3
+ */
4
+ /*global CSSLint*/
5
+ CSSLint.addRule({
6
+
7
+ //rule information
8
+ id: "errors",
9
+ name: "Parsing Errors",
10
+ desc: "This rule looks for recoverable syntax errors.",
11
+ browsers: "All",
12
+
13
+ //initialization
14
+ init: function(parser, reporter){
15
+ var rule = this;
16
+
17
+ parser.addListener("error", function(event){
18
+ reporter.error(event.message, event.line, event.col, rule);
19
+ });
20
+
21
+ }
22
+
23
+ });
@@ -0,0 +1,67 @@
1
+
2
+ /*global CSSLint*/
3
+ CSSLint.addRule({
4
+
5
+ //rule information
6
+ id: "fallback-colors",
7
+ name: "Require fallback colors",
8
+ desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
9
+ browsers: "IE6,IE7,IE8",
10
+
11
+ //initialization
12
+ init: function(parser, reporter){
13
+ var rule = this,
14
+ lastProperty,
15
+ propertiesToCheck = {
16
+ color: 1,
17
+ background: 1,
18
+ "background-color": 1
19
+ },
20
+ properties;
21
+
22
+ function startRule(event){
23
+ properties = {};
24
+ lastProperty = null;
25
+ }
26
+
27
+ parser.addListener("startrule", startRule);
28
+ parser.addListener("startfontface", startRule);
29
+ parser.addListener("startpage", startRule);
30
+ parser.addListener("startpagemargin", startRule);
31
+ parser.addListener("startkeyframerule", startRule);
32
+
33
+ parser.addListener("property", function(event){
34
+ var property = event.property,
35
+ name = property.text.toLowerCase(),
36
+ parts = event.value.parts,
37
+ i = 0,
38
+ colorType = "",
39
+ len = parts.length;
40
+
41
+ if(propertiesToCheck[name]){
42
+ while(i < len){
43
+ if (parts[i].type == "color"){
44
+ if ("alpha" in parts[i] || "hue" in parts[i]){
45
+
46
+ if (/([^\)]+)\(/.test(parts[i])){
47
+ colorType = RegExp.$1.toUpperCase();
48
+ }
49
+
50
+ if (!lastProperty || (lastProperty.property.text.toLowerCase() != name || lastProperty.colorType != "compat")){
51
+ reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
52
+ }
53
+ } else {
54
+ event.colorType = "compat";
55
+ }
56
+ }
57
+
58
+ i++;
59
+ }
60
+ }
61
+
62
+ lastProperty = event;
63
+ });
64
+
65
+ }
66
+
67
+ });
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Rule: You shouldn't use more than 10 floats. If you do, there's probably
3
+ * room for some abstraction.
4
+ */
5
+ /*global CSSLint*/
6
+ CSSLint.addRule({
7
+
8
+ //rule information
9
+ id: "floats",
10
+ name: "Disallow too many floats",
11
+ desc: "This rule tests if the float property is used too many times",
12
+ browsers: "All",
13
+
14
+ //initialization
15
+ init: function(parser, reporter){
16
+ var rule = this;
17
+ var count = 0;
18
+
19
+ //count how many times "float" is used
20
+ parser.addListener("property", function(event){
21
+ if (event.property.text.toLowerCase() == "float" &&
22
+ event.value.text.toLowerCase() != "none"){
23
+ count++;
24
+ }
25
+ });
26
+
27
+ //report the results
28
+ parser.addListener("endstylesheet", function(){
29
+ reporter.stat("floats", count);
30
+ if (count >= 10){
31
+ reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
32
+ }
33
+ });
34
+ }
35
+
36
+ });
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Rule: Avoid too many @font-face declarations in the same stylesheet.
3
+ */
4
+ /*global CSSLint*/
5
+ CSSLint.addRule({
6
+
7
+ //rule information
8
+ id: "font-faces",
9
+ name: "Don't use too many web fonts",
10
+ desc: "Too many different web fonts in the same stylesheet.",
11
+ browsers: "All",
12
+
13
+ //initialization
14
+ init: function(parser, reporter){
15
+ var rule = this,
16
+ count = 0;
17
+
18
+
19
+ parser.addListener("startfontface", function(){
20
+ count++;
21
+ });
22
+
23
+ parser.addListener("endstylesheet", function(){
24
+ if (count > 5){
25
+ reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
26
+ }
27
+ });
28
+ }
29
+
30
+ });
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Rule: You shouldn't need more than 9 font-size declarations.
3
+ */
4
+
5
+ /*global CSSLint*/
6
+ CSSLint.addRule({
7
+
8
+ //rule information
9
+ id: "font-sizes",
10
+ name: "Disallow too many font sizes",
11
+ desc: "Checks the number of font-size declarations.",
12
+ browsers: "All",
13
+
14
+ //initialization
15
+ init: function(parser, reporter){
16
+ var rule = this,
17
+ count = 0;
18
+
19
+ //check for use of "font-size"
20
+ parser.addListener("property", function(event){
21
+ if (event.property == "font-size"){
22
+ count++;
23
+ }
24
+ });
25
+
26
+ //report the results
27
+ parser.addListener("endstylesheet", function(){
28
+ reporter.stat("font-sizes", count);
29
+ if (count >= 10){
30
+ reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
31
+ }
32
+ });
33
+ }
34
+
35
+ });
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Rule: When using a vendor-prefixed gradient, make sure to use them all.
3
+ */
4
+ /*global CSSLint*/
5
+ CSSLint.addRule({
6
+
7
+ //rule information
8
+ id: "gradients",
9
+ name: "Require all gradient definitions",
10
+ desc: "When using a vendor-prefixed gradient, make sure to use them all.",
11
+ browsers: "All",
12
+
13
+ //initialization
14
+ init: function(parser, reporter){
15
+ var rule = this,
16
+ gradients;
17
+
18
+ parser.addListener("startrule", function(){
19
+ gradients = {
20
+ moz: 0,
21
+ webkit: 0,
22
+ oldWebkit: 0,
23
+ ms: 0,
24
+ o: 0
25
+ };
26
+ });
27
+
28
+ parser.addListener("property", function(event){
29
+
30
+ if (/\-(moz|ms|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)){
31
+ gradients[RegExp.$1] = 1;
32
+ } else if (/\-webkit\-gradient/i.test(event.value)){
33
+ gradients.oldWebkit = 1;
34
+ }
35
+
36
+ });
37
+
38
+ parser.addListener("endrule", function(event){
39
+ var missing = [];
40
+
41
+ if (!gradients.moz){
42
+ missing.push("Firefox 3.6+");
43
+ }
44
+
45
+ if (!gradients.webkit){
46
+ missing.push("Webkit (Safari 5+, Chrome)");
47
+ }
48
+
49
+ if (!gradients.oldWebkit){
50
+ missing.push("Old Webkit (Safari 4+, Chrome)");
51
+ }
52
+
53
+ if (!gradients.ms){
54
+ missing.push("Internet Explorer 10+");
55
+ }
56
+
57
+ if (!gradients.o){
58
+ missing.push("Opera 11.1+");
59
+ }
60
+
61
+ if (missing.length && missing.length < 5){
62
+ reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
63
+ }
64
+
65
+ });
66
+
67
+ }
68
+
69
+ });