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
@@ -1,47 +1,45 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckBlockLevelElementTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
include
|
11
|
+
include FdlintTest::HTML
|
13
12
|
|
14
13
|
def setup
|
15
|
-
@
|
14
|
+
@block_level_err = [:error, "行内标签不得包含块级标签,a标签例外"]
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_check_normal
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
])
|
24
|
-
assert_equal [], @rule.check_html_tag(tag)
|
18
|
+
src = %Q{<div><span>good day, commander!</span></div>}
|
19
|
+
parse src do |results|
|
20
|
+
assert_not_has_result results, @block_level_err
|
21
|
+
end
|
25
22
|
end
|
26
23
|
|
27
24
|
def test_check_block_in_inline
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
])
|
33
|
-
assert_equal [["行内标签不得包含块级标签,a标签例外", :error]], @rule.check_html_tag(tag)
|
25
|
+
src = %Q{<span><div>good day, commander!</div></span>}
|
26
|
+
parse src do |results|
|
27
|
+
assert_has_result results, @block_level_err
|
28
|
+
end
|
34
29
|
end
|
35
30
|
|
36
31
|
def test_check_inline_inline_block
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
src = %Q{<span><span>good day, commander!</span></span>}
|
33
|
+
parse src do |results|
|
34
|
+
assert_not_has_result results, @block_level_err
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_check_block_in_a
|
39
|
+
src = %Q{<a><div>good day, commander!</div></a>}
|
40
|
+
parse src do |results|
|
41
|
+
assert_not_has_result results, @block_level_err
|
42
|
+
end
|
45
43
|
end
|
46
44
|
|
47
45
|
end
|
@@ -1,26 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckButtonTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
include
|
11
|
+
include FdlintTest::HTML
|
13
12
|
|
14
13
|
def setup
|
15
|
-
@
|
14
|
+
@button_err = [:error, "所有按钮必须用button(button/submit/reset)"]
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_check_normal
|
19
18
|
src = %q(<button type="button" name="usernmae" />
|
20
19
|
<button type="submit" name="male" />
|
21
20
|
<button type="reset" name="food" />)
|
22
|
-
|
23
|
-
|
21
|
+
parse src do |results|
|
22
|
+
assert_not_has_result results, @button_err
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -28,9 +27,10 @@ module XRayTest
|
|
28
27
|
src = %q(<input type="button" value="btn" />
|
29
28
|
<input type="submit" name="submit" value="submit"/>
|
30
29
|
<input type="reset" />)
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
|
31
|
+
src.each_line do |src|
|
32
|
+
parse src do |results|
|
33
|
+
assert_has_result results, @button_err
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -1,46 +1,28 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckCSSInHeadTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
-
end
|
11
|
+
include FdlintTest::HTML
|
15
12
|
|
16
|
-
|
17
|
-
tag = css_link('test.css')
|
18
|
-
assert_equal [], @rule.check_html_tag(tag)
|
19
|
-
end
|
13
|
+
check_rule [:warn, '外链CSS置于head里(例外:应用里的footer样式)'] do
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def test_check_css_tag_in_body
|
28
|
-
tag = css_link('test.css')
|
29
|
-
body = XRay::HTML::Element.new('body', nil, [tag])
|
30
|
-
assert_equal [["外链CSS置于head里(例外:应用里的footer样式)", :warn]], @rule.check_html_tag(tag)
|
31
|
-
end
|
15
|
+
should_with_result do
|
16
|
+
[
|
17
|
+
%Q{<link rel="stylesheet" href="test.css"/>},
|
18
|
+
%Q{<body><link rel="stylesheet" href="test.css"/></body>}
|
19
|
+
]
|
20
|
+
end
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
found = results.find_all do |res|
|
36
|
-
res.message == "外链CSS置于head里(例外:应用里的footer样式)"
|
22
|
+
should_without_result do
|
23
|
+
%Q{<head><link rel="stylesheet" href="test.css"/></head>}
|
37
24
|
end
|
38
|
-
assert_equal 1, found.size
|
39
|
-
end
|
40
25
|
|
41
|
-
protected
|
42
|
-
def css_link(src)
|
43
|
-
XRay::HTML::Element.new('link', {:rel => 'stylesheet', :href=>src}, [], :self)
|
44
26
|
end
|
45
27
|
|
46
28
|
end
|
@@ -48,6 +30,3 @@ module XRayTest
|
|
48
30
|
end
|
49
31
|
end
|
50
32
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
@@ -1,39 +1,43 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckDTDTest < Test::Unit::TestCase
|
11
10
|
|
11
|
+
include FdlintTest::HTML
|
12
|
+
|
12
13
|
def setup
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_check_html5_dtd
|
17
|
-
|
18
|
-
|
17
|
+
parse '<!DOCTYPE html>' do |results|
|
18
|
+
assert results.blank?
|
19
|
+
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def test_check_xhtml_dtd
|
22
23
|
src = %q(html
|
23
24
|
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
24
25
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd")
|
25
|
-
|
26
|
-
|
26
|
+
parse DTDElement.new(src).outer_html do |results|
|
27
|
+
assert_has_result results, [:warn, '推荐使用HTML 5 DTD']
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
31
|
def test_check_doctype_upcase
|
30
|
-
|
31
|
-
|
32
|
+
parse '<!doctype html>' do |results|
|
33
|
+
assert_has_result results, [:warn, '必须使用大写的"DOCTYPE"']
|
34
|
+
end
|
32
35
|
end
|
33
36
|
|
34
37
|
def test_check_dtd_available
|
35
|
-
|
36
|
-
|
38
|
+
parse '<html><body></body></html>' do |results|
|
39
|
+
assert_has_result results, [:error, '必须存在文档类型声明']
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
end
|
@@ -1,18 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckFormElementNameTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
include
|
11
|
+
include FdlintTest::HTML
|
13
12
|
|
14
13
|
def setup
|
15
|
-
@
|
14
|
+
@err = [:error, 'text、radio、checkbox、textarea、select必须加name属性']
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_check_normal
|
@@ -21,8 +20,10 @@ module XRayTest
|
|
21
20
|
<input type="checkbox" name="food" />
|
22
21
|
<textarea name="bio">test</textarea>
|
23
22
|
<select name="city"></select>)
|
24
|
-
|
25
|
-
|
23
|
+
src.each_line do |src|
|
24
|
+
parse src do |results|
|
25
|
+
assert_not_has_result results, @err
|
26
|
+
end
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
@@ -32,9 +33,9 @@ module XRayTest
|
|
32
33
|
<input type="checkbox" />
|
33
34
|
<textarea>test</textarea>
|
34
35
|
<select></select>)
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
src.each_line do |src|
|
37
|
+
parse src do |results|
|
38
|
+
assert_has_result results, @err
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -1,48 +1,42 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckHeadTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
include
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
tag = XRay::HTML::Element.new('head')
|
31
|
-
assert @rule.check_html_tag(tag).include?(@expect)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_check_head_without_meta
|
35
|
-
tag = XRay::HTML::Element.new('head',nil, [
|
36
|
-
Element.new('title', nil, [TextElement.new('hello world!')])
|
37
|
-
])
|
38
|
-
assert @rule.check_html_tag(tag).include?(@expect)
|
11
|
+
include FdlintTest::HTML
|
12
|
+
|
13
|
+
should_with_result [:error, "head必须包含字符集meta和title"] do
|
14
|
+
[
|
15
|
+
%Q{<head></head>},
|
16
|
+
|
17
|
+
%Q{<head>
|
18
|
+
<title>hello world!</title>
|
19
|
+
<meta name="description">
|
20
|
+
<meta name="keywords">
|
21
|
+
</head>},
|
22
|
+
|
23
|
+
%Q{<head>
|
24
|
+
<meta charset="utf-8">
|
25
|
+
<meta name="description">
|
26
|
+
<meta name="keywords">
|
27
|
+
</head>}
|
28
|
+
]
|
39
29
|
end
|
40
30
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
should_without_result [:error, "head必须包含字符集meta和title"] do
|
32
|
+
<<-SRC
|
33
|
+
<head>
|
34
|
+
<meta charset="utf-8">
|
35
|
+
<title>hello world!</title>
|
36
|
+
<meta name="description">
|
37
|
+
<meta name="keywords">
|
38
|
+
</head>
|
39
|
+
SRC
|
46
40
|
end
|
47
41
|
|
48
42
|
end
|
@@ -1,33 +1,39 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckHyperlinkWithTargetTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
-
end
|
11
|
+
include FdlintTest::HTML
|
15
12
|
|
16
|
-
|
17
|
-
tag = XRay::HTML::Element.new('a', {:href=>'#nogo', :target=>'_self'})
|
18
|
-
assert_equal [], @rule.check_html_tag(tag)
|
19
|
-
end
|
13
|
+
check_rule [:warn, '功能a必须加target="_self",除非preventDefault过'] do
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
should_with_result do
|
16
|
+
[
|
17
|
+
%Q{<a href="#nogo"></a>},
|
18
|
+
|
19
|
+
%Q{
|
20
|
+
<base target="_blank">
|
21
|
+
<a href="#nogo"></a>
|
22
|
+
}
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
should_without_result do
|
27
|
+
[
|
28
|
+
%Q{<a href="#nogo" target="_self"></a>},
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
%Q{
|
31
|
+
<base target="_self">
|
32
|
+
<a href="#nogo"></a>
|
33
|
+
}
|
34
|
+
]
|
35
|
+
end
|
28
36
|
|
29
|
-
tag = XRay::HTML::Element.new('a', {:href=>'#nogo'})
|
30
|
-
assert_equal [], @rule.check_html_tag(tag)
|
31
37
|
end
|
32
38
|
|
33
39
|
end
|
@@ -1,36 +1,29 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckHyperlinkWithTitleTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
-
end
|
11
|
+
include FdlintTest::HTML
|
15
12
|
|
16
|
-
|
17
|
-
tag = XRay::HTML::Element.new('a', {:href=>'#nogo', :title=>'it is a hyperlink', :target=>'_self'})
|
18
|
-
assert_equal [], @rule.check_html_tag(tag)
|
19
|
-
end
|
13
|
+
check_rule [:error, '非功能能点的a标签必须加上title属性'] do
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
15
|
+
should_with_result do
|
16
|
+
%Q{<a href="new-page.html"></a>}
|
17
|
+
end
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
should_without_result do
|
20
|
+
[
|
21
|
+
%Q{<a href="new-page.html" title="new page"></a>},
|
22
|
+
|
23
|
+
%Q{<a href="#nogo"></a>}
|
24
|
+
]
|
25
|
+
end
|
30
26
|
|
31
|
-
def test_check_normal_a_without_title
|
32
|
-
tag = XRay::HTML::Element.new('a', {:href=>'new-page.html'})
|
33
|
-
assert_equal [['非功能能点的a标签必须加上title属性', :error]], @rule.check_html_tag(tag)
|
34
27
|
end
|
35
28
|
|
36
29
|
end
|
@@ -1,36 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckIDAndClassPropCaseTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_check_downcase_id
|
17
|
-
prop = XRay::HTML::Property.new('id', 'uploader')
|
18
|
-
assert_equal [], @rule.check_html_property(prop)
|
19
|
-
end
|
11
|
+
include FdlintTest::HTML
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal [], @rule.check_html_property(prop)
|
13
|
+
should_with_result [:error, "id名称全部小写,单词分隔使用中横线"] do
|
14
|
+
%Q{<a id="Nogo" href="#nogo"></a>}
|
24
15
|
end
|
25
16
|
|
26
|
-
|
27
|
-
|
28
|
-
assert_equal [["id名称全部小写,单词分隔使用中横线", :error]], @rule.check_html_property(prop)
|
17
|
+
should_with_result [:error, "class名称全部小写"] do
|
18
|
+
%Q{<a class="Nogo" href="#nogo" target="_self"></a>}
|
29
19
|
end
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
assert_equal [["class名称全部小写,单词分隔使用中横线", :error]], @rule.check_html_property(prop)
|
21
|
+
should_with_result [:error, "class名称单词分隔使用中横线"] do
|
22
|
+
%Q{<a class="no_go" href="#nogo" target="_self"></a>}
|
34
23
|
end
|
35
24
|
|
36
25
|
end
|
@@ -1,26 +1,25 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckImgWithAltPropTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
-
end
|
11
|
+
include FdlintTest::HTML
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
check_rule [:error, 'img标签必须加上alt属性'] do
|
14
|
+
|
15
|
+
should_with_result do
|
16
|
+
%Q{<img src="http://pnq.cc/icon.png" />}
|
17
|
+
end
|
18
|
+
|
19
|
+
should_without_result do
|
20
|
+
%Q{<img src="http://pnq.cc/icon.png" alt="test" />}
|
21
|
+
end
|
20
22
|
|
21
|
-
def test_check_img_without_alt
|
22
|
-
tag = XRay::HTML::Element.new('img', {:src=>'http://pnq.cc/icon.png'}, [], :self)
|
23
|
-
assert_equal [["img标签必须加上alt属性", :error]], @rule.check_html_tag(tag)
|
24
23
|
end
|
25
24
|
|
26
25
|
end
|
@@ -1,32 +1,32 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckNoCSSImportTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
include
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
11
|
+
include FdlintTest::HTML
|
12
|
+
|
13
|
+
check_rule [:error, '不通过@import在页面上引入CSS'] do
|
14
|
+
|
15
|
+
should_with_result do
|
16
|
+
<<-SRC
|
17
|
+
<style>
|
18
|
+
@import "style.css"
|
19
|
+
</style>
|
20
|
+
SRC
|
21
|
+
end
|
22
|
+
|
23
|
+
should_without_result do
|
24
|
+
<<-SRC
|
25
|
+
<style>
|
26
|
+
body { background-color: #fff; }
|
27
|
+
</style>
|
28
|
+
SRC
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -1,28 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
4
|
|
6
|
-
module
|
5
|
+
module FdlintTest
|
7
6
|
module HTML
|
8
7
|
module Rule
|
9
8
|
|
10
9
|
class CheckPropHaveValueTest < Test::Unit::TestCase
|
11
10
|
|
12
|
-
include
|
11
|
+
include FdlintTest::HTML
|
13
12
|
|
14
|
-
|
15
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
16
|
-
end
|
13
|
+
check_rule [:error, '不能仅有属性名'] do
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
15
|
+
should_with_result do
|
16
|
+
%Q{<input type="radio" checked />}
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
should_without_result do
|
20
|
+
%Q{<input type="radio" checked="true" />}
|
21
|
+
end
|
26
22
|
end
|
27
23
|
|
28
24
|
end
|