Skip to content

Commit d6e5b24

Browse files
Enable all cops
1 parent bc887cd commit d6e5b24

33 files changed

+184
-195
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto

.rubocop.yml

+3-49
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,8 @@
1+
inherit_from: .rubocop_todo.yml
2+
13
AllCops:
24
TargetRubyVersion: 2.5
3-
DisabledByDefault: true
5+
DisabledByDefault: false
46

57
Metrics/LineLength:
6-
Enabled: true
78
Max: 140
8-
9-
Style/HashSyntax:
10-
Enabled: true
11-
12-
Style/StringLiterals:
13-
Enabled: true
14-
EnforcedStyle: single_quotes
15-
16-
Style/MultilineIfThen:
17-
Enabled: true
18-
19-
Style/MethodDefParentheses:
20-
Enabled: true
21-
22-
Style/BracesAroundHashParameters:
23-
Enabled: true
24-
25-
Layout/IndentationWidth:
26-
Enabled: true
27-
28-
Layout/Tab:
29-
Enabled: true
30-
31-
Layout/EmptyLines:
32-
Enabled: true
33-
34-
Layout/TrailingBlankLines:
35-
Enabled: true
36-
37-
Layout/TrailingWhitespace:
38-
Enabled: true
39-
40-
Layout/SpaceBeforeBlockBraces:
41-
Enabled: true
42-
43-
Layout/SpaceInsideBlockBraces:
44-
Enabled: true
45-
46-
Layout/SpaceInsideHashLiteralBraces:
47-
Enabled: true
48-
49-
Layout/CaseIndentation:
50-
Enabled: true
51-
52-
Layout/EndAlignment:
53-
Enabled: true
54-
EnforcedStyleAlignWith: variable

.rubocop_todo.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2018-04-08 15:14:25 +1200 using RuboCop version 0.54.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
Metrics/AbcSize:
11+
Max: 19
12+
13+
# Offense count: 2
14+
# Configuration parameters: CountComments, ExcludedMethods.
15+
Metrics/BlockLength:
16+
Max: 32
17+
18+
# Offense count: 1
19+
Style/MixinUsage:
20+
Exclude:
21+
- 'exe/cpp_dependency_graph'

.vscode/launch.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"pathToBundler": "C:/tools/ruby25/bin/bundle.bat",
2525
"pathToRDebugIDE": "C:/tools/ruby25/bin/rdebug-ide.bat",
2626
"showDebuggerOutput": true,
27-
"args": ["visualise", "--root_dir", "../protobuf/src"]
27+
"args": ["visualise", "-r", "../TileDB", "-f", "dot"]
2828
},
2929
{
3030
"name": "Listen for rdebug-ide",

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
source 'https://rubygems.org'
44

5-
git_source(:github) { |repo_name| 'https://github.com/shreyasbharath/cpp_dependency_graph' }
5+
git_source(:github) { |_| 'https://github.com/shreyasbharath/cpp_dependency_graph' }
66

77
gemspec

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'rspec/core/rake_task'
35
require 'rubocop/rake_task'

TODO.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [ ] Create a github.io homepage
66
- [ ] Add interactive `html` or `svg` examples to homepage
77
- [ ] Add a [CONTRIBUTING.md](https://github.com/nayafia/contributing-template/blob/master/CONTRIBUTING-template.md)
8+
- [ ] Ruby gem docs
89
- [ ] Progress messages
910
- [ ] Progress bar?
1011
- [x] Allow user to specify a single component and the tool should print only that component
@@ -32,6 +33,8 @@
3233
- [ ] Visualisation
3334
- [ ] Highlight strongly coupled components (i.e. have lots of outgoing/incoming dependencies). How to visualise strongly coupled components?
3435
- [ ] Interface vs implementation coupling (interface is worse!). Highlighting interface vs implementation coupling between components on graph?
36+
- [ ] Hierarchy diagram for components with no cycles? (https://bl.ocks.org/mbostock/4339184)
37+
- [ ] Pack diagram for just visualising components (https://bl.ocks.org/mbostock/ca5b03a33affa4160321)
3538
- [ ] Look at using subgraphs of the dot/svg language to cluster component dependencies in the graph
3639
- [ ] Create a d3 donut graph with relative sizes of components in project? This'll probably show which components need to be further split up (something like this https://blog.kathyreid.id.au/2016/12/29/linux-australia-expense-breakdown-a-data-visualisation-in-d3-js/)
3740
- [ ] Node size - base it on how many source files (or lines of code) or how many connections going in/out of node?

bin/console

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env ruby
22

3+
# frozen_string_literal: true
4+
35
require 'bundler/setup'
46
require 'cpp_dependency_graph'
57

cpp_dependency_graph.gemspec

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
lib = File.expand_path('../lib', __FILE__)
3+
lib = File.expand_path('lib', __dir__)
44
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
55

66
require 'cpp_dependency_graph/version'
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
99
s.name = 'cpp_dependency_graph'
1010
s.version = CppDependencyGraph::VERSION
1111
s.authors = ['Shreyas Balakrishna']
12-
s.email = ['shreyasbharath@users.noreply.github.com>']
12+
s.email = ['shreyasbharath@gmail.com']
1313
s.summary = <<-SUMMARY
1414
CppDependencyGraph is a program that generates dependency visualisations (dot, d3.js) to study the architecture of C/C++ projects
1515
SUMMARY
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
1919
s.homepage = 'https://github.com/shreyasbharath/cpp_dependency_graph'
2020
s.licenses = ['MIT']
2121

22-
s.files = %x[git ls-files -z].split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } -
22+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } -
2323
%w[.rubocop.yml .travis.yml appveyor.yml]
2424
s.bindir = 'exe'
2525
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -39,6 +39,6 @@ Gem::Specification.new do |s|
3939
s.add_development_dependency 'rake', '~> 12.3'
4040
s.add_development_dependency 'rspec', '~> 3.7'
4141
s.add_development_dependency 'rubocop', '~> 0.54'
42-
s.add_development_dependency 'ruby-prof', '~> 0.17'
4342
s.add_development_dependency 'ruby-debug-ide', '~> 0.6'
43+
s.add_development_dependency 'ruby-prof', '~> 0.17'
4444
end

exe/cpp_dependency_graph

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env ruby
22

3+
# frozen_string_literal: true
4+
35
#--
46
# Copyright (c) 2018 Shreyas Balakrishna
57

@@ -53,12 +55,12 @@ DOCOPT
5355
begin
5456
args = Docopt.docopt(doc)
5557

56-
if (args['--version'])
58+
if args['--version']
5759
puts VERSION
5860
Kernel.exit(0)
5961
end
6062

61-
project_dir = args['--root_dir'].gsub(/\\/,'/')
63+
project_dir = args['--root_dir'].tr('\\', '/')
6264

6365
unless File.directory?(project_dir)
6466
puts('Not a valid project source directory')

lib/cpp_dependency_graph.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
require_relative 'cpp_dependency_graph/project'
44
require_relative 'cpp_dependency_graph/dependency_graph'
55
require_relative 'cpp_dependency_graph/include_dependency_graph'
6-
require_relative 'cpp_dependency_graph/graph_visualiser'
6+
require_relative 'cpp_dependency_graph/graph_to_dot_visualiser'
7+
require_relative 'cpp_dependency_graph/graph_to_html_visualiser'
78
require_relative 'cpp_dependency_graph/version'
89

910
# Generates dependency graphs of a project in various output forms
@@ -39,9 +40,9 @@ def generate_cyclic_dependencies(project_dir, format, file)
3940
def generate_visualisation(deps, format, file)
4041
case format
4142
when 'dot'
42-
GraphVisualiser.new.generate_dot_file(deps, file)
43+
GraphToDotVisualiser.new.generate(deps, file)
4344
when 'html'
44-
GraphVisualiser.new.generate_html_file(deps, file)
45+
GraphToHtmlVisualiser.new.generate(deps, file)
4546
when 'json'
4647
File.write(file, JSON.pretty_generate(deps))
4748
end
+14-13
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
# frozen_string_literal: true
22

3+
# Hash that allows lookup by key and value
34
class BidirectionalHash
45
def initialize
5-
@forward = Hash.new { |h, k| h[k] = [ ] }
6-
@reverse = Hash.new { |h, k| h[k] = [ ] }
6+
@forward = Hash.new { |h, k| h[k] = [] }
7+
@reverse = Hash.new { |h, k| h[k] = [] }
78
end
89

9-
def insert(k, v)
10-
@forward[k].push(v)
11-
@reverse[v].push(k)
12-
v
10+
def insert(key, value)
11+
@forward[key].push(value)
12+
@reverse[value].push(key)
13+
value
1314
end
1415

15-
def fetch(k)
16-
fetch_from(@forward, k)
16+
def fetch(key)
17+
fetch_from(@forward, key)
1718
end
1819

19-
def rfetch(v)
20-
fetch_from(@reverse, v)
20+
def rfetch(value)
21+
fetch_from(@reverse, value)
2122
end
2223

2324
protected
2425

25-
def fetch_from(h, k)
26-
return nil if(!h.has_key?(k))
27-
v = h[k]
26+
def fetch_from(hash, key)
27+
return nil unless hash.key?(key)
28+
v = hash[key]
2829
v.length == 1 ? v.first : v.dup
2930
end
3031
end

lib/cpp_dependency_graph/component_link.rb

+7-12
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
require 'json'
44

5+
# Represents a link between two entities, a source and a target
56
class ComponentLink
7+
attr_reader :source
8+
attr_reader :target
9+
610
def initialize(source, target, cyclic = false)
711
@source = source
812
@target = target
913
@cyclic = cyclic
1014
end
1115

12-
def source
13-
@source
14-
end
15-
16-
def target
17-
@target
18-
end
19-
2016
def cyclic?
2117
@cyclic
2218
end
2319

2420
def ==(other)
2521
(source == other.source && target == other.target && cyclic? == other.cyclic?) ||
26-
(source == other.target && target == other.source && cyclic? == other.cyclic?)
22+
(source == other.target && target == other.source && cyclic? == other.cyclic?)
2723
end
2824

2925
def hash
@@ -38,9 +34,8 @@ def to_s
3834
end
3935
end
4036

41-
def to_json(*a)
37+
def to_json(*options)
4238
{ json_class: self.class.name,
43-
source: source, target: target, cyclic: cyclic?
44-
}.to_json(*a)
39+
source: source, target: target, cyclic: cyclic? }.to_json(*options)
4540
end
4641
end

lib/cpp_dependency_graph/cycle_detector.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
class CycleDetector
77
def initialize(component_links)
88
@cyclic_links = component_links.flat_map do |source, links|
9-
links.select { |target| component_links[target].include?(source) }.map do |target|
10-
[CyclicLink.new(source, target), true]
11-
end
12-
end.to_h
9+
links.select { |target| component_links[target].include?(source) }.map do |target|
10+
[CyclicLink.new(source, target), true]
11+
end
12+
end.to_h
1313
end
1414

1515
def cyclic?(source, target)

lib/cpp_dependency_graph/cyclic_link.rb

+9-14
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,24 @@
22

33
# A special class designed to be used as a key in a hash
44
class CyclicLink
5-
def initialize(nodeA, nodeB)
6-
@nodeA = nodeA
7-
@nodeB = nodeB
8-
end
9-
10-
def nodeA
11-
@nodeA
12-
end
5+
attr_reader :node_a
6+
attr_reader :node_b
137

14-
def nodeB
15-
@nodeB
8+
def initialize(node_a, node_b)
9+
@node_a = node_a
10+
@node_b = node_b
1611
end
1712

1813
def eql?(other)
19-
(@nodeA == other.nodeA && @nodeB == other.nodeB) ||
20-
(@nodeA == other.nodeB && @nodeB == other.nodeA)
14+
(@node_a == other.node_a && @node_b == other.node_b) ||
15+
(@node_a == other.node_b && @node_b == other.node_a)
2116
end
2217

2318
def hash
24-
[@nodeA, @nodeB].to_set.hash
19+
[@node_a, @node_b].to_set.hash
2520
end
2621

2722
def to_s
28-
"#{nodeA} <-> #{nodeB}"
23+
"#{node_a} <-> #{node_b}"
2924
end
3025
end

0 commit comments

Comments
 (0)