File tree Expand file tree Collapse file tree 6 files changed +73
-10
lines changed Expand file tree Collapse file tree 6 files changed +73
-10
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ In this example we define default globs and exclude `src/compiler` folder:
174
174
` ` ` yaml
175
175
Globs:
176
176
- "**/*.cr"
177
+ - "**/*.ecr"
177
178
- "!lib"
178
179
179
180
Excluded:
Original file line number Diff line number Diff line change @@ -70,5 +70,31 @@ module Ameba
70
70
CRYSTAL
71
71
end
72
72
end
73
+
74
+ Ameba .ecr_supported? do
75
+ describe " #ast" do
76
+ it " parses an ECR file" do
77
+ source = Source .new <<-ECR , "filename.ecr"
78
+ hello <%= "world" %>
79
+ ECR
80
+
81
+ source.ast.to_s.should eq(<<-CRYSTAL )
82
+ __str__ << "hello "
83
+ ("world").to_s(__str__)
84
+
85
+ CRYSTAL
86
+ end
87
+
88
+ it " raises an exception when ECR parsing fails" do
89
+ source = Source .new <<-ECR , "filename.ecr"
90
+ hello <%= "world" >
91
+ ECR
92
+
93
+ expect_raises(Crystal ::SyntaxException ) do
94
+ source.ast
95
+ end
96
+ end
97
+ end
98
+ end
73
99
end
74
100
end
Original file line number Diff line number Diff line change 1
- require " ./ameba/*"
2
- require " ./ameba/ast/**"
3
- require " ./ameba/ext/**"
4
- require " ./ameba/rule/**"
5
- require " ./ameba/formatter/*"
6
- require " ./ameba/presenter/*"
7
- require " ./ameba/source/**"
8
-
9
1
# Ameba's entry module.
10
2
#
11
3
# To run the linter with default parameters:
@@ -40,4 +32,18 @@ module Ameba
40
32
def run (config = Config .load)
41
33
Runner .new(config).run
42
34
end
35
+
36
+ macro ecr_supported? (& )
37
+ {% if compare_versions(Crystal ::VERSION , " 1.15.0" ) >= 0 % }
38
+ {{ yield }}
39
+ {% end % }
40
+ end
43
41
end
42
+
43
+ require " ./ameba/*"
44
+ require " ./ameba/ast/**"
45
+ require " ./ameba/ext/**"
46
+ require " ./ameba/rule/**"
47
+ require " ./ameba/formatter/*"
48
+ require " ./ameba/presenter/*"
49
+ require " ./ameba/source/**"
Original file line number Diff line number Diff line change 1
1
require " semantic_version"
2
2
require " yaml"
3
+ require " ecr/processor"
3
4
require " ./glob_utils"
4
5
5
6
# A configuration entry for `Ameba::Runner`.
@@ -62,6 +63,10 @@ class Ameba::Config
62
63
!lib
63
64
)
64
65
66
+ Ameba .ecr_supported? do
67
+ DEFAULT_GLOBS << " **/*.ecr"
68
+ end
69
+
65
70
getter rules : Array (Rule ::Base )
66
71
property severity = Severity ::Convention
67
72
@@ -167,7 +172,7 @@ class Ameba::Config
167
172
# ```
168
173
# config = Ameba::Config.load
169
174
# config.sources # => list of default sources
170
- # config.globs = ["**/*.cr"]
175
+ # config.globs = ["**/*.cr", "**/*.ecr" ]
171
176
# config.excluded = ["spec"]
172
177
# config.sources # => list of sources pointing to files found by the wildcards
173
178
# ```
Original file line number Diff line number Diff line change @@ -24,7 +24,14 @@ module Ameba
24
24
def expand (globs )
25
25
globs
26
26
.flat_map do |glob |
27
- glob += " /**/*.cr" if File .directory?(glob)
27
+ if File .directory?(glob)
28
+ glob += " /**/*.cr"
29
+
30
+ Ameba .ecr_supported? do
31
+ glob += " /**/*.ecr"
32
+ end
33
+ end
34
+
28
35
Dir [glob]
29
36
end
30
37
.uniq!
Original file line number Diff line number Diff line change @@ -57,6 +57,24 @@ module Ameba
57
57
# source.ast
58
58
# ```
59
59
getter ast : Crystal ::ASTNode do
60
+ code = @code
61
+
62
+ Ameba .ecr_supported? do
63
+ if @path .ends_with?(" .ecr" )
64
+ begin
65
+ code = ECR .process_string(code, @path )
66
+ rescue ex : ECR ::Lexer ::SyntaxException
67
+ # Need to rescue to add the filename
68
+ raise Crystal ::SyntaxException .new(
69
+ ex.message,
70
+ ex.line_number,
71
+ ex.column_number,
72
+ @path
73
+ )
74
+ end
75
+ end
76
+ end
77
+
60
78
Crystal ::Parser .new(code)
61
79
.tap(& .wants_doc = true )
62
80
.tap(& .filename = path)
You can’t perform that action at this time.
0 commit comments