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
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'colored'
|
2
3
|
|
3
4
|
module Fdlint
|
@@ -6,36 +7,23 @@ module Fdlint
|
|
6
7
|
|
7
8
|
class ConsolePrinter < BasePrinter
|
8
9
|
|
10
|
+
def pre_validate( file )
|
11
|
+
Kernel.print "\n---> reviewing " << file.to_s << " "
|
12
|
+
end
|
13
|
+
|
9
14
|
def print( file, source, results )
|
10
15
|
|
11
16
|
super
|
12
|
-
|
13
|
-
if source
|
14
|
-
print_with_source
|
15
|
-
else
|
16
|
-
if @results && @results.empty?
|
17
|
-
puts "[OK] ".green << file.to_s
|
18
|
-
else
|
19
|
-
puts "[EE] ".red << file.to_s
|
20
|
-
|
21
|
-
@results.each do |r|
|
22
|
-
print_log_entry r
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def print_with_source
|
17
|
+
|
29
18
|
if @results.empty?
|
30
|
-
puts "[
|
19
|
+
puts " [✔]\n".green
|
31
20
|
else
|
32
|
-
puts "[
|
21
|
+
puts " [✗]\n".yellow
|
33
22
|
|
34
23
|
@results.each do |r|
|
35
24
|
print_log_entry r
|
36
25
|
end
|
37
26
|
end
|
38
|
-
|
39
27
|
|
40
28
|
end
|
41
29
|
|
@@ -49,11 +37,15 @@ module Fdlint
|
|
49
37
|
indent = ' ' * ( col - left )
|
50
38
|
|
51
39
|
puts " #{log_text entry}\n"
|
52
|
-
|
53
|
-
|
40
|
+
if source
|
41
|
+
puts " #{source.lines.to_a[row][left..right].gsub(/\t/, ' ')}"
|
42
|
+
puts " #{indent}^"
|
43
|
+
end
|
54
44
|
else
|
55
|
-
puts " #{log_text entry}
|
45
|
+
puts " #{log_text entry}"
|
56
46
|
end
|
47
|
+
|
48
|
+
puts "\n"
|
57
49
|
end
|
58
50
|
|
59
51
|
|
data/lib/fdlint/rule.rb
CHANGED
@@ -19,7 +19,7 @@ module Fdlint
|
|
19
19
|
#
|
20
20
|
# Returns an Array holding all validations for this file
|
21
21
|
def validations_for_file( opt={} )
|
22
|
-
(all[opt[:
|
22
|
+
(all[opt[:syntax]] || []).select do |validation|
|
23
23
|
validation.scope == :file
|
24
24
|
end
|
25
25
|
end
|
@@ -63,9 +63,9 @@ module Fdlint
|
|
63
63
|
debug { "done" }
|
64
64
|
end
|
65
65
|
|
66
|
-
def add(
|
67
|
-
debug { " -> adding rule: #{
|
68
|
-
cache = @rules[
|
66
|
+
def add( syntax, scope, opt )
|
67
|
+
debug { " -> adding rule: #{syntax.inspect} - #{scope.inspect} - #{opt[:desc]}" }
|
68
|
+
cache = @rules[syntax] ||= []
|
69
69
|
cache << Validation.new( scope, opt[:block] ).tap do |v|
|
70
70
|
v.desc = opt[:desc]
|
71
71
|
v.uri = opt[:uri]
|
data/lib/fdlint/validator.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fdlint/rule'
|
2
|
+
require 'fdlint/helper/file_reader'
|
2
3
|
require 'fdlint/helper/code_type'
|
3
4
|
require 'fdlint/parser'
|
4
5
|
require 'fdlint/parser/js/js_parser'
|
@@ -9,13 +10,15 @@ module Fdlint
|
|
9
10
|
|
10
11
|
class Validator
|
11
12
|
|
12
|
-
attr_reader :file, :source, :results, :
|
13
|
+
attr_reader :file, :source, :results, :syntax, :log_level
|
14
|
+
|
13
15
|
include Fdlint::Helper::Logger
|
14
16
|
|
15
17
|
def initialize( path = nil, options = {} )
|
16
18
|
@file = path
|
17
19
|
@source = options[:text]
|
18
|
-
@
|
20
|
+
@syntax = options[:syntax] || Helper::CodeType.guess( source, file )
|
21
|
+
@log_level = options[:log_level]
|
19
22
|
end
|
20
23
|
|
21
24
|
def validate
|
@@ -30,7 +33,13 @@ module Fdlint
|
|
30
33
|
results << InvalidFileEncoding.new
|
31
34
|
end
|
32
35
|
|
33
|
-
|
36
|
+
filter_results_by_log_level if log_level
|
37
|
+
|
38
|
+
if block_given?
|
39
|
+
yield file, source, results
|
40
|
+
else
|
41
|
+
results
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
def validate_file
|
@@ -65,8 +74,45 @@ module Fdlint
|
|
65
74
|
end
|
66
75
|
|
67
76
|
def parse
|
68
|
-
parser.parse_no_throw
|
69
|
-
parser.results
|
77
|
+
root = parser.parse_no_throw
|
78
|
+
parser.results.tap do |results|
|
79
|
+
if root.respond_to? :query
|
80
|
+
parse_inline_script( root, results )
|
81
|
+
parse_inline_stylesheet( root, results )
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def parse_inline_script( root, results )
|
87
|
+
root.query('script') do |script|
|
88
|
+
|
89
|
+
next if script.has_prop?( :src )
|
90
|
+
|
91
|
+
script_row = script.position.row
|
92
|
+
script_col = script.outer_html[/^\s*<script*?>/i].size
|
93
|
+
src = script.text
|
94
|
+
|
95
|
+
Validator.new( nil, :text => src, :syntax => :js ).validate.each do |ret|
|
96
|
+
ret.column += script_col if ret.row == 1
|
97
|
+
ret.row += script_row - 1
|
98
|
+
results << ret
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse_inline_stylesheet( root, results )
|
104
|
+
root.query('style') do |style|
|
105
|
+
|
106
|
+
style_row = style.position.row
|
107
|
+
style_col = style.outer_html[/^\s*<style*?>/i].size
|
108
|
+
src = style.text
|
109
|
+
|
110
|
+
Validator.new( nil, :text => src, :syntax => :css ).validate.each do |ret|
|
111
|
+
ret.column += style_col if ret.row == 1
|
112
|
+
ret.row += style_row - 1
|
113
|
+
results << ret
|
114
|
+
end
|
115
|
+
end
|
70
116
|
end
|
71
117
|
|
72
118
|
def parser
|
@@ -78,7 +124,7 @@ module Fdlint
|
|
78
124
|
:js => ::Fdlint::Parser::JS::JsParser,
|
79
125
|
:css => ::Fdlint::Parser::CSS::CssParser,
|
80
126
|
:html => ::Fdlint::Parser::HTML::HtmlParser
|
81
|
-
}.fetch(
|
127
|
+
}.fetch( syntax ).new( source )
|
82
128
|
|
83
129
|
file = File.new(self.file) if self.file
|
84
130
|
|
@@ -90,11 +136,17 @@ module Fdlint
|
|
90
136
|
end
|
91
137
|
|
92
138
|
def content_level_rules
|
93
|
-
Fdlint::Rule.send( :"for_#{
|
139
|
+
Fdlint::Rule.send( :"for_#{syntax}_content" )
|
94
140
|
end
|
95
141
|
|
96
142
|
def file_level_rules
|
97
|
-
Fdlint::Rule.for_file( :
|
143
|
+
Fdlint::Rule.for_file( :syntax => syntax )
|
144
|
+
end
|
145
|
+
|
146
|
+
def filter_results_by_log_level
|
147
|
+
@results.select! do |r|
|
148
|
+
LogEntry.level_greater_or_equal? r.level, log_level
|
149
|
+
end
|
98
150
|
end
|
99
151
|
|
100
152
|
end
|
data/lib/fdlint/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
html_path = "spec_results.html"
|
2
|
+
`spec -f h:#{html_path} -f p spec` # run the spec. send progress to screen. save html results to html_path
|
3
|
+
|
4
|
+
# find out how many errors were found
|
5
|
+
html = open(html_path).read
|
6
|
+
examples = html.match(/(\d+) examples/)[0].to_i rescue 0
|
7
|
+
failures = html.match(/(\d+) failures/)[0].to_i rescue 0
|
8
|
+
pending = html.match(/(\d+) pending/)[0].to_i rescue 0
|
9
|
+
|
10
|
+
if failures.zero?
|
11
|
+
puts "0 failures! #{examples} run, #{pending} pending"
|
12
|
+
else
|
13
|
+
puts "\aDID NOT COMMIT YOUR FILES!"
|
14
|
+
puts "View spec results at #{File.expand_path(html_path)}"
|
15
|
+
puts
|
16
|
+
puts "#{failures} failures! #{examples} run, #{pending} pending"
|
17
|
+
exit 1
|
18
|
+
end
|
data/rules.d/css.rule.rb
CHANGED
data/rules.d/filename.rule.rb
CHANGED
@@ -2,7 +2,7 @@ rules_for 'css', 'js'
|
|
2
2
|
|
3
3
|
review( 'file' ) {
|
4
4
|
rule { |file|
|
5
|
-
|
5
|
+
AD_REG ||= /(?:[^a-z0-9%_-]|^)
|
6
6
|
#以ad开头,与后面文字组合,构成常见的广告单词
|
7
7
|
ad
|
8
8
|
(?:
|
@@ -12,6 +12,8 @@ review( 'file' ) {
|
|
12
12
|
|fshow|pic|vert|view|info|click|sponsor|banner
|
13
13
|
|click|ver|name|x|log|
|
14
14
|
)/x
|
15
|
+
|
16
|
+
if file.path =~ AD_REG
|
15
17
|
error '路径和文件名中不应该出现ad'
|
16
18
|
end
|
17
19
|
}
|
data/rules.d/html.rule.rb
CHANGED
@@ -24,8 +24,12 @@ review( 'property' ) { |prop|
|
|
24
24
|
error "不能定义内嵌样式style"
|
25
25
|
end
|
26
26
|
|
27
|
-
if prop =~ /[A-
|
28
|
-
error "
|
27
|
+
if prop =~ /[A-Z]/
|
28
|
+
error "属性名必须小写"
|
29
|
+
end
|
30
|
+
|
31
|
+
if prop =~ /_/
|
32
|
+
error "属性名连字符用中横线"
|
29
33
|
end
|
30
34
|
|
31
35
|
if prop =~ 'id' and prop.value =~ /[A-Z]/
|
@@ -33,7 +37,10 @@ review( 'property' ) { |prop|
|
|
33
37
|
end
|
34
38
|
|
35
39
|
if prop =~ 'class' and prop.value =~ /[A-Z]/
|
36
|
-
error "class
|
40
|
+
error "class名称全部小写"
|
41
|
+
end
|
42
|
+
if prop =~ 'class' and prop.value =~ /[_]/
|
43
|
+
error "class名称单词分隔使用中横线"
|
37
44
|
end
|
38
45
|
|
39
46
|
if prop.value and prop.sep != '"'
|
@@ -67,16 +74,22 @@ review( 'tag' ) { |tag|
|
|
67
74
|
|
68
75
|
review( 'tag' ) {
|
69
76
|
|
77
|
+
has_target = false
|
78
|
+
|
79
|
+
before( 'doc' ) {
|
80
|
+
has_target = false
|
81
|
+
}
|
82
|
+
|
70
83
|
# <base target='_self'>
|
71
84
|
after( 'tag' ) { |tag|
|
72
|
-
if tag =~ 'base' and tag
|
73
|
-
|
85
|
+
if tag =~ 'base' and tag['target'] == '_self'
|
86
|
+
has_target = true
|
74
87
|
end
|
75
88
|
}
|
76
89
|
|
77
90
|
rule { |tag|
|
78
|
-
unless
|
79
|
-
if tag =~ 'a' and tag.prop_value('href') =~ /^#/ and tag
|
91
|
+
unless has_target
|
92
|
+
if tag =~ 'a' and tag.prop_value('href') =~ /^#/ and tag['target'] != '_self'
|
80
93
|
warn '功能a必须加target="_self",除非preventDefault过'
|
81
94
|
end
|
82
95
|
end
|
@@ -84,34 +97,34 @@ review( 'tag' ) {
|
|
84
97
|
|
85
98
|
}
|
86
99
|
|
87
|
-
|
100
|
+
group( 'uniq links' ) {
|
88
101
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
elsif tag.stylesheet_link?
|
97
|
-
src = tag['href'].to_s
|
98
|
-
if !src.empty?
|
99
|
-
@styles_used ||= []
|
100
|
-
@styles_used << src
|
101
|
-
end
|
102
|
-
end
|
102
|
+
scripts_used = nil
|
103
|
+
styles_used = nil
|
104
|
+
|
105
|
+
before( 'doc' ) {
|
106
|
+
scripts_used = []
|
107
|
+
styles_used = []
|
103
108
|
}
|
104
109
|
|
105
|
-
|
110
|
+
review( 'tag' ) { |tag|
|
106
111
|
if tag =~ 'script'
|
107
112
|
src = tag['src'].to_s
|
108
|
-
if
|
109
|
-
|
113
|
+
if src.present?
|
114
|
+
if scripts_used.include?( src )
|
115
|
+
error "避免重复引用同一文件"
|
116
|
+
else
|
117
|
+
scripts_used << src
|
118
|
+
end
|
110
119
|
end
|
111
120
|
elsif tag.stylesheet_link?
|
112
|
-
src = tag['
|
113
|
-
if
|
114
|
-
|
121
|
+
src = tag['href'].to_s
|
122
|
+
if src.present?
|
123
|
+
if styles_used.include?( src )
|
124
|
+
error "避免重复引用同一文件"
|
125
|
+
else
|
126
|
+
styles_used << src
|
127
|
+
end
|
115
128
|
end
|
116
129
|
end
|
117
130
|
}
|
@@ -152,8 +165,8 @@ review( 'tag' ) { |tag|
|
|
152
165
|
end
|
153
166
|
|
154
167
|
if tag.stylesheet_link?
|
155
|
-
if
|
156
|
-
|
168
|
+
if !tag.in_scope?('head')
|
169
|
+
warn "外链CSS置于head里(例外:应用里的footer样式)"
|
157
170
|
end
|
158
171
|
end
|
159
172
|
|
@@ -162,8 +175,8 @@ review( 'tag' ) { |tag|
|
|
162
175
|
end
|
163
176
|
}
|
164
177
|
|
165
|
-
review( 'text_tag' ) do |text_tag|
|
166
|
-
if text_tag.text =~ /[<>]/
|
178
|
+
review( 'text_tag' ) do |text_tag, source, file|
|
179
|
+
if text_tag.text =~ /[<>]/ && !(text_tag.in_scope?('script') || text_tag.in_scope?('style'))
|
167
180
|
error "特殊HTML符号(>和<)必须转义"
|
168
181
|
end
|
169
182
|
end
|
data/rules.d/js.rule.rb
CHANGED
@@ -102,7 +102,7 @@ review( 'expr_equal' ) { |expr|
|
|
102
102
|
end
|
103
103
|
}
|
104
104
|
|
105
|
-
review( '
|
105
|
+
review( 'stat_try' ) { |stat|
|
106
106
|
if stat.try_part.contains?('try') ||
|
107
107
|
stat.catch_part && (stat.catch_part.contains? 'try') ||
|
108
108
|
stat.finally_part && (stat.finally_part.contains? 'try')
|
@@ -187,7 +187,7 @@ review( 'statement' ) { |stat, source, file, parser|
|
|
187
187
|
|
188
188
|
review( 'expr_logical_or' ) { |expr, source|
|
189
189
|
if expr.left && expr.right
|
190
|
-
left = expr.position.pos -
|
190
|
+
left = expr.position.pos - 1
|
191
191
|
unless expr.type == "(" || expr.type == "."
|
192
192
|
unless source[left, expr.type.size + 2] == (" " << expr.type << " ")
|
193
193
|
error '操作符(如, +/-/*/% 等)两边留空'
|
data/test/all_tests.rb
CHANGED
@@ -2,6 +2,9 @@ gem 'test-unit' if defined? gem
|
|
2
2
|
require 'test/unit'
|
3
3
|
require 'test/unit/testsuite'
|
4
4
|
require 'test/unit/ui/console/testrunner'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
$logger = Logger.new('/dev/null')
|
5
8
|
|
6
9
|
unless Kernel.respond_to?(:require_relative)
|
7
10
|
module Kernel
|
@@ -18,67 +21,50 @@ require_relative 'css/mac_line_end_support_test'
|
|
18
21
|
require_relative 'css/rule/check_list_rule_test'
|
19
22
|
require_relative 'css/rule/check_encoding_test'
|
20
23
|
require_relative 'css/rule/file_name_test'
|
21
|
-
require_relative 'css/rule/compression_test'
|
22
24
|
require_relative 'html/parser_test'
|
23
25
|
require_relative 'html/rule_test'
|
24
26
|
require_relative 'html/query_test'
|
25
27
|
require_relative 'html/mixed_type_test'
|
26
28
|
require_relative 'js/parser_test'
|
27
29
|
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
30
|
require_relative 'runner/log_level_test'
|
35
31
|
|
36
|
-
|
37
|
-
module XRayTest
|
32
|
+
module FdlintTest
|
38
33
|
|
39
34
|
class ALL < Test::Unit::TestSuite
|
40
35
|
|
41
36
|
def self.suite
|
42
|
-
|
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
|
37
|
+
Test::Unit::TestSuite.new.tap do |tests|
|
60
38
|
|
61
|
-
|
62
|
-
|
63
|
-
|
39
|
+
tests << PositionInfoTest.suite
|
40
|
+
tests << ParserVisitableTest.suite
|
41
|
+
|
42
|
+
#CSS
|
43
|
+
tests << CSS::ParserTest.suite
|
44
|
+
tests << CSS::MacLineEndSupportTest.suite
|
45
|
+
tests << CSS::Rule::CheckListRuleTest.suite
|
46
|
+
tests << CSS::Rule::CheckEncodingTest.suite
|
47
|
+
tests << CSS::Rule::CheckFileNameTest.suite
|
64
48
|
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
#HTML
|
50
|
+
tests << HTML::ParserTest.suite
|
51
|
+
tests << HTML::RuleTest.suite
|
52
|
+
tests << HTML::QueryTest.suite
|
53
|
+
tests << HTML::MixedTypeTest.suite
|
68
54
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
tests << CLI::OutputFormatTest.suite
|
73
|
-
tests << CLI::LogLevelTest.suite
|
55
|
+
#JS
|
56
|
+
tests << JS::ParserTest.suite
|
57
|
+
tests << JS::RuleTest.suite
|
74
58
|
|
75
|
-
|
76
|
-
|
59
|
+
#CLI
|
60
|
+
#CLI is no longer tested in unit tests
|
77
61
|
|
78
|
-
|
62
|
+
#RUNNER
|
63
|
+
tests << Runner::LogLevelTest.suite
|
64
|
+
end
|
79
65
|
end
|
80
66
|
end
|
81
67
|
|
82
68
|
end
|
83
69
|
|
84
|
-
Test::Unit::UI::Console::TestRunner.run(
|
70
|
+
Test::Unit::UI::Console::TestRunner.run( FdlintTest::ALL )
|
@@ -2,32 +2,30 @@
|
|
2
2
|
|
3
3
|
require_relative '../helper'
|
4
4
|
|
5
|
-
require 'node'
|
6
|
-
require 'log_entry'
|
7
|
-
require 'css/struct'
|
8
|
-
require 'css/rule/checklist'
|
5
|
+
require 'fdlint/parser/node'
|
6
|
+
require 'fdlint/log_entry'
|
7
|
+
require 'fdlint/parser/css/struct'
|
9
8
|
|
10
|
-
module
|
9
|
+
module FdlintTest
|
11
10
|
module CSS
|
12
11
|
|
13
12
|
class MacLineEndSupportTest < Test::Unit::TestCase
|
14
13
|
|
15
14
|
def setup
|
16
|
-
@runner = XRay::Runner.new :encoding => 'gb2312'
|
17
15
|
end
|
18
16
|
|
19
17
|
def test_check_mac_line_end_with_good_css
|
20
18
|
file = "#{FIXTURE_PATH}/css/mac-line-sep-good.css"
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
assert_nothing_thrown "Mac style line end should be supported" do
|
20
|
+
Fdlint::Validator.new( file ).validate
|
21
|
+
end
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_check_mac_line_end_with_error_css
|
27
25
|
file = "#{FIXTURE_PATH}/css/mac-line-sep-err.css"
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
assert_nothing_thrown "Mac style line end should be supported" do
|
27
|
+
Fdlint::Validator.new( file ).validate
|
28
|
+
end
|
31
29
|
end
|
32
30
|
|
33
31
|
|
data/test/css/parser_test.rb
CHANGED
@@ -2,14 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative '../helper'
|
4
4
|
|
5
|
-
require 'css/
|
5
|
+
require 'fdlint/parser/css/css_parser'
|
6
6
|
|
7
7
|
|
8
|
-
module
|
8
|
+
module FdlintTest
|
9
9
|
module CSS
|
10
10
|
class ParserTest < Test::Unit::TestCase
|
11
|
-
ParseError =
|
12
|
-
include XRay::CSS
|
11
|
+
ParseError = Fdlint::Parser::ParseError
|
13
12
|
|
14
13
|
def test_parse_stylesheet_empty
|
15
14
|
css = " \n "
|
@@ -261,7 +260,7 @@ END
|
|
261
260
|
private
|
262
261
|
|
263
262
|
def create_parser(css)
|
264
|
-
Parser.new css
|
263
|
+
Fdlint::Parser::CSS::CssParser.new css
|
265
264
|
end
|
266
265
|
|
267
266
|
def parse_css(css, name = 'stylesheet')
|
@@ -2,19 +2,17 @@
|
|
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 CheckEncodingTest < Test::Unit::TestCase
|
14
13
|
|
15
14
|
def setup
|
16
|
-
@
|
17
|
-
@expect_err = XRay::LogEntry.new("File can't be read as gb2312 charset", :fatal)
|
15
|
+
@expect_err = Fdlint::LogEntry.new("File can't be read as gb2312 charset", :fatal)
|
18
16
|
end
|
19
17
|
|
20
18
|
def test_check_utf8_file_well_written
|
@@ -50,8 +48,9 @@ module XRayTest
|
|
50
48
|
|
51
49
|
private
|
52
50
|
def check_file( file )
|
53
|
-
|
54
|
-
|
51
|
+
Fdlint::Validator.new( file ).validate do |file, source, results|
|
52
|
+
yield results
|
53
|
+
end
|
55
54
|
end
|
56
55
|
|
57
56
|
def has_encoding_error?( results )
|