diff --git a/README.md b/README.md index 58b74e6e0..729ecfca0 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,7 @@ In this example we define default globs and exclude `src/compiler` folder: ``` yaml Globs: - "**/*.cr" + - "**/*.ecr" - "!lib" Excluded: diff --git a/src/ameba/config.cr b/src/ameba/config.cr index 89a710e53..c1832f702 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -1,5 +1,6 @@ require "semantic_version" require "yaml" +require "ecr/processor" require "./glob_utils" # A configuration entry for `Ameba::Runner`. @@ -57,10 +58,18 @@ class Ameba::Config Path[XDG_CONFIG_HOME] / "ameba/config.yml", } - DEFAULT_GLOBS = %w( - **/*.cr - !lib - ) + {% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %} + DEFAULT_GLOBS = %w( + **/*.cr + **/*.ecr + !lib + ) + {% else %} + DEFAULT_GLOBS = %w( + **/*.cr + !lib + ) + {% end %} getter rules : Array(Rule::Base) property severity = Severity::Convention @@ -167,7 +176,7 @@ class Ameba::Config # ``` # config = Ameba::Config.load # config.sources # => list of default sources - # config.globs = ["**/*.cr"] + # config.globs = ["**/*.cr", "**/*.ecr"] # config.excluded = ["spec"] # config.sources # => list of sources pointing to files found by the wildcards # ``` diff --git a/src/ameba/glob_utils.cr b/src/ameba/glob_utils.cr index 63dd67cc7..60d41bd72 100644 --- a/src/ameba/glob_utils.cr +++ b/src/ameba/glob_utils.cr @@ -25,6 +25,11 @@ module Ameba globs .flat_map do |glob| glob += "/**/*.cr" if File.directory?(glob) + + {% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %} + glob += "/**/*.ecr" if File.directory?(glob) + {% end %} + Dir[glob] end .uniq! diff --git a/src/ameba/source.cr b/src/ameba/source.cr index 29d9d1990..48f573d08 100644 --- a/src/ameba/source.cr +++ b/src/ameba/source.cr @@ -57,6 +57,24 @@ module Ameba # source.ast # ``` getter ast : Crystal::ASTNode do + code = @code + + {% if compare_versions(Crystal::VERSION, "1.15.0") >= 0 %} + if @path.ends_with?(".ecr") + begin + code = ECR.process_string(code, @path) + rescue ex : Crystal::SyntaxException + # Need to rescue to add the filename + raise Crystal::SyntaxException.new( + ex.message, + ex.line_number, + ex.column_number, + @path + ) + end + end + {% end %} + Crystal::Parser.new(code) .tap(&.wants_doc = true) .tap(&.filename = path)