rubycritic 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubycritic/analysers/config.reek +2 -0
- data/lib/rubycritic/analysers/flay.rb +15 -0
- data/lib/rubycritic/analysers_runner.rb +3 -1
- data/lib/rubycritic/report_generators/reporter.rb +3 -3
- data/lib/rubycritic/smell_adapters/flay.rb +45 -0
- data/lib/rubycritic/smell_adapters/flog.rb +3 -2
- data/lib/rubycritic/smell_adapters/reek.rb +4 -3
- data/lib/rubycritic/smelly_pathnames_serializer.rb +1 -1
- data/lib/rubycritic/source_locator.rb +4 -8
- data/lib/rubycritic/version.rb +1 -1
- data/rubycritic.gemspec +1 -0
- data/test/lib/rubycritic/metric_adapters/flay_adapter_test.rb +25 -0
- data/test/lib/rubycritic/source_locator_test.rb +19 -9
- data/test/samples/flay/smelly.rb +17 -0
- data/test/samples/reek/not_smelly.rb +10 -3
- metadata +22 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a776a51f8d90b8d2b65bb2e81f6b4dea87cd63a4
         | 
| 4 | 
            +
              data.tar.gz: 4f35ecbef41031dd622513ef120ca1fab15e1e10
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 078000998ba31e7c53c637dfda9184e8dfcdc90e28750afd88a4c35949f86feb38b785be71a2038d7704d2acd12d9182b905f19cafa00329ae20f99db51f1592
         | 
| 7 | 
            +
              data.tar.gz: fff0b984ed7ebe0e120ceb0ed13947eacea027162312e80e84d7dbe9e96b1f998ecd8be4cd9dfd8e3fc659a50a252261a8ec63ba6310b323b42eda3885327d17
         | 
| @@ -1,4 +1,6 @@ | |
| 1 1 | 
             
            require "rubycritic/active_support/methods"
         | 
| 2 | 
            +
            require "rubycritic/analysers/flay"
         | 
| 3 | 
            +
            require "rubycritic/smell_adapters/flay"
         | 
| 2 4 | 
             
            require "rubycritic/analysers/reek"
         | 
| 3 5 | 
             
            require "rubycritic/smell_adapters/reek"
         | 
| 4 6 |  | 
| @@ -7,7 +9,7 @@ module Rubycritic | |
| 7 9 | 
             
              class AnalysersRunner
         | 
| 8 10 | 
             
                include ActiveSupport
         | 
| 9 11 |  | 
| 10 | 
            -
                ANALYSERS = ["Reek"]
         | 
| 12 | 
            +
                ANALYSERS = ["Flay", "Reek"]
         | 
| 11 13 |  | 
| 12 14 | 
             
                def initialize(paths)
         | 
| 13 15 | 
             
                  @paths = paths
         | 
| @@ -35,9 +35,9 @@ module Rubycritic | |
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 37 | 
             
                def file_generators
         | 
| 38 | 
            -
                  @file_generators ||= @source_pathnames.map do | | 
| 39 | 
            -
                    file_smells = @smelly_pathnames[ | 
| 40 | 
            -
                    FileGenerator.new( | 
| 38 | 
            +
                  @file_generators ||= @source_pathnames.map do |file_pathname|
         | 
| 39 | 
            +
                    file_smells = @smelly_pathnames[file_pathname]
         | 
| 40 | 
            +
                    FileGenerator.new(file_pathname, file_smells)
         | 
| 41 41 | 
             
                  end
         | 
| 42 42 | 
             
                end
         | 
| 43 43 | 
             
              end
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            require "rubycritic/smell"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Rubycritic
         | 
| 4 | 
            +
              module SmellAdapter
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                class Flay
         | 
| 7 | 
            +
                  def initialize(flay)
         | 
| 8 | 
            +
                    @flay = flay
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def smells
         | 
| 12 | 
            +
                    @flay.hashes.map do |structural_hash, nodes|
         | 
| 13 | 
            +
                      create_smell(structural_hash, nodes)
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  private
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def create_smell(structural_hash, nodes)
         | 
| 20 | 
            +
                    is_identical = @flay.identical[structural_hash]
         | 
| 21 | 
            +
                    similarity   = is_identical ? "Identical" : "Similar"
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    locations = smell_locations(nodes)
         | 
| 24 | 
            +
                    context   = "#{similarity} code"
         | 
| 25 | 
            +
                    message   = "found in #{nodes.size} nodes"
         | 
| 26 | 
            +
                    score     = @flay.masses[structural_hash]
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    Smell.new(
         | 
| 29 | 
            +
                      :locations => locations,
         | 
| 30 | 
            +
                      :context => context,
         | 
| 31 | 
            +
                      :message => message,
         | 
| 32 | 
            +
                      :score => score,
         | 
| 33 | 
            +
                      :type => "DuplicateCode"
         | 
| 34 | 
            +
                    )
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def smell_locations(nodes)
         | 
| 38 | 
            +
                    nodes.map do |node|
         | 
| 39 | 
            +
                      Location.new(node.file, node.line)
         | 
| 40 | 
            +
                    end.sort
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -19,8 +19,9 @@ module Rubycritic | |
| 19 19 | 
             
                  private
         | 
| 20 20 |  | 
| 21 21 | 
             
                  def create_smell(context, score)
         | 
| 22 | 
            -
                    location =  | 
| 22 | 
            +
                    location = smell_location(context)
         | 
| 23 23 | 
             
                    message  = "has a complexity of #{score.round}"
         | 
| 24 | 
            +
             | 
| 24 25 | 
             
                    Smell.new(
         | 
| 25 26 | 
             
                      :locations => [location],
         | 
| 26 27 | 
             
                      :context => context,
         | 
| @@ -30,7 +31,7 @@ module Rubycritic | |
| 30 31 | 
             
                    )
         | 
| 31 32 | 
             
                  end
         | 
| 32 33 |  | 
| 33 | 
            -
                  def  | 
| 34 | 
            +
                  def smell_location(context)
         | 
| 34 35 | 
             
                    line = @flog.method_locations[context]
         | 
| 35 36 | 
             
                    file_path, file_line = line.split(":")
         | 
| 36 37 | 
             
                    Location.new(file_path, file_line)
         | 
| @@ -18,16 +18,17 @@ module Rubycritic | |
| 18 18 |  | 
| 19 19 | 
             
                  def create_smell(smell)
         | 
| 20 20 | 
             
                    locations = smell_locations(smell.source, smell.lines)
         | 
| 21 | 
            -
                    message   = smell.message
         | 
| 22 21 | 
             
                    context   = smell.context
         | 
| 22 | 
            +
                    message   = smell.message
         | 
| 23 23 | 
             
                    type      = smell.subclass
         | 
| 24 | 
            +
             | 
| 24 25 | 
             
                    Smell.new(:locations => locations, :context => context, :message => message, :type => type)
         | 
| 25 26 | 
             
                  end
         | 
| 26 27 |  | 
| 27 28 | 
             
                  def smell_locations(file_path, file_lines)
         | 
| 28 | 
            -
                    file_lines.uniq. | 
| 29 | 
            +
                    file_lines.uniq.map do |file_line|
         | 
| 29 30 | 
             
                      Location.new(file_path, file_line)
         | 
| 30 | 
            -
                    end
         | 
| 31 | 
            +
                    end.sort
         | 
| 31 32 | 
             
                  end
         | 
| 32 33 | 
             
                end
         | 
| 33 34 |  | 
| @@ -7,7 +7,7 @@ module Rubycritic | |
| 7 7 | 
             
                RUBY_FILES = File.join("**", "*#{RUBY_EXTENSION}")
         | 
| 8 8 |  | 
| 9 9 | 
             
                def initialize(paths)
         | 
| 10 | 
            -
                  @ | 
| 10 | 
            +
                  @initial_paths = paths
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                def pathnames
         | 
| @@ -21,17 +21,13 @@ module Rubycritic | |
| 21 21 | 
             
                private
         | 
| 22 22 |  | 
| 23 23 | 
             
                def expand_paths
         | 
| 24 | 
            -
                  @ | 
| 24 | 
            +
                  @initial_paths.map do |path|
         | 
| 25 25 | 
             
                    if File.directory?(path)
         | 
| 26 | 
            -
                      Pathname.glob( | 
| 26 | 
            +
                      Pathname.glob(File.join(path, RUBY_FILES))
         | 
| 27 27 | 
             
                    elsif File.exists?(path) && File.extname(path) == RUBY_EXTENSION
         | 
| 28 28 | 
             
                      Pathname.new(path)
         | 
| 29 29 | 
             
                    end
         | 
| 30 | 
            -
                  end.flatten.compact.sort
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def files_contained_in(path)
         | 
| 34 | 
            -
                  (path == ".") ? RUBY_FILES : File.join(path, RUBY_FILES)
         | 
| 30 | 
            +
                  end.flatten.compact.map(&:cleanpath).sort
         | 
| 35 31 | 
             
                end
         | 
| 36 32 | 
             
              end
         | 
| 37 33 |  | 
    
        data/lib/rubycritic/version.rb
    CHANGED
    
    
    
        data/rubycritic.gemspec
    CHANGED
    
    
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            require "test_helper"
         | 
| 2 | 
            +
            require "rubycritic/analysers/flay"
         | 
| 3 | 
            +
            require "rubycritic/smell_adapters/flay"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe Rubycritic::SmellAdapter::Flay do
         | 
| 6 | 
            +
              before do
         | 
| 7 | 
            +
                sample_path = "test/samples/flay/smelly.rb"
         | 
| 8 | 
            +
                flay = Rubycritic::Analyser::Flay.new([sample_path])
         | 
| 9 | 
            +
                @adapter = Rubycritic::SmellAdapter::Flay.new(flay)
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              it "detects smells" do
         | 
| 13 | 
            +
                @adapter.smells.wont_be_empty
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              it "has smells with messages" do
         | 
| 17 | 
            +
                smell = @adapter.smells.first
         | 
| 18 | 
            +
                smell.message.must_equal "found in 2 nodes"
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              it "has smells with messages" do
         | 
| 22 | 
            +
                smell = @adapter.smells.first
         | 
| 23 | 
            +
                smell.score.must_be_kind_of Numeric
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -18,24 +18,34 @@ describe Rubycritic::SourceLocator do | |
| 18 18 | 
             
                  Rubycritic::SourceLocator.new(paths).paths.must_equal paths
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 | 
            +
                it "finds all the files inside a given directory" do
         | 
| 22 | 
            +
                  initial_paths = ["dir1"]
         | 
| 23 | 
            +
                  final_paths = ["dir1/file1.rb"]
         | 
| 24 | 
            +
                  Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 21 27 | 
             
                it "finds all the files" do
         | 
| 22 | 
            -
                   | 
| 23 | 
            -
                   | 
| 28 | 
            +
                  initial_paths = ["."]
         | 
| 29 | 
            +
                  final_paths = ["dir1/file1.rb", "file0.rb"]
         | 
| 30 | 
            +
                  Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
         | 
| 24 31 | 
             
                end
         | 
| 25 32 |  | 
| 26 | 
            -
                it " | 
| 27 | 
            -
                   | 
| 28 | 
            -
                   | 
| 33 | 
            +
                it "cleans paths of consecutive slashes and useless dots" do
         | 
| 34 | 
            +
                  initial_paths = [".//file0.rb"]
         | 
| 35 | 
            +
                  final_paths = ["file0.rb"]
         | 
| 36 | 
            +
                  Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
         | 
| 29 37 | 
             
                end
         | 
| 30 38 |  | 
| 31 39 | 
             
                it "ignores paths to non-existent files" do
         | 
| 32 | 
            -
                   | 
| 33 | 
            -
                   | 
| 40 | 
            +
                  initial_paths = ["non_existent_dir1/non_existent_file1.rb", "non_existent_file0.rb"]
         | 
| 41 | 
            +
                  final_paths = []
         | 
| 42 | 
            +
                  Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
         | 
| 34 43 | 
             
                end
         | 
| 35 44 |  | 
| 36 45 | 
             
                it "ignores paths to files that do not match the Ruby extension" do
         | 
| 37 | 
            -
                   | 
| 38 | 
            -
                   | 
| 46 | 
            +
                  initial_paths = ["file_with_no_extension", "file_with_different_extension.py"]
         | 
| 47 | 
            +
                  final_paths = []
         | 
| 48 | 
            +
                  Rubycritic::SourceLocator.new(initial_paths).paths.must_equal final_paths
         | 
| 39 49 | 
             
                end
         | 
| 40 50 | 
             
              end
         | 
| 41 51 |  | 
| @@ -1,7 +1,14 @@ | |
| 1 | 
            -
            class  | 
| 2 | 
            -
              attr_reader : | 
| 1 | 
            +
            class Perfume
         | 
| 2 | 
            +
              attr_reader :perfumed
         | 
| 3 3 |  | 
| 4 | 
            -
              def  | 
| 4 | 
            +
              def ignoreRubyStyle(oneParameter)
         | 
| 5 5 | 
             
                oneVariable = oneParameter
         | 
| 6 6 | 
             
              end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def allowNestingIteratorsTwoLevelsDeep
         | 
| 9 | 
            +
                loop do
         | 
| 10 | 
            +
                  loop do
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 7 14 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rubycritic
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Guilherme Simoes
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-04- | 
| 11 | 
            +
            date: 2014-04-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: virtus
         | 
| @@ -24,6 +24,20 @@ dependencies: | |
| 24 24 | 
             
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '1.0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: flay
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - '='
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 2.4.0
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - '='
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 2.4.0
         | 
| 27 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 42 | 
             
              name: flog
         | 
| 29 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -128,6 +142,7 @@ files: | |
| 128 142 | 
             
            - lib/rubycritic.rb
         | 
| 129 143 | 
             
            - lib/rubycritic/active_support/methods.rb
         | 
| 130 144 | 
             
            - lib/rubycritic/analysers/config.reek
         | 
| 145 | 
            +
            - lib/rubycritic/analysers/flay.rb
         | 
| 131 146 | 
             
            - lib/rubycritic/analysers/flog.rb
         | 
| 132 147 | 
             
            - lib/rubycritic/analysers/reek.rb
         | 
| 133 148 | 
             
            - lib/rubycritic/analysers_runner.rb
         | 
| @@ -151,6 +166,7 @@ files: | |
| 151 166 | 
             
            - lib/rubycritic/report_generators/view_helpers.rb
         | 
| 152 167 | 
             
            - lib/rubycritic/revision_comparator.rb
         | 
| 153 168 | 
             
            - lib/rubycritic/smell.rb
         | 
| 169 | 
            +
            - lib/rubycritic/smell_adapters/flay.rb
         | 
| 154 170 | 
             
            - lib/rubycritic/smell_adapters/flog.rb
         | 
| 155 171 | 
             
            - lib/rubycritic/smell_adapters/reek.rb
         | 
| 156 172 | 
             
            - lib/rubycritic/smells_aggregator.rb
         | 
| @@ -163,6 +179,7 @@ files: | |
| 163 179 | 
             
            - rubycritic.gemspec
         | 
| 164 180 | 
             
            - test/lib/rubycritic/analysers_runner_test.rb
         | 
| 165 181 | 
             
            - test/lib/rubycritic/location_test.rb
         | 
| 182 | 
            +
            - test/lib/rubycritic/metric_adapters/flay_adapter_test.rb
         | 
| 166 183 | 
             
            - test/lib/rubycritic/metric_adapters/flog_adapter_test.rb
         | 
| 167 184 | 
             
            - test/lib/rubycritic/metric_adapters/reek_adapter_test.rb
         | 
| 168 185 | 
             
            - test/lib/rubycritic/smell_test.rb
         | 
| @@ -172,6 +189,7 @@ files: | |
| 172 189 | 
             
            - test/lib/rubycritic/source_control_systems/source_control_system_test.rb
         | 
| 173 190 | 
             
            - test/lib/rubycritic/source_locator_test.rb
         | 
| 174 191 | 
             
            - test/lib/rubycritic/version_test.rb
         | 
| 192 | 
            +
            - test/samples/flay/smelly.rb
         | 
| 175 193 | 
             
            - test/samples/flog/smelly.rb
         | 
| 176 194 | 
             
            - test/samples/location/dir1/file1.rb
         | 
| 177 195 | 
             
            - test/samples/location/file0.rb
         | 
| @@ -207,6 +225,7 @@ summary: Ruby code smell detector | |
| 207 225 | 
             
            test_files:
         | 
| 208 226 | 
             
            - test/lib/rubycritic/analysers_runner_test.rb
         | 
| 209 227 | 
             
            - test/lib/rubycritic/location_test.rb
         | 
| 228 | 
            +
            - test/lib/rubycritic/metric_adapters/flay_adapter_test.rb
         | 
| 210 229 | 
             
            - test/lib/rubycritic/metric_adapters/flog_adapter_test.rb
         | 
| 211 230 | 
             
            - test/lib/rubycritic/metric_adapters/reek_adapter_test.rb
         | 
| 212 231 | 
             
            - test/lib/rubycritic/smell_test.rb
         | 
| @@ -216,6 +235,7 @@ test_files: | |
| 216 235 | 
             
            - test/lib/rubycritic/source_control_systems/source_control_system_test.rb
         | 
| 217 236 | 
             
            - test/lib/rubycritic/source_locator_test.rb
         | 
| 218 237 | 
             
            - test/lib/rubycritic/version_test.rb
         | 
| 238 | 
            +
            - test/samples/flay/smelly.rb
         | 
| 219 239 | 
             
            - test/samples/flog/smelly.rb
         | 
| 220 240 | 
             
            - test/samples/location/dir1/file1.rb
         | 
| 221 241 | 
             
            - test/samples/location/file0.rb
         |