Sha256: 5783e17e1f5ac81b66d7aaa134af40e5d3fc6b4d349901d0f31f6990233abb07
Contents?: true
Size: 1.77 KB
Versions: 1
Compression:
Stored size: 1.77 KB
Contents
require 'rubycritic/analysers/helpers/flay' require 'rubycritic/core/smell' require 'rubycritic/colorize' module RubyCritic module Analyser class FlaySmells include Colorize def initialize(analysed_modules) @analysed_modules = paths_to_analysed_modules(analysed_modules) @flay = Flay.new(@analysed_modules.keys) end def run @flay.hashes.each do |structural_hash, nodes| smell = create_smell(structural_hash, nodes) nodes.map(&:file).uniq.each do |file| @analysed_modules[file].smells << smell end nodes.each do |node| @analysed_modules[node.file].duplication += node.mass end print green '.' end puts '' end def to_s 'flay smells' end private def paths_to_analysed_modules(analysed_modules) paths = {} analysed_modules.each do |analysed_module| paths[analysed_module.path] = analysed_module end paths end def create_smell(structural_hash, nodes) mass = @flay.masses[structural_hash] Smell.new( locations: smell_locations(nodes), context: similarity(structural_hash), message: "found in #{nodes.size} nodes", score: mass, type: 'DuplicateCode', analyser: 'flay', cost: cost(mass) ) end def smell_locations(nodes) nodes.map do |node| Location.new(node.file, node.line) end.sort end def similarity(structural_hash) if @flay.identical[structural_hash] 'Identical code' else 'Similar code' end end def cost(mass) mass / 25 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubycritic-2.9.3 | lib/rubycritic/analysers/smells/flay.rb |