Skip to content

Simple refactoring between javascript and typescript. #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/cc/engine/analyzers/javascript/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ def transform_sexp(sexp)
sexp
end

private
protected

def process_file(file)
parse(file, REQUEST_PATH)
parse(file, self.class::REQUEST_PATH)
end

def default_filters
DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
self.class::DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
end

def default_post_filters
DEFAULT_POST_FILTERS.map { |filter| Sexp::Matcher.parse filter }
self.class::DEFAULT_POST_FILTERS.map { |filter| Sexp::Matcher.parse filter }
end
end
end
Expand Down
51 changes: 5 additions & 46 deletions lib/cc/engine/analyzers/typescript/main.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,20 @@
# frozen_string_literal: true

require "cc/engine/analyzers/analyzer_base"
require "cc/engine/analyzers/javascript/main"

module CC
module Engine
module Analyzers
module TypeScript
class Main < CC::Engine::Analyzers::Base
module TypeScript # TODO: inconsistent naming w/ Javascript
class Main < CC::Engine::Analyzers::Javascript::Main
PATTERNS = [
"**/*.ts",
"**/*.tsx",
].freeze
LANGUAGE = "typescript"
DEFAULT_MASS_THRESHOLD = 45
DEFAULT_FILTERS = [
"(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".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)
parse(file, REQUEST_PATH)
end

def default_filters
DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
end
LANGUAGE = "typescript"

def default_post_filters
DEFAULT_POST_FILTERS.map { |filter| Sexp::Matcher.parse filter }
end
REQUEST_PATH = "/typescript".freeze
end
end
end
Expand Down