fdlint 0.2.0.pre → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +36 -15
- data/Rakefile +1 -1
- data/bin/fdlint +30 -9
- data/lib/fdlint/cli.rb +62 -10
- data/lib/fdlint/helper/logger.rb +1 -1
- data/lib/fdlint/log_entry.rb +14 -0
- data/lib/fdlint/parser/html/html_parser.rb +10 -12
- data/lib/fdlint/parser/html/query.rb +64 -50
- data/lib/fdlint/parser/html/struct.rb +20 -3
- data/lib/fdlint/parser/parser_visitable.rb +11 -5
- data/lib/fdlint/printer/base_printer.rb +6 -0
- data/lib/fdlint/printer/console_printer.rb +15 -23
- data/lib/fdlint/rule.rb +4 -4
- data/lib/fdlint/support/core/object.rb +6 -0
- data/lib/fdlint/support/core_ext.rb +1 -0
- data/lib/fdlint/validator.rb +60 -8
- data/lib/fdlint/version.rb +1 -1
- data/lib/hook/git_pre_commit +18 -0
- data/rules.d/css.rule.rb +1 -1
- data/rules.d/filename.rule.rb +3 -1
- data/rules.d/html.rule.rb +45 -32
- data/rules.d/js.rule.rb +2 -2
- data/test/all_tests.rb +28 -42
- data/test/css/mac_line_end_support_test.rb +10 -12
- data/test/css/parser_test.rb +4 -5
- data/test/css/rule/check_encoding_test.rb +7 -8
- data/test/css/rule/check_list_rule_test.rb +85 -102
- data/test/css/rule/file_name_test.rb +18 -39
- data/test/default_test.rb +1 -14
- data/test/fixtures/css/ad.css +0 -0
- data/test/fixtures/css/adver/test.css +0 -0
- data/test/fixtures/css/camelCase.css +0 -0
- data/test/fixtures/css/min/ad.css +0 -0
- data/test/fixtures/css/min/ad.min.css +0 -0
- data/test/fixtures/html/mixed_log_levels.html +1 -0
- data/test/fixtures/html/mixed_types.html +3 -0
- data/test/helper.rb +116 -16
- data/test/html/mixed_type_test.rb +14 -20
- data/test/html/parser/parse_comment_test.rb +4 -4
- data/test/html/parser/parse_dtd_test.rb +7 -7
- data/test/html/parser/parse_script_tag_test.rb +21 -14
- data/test/html/parser/parse_with_auto_close_tag_test.rb +12 -10
- data/test/html/parser/parse_with_diff_case_test.rb +8 -9
- data/test/html/parser/parse_with_emtpy_test.rb +5 -3
- data/test/html/parser/parse_with_multi_children_test.rb +4 -4
- data/test/html/parser/parse_with_multi_line_test.rb +5 -5
- data/test/html/parser/parse_with_prop_test.rb +10 -10
- data/test/html/parser/parse_with_script_tag_test.rb +4 -4
- data/test/html/parser/parse_with_selfclosing_test.rb +11 -11
- data/test/html/parser/parse_with_simple_tag_test.rb +7 -7
- data/test/html/parser/parse_with_simple_tree_test.rb +6 -6
- data/test/html/parser/parse_with_style_tag_test.rb +4 -4
- data/test/html/parser/parse_with_text_test.rb +7 -7
- data/test/html/parser_test.rb +19 -19
- data/test/html/query_test.rb +18 -18
- data/test/html/rule/check_block_level_element_test.rb +22 -24
- data/test/html/rule/check_button_test.rb +9 -9
- data/test/html/rule/check_css_in_head_test.rb +11 -32
- data/test/html/rule/check_dtd_test.rb +15 -11
- data/test/html/rule/check_form_element_name_test.rb +10 -9
- data/test/html/rule/check_head_contain_meta_and_title_test.rb +28 -34
- data/test/html/rule/check_hyperlink_with_target_test.rb +23 -17
- data/test/html/rule/check_hyperlink_with_title_test.rb +13 -20
- data/test/html/rule/check_id_n_class_downcase_test.rb +8 -19
- data/test/html/rule/check_img_with_alt_prop_test.rb +11 -12
- data/test/html/rule/check_no_import_css_test.rb +20 -20
- data/test/html/rule/check_prop_have_value_test.rb +9 -13
- data/test/html/rule/check_prop_seperator_test.rb +9 -13
- data/test/html/rule/check_style_prop_test.rb +7 -12
- data/test/html/rule/check_tag_closed_test.rb +15 -40
- data/test/html/rule/check_tag_downcase_test.rb +31 -28
- data/test/html/rule/check_unescape_char_test.rb +17 -17
- data/test/html/rule/check_unique_import_test.rb +15 -33
- data/test/html/rule_test.rb +2 -6
- data/test/js/expr/expr.rb +1 -1
- data/test/js/expr/left_hand.rb +1 -1
- data/test/js/expr/operate.rb +1 -1
- data/test/js/expr/primary.rb +1 -1
- data/test/js/parser_test.rb +3 -6
- data/test/js/rule/alert_check_test.rb +5 -19
- data/test/js/rule/base_test.rb +5 -19
- data/test/js/rule/jq_check_test.rb +26 -58
- data/test/js/rule/nest_try_catch_test.rb +26 -43
- data/test/js/rule/new_object_and_new_array_test.rb +5 -21
- data/test/js/rule/no_eval_test.rb +3 -19
- data/test/js/rule/no_global_test.rb +34 -73
- data/test/js/rule/private_method_check_test.rb +14 -43
- data/test/js/rule/semicolon_test.rb +18 -47
- data/test/js/rule/stat_if_with_brace_test.rb +30 -53
- data/test/js/rule/stat_if_with_muti_else_test.rb +36 -53
- data/test/js/rule/use_strict_equal_test.rb +16 -29
- data/test/js/rule_test.rb +2 -4
- data/test/js/stat/if.rb +1 -1
- data/test/js/stat/iter.rb +1 -1
- data/test/js/stat/stat.rb +1 -1
- data/test/js/stat/switch.rb +1 -1
- data/test/js/stat/try.rb +1 -1
- data/test/js/stat/var.rb +1 -1
- data/test/parser_visitable_test.rb +14 -36
- data/test/position_info_test.rb +4 -5
- data/test/runner/log_level_test.rb +30 -25
- metadata +11 -14
- data/lib/fdlint/file_validator.rb +0 -38
- data/lib/fdlint/parser/html/rule/check_tag_rule.rb +0 -80
- data/test/css/rule/compression_test.rb +0 -53
- data/test/html/rule/check_class_count_test.rb +0 -36
- data/test/html/rule/check_html_template_test.rb +0 -103
- data/test/js/rule/all_test.rb +0 -23
- data/test/js/rule/file_checker_test.rb +0 -131
- data/test/rule_dsl/dsl_basic_test.rb +0 -91
- data/test/rule_dsl/importing_test.rb +0 -48
- data/test/test_helper.rb +0 -9
@@ -2,164 +2,147 @@
|
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
4
|
|
5
|
-
require 'node'
|
6
|
-
require 'css/struct'
|
7
|
-
require 'css/rule/checklist'
|
5
|
+
require 'fdlint/parser/node'
|
6
|
+
require 'fdlint/parser/css/struct'
|
8
7
|
|
9
|
-
module
|
8
|
+
module FdlintTest
|
10
9
|
module CSS
|
11
10
|
module Rule
|
12
11
|
|
13
12
|
class CheckListRuleTest < Test::Unit::TestCase
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
Node = XRay::Node
|
18
|
-
XRay::Rule.import_all
|
14
|
+
Node = Fdlint::Parser::Node
|
15
|
+
Fdlint::Rule.rules
|
19
16
|
|
20
17
|
def setup
|
21
|
-
|
18
|
+
@file = nil
|
22
19
|
end
|
23
20
|
|
24
21
|
# selector
|
25
22
|
|
26
23
|
def test_check_selector_with_id
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
# 路径中不包含 /lib/ 文件会被辨认为页面级别样式
|
26
|
+
# 此时检查 selecotr id 的规则才会生效
|
27
|
+
css_file_level :page
|
30
28
|
|
31
|
-
|
29
|
+
parse :selector, '#mydiv a' do |results|
|
30
|
+
assert_has_result results, [:error, '页面级别样式不使用id']
|
31
|
+
end
|
32
32
|
|
33
|
-
selector
|
34
|
-
|
35
|
-
|
33
|
+
parse :selector, 'ul #mydiv dt' do |results|
|
34
|
+
assert_has_result results, [:error, '页面级别样式不使用id']
|
35
|
+
end
|
36
36
|
|
37
|
-
selector
|
38
|
-
|
39
|
-
|
37
|
+
parse :selector, '.guide-part ul li' do |results|
|
38
|
+
assert results.blank?
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_check_selector_with_global_tag
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
assert_equal :error, level
|
43
|
+
# 路径中不包含 /lib/ 文件会被辨认为页面级别样式
|
44
|
+
# 此时检查 global selecotr 的规则才会生效
|
45
|
+
css_file_level :page
|
47
46
|
|
48
|
-
selector
|
49
|
-
|
47
|
+
parse :selector, 'a' do |results|
|
48
|
+
assert_has_result results, [:error, '页面级别样式不能全局定义标签样式']
|
49
|
+
end
|
50
50
|
|
51
|
-
|
51
|
+
parse :selector, 'body' do |results|
|
52
|
+
assert_has_result results, [:error, '页面级别样式不能全局定义标签样式']
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
def test_check_selector_level
|
55
|
-
selector
|
56
|
-
|
57
|
-
|
58
|
-
assert_equal :error, level
|
59
|
-
|
60
|
-
selector = Node.new '.mypart ul li a'
|
61
|
-
ret = check_selector_level selector
|
62
|
-
assert_nil ret
|
63
|
-
|
64
|
-
selector = Node.new 'html>div.mypart ul li a'
|
65
|
-
message, level = check_selector_level selector
|
66
|
-
assert_equal :error, level
|
67
|
-
|
68
|
-
selector = Node.new 'div.mypart ul li a'
|
69
|
-
ret = check_selector_level selector
|
70
|
-
assert_nil ret
|
71
|
-
end
|
57
|
+
parse :selector, '.mypart .mysubpart ul li a' do |results|
|
58
|
+
assert_has_result results, [:error, 'CSS级联深度不能超过4层']
|
59
|
+
end
|
72
60
|
|
73
|
-
|
74
|
-
|
75
|
-
|
61
|
+
parse :selector, 'html>div.mypart ul li a' do |results|
|
62
|
+
assert_has_result results, [:error, 'CSS级联深度不能超过4层']
|
63
|
+
end
|
64
|
+
|
65
|
+
parse :selector, '.mypart ul li a' do |results|
|
66
|
+
assert results.blank?
|
67
|
+
end
|
76
68
|
|
77
|
-
|
69
|
+
parse :selector, 'div.mypart ul li a' do |results|
|
70
|
+
assert results.blank?
|
71
|
+
end
|
78
72
|
end
|
79
73
|
|
80
|
-
def
|
81
|
-
|
74
|
+
def test_check_selector_with_star
|
75
|
+
parse :selector, '* html' do |results|
|
76
|
+
assert_has_result results, [:error, '禁止使用星号选择符']
|
77
|
+
end
|
82
78
|
end
|
83
79
|
|
84
80
|
# declaration
|
85
81
|
|
86
82
|
def test_check_good_declaration_font
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
message, level = check_declaration_font dec
|
92
|
-
assert_equal nil, level
|
83
|
+
parse :declaration, 'font: Arail;' do |results|
|
84
|
+
assert results.blank?
|
85
|
+
end
|
93
86
|
end
|
94
87
|
|
95
88
|
def test_check_declaration_font
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
message, level = check_declaration_font dec
|
101
|
-
assert_equal :error, level
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_check_redefine_a_hover_color
|
105
|
-
selector = Node.new 'a:hover'
|
106
|
-
|
107
|
-
prop = Node.new 'color'
|
108
|
-
expr = Node.new '#f00'
|
109
|
-
dec = Declaration.new(prop, expr)
|
110
|
-
|
111
|
-
ruleset = RuleSet.new(selector, [dec])
|
112
|
-
|
113
|
-
message, level = check_ruleset_redefine_a_hover_color ruleset
|
114
|
-
assert_equal :error, level
|
89
|
+
parse :declaration, 'font: 宋体;' do |results|
|
90
|
+
assert_has_result results, [:error, '字体名称中的中文必须用ascii字符表示']
|
91
|
+
end
|
115
92
|
end
|
116
93
|
|
117
|
-
def test_check_redefine_lib_css
|
118
|
-
selector = Node.new '.fd-hide'
|
119
|
-
message, level = check_selector_redefine_lib_css selector
|
120
|
-
assert_equal :error, level
|
121
|
-
|
122
|
-
@scope = :lib
|
123
|
-
ret = check_selector_redefine_lib_css selector
|
124
|
-
assert_nil ret
|
125
|
-
end
|
126
|
-
|
127
94
|
def test_check_property_hack
|
128
|
-
props = %w(_background +font-size *color)
|
95
|
+
props = %w(_background +font-size *color d\isplay)
|
129
96
|
props.each do |prop|
|
130
|
-
prop
|
131
|
-
|
132
|
-
|
97
|
+
parse :property, prop do |results|
|
98
|
+
assert_has_result results, [:error, '合理使用hack']
|
99
|
+
end
|
133
100
|
end
|
134
101
|
end
|
135
102
|
|
136
|
-
def test_check_property_slash_hack
|
137
|
-
prop = Node.new 'd\isplay'
|
138
|
-
message, level = check_property_hack prop
|
139
|
-
assert_equal :error, level
|
140
|
-
end
|
141
|
-
|
142
103
|
def test_check_selector_using_hack
|
143
|
-
selector
|
144
|
-
|
145
|
-
|
104
|
+
parse :selector, 'html*' do |results|
|
105
|
+
assert_has_result results, [:error, '合理使用hack']
|
106
|
+
end
|
146
107
|
end
|
147
108
|
|
148
109
|
def test_check_value_use_css_expression
|
149
|
-
|
150
|
-
|
151
|
-
|
110
|
+
parse :value, 'expression(onfocus=this.blur())' do |results|
|
111
|
+
assert_has_result results, [:error, '禁止使用CSS表达式']
|
112
|
+
end
|
152
113
|
end
|
153
114
|
|
154
115
|
def test_check_value_use_hack
|
155
116
|
exprs = %w(9px\0 #000\9)
|
156
117
|
exprs.each do |expr|
|
157
|
-
expr
|
158
|
-
|
159
|
-
|
118
|
+
parse :value, expr do |results|
|
119
|
+
assert_has_result results, [:error, '合理使用hack']
|
120
|
+
end
|
160
121
|
end
|
161
122
|
end
|
162
123
|
|
124
|
+
private
|
125
|
+
|
126
|
+
def css_file_level level
|
127
|
+
if level == :page
|
128
|
+
@file = File.new( '.' )
|
129
|
+
elsif level == :lib
|
130
|
+
@file = File.new( File.join FIXTURE_PATH, 'css/lib/' )
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def parse type, text
|
135
|
+
parser = Fdlint::Parser::CSS::CssParser.new( text ).tap do |parser|
|
136
|
+
visitors = Fdlint::Rule.for_css_content.map do |validation|
|
137
|
+
validation.to_visitor file: @file
|
138
|
+
end
|
139
|
+
parser.add_visitors visitors
|
140
|
+
parser.send "parse_#{type}"
|
141
|
+
end
|
142
|
+
|
143
|
+
yield parser.results.flatten
|
144
|
+
end
|
145
|
+
|
163
146
|
end
|
164
147
|
|
165
148
|
end
|
@@ -2,72 +2,51 @@
|
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
4
|
|
5
|
-
require 'node'
|
6
|
-
require 'css/struct'
|
7
|
-
require 'css/rule/checklist'
|
5
|
+
require 'fdlint/parser/node'
|
6
|
+
require 'fdlint/parser/css/struct'
|
8
7
|
|
9
|
-
module
|
8
|
+
module FdlintTest
|
10
9
|
module CSS
|
11
10
|
module Rule
|
12
11
|
|
13
12
|
class CheckFileNameTest < Test::Unit::TestCase
|
14
13
|
|
15
|
-
include XRay::Rule
|
16
|
-
|
17
14
|
def setup
|
15
|
+
Fdlint::Rule.all
|
18
16
|
end
|
19
17
|
|
20
18
|
def test_file_name_with_ad
|
21
|
-
check 'css/ad.css' do |results|
|
22
|
-
|
23
|
-
assert_equal [expect_err], results, "文件名中不应出现ad"
|
19
|
+
check fixture_path('css/ad.css') do |results|
|
20
|
+
assert_has_result results, [:error, "路径和文件名中不应该出现ad"]
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
27
24
|
def test_path_name_with_ad
|
28
|
-
check "
|
29
|
-
|
30
|
-
assert_equal [expect_err], results, "文件路径中不应出现ad"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_file_name_without_ad
|
35
|
-
check 'not-exsiting-file.css' do |results|
|
36
|
-
assert results.empty?, "文件名中不应出现ad,包括路径"
|
25
|
+
check fixture_path( "css/adver/test.css" ) do |results|
|
26
|
+
assert_has_result results, [:error, "路径和文件名中不应该出现ad"]
|
37
27
|
end
|
38
28
|
end
|
39
29
|
|
40
30
|
def test_file_name_with_underscore
|
41
|
-
check '
|
42
|
-
|
43
|
-
assert_equal [expect_err], results, "文件名中单词的分隔符应该使用中横线“-”"
|
31
|
+
check fixture_path( 'css/using_id.css' ) do |results|
|
32
|
+
assert_has_result results, [:warn, "文件名中的连字符建议使用“-”而不是“_”"]
|
44
33
|
end
|
45
34
|
end
|
46
35
|
|
47
36
|
def test_file_name_with_upcase
|
48
|
-
check '
|
49
|
-
|
50
|
-
assert_equal [expect_err], results, "文件夹和文件命名必须用小写字母"
|
37
|
+
check fixture_path( 'css/camelCase.css' ) do |results|
|
38
|
+
assert_has_result results, [:error, "文件夹和文件命名必须用小写字母"]
|
51
39
|
end
|
52
40
|
end
|
53
41
|
|
54
|
-
|
55
|
-
check 'test-post-offer/main.css' do |results|
|
56
|
-
expect_err = ["文件夹只有需要版本区分时才可用中横线分隔,如fdev-v3", :error]
|
57
|
-
assert_equal [expect_err], results, "文件夹只有需要版本区分时才可用中横线分隔"
|
58
|
-
end
|
59
|
-
end
|
42
|
+
protected
|
60
43
|
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
def check(file, &block)
|
45
|
+
Fdlint::Validator.new( file ).tap do |validator|
|
46
|
+
validator.validate_file
|
47
|
+
yield validator.results
|
48
|
+
end
|
64
49
|
end
|
65
|
-
end
|
66
|
-
|
67
|
-
protected
|
68
|
-
def check(file, &block)
|
69
|
-
yield check_css_file(file)
|
70
|
-
end
|
71
50
|
|
72
51
|
end
|
73
52
|
|
data/test/default_test.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/helper.rb
CHANGED
@@ -9,33 +9,133 @@ end
|
|
9
9
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '../lib')
|
10
10
|
|
11
11
|
require 'test/unit'
|
12
|
-
require 'node'
|
13
|
-
require 'log_entry.rb'
|
14
|
-
require 'runner'
|
15
12
|
require 'pathname'
|
16
13
|
require 'logger'
|
17
14
|
|
15
|
+
require 'fdlint'
|
16
|
+
|
18
17
|
FIXTURE_ABS_PATH = File.expand_path(File.join( File.dirname(__FILE__) , '/fixtures' ))
|
19
18
|
FIXTURE_REL_PATH = Pathname.new(FIXTURE_ABS_PATH).relative_path_from(Pathname.new(File.expand_path '.'))
|
20
19
|
FIXTURE_PATH = FIXTURE_REL_PATH
|
21
20
|
|
22
|
-
XRay::Rule.import_all
|
23
|
-
|
24
|
-
module XRayTest
|
25
|
-
class Logger < ::Logger
|
26
|
-
def initialize
|
27
|
-
super(STDOUT)
|
28
|
-
debug = ARGV.include? '-d'
|
29
|
-
self.level = debug ? Logger::INFO : Logger::WARN
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
21
|
def has_ruby?(ver)
|
35
22
|
not `which ruby#{ver}`.empty?
|
36
23
|
end
|
37
24
|
|
38
25
|
def fixture(path)
|
39
|
-
IO.read
|
26
|
+
IO.read fixture_path( path )
|
27
|
+
end
|
28
|
+
|
29
|
+
def fixture_path( path )
|
30
|
+
File.join( FIXTURE_PATH, path )
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_has_result( results, condition, msg=nil)
|
34
|
+
level, text = *condition
|
35
|
+
assert(
|
36
|
+
results.index do |ret|
|
37
|
+
ret.level == level && ret.message == text
|
38
|
+
end,
|
39
|
+
msg
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def assert_not_has_result( results, condition, msg=nil)
|
44
|
+
level, text = *condition
|
45
|
+
assert_nil(
|
46
|
+
results.index do |ret|
|
47
|
+
ret.level == level && ret.message == text
|
48
|
+
end,
|
49
|
+
msg
|
50
|
+
)
|
40
51
|
end
|
41
52
|
|
53
|
+
module FdlintTest
|
54
|
+
|
55
|
+
module RuleTest
|
56
|
+
|
57
|
+
def self.extended(klass)
|
58
|
+
def klass.included(cls)
|
59
|
+
cls.send :include, FdlintTest::RuleTest
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.included(klass)
|
64
|
+
klass.send :extend, ClassMethods
|
65
|
+
klass.send :include, InstanceMethods
|
66
|
+
end
|
67
|
+
|
68
|
+
module ClassMethods
|
69
|
+
|
70
|
+
def check_rule expect, &block
|
71
|
+
@expect = expect
|
72
|
+
yield
|
73
|
+
end
|
74
|
+
|
75
|
+
def should_with_result expect=@expect, &block
|
76
|
+
level, msg = *expect
|
77
|
+
texts(&block).each_with_index do |src, i|
|
78
|
+
define_method "test_should_with_result_#{msg}_#{i}_#{src[0,20]}" do
|
79
|
+
parse src do |results|
|
80
|
+
assert_has_result results, expect, msg
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def should_without_result expect=@expect, &block
|
87
|
+
level, msg = *expect
|
88
|
+
texts(&block).each_with_index do |src, i|
|
89
|
+
define_method "test_should_without_result_#{msg}_#{i}" do
|
90
|
+
parse src do |results|
|
91
|
+
assert_not_has_result results, expect, msg
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def texts( &block )
|
98
|
+
texts = block.call
|
99
|
+
texts = [texts] if texts.is_a? String
|
100
|
+
texts
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module InstanceMethods
|
105
|
+
def parse text, &block
|
106
|
+
Fdlint::Validator.new( nil, :text => text, :syntax => syntax ).validate.tap do |results|
|
107
|
+
yield results if block_given?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
module HTML
|
115
|
+
include Fdlint::Parser::HTML
|
116
|
+
extend FdlintTest::RuleTest
|
117
|
+
|
118
|
+
def parser( text )
|
119
|
+
@parser ||= HtmlParser.new(text)
|
120
|
+
end
|
121
|
+
|
122
|
+
def syntax
|
123
|
+
:html
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
module JS
|
129
|
+
include Fdlint::Parser::JS
|
130
|
+
extend FdlintTest::RuleTest
|
131
|
+
|
132
|
+
def parser( text )
|
133
|
+
@parser ||= JsParser.new(text)
|
134
|
+
end
|
135
|
+
|
136
|
+
def syntax
|
137
|
+
:js
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
@@ -1,32 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require_relative '../helper'
|
3
|
-
require 'html/
|
4
|
-
require 'html/query'
|
3
|
+
require 'fdlint/parser/html/html_parser'
|
4
|
+
require 'fdlint/parser/html/query'
|
5
5
|
|
6
|
-
module
|
6
|
+
module FdlintTest
|
7
7
|
module HTML
|
8
8
|
|
9
9
|
class MixedTypeTest < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
12
|
-
@runner = ::XRay::Runner.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_check_html_script_and_style
|
16
|
-
html = %Q{<div class="mod">
|
17
|
-
<script> var a=1; </script>
|
18
|
-
<style>.mod {_font:arial;}</style>
|
19
|
-
</div>}
|
11
|
+
include FdlintTest::HTML
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
def test_check_html_script_and_style
|
14
|
+
src = %Q{<div class="mod">
|
15
|
+
<script> var a=1; </script>
|
16
|
+
<style>.mod {_font:arial;}</style>
|
17
|
+
</div>}
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
parse src do |results|
|
20
|
+
assert_has_result results, [:error, '必须存在文档类型声明']
|
21
|
+
assert_has_result results, [:error, '禁止使用未定义的变量(或全局变量)']
|
22
|
+
assert_has_result results, [:error, '合理使用hack']
|
23
|
+
end
|
30
24
|
end
|
31
25
|
|
32
26
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseCommentTest < Test::Unit::TestCase
|
8
8
|
|
9
|
-
include
|
10
|
-
|
9
|
+
include Fdlint::Parser::HTML
|
10
|
+
|
11
11
|
def test_simple_comment
|
12
12
|
parse('<!--content-->') do |e|
|
13
13
|
assert_equal CommentElement.new('content'), e
|
@@ -37,7 +37,7 @@ module XRayTest
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def parse(src, &block)
|
40
|
-
|
40
|
+
Fdlint::Parser::HTML::HtmlParser.parse(src, &block)
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative '../../helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module FdlintTest
|
4
4
|
module HTML
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
class ParseDTDTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
include
|
8
|
+
|
9
|
+
include Fdlint::Parser::HTML
|
10
10
|
|
11
11
|
def test_parse_html5_dtd
|
12
12
|
parse('<!DOCTYPE html>') do |e|
|
13
|
-
assert_equal DTDElement.new('html'), e
|
13
|
+
assert_equal Document.new(DTDElement.new('html')), e
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -20,9 +20,9 @@ module XRayTest
|
|
20
20
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">)
|
21
21
|
|
22
22
|
parse(src) do |e|
|
23
|
-
assert_equal DTDElement.new(%q(html
|
23
|
+
assert_equal Document.new(DTDElement.new(%q(html
|
24
24
|
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
25
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd")), e
|
25
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"))), e
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -36,7 +36,7 @@ module XRayTest
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def parse(src, &block)
|
39
|
-
|
39
|
+
HtmlParser.parse(src, &block)
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|