Skip to content

Commit 3b79997

Browse files
Shreyas Balakrishnashreyasbharath
Shreyas Balakrishna
authored andcommitted
fixup! fixup! fixup! fixup! fixup! Blah
1 parent a7d0ae1 commit 3b79997

15 files changed

+52
-41
lines changed

Diff for: .rubocop.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4-
TargetRubyVersion: 2.5
4+
TargetRubyVersion: 2.7
55
DisabledByDefault: false
66

7-
Metrics/LineLength:
7+
Layout/LineLength:
88
Max: 140

Diff for: cpp_dependency_graph.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Gem::Specification.new do |s|
2929
s.rubygems_version = '3.1.2'
3030

3131
s.add_runtime_dependency 'docopt', '~> 0.6'
32-
s.add_runtime_dependency 'ruby-graphviz', '~> 1.2'
3332
s.add_runtime_dependency 'json', '~> 2.3.0'
33+
s.add_runtime_dependency 'ruby-graphviz', '~> 1.2'
3434

3535
s.add_development_dependency 'bundler', '~> 2.1'
3636
s.add_development_dependency 'debase', '~> 0.2'

Diff for: lib/cpp_dependency_graph/bidirectional_hash.rb

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def rfetch(value)
2525

2626
def fetch_from(hash, key)
2727
return nil unless hash.key?(key)
28+
2829
v = hash[key]
2930
v.length == 1 ? v.first : v.dup
3031
end

Diff for: lib/cpp_dependency_graph/component_dependency_graph.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def all_cyclic_links
2020

2121
def links(name)
2222
return {} unless all_links.key?(name)
23+
2324
links = incoming_links(name)
2425
links.merge!(outgoing_links(name))
2526
links

Diff for: lib/cpp_dependency_graph/dir_tree.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DirTree
1111
attr_reader :tree
1212

1313
def initialize(path)
14-
@tree ||= File.directory?(path) ? parse_dirs(path) : {}
14+
@tree = File.directory?(path) ? parse_dirs(path) : {}
1515
end
1616

1717
private
@@ -22,9 +22,12 @@ def parse_dirs(path, name = nil)
2222
# TODO: Use Dir.map.compact|filter instead here
2323
Dir.foreach(path) do |entry|
2424
next if ['..', '.'].include?(entry)
25+
2526
full_path = File.join(path, entry)
2627
next unless File.directory?(full_path)
28+
2729
next unless source_files_present?(full_path)
30+
2831
data[:children] << parse_dirs(full_path, entry)
2932
end
3033
data

Diff for: lib/cpp_dependency_graph/directory_parser.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
# Utility methods for parsing directories
14
module DirectoryParser
25
def fetch_all_dirs(root_dir)
36
Find.find(root_dir).select { |e| File.directory?(e) && e != root_dir }

Diff for: lib/cpp_dependency_graph/file_dependency_graph.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def all_cyclic_links
2020

2121
def links(name)
2222
return {} unless all_links.key?(name)
23+
2324
links = incoming_links(name)
2425
links.merge!(outgoing_links(name))
2526
links

Diff for: lib/cpp_dependency_graph/graph_to_dot_visualiser.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
class GraphToDotVisualiser
77
def generate(deps, file)
88
@g = GraphViz.new('dependency_graph')
9-
nodes = create_nodes(deps)
10-
connect_nodes(deps, nodes)
11-
@g.output(:dot => file)
9+
create_nodes(deps)
10+
connect_nodes(deps)
11+
@g.output(dot: file)
1212
end
1313

1414
private
@@ -17,20 +17,20 @@ def create_nodes(deps)
1717
node_names = deps.flat_map do |_, links|
1818
links.map { |link| [link.source, link.target] }.flatten
1919
end.uniq
20-
nodes = node_names.map { |name| [name, create_node(name)] }.to_h
21-
nodes
20+
node_names.each do |name|
21+
add_node(name)
22+
end
2223
end
2324

24-
def create_node(name)
25-
node = @g.add_node(name, :shape => 'box3d')
26-
node
25+
def add_node(name)
26+
@g.add_node(name, shape: 'box3d')
2727
end
2828

29-
def connect_nodes(deps, nodes)
29+
def connect_nodes(deps)
3030
deps.each do |source, links|
3131
links.each do |link|
3232
if link.cyclic?
33-
@g.add_edges(source, link.target, :color => 'red')
33+
@g.add_edges(source, link.target, color: 'red')
3434
else
3535
@g.add_edges(source, link.target)
3636
end

Diff for: lib/cpp_dependency_graph/include_component_dependency_graph.rb

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def initialize(project)
1111
end
1212

1313
def all_links
14-
components = @project.source_components
1514
@project.source_files.map do |file|
1615
links = file.includes.map { |inc| Link.new(file.basename, inc, false) }
1716
[file.basename, links]

Diff for: lib/cpp_dependency_graph/include_to_component_resolver.rb

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def external_includes(component)
1919

2020
def component_for_include(include)
2121
return '' unless source_files.key?(include)
22+
2223
@component_include_map_cache[include] = component_for_include_private(include) unless @component_include_map_cache.key?(include)
2324
@component_include_map_cache[include]
2425
end
@@ -35,6 +36,7 @@ def component_for_include_private(include)
3536
header_file = source_files[include]
3637
implementation_files = implementation_files(header_file)
3738
return header_file.parent_component if implementation_files.empty?
39+
3840
implementation_files[0].parent_component
3941
end
4042

Diff for: lib/cpp_dependency_graph/project.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def source_components
2121

2222
def source_component(name)
2323
return SourceComponent.new('NULL') unless source_components.key?(name)
24+
2425
source_components[name]
2526
end
2627

@@ -65,5 +66,4 @@ def build_source_components
6566
end.to_h
6667
components.delete_if { |_, v| v.source_files.size.zero? }
6768
end
68-
6969
end

Diff for: lib/cpp_dependency_graph/source_file.rb

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def file_contents
5353
def sanitised_file_contents
5454
contents = File.read(@path)
5555
return contents if contents.valid_encoding?
56+
5657
contents.encode('UTF-16be', invalid: :replace, replace: '?').encode('UTF-8')
5758
end
5859
end

Diff for: spec/test/component_dependency_graph_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
expect(links['Framework']).to be_empty
1616
expect(links['System']).to be_empty
1717
expect(links['Engine']).to contain_exactly(Link.new('Engine', 'DataAccess', false), Link.new('Engine', 'Framework', false),
18-
Link.new('Engine', 'UI', true))
18+
Link.new('Engine', 'UI', true))
1919
end
2020

2121
it 'returns empty links for an unknown component of a project' do

Diff for: spec/test/dir_tree_spec.rb

+22-23
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,28 @@
1212
end
1313

1414
it 'returns all directories and its subdirectories as a tree hash structure' do
15-
expected_tree = JSON.parse('{
16-
"name": "spec/test/example_project",
17-
"children": [{
18-
"name": "DataAccess",
19-
"children": []
20-
}, {
21-
"name": "Engine",
22-
"children": []
23-
}, {
24-
"name": "Framework",
25-
"children": []
26-
}, {
27-
"name": "main",
28-
"children": []
29-
}, {
30-
"name": "System",
31-
"children": []
32-
}, {
33-
"name": "UI",
34-
"children": []
35-
}]
36-
}',
37-
symbolize_names: true)
15+
# expected_tree = JSON.parse('{
16+
# "name": "spec/test/example_project",
17+
# "children": [{
18+
# "name": "DataAccess",
19+
# "children": []
20+
# }, {
21+
# "name": "Engine",
22+
# "children": []
23+
# }, {
24+
# "name": "Framework",
25+
# "children": []
26+
# }, {
27+
# "name": "main",
28+
# "children": []
29+
# }, {
30+
# "name": "System",
31+
# "children": []
32+
# }, {
33+
# "name": "UI",
34+
# "children": []
35+
# }]
36+
# }')
3837
# expect(dir_tree.tree).to eq(expected_tree)
3938
end
4039
end

Diff for: spec/test/project_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
it 'all source files of project' do
3636
project = Project.new('spec/test/example_project')
3737
source_files = project.source_files.values.map(&:basename)
38-
expect(source_files).to contain_exactly('DA.h', 'Display.cpp', 'Display.h', 'Engine.cpp', 'Engine.h', 'Engine.h', 'OldEngine.h', 'System.cpp', 'System.h', 'framework.h', 'main.cpp')
38+
expect(source_files).to contain_exactly('DA.h', 'Display.cpp', 'Display.h', 'Engine.cpp', 'Engine.h', 'Engine.h',
39+
'OldEngine.h', 'System.cpp', 'System.h', 'framework.h', 'main.cpp')
3940
end
4041
end

0 commit comments

Comments
 (0)