fdlint 0.1.3 → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -9
- data/Gemfile.lock +14 -4
- data/Rakefile +9 -85
- data/bin/fdlint +71 -8
- data/lib/fdlint/cli.rb +102 -0
- data/lib/{file_validator.rb → fdlint/file_validator.rb} +0 -0
- data/lib/fdlint/helper/code_type.rb +55 -0
- data/lib/fdlint/helper/file_reader.rb +19 -0
- data/lib/fdlint/helper/logger.rb +35 -0
- data/lib/fdlint/log_entry.rb +51 -0
- data/lib/fdlint/parser/base_parser.rb +151 -0
- data/lib/{css/parser.rb → fdlint/parser/css/css_parser.rb} +31 -28
- data/lib/{css → fdlint/parser/css}/struct.rb +5 -5
- data/lib/{encoding_error.rb → fdlint/parser/encoding_error.rb} +2 -2
- data/lib/{html/parser.rb → fdlint/parser/html/html_parser.rb} +26 -20
- data/lib/{html → fdlint/parser/html}/query.rb +0 -0
- data/lib/{html → fdlint/parser/html}/rule/check_tag_rule.rb +0 -0
- data/lib/{html → fdlint/parser/html}/struct.rb +82 -38
- data/lib/fdlint/parser/js/expr/expr.rb +71 -0
- data/lib/fdlint/parser/js/expr/left_hand.rb +65 -0
- data/lib/fdlint/parser/js/expr/operate.rb +94 -0
- data/lib/fdlint/parser/js/expr/primary.rb +168 -0
- data/lib/{js/parser.rb → fdlint/parser/js/js_parser.rb} +11 -9
- data/lib/fdlint/parser/js/stat/if.rb +27 -0
- data/lib/fdlint/parser/js/stat/iter.rb +88 -0
- data/lib/fdlint/parser/js/stat/stat.rb +120 -0
- data/lib/fdlint/parser/js/stat/switch.rb +67 -0
- data/lib/fdlint/parser/js/stat/try.rb +30 -0
- data/lib/fdlint/parser/js/stat/var.rb +42 -0
- data/lib/fdlint/parser/js/struct.rb +257 -0
- data/lib/fdlint/parser/node.rb +27 -0
- data/lib/fdlint/parser/parse_error.rb +10 -0
- data/lib/fdlint/parser/parser_visitable.rb +134 -0
- data/lib/{position_info.rb → fdlint/parser/position_info.rb} +12 -1
- data/lib/fdlint/parser.rb +3 -0
- data/lib/fdlint/printer/base_printer.rb +20 -0
- data/lib/fdlint/printer/console_printer.rb +80 -0
- data/lib/fdlint/printer/nocolor_printer.rb +29 -0
- data/lib/fdlint/printer/vim_printer.rb +21 -0
- data/lib/fdlint/printer.rb +1 -0
- data/lib/fdlint/rule/dsl.rb +83 -0
- data/lib/fdlint/rule/validation.rb +79 -0
- data/lib/fdlint/rule.rb +81 -0
- data/lib/fdlint/support/core/array.rb +5 -0
- data/lib/fdlint/support/core/file.rb +8 -0
- data/lib/fdlint/support/core/hash.rb +5 -0
- data/lib/fdlint/support/core/nil.rb +7 -0
- data/lib/fdlint/support/core/string.rb +7 -0
- data/lib/fdlint/support/core_ext.rb +5 -0
- data/lib/fdlint/validator.rb +102 -0
- data/lib/fdlint/version.rb +3 -0
- data/lib/fdlint.rb +5 -0
- data/rules.d/css.rule.rb +100 -0
- data/rules.d/filename.rule.rb +49 -0
- data/rules.d/html.rule.rb +169 -0
- data/rules.d/js.jquery.rule.rb +49 -0
- data/rules.d/js.rule.rb +205 -0
- data/test/default_test.rb +14 -0
- data/test/fixtures/js/scope-test.js +15 -2
- data/test/test_helper.rb +9 -0
- metadata +269 -221
- data/lib/base_parser.rb +0 -143
- data/lib/cmd_runner.rb +0 -145
- data/lib/context.rb +0 -31
- data/lib/css/reader.rb +0 -30
- data/lib/css/rule/check_compression_rule.rb +0 -48
- data/lib/css/rule/checklist.rb +0 -45
- data/lib/helper/code_type.rb +0 -50
- data/lib/helper/color_string.rb +0 -44
- data/lib/helper/file_reader.rb +0 -22
- data/lib/helper/strenc.rb +0 -65
- data/lib/js/expr/expr.rb +0 -66
- data/lib/js/expr/left_hand.rb +0 -63
- data/lib/js/expr/operate.rb +0 -92
- data/lib/js/expr/primary.rb +0 -166
- data/lib/js/rule/all.rb +0 -35
- data/lib/js/rule/checklist.rb +0 -41
- data/lib/js/rule/file_checker.rb +0 -42
- data/lib/js/rule/helper.rb +0 -96
- data/lib/js/rule/no_global.rb +0 -87
- data/lib/js/stat/if.rb +0 -25
- data/lib/js/stat/iter.rb +0 -85
- data/lib/js/stat/stat.rb +0 -117
- data/lib/js/stat/switch.rb +0 -65
- data/lib/js/stat/try.rb +0 -28
- data/lib/js/stat/var.rb +0 -40
- data/lib/js/struct.rb +0 -248
- data/lib/log_entry.rb +0 -49
- data/lib/node.rb +0 -28
- data/lib/parse_error.rb +0 -13
- data/lib/parser_visitable.rb +0 -138
- data/lib/printer/base_printer.rb +0 -24
- data/lib/printer/console_printer.rb +0 -66
- data/lib/printer/nocolor_printer.rb +0 -27
- data/lib/printer/vim_printer.rb +0 -19
- data/lib/rule.rb +0 -241
- data/lib/rule_helper.rb +0 -14
- data/lib/runner.rb +0 -225
- data/rules.d/css.rule +0 -127
- data/rules.d/html.dtd.rule +0 -22
- data/rules.d/html.prop.rule +0 -51
- data/rules.d/html.tag.rule +0 -136
- data/rules.d/js.file.rule +0 -13
- data/rules.d/js.jquery.rule +0 -56
- data/rules.d/js.mergefile.rule +0 -71
- data/rules.d/js.rule +0 -84
data/rules.d/js.rule
DELETED
@@ -1,84 +0,0 @@
|
|
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
|
-
|