Class: StudFinder::JsComplexity
- Inherits:
-
Object
- Object
- StudFinder::JsComplexity
- Defined in:
- lib/stud_finder/js_complexity.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- ESLINT_MISSING =
'js_eslint_missing'- ESLINT_FAILED =
'js_eslint_failed'- ESLINT_MALFORMED =
'js_eslint_malformed'- TS_PARSER_MISSING =
'js_ts_parser_missing'- TIMEOUT =
'js_eslint_timeout'- BATCH_SIZE =
500- TS_EXTENSIONS =
%w[.ts .tsx].freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(repo_path:, files:, js_timeout: 60, stderr: $stderr) ⇒ JsComplexity
constructor
A new instance of JsComplexity.
Constructor Details
#initialize(repo_path:, files:, js_timeout: 60, stderr: $stderr) ⇒ JsComplexity
Returns a new instance of JsComplexity.
19 20 21 22 23 24 25 |
# File 'lib/stud_finder/js_complexity.rb', line 19 def initialize(repo_path:, files:, js_timeout: 60, stderr: $stderr) @repo_path = File.(repo_path) @files = files @js_timeout = js_timeout @stderr = stderr @warnings = [] end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stud_finder/js_complexity.rb', line 27 def call eslint = eslint_binary return missing_eslint unless eslint major = eslint_major(eslint) return missing_eslint unless major ts_parser = ts_parser_available? warn_once(TS_PARSER_MISSING) if ts_files? && !ts_parser counts = zero_counts analyzable_files(ts_parser).each_slice(BATCH_SIZE) do |batch| counts.merge!(run_batch(eslint, major, ts_parser, batch)) { |_file, old, new| [old, new].max } end Result.new(counts: counts, warnings: @warnings) end |