Skip to content

Commit 1fbafc0

Browse files
authored
Merge pull request #88 from evolve75/rubocop-fixes
Various Rubocop fixes
2 parents ab41e9c + b39b50b commit 1fbafc0

27 files changed

+768
-619
lines changed

.rubocop.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
# Local configuration for the rubocop linter.
2+
3+
# Inherit from the working file.
4+
inherit_from: .rubocop_todo.yml
5+
6+
AllCops:
7+
NewCops: enable
8+
TargetRubyVersion: 2.6
9+
10+
Lint/UselessAssignment:
11+
Exclude:
12+
- 'examples/example_basic.rb'

.rubocop_todo.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2022-06-20 06:06:47 UTC using RuboCop version 1.24.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: 47
10+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
11+
Metrics/AbcSize:
12+
Max: 97
13+
14+
# Offense count: 2
15+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
16+
# IgnoredMethods: refine
17+
Metrics/BlockLength:
18+
Max: 119
19+
20+
# Offense count: 3
21+
# Configuration parameters: CountComments, CountAsOne.
22+
Metrics/ClassLength:
23+
Max: 1066
24+
25+
# Offense count: 2
26+
# Configuration parameters: IgnoredMethods.
27+
Metrics/CyclomaticComplexity:
28+
Max: 8
29+
30+
# Offense count: 47
31+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
32+
Metrics/MethodLength:
33+
Max: 45
34+
35+
# Offense count: 1
36+
# Configuration parameters: IgnoredMethods.
37+
Metrics/PerceivedComplexity:
38+
Max: 9
39+
40+
# Offense count: 5
41+
Security/MarshalLoad:
42+
Exclude:
43+
- 'lib/tree.rb'
44+
- 'spec/tree_spec.rb'
45+
- 'test/test_tree.rb'

API-CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ smooth transition to the new APIs.
2020
* Use of integers as node-names now no longer requires the optional
2121
`num_as_name` method argument.
2222

23+
* The predicate methods beginning with `is_` or `has_` are now aliases to the
24+
real methods **without** these prefixes. For example,
25+
`Tree::TreeNode#is_root?` is now aliased to `Tree::TreeNode#root?`. This is to
26+
comply with the Ruby standard. These original prefixed method names should be
27+
considered as deprecated and the corresponding non-prefixed method names
28+
should be used instead. it is possible that the old prefixed method names
29+
might be removed in the future.
30+
2331
* [structured_warnings][] has been **removed** from the code-base and is no
2432
longer a dependency. This was a long-standing point of friction for many
2533
users.

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22

3-
source "https://rubygems.org"
3+
source 'https://rubygems.org'
44
gemspec

History.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
* Support for `CamelCase` methods has been dropped.
1212

13+
* The predicate methods beginning with `is_` or `has_` are now aliases to real
14+
methods **without** these prefixes. For example, `Tree::TreeNode#is_root?` is
15+
now aliased to `Tree::TreeNode#root?`. This is to comply with the Ruby
16+
standard. The original prefixed method names should be considered as
17+
deprecated and the corresponding non-prefixed method names should be used
18+
instead. it is possible that the old prefixed method names might be removed in
19+
the future.
20+
1321
* RubyTree now supports MRI Ruby versions `2.6.x`, `2.7.x`, and `3.0.x`.
1422

1523
* Explicit support for `rbx` Ruby has been removed (_might_ still work, but not

Rakefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3232
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
#
34+
#
35+
# frozen_string_literal: true
3436

3537
require 'rubygems'
36-
GEM_SPEC = eval(File.read('./rubytree.gemspec')) # Load the gemspec.
38+
39+
# @todo: Check if Bundler needs to be `require`d.
40+
GEM_SPEC = Bundler.load_gemspec(File.join(__dir__, 'rubytree.gemspec'))
3741

3842
PKG_NAME = GEM_SPEC.name
3943
PKG_VER = GEM_SPEC.version
@@ -55,6 +59,7 @@ task :version do
5559
end
5660

5761
require 'rake/clean'
62+
desc 'Remove all generated files.'
5863
task clean: 'gem:clobber_package'
5964
CLEAN.include('coverage')
6065
task clobber: [:clean, 'doc:clobber_rdoc', 'doc:clobber_yard']
@@ -70,8 +75,8 @@ namespace :doc do # ................................ Documentation
7075
require 'rdoc/task'
7176
Rake::RDocTask.new do |rdoc|
7277
rdoc.rdoc_dir = 'rdoc'
73-
rdoc.title = "#{PKG_NAME}-#{PKG_VER}"
74-
rdoc.main = 'README.rdoc'
78+
rdoc.title = "RubyTree Documenation: #{PKG_NAME}-#{PKG_VER}"
79+
rdoc.main = 'README.md'
7580
rdoc.rdoc_files.include(GEM_SPEC.extra_rdoc_files)
7681
rdoc.rdoc_files.include('./lib/**/*.rb')
7782
end
@@ -98,7 +103,8 @@ end
98103
desc 'Run the unit tests'
99104
task test: %w[test:unit]
100105

101-
namespace :test do # ................................ Test related
106+
# ................................ Test related
107+
namespace :test do
102108
desc 'Run all the tests'
103109
task all: %w[test:unit test:spec test:examples]
104110

@@ -109,7 +115,8 @@ namespace :test do # ................................ Test related
109115
test.verbose = false
110116
end
111117

112-
begin # ................................ rspec tests
118+
# ................................ rspec tests
119+
begin
113120
require 'rspec/core/rake_task'
114121

115122
RSpec::Core::RakeTask.new(:spec) do |t|
@@ -146,7 +153,8 @@ namespace :test do # ................................ Test related
146153
end
147154
end
148155

149-
namespace :tag do # ................................ Emacs Tags
156+
# ................................ Emacs Tags
157+
namespace :tag do
150158
require 'rtagstask'
151159
RTagsTask.new(:tags) do |rd|
152160
rd.vi = false
@@ -156,7 +164,8 @@ rescue LoadError
156164
# Oh well. Can't have everything.
157165
end
158166

159-
namespace :gem do # ................................ Gem related
167+
# ................................ Gem related
168+
namespace :gem do
160169
require 'rubygems/package_task'
161170
Gem::PackageTask.new(GEM_SPEC) do |pkg|
162171
pkg.need_zip = true
@@ -169,7 +178,8 @@ namespace :gem do # ................................ Gem related
169178
end
170179
end
171180

172-
require 'rubocop/rake_task' # ................................ Ruby linting
181+
# ................................ Ruby linting
182+
require 'rubocop/rake_task'
173183

174184
RuboCop::RakeTask.new(:rubocop) do |t|
175185
t.options = ['--display-cop-names']

examples/example_basic.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# example_basic.rb:: Basic usage of the tree library.
44
#
55
# Author: Anupam Sengupta
6-
# Time-stamp: <2015-12-31 22:17:30 anupam>
7-
# Copyright (C) 2013, 2015 Anupam Sengupta <anupamsg@gmail.com>
6+
# Time-stamp: <2022-06-19 22:52:29 anupam>
7+
# Copyright (C) 2013, 2015, 2022 Anupam Sengupta <anupamsg@gmail.com>
88
#
99
# The following example implements this tree structure:
1010
#
@@ -21,22 +21,29 @@
2121
# +-------+-------+
2222
# | GRANDCHILD 1 |
2323
# +---------------+
24+
#
25+
# frozen_string_literal: true
2426

2527
# ..... Example starts.
2628
require 'tree' # Load the library
2729

28-
# ..... Create the root node first. Note that every node has a name and an optional content payload.
30+
# ..... Create the root node first. Note that every node has a name and an
31+
# ..... optional content payload.
2932
root_node = Tree::TreeNode.new('ROOT', 'Root Content')
3033
root_node.print_tree
3134

32-
# ..... Now insert the child nodes. Note that you can "chain" the child insertions for a given path to any depth.
33-
root_node << Tree::TreeNode.new('CHILD1', 'Child1 Content') << Tree::TreeNode.new('GRANDCHILD1', 'GrandChild1 Content')
35+
# ..... Now insert the child nodes. Note that you can "chain" the child
36+
# ..... insertions for a given path to any depth.
37+
root_node << Tree::TreeNode.new('CHILD1', 'Child1 Content') \
38+
<< Tree::TreeNode.new('GRANDCHILD1', 'GrandChild1 Content')
3439
root_node << Tree::TreeNode.new('CHILD2', 'Child2 Content')
3540

36-
# ..... Lets print the representation to stdout. This is primarily used for debugging purposes.
41+
# ..... Lets print the representation to stdout. This is primarily used for
42+
# ..... debugging purposes.
3743
root_node.print_tree
3844

39-
# ..... Lets directly access children and grandchildren of the root. The can be "chained" for a given path to any depth.
45+
# ..... Lets directly access children and grandchildren of the root. The can be
46+
# ..... "chained" for a given path to any depth.
4047
child1 = root_node['CHILD1']
4148
grand_child1 = root_node['CHILD1']['GRANDCHILD1']
4249

lib/rubytree.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#
99
# Author:: Anupam Sengupta (anupamsg@gmail.com)
1010
#
11-
# Copyright (c) 2012, 2015 Anupam Sengupta
12-
#
13-
# All rights reserved.
11+
# Copyright (c) 2012-2022 Anupam Sengupta. All rights reserved.
1412
#
1513
# Redistribution and use in source and binary forms, with or without
1614
# modification, are permitted provided that the following conditions are met:
@@ -37,5 +35,6 @@
3735
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3836
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3937
#
38+
# frozen_string_literal: true
4039

4140
require 'tree'

0 commit comments

Comments
 (0)