fdlint 0.2.0.pre → 0.2.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.
- 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
data/test/js/rule_test.rb
CHANGED
@@ -5,7 +5,7 @@ require 'test/unit/ui/console/testrunner'
|
|
5
5
|
|
6
6
|
require File.expand_path('../helper', File.dirname(__FILE__))
|
7
7
|
|
8
|
-
module
|
8
|
+
module FdlintTest
|
9
9
|
|
10
10
|
module JS
|
11
11
|
|
@@ -21,8 +21,6 @@ module XRayTest
|
|
21
21
|
nest_try_catch_test
|
22
22
|
jq_check_test
|
23
23
|
no_global_test
|
24
|
-
all_test
|
25
|
-
file_checker_test
|
26
24
|
alert_check_test
|
27
25
|
private_method_check_test
|
28
26
|
)
|
@@ -43,5 +41,5 @@ module XRayTest
|
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
|
-
Test::Unit::UI::Console::TestRunner.run(
|
44
|
+
Test::Unit::UI::Console::TestRunner.run(FdlintTest::JS::RuleTest) if __FILE__ == $0
|
47
45
|
|
data/test/js/stat/if.rb
CHANGED
data/test/js/stat/iter.rb
CHANGED
data/test/js/stat/stat.rb
CHANGED
data/test/js/stat/switch.rb
CHANGED
data/test/js/stat/try.rb
CHANGED
data/test/js/stat/var.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
|
3
|
-
require 'node'
|
4
|
-
require 'parser_visitable'
|
3
|
+
require 'fdlint/parser/node'
|
4
|
+
require 'fdlint/parser/parser_visitable'
|
5
5
|
|
6
6
|
|
7
|
-
module
|
7
|
+
module FdlintTest
|
8
8
|
|
9
9
|
class ParserVisitableTest < Test::Unit::TestCase
|
10
10
|
|
11
|
-
Node
|
12
|
-
ParserVisitable =
|
11
|
+
Node = Fdlint::Parser::Node
|
12
|
+
ParserVisitable = Fdlint::Parser::ParserVisitable
|
13
13
|
|
14
14
|
class MockParser
|
15
15
|
|
16
16
|
include ParserVisitable
|
17
17
|
|
18
18
|
def parse_node
|
19
|
-
puts 'parse node'
|
20
|
-
|
21
19
|
parse_node_a
|
22
20
|
parse_node_b
|
23
21
|
|
@@ -25,12 +23,10 @@ module XRayTest
|
|
25
23
|
end
|
26
24
|
|
27
25
|
def parse_node_a
|
28
|
-
puts 'parse node a'
|
29
26
|
Node.new 'node a'
|
30
27
|
end
|
31
28
|
|
32
29
|
def parse_node_b
|
33
|
-
puts 'parse node b'
|
34
30
|
|
35
31
|
parse_node_c
|
36
32
|
|
@@ -38,63 +34,45 @@ module XRayTest
|
|
38
34
|
end
|
39
35
|
|
40
36
|
def parse_node_c
|
41
|
-
puts 'parse node c'
|
42
37
|
Node.new 'node c'
|
43
38
|
end
|
39
|
+
|
40
|
+
def source
|
41
|
+
end
|
44
42
|
|
45
43
|
end
|
46
44
|
|
47
45
|
class SimpleVisitor
|
48
46
|
|
49
|
-
def visit_node(node)
|
50
|
-
puts "visit node: #{node}"
|
47
|
+
def visit_node(node, source, parser)
|
51
48
|
['visit node', :info]
|
52
49
|
end
|
53
50
|
|
54
|
-
def visit_node_a(node)
|
55
|
-
puts "visit node a: #{node}"
|
51
|
+
def visit_node_a(node, source, parser)
|
56
52
|
['visit node a', :warn]
|
57
53
|
end
|
58
54
|
|
59
|
-
def visit_node_b(node)
|
60
|
-
puts "visit node b: #{node}"
|
55
|
+
def visit_node_b(node, source, parser)
|
61
56
|
[
|
62
57
|
['visit node b 1', :warn],
|
63
58
|
['visit node b 2', :info]
|
64
59
|
]
|
65
60
|
end
|
66
61
|
|
67
|
-
def visit_node_c(node)
|
68
|
-
puts "visit node c: #{node}"
|
62
|
+
def visit_node_c(node, source, parser)
|
69
63
|
['visit node c', :warn]
|
70
64
|
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class SimpleObserver
|
74
|
-
attr_reader :times
|
75
65
|
|
76
|
-
def update(result, parser)
|
77
|
-
puts "observer: #{result}"
|
78
|
-
@times ||= 0
|
79
|
-
@times += 1
|
80
|
-
end
|
81
66
|
end
|
82
67
|
|
83
|
-
|
84
68
|
def test_default
|
85
69
|
parser = MockParser.new
|
86
70
|
|
87
|
-
|
88
|
-
parser.add_visitor SimpleVisitor.new
|
89
|
-
|
90
|
-
observer = SimpleObserver.new
|
91
|
-
parser.add_observer observer
|
92
|
-
|
71
|
+
parser.add_visitors SimpleVisitor.new
|
93
72
|
parser.parse_node
|
94
73
|
|
95
74
|
results = parser.results
|
96
|
-
assert_equal
|
97
|
-
assert_equal 5, observer.times
|
75
|
+
assert_equal 4, results.length
|
98
76
|
end
|
99
77
|
|
100
78
|
end
|
data/test/position_info_test.rb
CHANGED
@@ -2,15 +2,14 @@
|
|
2
2
|
|
3
3
|
require_relative 'helper'
|
4
4
|
|
5
|
-
require 'position_info'
|
5
|
+
require 'fdlint/parser/position_info'
|
6
6
|
|
7
|
-
module
|
7
|
+
module FdlintTest
|
8
8
|
|
9
9
|
class PositionInfoTest < Test::Unit::TestCase
|
10
10
|
|
11
|
-
PositionInfo =
|
12
|
-
|
13
|
-
Position = XRay::Position
|
11
|
+
PositionInfo = Fdlint::Parser::PositionInfo
|
12
|
+
Position = Fdlint::Parser::Position
|
14
13
|
|
15
14
|
@@test_paragraph = %(this is line one
|
16
15
|
this is line two this is line two
|
@@ -2,54 +2,59 @@
|
|
2
2
|
require 'test/unit'
|
3
3
|
require_relative '../helper'
|
4
4
|
|
5
|
-
module
|
5
|
+
module FdlintTest
|
6
6
|
|
7
7
|
module Runner
|
8
8
|
|
9
9
|
class LogLevelTest < Test::Unit::TestCase
|
10
10
|
|
11
11
|
def setup
|
12
|
-
@runner = XRay::Runner.new
|
13
12
|
@html = fixture('html/mixed_log_levels.html')
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_output_every_thing_by_default
|
17
|
-
|
18
|
-
|
16
|
+
validate do |res|
|
17
|
+
assert_contain( res, :fatal, :error, :warn )
|
18
|
+
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_output_fatals_only
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
validate :fatal do |res|
|
23
|
+
assert_contain( res, :fatal )
|
24
|
+
assert_not_contain( res, :error, :warn )
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def _test_output_fatals_and_errors
|
29
|
+
validate :error do |res|
|
30
|
+
assert_contain( res, :fatal, :error )
|
31
|
+
assert_not_contain( res, :error, :warn )
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def _test_output_fatals_errors_and_warnnings
|
36
|
+
validate :warn do |res|
|
37
|
+
assert_contain( res, :fatal, :error, :warn )
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
|
-
|
43
|
-
types
|
44
|
-
|
42
|
+
|
43
|
+
def assert_contain( results, *types )
|
44
|
+
types.each do |type|
|
45
|
+
assert( results.any? { |r| r.level == type } )
|
46
|
+
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def assert_not_contain( results, *types )
|
50
|
+
types.each do |type|
|
51
|
+
assert( ! (results.any? { |r| r.level == type } ) )
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate log_level=nil
|
56
|
+
yield Fdlint::Validator.new( nil, text: @html, log_level: log_level ).validate
|
51
57
|
end
|
52
|
-
end
|
53
58
|
|
54
59
|
end
|
55
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fdlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- qhwa,bencode
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -109,7 +109,6 @@ files:
|
|
109
109
|
- bin/fdlint
|
110
110
|
- lib/fdlint.rb
|
111
111
|
- lib/fdlint/cli.rb
|
112
|
-
- lib/fdlint/file_validator.rb
|
113
112
|
- lib/fdlint/helper/code_type.rb
|
114
113
|
- lib/fdlint/helper/file_reader.rb
|
115
114
|
- lib/fdlint/helper/logger.rb
|
@@ -121,7 +120,6 @@ files:
|
|
121
120
|
- lib/fdlint/parser/encoding_error.rb
|
122
121
|
- lib/fdlint/parser/html/html_parser.rb
|
123
122
|
- lib/fdlint/parser/html/query.rb
|
124
|
-
- lib/fdlint/parser/html/rule/check_tag_rule.rb
|
125
123
|
- lib/fdlint/parser/html/struct.rb
|
126
124
|
- lib/fdlint/parser/js/expr/expr.rb
|
127
125
|
- lib/fdlint/parser/js/expr/left_hand.rb
|
@@ -151,10 +149,12 @@ files:
|
|
151
149
|
- lib/fdlint/support/core/file.rb
|
152
150
|
- lib/fdlint/support/core/hash.rb
|
153
151
|
- lib/fdlint/support/core/nil.rb
|
152
|
+
- lib/fdlint/support/core/object.rb
|
154
153
|
- lib/fdlint/support/core/string.rb
|
155
154
|
- lib/fdlint/support/core_ext.rb
|
156
155
|
- lib/fdlint/validator.rb
|
157
156
|
- lib/fdlint/version.rb
|
157
|
+
- lib/hook/git_pre_commit
|
158
158
|
- rules.d/css.rule.rb
|
159
159
|
- rules.d/filename.rule.rb
|
160
160
|
- rules.d/html.rule.rb
|
@@ -169,10 +169,12 @@ files:
|
|
169
169
|
- test/css/parser_test.rb
|
170
170
|
- test/css/rule/check_encoding_test.rb
|
171
171
|
- test/css/rule/check_list_rule_test.rb
|
172
|
-
- test/css/rule/compression_test.rb
|
173
172
|
- test/css/rule/file_name_test.rb
|
174
173
|
- test/default_test.rb
|
174
|
+
- test/fixtures/css/ad.css
|
175
|
+
- test/fixtures/css/adver/test.css
|
175
176
|
- test/fixtures/css/broken.css
|
177
|
+
- test/fixtures/css/camelCase.css
|
176
178
|
- test/fixtures/css/cbu/36.css
|
177
179
|
- test/fixtures/css/cbu/china_top.css
|
178
180
|
- test/fixtures/css/cbu/default-merge.css
|
@@ -199,6 +201,8 @@ files:
|
|
199
201
|
- test/fixtures/css/mac-line-sep-err.css
|
200
202
|
- test/fixtures/css/mac-line-sep-good-min.css
|
201
203
|
- test/fixtures/css/mac-line-sep-good.css
|
204
|
+
- test/fixtures/css/min/ad.css
|
205
|
+
- test/fixtures/css/min/ad.min.css
|
202
206
|
- test/fixtures/css/multi-encoding-in-a-file.css
|
203
207
|
- test/fixtures/css/simple.css
|
204
208
|
- test/fixtures/css/using_expr.css
|
@@ -268,12 +272,10 @@ files:
|
|
268
272
|
- test/html/query_test.rb
|
269
273
|
- test/html/rule/check_block_level_element_test.rb
|
270
274
|
- test/html/rule/check_button_test.rb
|
271
|
-
- test/html/rule/check_class_count_test.rb
|
272
275
|
- test/html/rule/check_css_in_head_test.rb
|
273
276
|
- test/html/rule/check_dtd_test.rb
|
274
277
|
- test/html/rule/check_form_element_name_test.rb
|
275
278
|
- test/html/rule/check_head_contain_meta_and_title_test.rb
|
276
|
-
- test/html/rule/check_html_template_test.rb
|
277
279
|
- test/html/rule/check_hyperlink_with_target_test.rb
|
278
280
|
- test/html/rule/check_hyperlink_with_title_test.rb
|
279
281
|
- test/html/rule/check_id_n_class_downcase_test.rb
|
@@ -293,9 +295,7 @@ files:
|
|
293
295
|
- test/js/expr/primary.rb
|
294
296
|
- test/js/parser_test.rb
|
295
297
|
- test/js/rule/alert_check_test.rb
|
296
|
-
- test/js/rule/all_test.rb
|
297
298
|
- test/js/rule/base_test.rb
|
298
|
-
- test/js/rule/file_checker_test.rb
|
299
299
|
- test/js/rule/jq_check_test.rb
|
300
300
|
- test/js/rule/nest_try_catch_test.rb
|
301
301
|
- test/js/rule/new_object_and_new_array_test.rb
|
@@ -315,10 +315,7 @@ files:
|
|
315
315
|
- test/js/stat/var.rb
|
316
316
|
- test/parser_visitable_test.rb
|
317
317
|
- test/position_info_test.rb
|
318
|
-
- test/rule_dsl/dsl_basic_test.rb
|
319
|
-
- test/rule_dsl/importing_test.rb
|
320
318
|
- test/runner/log_level_test.rb
|
321
|
-
- test/test_helper.rb
|
322
319
|
homepage: https://github.com/qhwa/fdlint
|
323
320
|
licenses: []
|
324
321
|
metadata: {}
|
@@ -336,9 +333,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
336
333
|
version: '0'
|
337
334
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
338
335
|
requirements:
|
339
|
-
- - "
|
336
|
+
- - ">="
|
340
337
|
- !ruby/object:Gem::Version
|
341
|
-
version:
|
338
|
+
version: '0'
|
342
339
|
requirements: []
|
343
340
|
rubyforge_project:
|
344
341
|
rubygems_version: 2.2.2
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module XRay
|
2
|
-
|
3
|
-
class FileValidator
|
4
|
-
def initialize( options )
|
5
|
-
@options = options
|
6
|
-
@validators = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def add_validator( val )
|
10
|
-
@validators << val
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_validators( vals)
|
14
|
-
vals.each { |val| add_validator val }
|
15
|
-
end
|
16
|
-
|
17
|
-
def check( file )
|
18
|
-
results = []
|
19
|
-
@validators.each do |val|
|
20
|
-
if val.respond_to? :check_file
|
21
|
-
val_results = val.check_file(file)
|
22
|
-
if val_results
|
23
|
-
if val_results.is_a? Array
|
24
|
-
results.concat val_results
|
25
|
-
else
|
26
|
-
results << val_results
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
results
|
32
|
-
end
|
33
|
-
|
34
|
-
alias_method :validate, :check
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../../rule'
|
3
|
-
require_relative '../struct'
|
4
|
-
require_relative '../query'
|
5
|
-
require_relative '../../context'
|
6
|
-
|
7
|
-
module XRay
|
8
|
-
module HTML
|
9
|
-
module Rule
|
10
|
-
|
11
|
-
class CheckTagRule
|
12
|
-
|
13
|
-
include ::XRay::Rule, Context
|
14
|
-
|
15
|
-
attr_reader :imported_scripts, :imported_css
|
16
|
-
|
17
|
-
def initialize(opt=nil)
|
18
|
-
@imported_scripts, @imported_css = [], []
|
19
|
-
end
|
20
|
-
|
21
|
-
def script_used?( src )
|
22
|
-
@imported_scripts.include? src
|
23
|
-
end
|
24
|
-
|
25
|
-
def style_used?( src )
|
26
|
-
@imported_css.include? src
|
27
|
-
end
|
28
|
-
|
29
|
-
def visit_doc(html)
|
30
|
-
check_html_doc html
|
31
|
-
end
|
32
|
-
|
33
|
-
def visit_dtd(dtd)
|
34
|
-
@have_dtd = true
|
35
|
-
check_html_dtd dtd
|
36
|
-
end
|
37
|
-
|
38
|
-
def visit_tag(tag)
|
39
|
-
results = check_html_tag tag
|
40
|
-
record_script(tag) or record_style(tag)
|
41
|
-
results
|
42
|
-
end
|
43
|
-
|
44
|
-
def visit_text(tag)
|
45
|
-
check_html_text tag
|
46
|
-
end
|
47
|
-
|
48
|
-
def visit_property(prop)
|
49
|
-
check_html_property prop
|
50
|
-
end
|
51
|
-
|
52
|
-
def record_script( tag )
|
53
|
-
if tag.tag_name_equal? 'script'
|
54
|
-
src = tag.prop_value(:src).to_s
|
55
|
-
unless src.empty? or script_used? src
|
56
|
-
@imported_scripts << src
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def record_style( tag )
|
62
|
-
if tag.tag_name_equal? 'link' and tag.prop_value(:rel) =~ /stylesheet/i
|
63
|
-
src = tag.prop_value(:href).to_s
|
64
|
-
unless src.empty? or style_used? src
|
65
|
-
@imported_css << src
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def has_dtd?
|
71
|
-
@have_dtd
|
72
|
-
end
|
73
|
-
|
74
|
-
alias_method :have_dtd?, :has_dtd?
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative '../../helper'
|
3
|
-
|
4
|
-
require 'file_validator'
|
5
|
-
require 'css/rule/check_compression_rule'
|
6
|
-
|
7
|
-
module XRayTest
|
8
|
-
module CSS
|
9
|
-
module Rule
|
10
|
-
|
11
|
-
class CompressionTest < Test::Unit::TestCase
|
12
|
-
|
13
|
-
def setup
|
14
|
-
@validator = XRay::FileValidator.new( :encoding => 'gb2312' )
|
15
|
-
@validator.add_validator XRay::CSS::Rule::CompressionChecker.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_source_file_with_min
|
19
|
-
file = "#{FIXTURE_PATH}/css/empty.css"
|
20
|
-
results = @validator.check file
|
21
|
-
|
22
|
-
assert results.empty?, "同目录下有min文件,测试应通过"
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_source_file_without_min
|
26
|
-
file = "#{FIXTURE_PATH}/css/import.css"
|
27
|
-
results = @validator.check file
|
28
|
-
|
29
|
-
expect_err = XRay::LogEntry.new('发布上线的文件需要压缩,命名规则如a.js->a-min.js,且两者在同一目录下', :error)
|
30
|
-
assert_equal [expect_err], results, "同目录下没有对应的min文件,测试不应通过"
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_merge_file
|
34
|
-
file = 'merge.css'
|
35
|
-
results = @validator.check file
|
36
|
-
|
37
|
-
assert results.empty?, "merge文件不需要被压缩"
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_min_file
|
41
|
-
file = 'test-min.css'
|
42
|
-
results = @validator.check file
|
43
|
-
|
44
|
-
assert results.empty?, "本身已经被压缩,不需要再检查"
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require_relative '../../helper'
|
4
|
-
require 'html/rule/check_tag_rule'
|
5
|
-
|
6
|
-
module XRayTest
|
7
|
-
module HTML
|
8
|
-
module Rule
|
9
|
-
|
10
|
-
class CheckClassCountTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
def setup
|
13
|
-
@rule = XRay::HTML::Rule::CheckTagRule.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_check_normal
|
17
|
-
prop = XRay::HTML::Property.new('class', 'info')
|
18
|
-
assert_equal [], @rule.check_html_property(prop)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_check_too_many_classes
|
22
|
-
prop = XRay::HTML::Property.new('class', 'info new red bigger')
|
23
|
-
expected = ["一个节点上定义的class个数最多不超过3个(不含lib中的class)", :error]
|
24
|
-
assert_equal [expected], @rule.check_html_property(prop)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_check_filter_fdev_classes
|
28
|
-
prop = XRay::HTML::Property.new('class', 'info new red fd-main w952 layout grid layout- grid-')
|
29
|
-
assert_equal [], @rule.check_html_property(prop)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|