fdlint 0.1.0

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.
Files changed (218) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +14 -0
  3. data/README.md +68 -0
  4. data/Rakefile +92 -0
  5. data/bin/fdlint +17 -0
  6. data/lib/base_parser.rb +143 -0
  7. data/lib/cmd_runner.rb +145 -0
  8. data/lib/context.rb +31 -0
  9. data/lib/css/parser.rb +186 -0
  10. data/lib/css/reader.rb +30 -0
  11. data/lib/css/rule/check_compression_rule.rb +48 -0
  12. data/lib/css/rule/checklist.rb +45 -0
  13. data/lib/css/struct.rb +111 -0
  14. data/lib/encoding_error.rb +6 -0
  15. data/lib/file_validator.rb +38 -0
  16. data/lib/helper/code_type.rb +50 -0
  17. data/lib/helper/color_string.rb +44 -0
  18. data/lib/helper/file_reader.rb +22 -0
  19. data/lib/helper/strenc.rb +65 -0
  20. data/lib/html/parser.rb +212 -0
  21. data/lib/html/query.rb +96 -0
  22. data/lib/html/rule/check_tag_rule.rb +80 -0
  23. data/lib/html/struct.rb +291 -0
  24. data/lib/js/expr/expr.rb +66 -0
  25. data/lib/js/expr/left_hand.rb +63 -0
  26. data/lib/js/expr/operate.rb +92 -0
  27. data/lib/js/expr/primary.rb +166 -0
  28. data/lib/js/parser.rb +116 -0
  29. data/lib/js/rule/all.rb +35 -0
  30. data/lib/js/rule/checklist.rb +41 -0
  31. data/lib/js/rule/file_checker.rb +42 -0
  32. data/lib/js/rule/helper.rb +96 -0
  33. data/lib/js/rule/no_global.rb +87 -0
  34. data/lib/js/stat/if.rb +25 -0
  35. data/lib/js/stat/iter.rb +85 -0
  36. data/lib/js/stat/stat.rb +117 -0
  37. data/lib/js/stat/switch.rb +65 -0
  38. data/lib/js/stat/try.rb +28 -0
  39. data/lib/js/stat/var.rb +40 -0
  40. data/lib/js/struct.rb +248 -0
  41. data/lib/log_entry.rb +49 -0
  42. data/lib/node.rb +28 -0
  43. data/lib/parse_error.rb +13 -0
  44. data/lib/parser_visitable.rb +138 -0
  45. data/lib/position_info.rb +46 -0
  46. data/lib/printer/base_printer.rb +24 -0
  47. data/lib/printer/console_printer.rb +66 -0
  48. data/lib/printer/nocolor_printer.rb +27 -0
  49. data/lib/printer/vim_printer.rb +19 -0
  50. data/lib/rule.rb +241 -0
  51. data/lib/rule_helper.rb +14 -0
  52. data/lib/runner.rb +225 -0
  53. data/rules.d/css.rule +127 -0
  54. data/rules.d/html.dtd.rule +22 -0
  55. data/rules.d/html.prop.rule +51 -0
  56. data/rules.d/html.tag.rule +136 -0
  57. data/rules.d/js.file.rule +13 -0
  58. data/rules.d/js.jquery.rule +56 -0
  59. data/rules.d/js.mergefile.rule +71 -0
  60. data/rules.d/js.rule +84 -0
  61. data/test/all_tests.rb +84 -0
  62. data/test/cli/cli_test.rb +70 -0
  63. data/test/cli/log_level_test.rb +51 -0
  64. data/test/cli/output_format_test.rb +47 -0
  65. data/test/cli/type_test.rb +77 -0
  66. data/test/css/mac_line_end_support_test.rb +38 -0
  67. data/test/css/parser_test.rb +276 -0
  68. data/test/css/rule/check_encoding_test.rb +66 -0
  69. data/test/css/rule/check_list_rule_test.rb +167 -0
  70. data/test/css/rule/compression_test.rb +53 -0
  71. data/test/css/rule/file_name_test.rb +76 -0
  72. data/test/fixtures/css/broken.css +4 -0
  73. data/test/fixtures/css/cbu/36.css +52 -0
  74. data/test/fixtures/css/cbu/china_top.css +324 -0
  75. data/test/fixtures/css/cbu/default-merge.css +3 -0
  76. data/test/fixtures/css/cbu/default.css +13 -0
  77. data/test/fixtures/css/cbu/diy-merge.css +25 -0
  78. data/test/fixtures/css/cbu/fns-v1.css +27 -0
  79. data/test/fixtures/css/cbu/index_v0.1.css +12 -0
  80. data/test/fixtures/css/cbu/merge.css +11 -0
  81. data/test/fixtures/css/cbu/min.css +2 -0
  82. data/test/fixtures/css/cbu/my_home_admin.css +126 -0
  83. data/test/fixtures/css/cbu/nav.css +95 -0
  84. data/test/fixtures/css/cbu/pic_list.css +386 -0
  85. data/test/fixtures/css/cbu/quote-edit.css +18 -0
  86. data/test/fixtures/css/cbu/selloffer.shopwindow.css +1 -0
  87. data/test/fixtures/css/cbu/v1.css +9 -0
  88. data/test/fixtures/css/css3.css +30 -0
  89. data/test/fixtures/css/empty-min.css +0 -0
  90. data/test/fixtures/css/empty.css +0 -0
  91. data/test/fixtures/css/font-family.css +4 -0
  92. data/test/fixtures/css/gb-good.css +14 -0
  93. data/test/fixtures/css/gb_using_star.css +4 -0
  94. data/test/fixtures/css/import.css +18 -0
  95. data/test/fixtures/css/mac-line-sep-err-min.css +1 -0
  96. data/test/fixtures/css/mac-line-sep-err.css +1 -0
  97. data/test/fixtures/css/mac-line-sep-good-min.css +1 -0
  98. data/test/fixtures/css/mac-line-sep-good.css +1 -0
  99. data/test/fixtures/css/multi-encoding-in-a-file.css +0 -0
  100. data/test/fixtures/css/simple.css +1 -0
  101. data/test/fixtures/css/using_expr.css +8 -0
  102. data/test/fixtures/css/using_hack.css +21 -0
  103. data/test/fixtures/css/using_id.css +1 -0
  104. data/test/fixtures/css/using_star.css +4 -0
  105. data/test/fixtures/css/utf8_good.css +6 -0
  106. data/test/fixtures/css/utf8_good_declaring_charset.css +7 -0
  107. data/test/fixtures/css/utf8_using_star.css +5 -0
  108. data/test/fixtures/html/1-1.html +120 -0
  109. data/test/fixtures/html/1-2.html +120 -0
  110. data/test/fixtures/html/cms.html +373 -0
  111. data/test/fixtures/html/css_out_of_head.html +9 -0
  112. data/test/fixtures/html/fdev-template.html +22 -0
  113. data/test/fixtures/html/google.com.html +33 -0
  114. data/test/fixtures/html/mixed_log_levels.html +4 -0
  115. data/test/fixtures/html/mixed_types.html +13 -0
  116. data/test/fixtures/html/no_dtd.html +6 -0
  117. data/test/fixtures/html/readme.html +94 -0
  118. data/test/fixtures/html/review.board.html +163 -0
  119. data/test/fixtures/html/syntax_err.html +3 -0
  120. data/test/fixtures/html/train/detail/345/233/276/346/226/207/347/273/223/345/220/210.html +208 -0
  121. data/test/fixtures/html/train/detail/347/232/204Flash.html +212 -0
  122. data/test/fixtures/html/train/detail/347/232/204Vedio.html +212 -0
  123. data/test/fixtures/html/train/index.html +37 -0
  124. data/test/fixtures/html/train/test.html +1 -0
  125. data/test/fixtures/html/train//344/277/256/346/224/271/344/270/200/347/272/247/345/210/206/347/261/273.html +112 -0
  126. data/test/fixtures/html/train//344/277/256/346/224/271/345/255/220/345/210/206/347/261/273.html +108 -0
  127. data/test/fixtures/html/train//344/277/256/346/224/271/350/257/276/347/250/213.html +195 -0
  128. data/test/fixtures/html/train//345/215/232/345/256/242/350/256/276/347/275/256.html +142 -0
  129. data/test/fixtures/html/train//346/265/217/350/247/210/350/256/260/345/275/225.html +191 -0
  130. data/test/fixtures/html/train//346/267/273/345/212/240/344/270/200/347/272/247/345/210/206/347/261/273.html +113 -0
  131. data/test/fixtures/html/train//346/267/273/345/212/240/345/255/220/345/210/206/347/261/273.html +112 -0
  132. data/test/fixtures/html/train//346/267/273/345/212/240/350/257/276/347/250/213.html +195 -0
  133. data/test/fixtures/html/train//347/231/273/345/275/225.html +20 -0
  134. data/test/fixtures/html/train//347/256/241/347/220/206/345/210/206/347/261/273.html +210 -0
  135. data/test/fixtures/html/train//347/256/241/347/220/206/345/217/215/351/246/210.html +222 -0
  136. data/test/fixtures/html/train//347/256/241/347/220/206/350/257/276/347/250/213.html +284 -0
  137. data/test/fixtures/html/train//347/256/241/347/220/206/350/264/246/346/210/267.html +107 -0
  138. data/test/fixtures/html/train//347/275/221/344/270/212/345/237/271/350/256/255home/351/241/265.html +354 -0
  139. data/test/fixtures/html/train//347/275/221/345/225/206/345/237/271/350/256/255list/351/241/265.html +255 -0
  140. data/test/fixtures/html/train//350/256/276/347/275/256/351/246/226/351/241/265/346/216/250/350/215/220.html +168 -0
  141. data/test/fixtures/html/train//350/257/264/346/230/216.txt +3 -0
  142. data/test/fixtures/html/train//351/246/226/351/241/265/345/271/277/345/221/212/350/256/276/347/275/256.html +297 -0
  143. data/test/fixtures/html/unescaped.html +2 -0
  144. data/test/fixtures/html/view.vm +916 -0
  145. data/test/fixtures/js/jquery-1.7.js +9300 -0
  146. data/test/fixtures/js/scope-test.js +22 -0
  147. data/test/helper.rb +41 -0
  148. data/test/html/mixed_type_test.rb +35 -0
  149. data/test/html/parser/parse_comment_test.rb +47 -0
  150. data/test/html/parser/parse_dtd_test.rb +46 -0
  151. data/test/html/parser/parse_script_tag_test.rb +55 -0
  152. data/test/html/parser/parse_with_auto_close_tag_test.rb +41 -0
  153. data/test/html/parser/parse_with_diff_case_test.rb +38 -0
  154. data/test/html/parser/parse_with_emtpy_test.rb +22 -0
  155. data/test/html/parser/parse_with_multi_children_test.rb +27 -0
  156. data/test/html/parser/parse_with_multi_line_test.rb +41 -0
  157. data/test/html/parser/parse_with_prop_test.rb +88 -0
  158. data/test/html/parser/parse_with_script_tag_test.rb +26 -0
  159. data/test/html/parser/parse_with_selfclosing_test.rb +39 -0
  160. data/test/html/parser/parse_with_simple_tag_test.rb +44 -0
  161. data/test/html/parser/parse_with_simple_tree_test.rb +40 -0
  162. data/test/html/parser/parse_with_style_tag_test.rb +22 -0
  163. data/test/html/parser/parse_with_text_test.rb +45 -0
  164. data/test/html/parser_test.rb +52 -0
  165. data/test/html/query_test.rb +52 -0
  166. data/test/html/rule/check_block_level_element_test.rb +52 -0
  167. data/test/html/rule/check_button_test.rb +45 -0
  168. data/test/html/rule/check_class_count_test.rb +36 -0
  169. data/test/html/rule/check_css_in_head_test.rb +53 -0
  170. data/test/html/rule/check_dtd_test.rb +46 -0
  171. data/test/html/rule/check_form_element_name_test.rb +49 -0
  172. data/test/html/rule/check_head_contain_meta_and_title_test.rb +52 -0
  173. data/test/html/rule/check_html_template_test.rb +103 -0
  174. data/test/html/rule/check_hyperlink_with_target_test.rb +40 -0
  175. data/test/html/rule/check_hyperlink_with_title_test.rb +43 -0
  176. data/test/html/rule/check_id_n_class_downcase_test.rb +40 -0
  177. data/test/html/rule/check_img_with_alt_prop_test.rb +33 -0
  178. data/test/html/rule/check_no_import_css_test.rb +36 -0
  179. data/test/html/rule/check_prop_have_value_test.rb +32 -0
  180. data/test/html/rule/check_prop_seperator_test.rb +32 -0
  181. data/test/html/rule/check_style_prop_test.rb +30 -0
  182. data/test/html/rule/check_tag_closed_test.rb +59 -0
  183. data/test/html/rule/check_tag_downcase_test.rb +51 -0
  184. data/test/html/rule/check_unescape_char_test.rb +35 -0
  185. data/test/html/rule/check_unique_import_test.rb +56 -0
  186. data/test/html/rule_test.rb +62 -0
  187. data/test/js/expr/expr.rb +57 -0
  188. data/test/js/expr/left_hand.rb +25 -0
  189. data/test/js/expr/operate.rb +145 -0
  190. data/test/js/expr/primary.rb +89 -0
  191. data/test/js/parser_test.rb +98 -0
  192. data/test/js/rule/alert_check_test.rb +37 -0
  193. data/test/js/rule/all_test.rb +23 -0
  194. data/test/js/rule/base_test.rb +34 -0
  195. data/test/js/rule/file_checker_test.rb +131 -0
  196. data/test/js/rule/jq_check_test.rb +90 -0
  197. data/test/js/rule/nest_try_catch_test.rb +71 -0
  198. data/test/js/rule/new_object_and_new_array_test.rb +38 -0
  199. data/test/js/rule/no_eval_test.rb +34 -0
  200. data/test/js/rule/no_global_test.rb +88 -0
  201. data/test/js/rule/private_method_check_test.rb +58 -0
  202. data/test/js/rule/semicolon_test.rb +63 -0
  203. data/test/js/rule/stat_if_with_brace_test.rb +68 -0
  204. data/test/js/rule/stat_if_with_muti_else_test.rb +68 -0
  205. data/test/js/rule/use_strict_equal_test.rb +44 -0
  206. data/test/js/rule_test.rb +47 -0
  207. data/test/js/stat/if.rb +26 -0
  208. data/test/js/stat/iter.rb +115 -0
  209. data/test/js/stat/stat.rb +91 -0
  210. data/test/js/stat/switch.rb +37 -0
  211. data/test/js/stat/try.rb +32 -0
  212. data/test/js/stat/var.rb +38 -0
  213. data/test/parser_visitable_test.rb +102 -0
  214. data/test/position_info_test.rb +66 -0
  215. data/test/rule_dsl/dsl_basic_test.rb +91 -0
  216. data/test/rule_dsl/importing_test.rb +48 -0
  217. data/test/runner/log_level_test.rb +58 -0
  218. metadata +317 -0
data/rules.d/js.rule ADDED
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ # vi: filetype=ruby
3
+
4
+ js
5
+
6
+ check_statement do |stat|
7
+ ary = %w(empty var continue break return throw expression)
8
+ if ary.include?(stat.type) && !stat.end_with_semicolon?
9
+ ['所有语句结束带上分号', :error]
10
+ end
11
+ end
12
+
13
+ check_stat_if do |stat|
14
+ if stat.true_part.type != 'block' ||
15
+ stat.false_part && stat.false_part.type != 'if' && stat.false_part.type != 'block'
16
+
17
+ ['所有条件区域必须用花括号括起来', :error]
18
+ end
19
+ end
20
+
21
+ check_stat_if do |stat|
22
+ count = 0;
23
+ while stat.false_part && stat.false_part.type == 'if'
24
+ count += 1
25
+ stat = stat.false_part
26
+ end
27
+ count += 1 if stat.false_part
28
+ if count >= 3
29
+ ['3个条件及以上的条件语句用switch代替if else', :error]
30
+ end
31
+ end
32
+
33
+ check_expr_new do |expr|
34
+ expr = expr.left
35
+ expr = expr.left if expr.type == '('
36
+
37
+ if expr.type == 'id'
38
+ if expr.text == 'Object'
39
+ ['使用{}代替new Object()', :error]
40
+ elsif expr.text == 'Array'
41
+ ['使用[]代替new Array()', :error]
42
+ end
43
+ end
44
+ end
45
+
46
+ check_expr_member do |expr|
47
+ expr = context.find_expr_member(expr) { |expr| expr.type == '(' }
48
+ checks = %w(
49
+ (.,window,eval)
50
+ eval
51
+ )
52
+ if expr && checks.include?(expr.left.text)
53
+ ['不允许使用eval', :error]
54
+ end
55
+ end
56
+
57
+ check_expr_member do |expr|
58
+ if expr.left && expr.left.text == 'alert'
59
+ ['必须去掉临时调试代码。如果一定要使用alert功能,请使用 window.alert', :warn]
60
+ end
61
+ end
62
+
63
+ check_expr_member do |expr|
64
+ if expr.left
65
+ if expr.left.text =~ /(?<!this|self),_/
66
+ ['禁止调用对象的私有方法', :error]
67
+ end
68
+ end
69
+ end
70
+
71
+ check_expr_equal do |expr|
72
+ if expr.type == '==' || expr.type == '!='
73
+ ['避免使用==和!=操作符', :warn]
74
+ end
75
+ end
76
+
77
+ check_stat_try do |stat|
78
+ if stat.try_part.contains?('try') ||
79
+ stat.catch_part && (stat.catch_part.contains? 'try') ||
80
+ stat.finally_part && (stat.finally_part.contains? 'try')
81
+ ['try catch一般不允许嵌套,若嵌套,需要充分的理由', :warn]
82
+ end
83
+ end
84
+
data/test/all_tests.rb ADDED
@@ -0,0 +1,84 @@
1
+ gem 'test-unit' if defined? gem
2
+ require 'test/unit'
3
+ require 'test/unit/testsuite'
4
+ require 'test/unit/ui/console/testrunner'
5
+
6
+ unless Kernel.respond_to?(:require_relative)
7
+ module Kernel
8
+ def require_relative(path)
9
+ require File.expand_path(path.to_str, File.dirname(caller[0]))
10
+ end
11
+ end
12
+ end
13
+
14
+ require_relative 'parser_visitable_test'
15
+ require_relative 'position_info_test'
16
+ require_relative 'css/parser_test'
17
+ require_relative 'css/mac_line_end_support_test'
18
+ require_relative 'css/rule/check_list_rule_test'
19
+ require_relative 'css/rule/check_encoding_test'
20
+ require_relative 'css/rule/file_name_test'
21
+ require_relative 'css/rule/compression_test'
22
+ require_relative 'html/parser_test'
23
+ require_relative 'html/rule_test'
24
+ require_relative 'html/query_test'
25
+ require_relative 'html/mixed_type_test'
26
+ require_relative 'js/parser_test'
27
+ require_relative 'js/rule_test'
28
+ require_relative 'rule_dsl/dsl_basic_test'
29
+ require_relative 'rule_dsl/importing_test'
30
+ require_relative 'cli/cli_test'
31
+ require_relative 'cli/type_test'
32
+ require_relative 'cli/output_format_test'
33
+ require_relative 'cli/log_level_test'
34
+ require_relative 'runner/log_level_test'
35
+
36
+
37
+ module XRayTest
38
+
39
+ class ALL < Test::Unit::TestSuite
40
+
41
+ def self.suite
42
+ tests = Test::Unit::TestSuite.new
43
+
44
+ tests << PositionInfoTest.suite
45
+ tests << ParserVisitableTest.suite
46
+
47
+ #CSS
48
+ tests << CSS::ParserTest.suite
49
+ tests << CSS::MacLineEndSupportTest.suite
50
+ tests << CSS::Rule::CheckListRuleTest.suite
51
+ tests << CSS::Rule::CheckEncodingTest.suite
52
+ tests << CSS::Rule::CheckFileNameTest.suite
53
+ tests << CSS::Rule::CompressionTest.suite
54
+
55
+ #HTML
56
+ tests << HTML::ParserTest.suite
57
+ tests << HTML::RuleTest.suite
58
+ tests << HTML::QueryTest.suite
59
+ tests << HTML::MixedTypeTest.suite
60
+
61
+ #JS
62
+ tests << JS::ParserTest.suite
63
+ tests << JS::RuleTest.suite
64
+
65
+ #RULE
66
+ tests << Rule::DSLBasicTest.suite
67
+ tests << Rule::ImportingTest.suite
68
+
69
+ #CLI
70
+ tests << CLI::CLITest.suite
71
+ tests << CLI::TypeTest.suite
72
+ tests << CLI::OutputFormatTest.suite
73
+ tests << CLI::LogLevelTest.suite
74
+
75
+ #RUNNER
76
+ tests << Runner::LogLevelTest.suite
77
+
78
+ tests
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ Test::Unit::UI::Console::TestRunner.run( XRayTest::ALL )
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ require 'test/unit'
3
+ require_relative '../helper'
4
+
5
+ module XRayTest
6
+
7
+ module CLI
8
+
9
+ class CLITest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @bin = File.expand_path(File.join File.dirname(__FILE__), '../../bin/fdlint')
13
+ end
14
+
15
+ def test_cli_main
16
+ if has_ruby? '1.9.1'
17
+ @cmd = "ruby1.9.1 #{@bin}"
18
+ do_all_test
19
+ else
20
+ warn 'Skipping Ruby1.9 CLI Test!'
21
+ end
22
+ end
23
+
24
+ def do_all_test
25
+ public_methods.grep(/^do_test_/).each do |m|
26
+ send m
27
+ end
28
+ end
29
+
30
+ def do_test_check_html_file
31
+ res = `#{@cmd} #{FIXTURE_ABS_PATH}/html/syntax_err.html`
32
+ assert res.index "[FATAL] [3,1]"
33
+ end
34
+
35
+ def do_test_check_css_file
36
+ res = `#{@cmd} #{FIXTURE_ABS_PATH}/css/using_star.css`
37
+ assert res.include? '禁止使用星号选择符'
38
+ end
39
+
40
+ def do_test_check_js_file
41
+ res = `#{@cmd} #{FIXTURE_ABS_PATH}/js/scope-test.js`
42
+ assert res.include? '[ERROR] [13,10] 禁止使用未定义的变量(或全局变量)'
43
+ assert res.include? '[ERROR] [19,3] 禁止使用未定义的变量(或全局变量)'
44
+ end
45
+
46
+ unless `which cat`.empty?
47
+
48
+ def do_test_check_html_text
49
+ res = `cat #{FIXTURE_ABS_PATH}/html/syntax_err.html | #{@cmd}`
50
+ assert res.include? "[FATAL] [3,1]"
51
+ end
52
+
53
+ def do_test_check_css_text
54
+ res = `cat #{FIXTURE_ABS_PATH}/css/using_star.css | #{@cmd}`
55
+ assert res.include? '禁止使用星号选择符'
56
+ end
57
+
58
+ def do_test_check_js_text
59
+ res = `cat #{FIXTURE_ABS_PATH}/js/scope-test.js | #{@cmd}`
60
+ assert res.include? '[ERROR] [13,10] 禁止使用未定义的变量(或全局变量)'
61
+ assert res.include? '[ERROR] [19,3] 禁止使用未定义的变量(或全局变量)'
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'test/unit'
3
+ require_relative '../helper'
4
+
5
+ module XRayTest
6
+
7
+ module CLI
8
+
9
+ class LogLevelTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @bin = File.expand_path(File.join File.dirname(__FILE__), '../../bin/fdlint')
13
+ @fixture = File.expand_path(File.join File.dirname(__FILE__), '../fixtures/html/mixed_log_levels.html')
14
+ @cmd = "ruby #{@bin} #{@fixture}"
15
+ end
16
+
17
+ unless `which cat`.empty?
18
+ def test_output_all_by_default
19
+ res = `#{@cmd}`
20
+ assert res.include? 'WARN'
21
+ assert res.include? 'ERROR'
22
+ assert res.include? 'FATAL'
23
+ end
24
+
25
+ def test_output_fatals
26
+ res = `#{@cmd} --level=fatal`
27
+ assert !res.include?('WARN')
28
+ assert !res.include?('ERROR')
29
+ assert res.include? 'FATAL'
30
+ end
31
+
32
+ def test_output_fatals_and_errors
33
+ res = `#{@cmd} --level=error`
34
+ assert !res.include?('WARN')
35
+ assert res.include?('ERROR')
36
+ assert res.include? 'FATAL'
37
+ end
38
+
39
+ def test_output_fatals_errors_and_warnings
40
+ res = `#{@cmd} --level=warn`
41
+ assert res.include?('WARN')
42
+ assert res.include?('ERROR')
43
+ assert res.include? 'FATAL'
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require 'test/unit'
3
+ require_relative '../helper'
4
+
5
+ module XRayTest
6
+
7
+ module CLI
8
+
9
+ class OutputFormatTest < Test::Unit::TestCase
10
+
11
+ @@bin = File.expand_path(File.join File.dirname(__FILE__), '../../bin/fdlint')
12
+ @@cmd = "ruby #{@@bin}"
13
+
14
+ def test_with_console_format
15
+ res = `#{@@cmd} #{FIXTURE_ABS_PATH}/css/empty.css`
16
+ assert res.include? "[OK] /home/qhwa/projects/fdlint/test/fixtures/css/empty.c"
17
+ end
18
+
19
+ def test_with_nocolor_format
20
+ res = `#{@@cmd} --format=nocolor #{FIXTURE_ABS_PATH}/css/empty.css`
21
+ assert res.include? "[OK] /home/qhwa/projects/fdlint/test/fixtures/css/empty.c"
22
+ end
23
+
24
+ def test_with_vim_format
25
+ res = `#{@@cmd} --format=vim #{FIXTURE_ABS_PATH}/css/empty.css`
26
+ assert res.empty?
27
+ end
28
+
29
+ def test_reulsts_with_vim_format
30
+ res = `#{@@cmd} --format=vim #{FIXTURE_ABS_PATH}/css/using_expr.css`
31
+ assert res.include? 'using_expr.css:[error]:5,7:禁止使用CSS表达式'
32
+ assert res.include? 'using_expr.css:[error]:6,6:禁止使用CSS表达式'
33
+ end
34
+
35
+ unless `which cat`.empty?
36
+ def test_results_with_vim_format_in_pipline
37
+ res = `cat #{FIXTURE_ABS_PATH}/css/using_expr.css | #{@@cmd} --format=vim `
38
+ assert res.include? '-:[error]:5,7:禁止使用CSS表达式'
39
+ assert res.include? '-:[error]:6,6:禁止使用CSS表达式'
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require 'test/unit'
3
+ require_relative '../helper'
4
+
5
+ module XRayTest
6
+
7
+ module CLI
8
+
9
+ class TypeTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @bin = File.expand_path(File.join File.dirname(__FILE__), '../../bin/fdlint')
13
+ end
14
+
15
+ def test_cli_main
16
+ if has_ruby? '1.9.1'
17
+ @cmd = "ruby1.9.1 #{@bin}"
18
+ do_all_test
19
+ else
20
+ warn 'Skipping Ruby1.9 CLI Test!'
21
+ end
22
+
23
+ end
24
+
25
+ def do_all_test
26
+ public_methods.grep(/^do_test_/).each do |m|
27
+ send m
28
+ end
29
+ end
30
+
31
+ def do_test_check_html_file
32
+ res = `#{@cmd} --html #{FIXTURE_ABS_PATH}/html/syntax_err.html`
33
+ assert res.index "[FATAL] [3,1]"
34
+ end
35
+
36
+ def do_test_check_js_file_with_html_type
37
+ res = `#{@cmd} --html #{FIXTURE_ABS_PATH}/js/scope-test.js`
38
+ assert res.empty?
39
+ end
40
+
41
+ def do_test_check_css_file
42
+ res = `#{@cmd} --css #{FIXTURE_ABS_PATH}/css/using_star.css`
43
+ assert res.include? '禁止使用星号选择符'
44
+ end
45
+
46
+ def do_test_check_js_file
47
+ res = `#{@cmd} --js #{FIXTURE_ABS_PATH}/js/scope-test.js`
48
+ assert res.include? '[ERROR] [13,10] 禁止使用未定义的变量(或全局变量)'
49
+ assert res.include? '[ERROR] [19,3] 禁止使用未定义的变量(或全局变量)'
50
+ end
51
+
52
+ unless `which cat`.empty?
53
+
54
+ def do_test_check_html_text
55
+ res = `cat #{FIXTURE_ABS_PATH}/html/syntax_err.html | #{@cmd} --html`
56
+ assert res.include? "[FATAL] [3,1]"
57
+ end
58
+
59
+ def do_test_check_css_text
60
+ res = `cat #{FIXTURE_ABS_PATH}/css/using_star.css | #{@cmd} --css`
61
+ assert res.include? '禁止使用星号选择符'
62
+ end
63
+
64
+ def do_test_check_js_text
65
+ res = `cat #{FIXTURE_ABS_PATH}/js/scope-test.js | #{@cmd} --js`
66
+ assert res.include? '[ERROR] [13,10] 禁止使用未定义的变量(或全局变量)'
67
+ assert res.include? '[ERROR] [19,3] 禁止使用未定义的变量(或全局变量)'
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../helper'
4
+
5
+ require 'node'
6
+ require 'log_entry'
7
+ require 'css/struct'
8
+ require 'css/rule/checklist'
9
+
10
+ module XRayTest
11
+ module CSS
12
+
13
+ class MacLineEndSupportTest < Test::Unit::TestCase
14
+
15
+ def setup
16
+ @runner = XRay::Runner.new :encoding => 'gb2312'
17
+ end
18
+
19
+ def test_check_mac_line_end_with_good_css
20
+ file = "#{FIXTURE_PATH}/css/mac-line-sep-good.css"
21
+ results = @runner.check_css_file file
22
+
23
+ assert results.empty?, "Mac style line end should be supported"
24
+ end
25
+
26
+ def test_check_mac_line_end_with_error_css
27
+ file = "#{FIXTURE_PATH}/css/mac-line-sep-err.css"
28
+ results = @runner.check_css_file file
29
+
30
+ assert_equal 1, results.size, "check as usual"
31
+ end
32
+
33
+
34
+ end
35
+
36
+ end
37
+ end
38
+