diff --git a/lib/cc/engine/analyzers/javascript/main.rb b/lib/cc/engine/analyzers/javascript/main.rb index 05ae2d8a..00873f51 100644 --- a/lib/cc/engine/analyzers/javascript/main.rb +++ b/lib/cc/engine/analyzers/javascript/main.rb @@ -14,13 +14,13 @@ class Main < CC::Engine::Analyzers::Base LANGUAGE = "javascript" DEFAULT_MASS_THRESHOLD = 45 DEFAULT_FILTERS = [ - "(directives (Directive (value (DirectiveLiteral ___))))", + "(directives (Directive (value (DirectiveLiteral ___))))".freeze, "(ImportDeclaration ___)".freeze, "(VariableDeclarator _ (init (CallExpression (_ (Identifier require)) ___)))".freeze, ].freeze DEFAULT_POST_FILTERS = [ - "(NUKE ___)", - "(Program _ ___)", + "(NUKE ___)".freeze, + "(Program _ ___)".freeze, ].freeze POINTS_PER_OVERAGE = 30_000 REQUEST_PATH = "/javascript".freeze diff --git a/lib/cc/engine/analyzers/typescript/main.rb b/lib/cc/engine/analyzers/typescript/main.rb index 363df144..f7838dbc 100644 --- a/lib/cc/engine/analyzers/typescript/main.rb +++ b/lib/cc/engine/analyzers/typescript/main.rb @@ -10,20 +10,39 @@ class Main < CC::Engine::Analyzers::Base PATTERNS = [ "**/*.ts", "**/*.tsx", - ] + ].freeze LANGUAGE = "typescript" DEFAULT_MASS_THRESHOLD = 45 DEFAULT_FILTERS = [ - "(ImportDeclaration ___)", - "(VariableDeclarator _ (init (CallExpression (_ (Identifier require)) ___)))", - ] + "(ImportDeclaration ___)".freeze, + "(VariableDeclarator _ (init (CallExpression (_ (Identifier require)) ___)))".freeze, + ].freeze + DEFAULT_POST_FILTERS = [ + "(NUKE ___)".freeze, + "(Program _ ___)".freeze, + ].freeze POINTS_PER_OVERAGE = 30_000 - REQUEST_PATH = "/typescript" + REQUEST_PATH = "/typescript".freeze def use_sexp_lines? false end + ## + # Transform sexp as such: + # + # s(:Program, :module, s(:body, ... )) + # => s(:NUKE, s(:Program, :module, s(:NUKE, ... ))) + + def transform_sexp(sexp) + return sexp unless sexp.body + + sexp.body.sexp_type = :NUKE # negate top level body + sexp = s(:NUKE, sexp) # wrap with extra node to force full process + + sexp + end + private def process_file(file) @@ -33,6 +52,10 @@ def process_file(file) def default_filters DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter } end + + def default_post_filters + DEFAULT_POST_FILTERS.map { |filter| Sexp::Matcher.parse filter } + end end end end