Skip to content

Commit 50d8c01

Browse files
committed
Tweaks comments to match formatting convention
1 parent d816dfb commit 50d8c01

File tree

7 files changed

+33
-36
lines changed

7 files changed

+33
-36
lines changed

lib/bashcov.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ def command_name
6969
end
7070

7171
def bash_path
72-
# First attempt to use the value from `options`, but ignore all exceptions.
73-
# This is used early for the `BASH_VERSION` definition, so first use will likely error.
72+
# first attempt to use the value from `options`, but ignore all exceptions
73+
# this is used early for the `BASH_VERSION` definition, so first use will likely error
7474
begin
7575
return @options.bash_path if @options.bash_path
7676
rescue NoMethodError; end # rubocop:disable Lint/SuppressedException
7777

78-
# Support the same `BASHCOV_BASH_PATH` environment variable used in the spec tests.
78+
# support the same `BASHCOV_BASH_PATH` environment variable used in the spec tests
7979
return ENV.fetch("BASHCOV_BASH_PATH", nil) unless ENV.fetch("BASHCOV_BASH_PATH", "").empty?
8080

81-
# Fall back to standard Bash location, if available.
81+
# fall back to standard Bash location, if available
8282
return "/bin/bash" if File.executable?("/bin/bash")
8383

84-
# Otherwise, try to execute a Bash from `PATH`.
84+
# otherwise, try to execute a Bash from `PATH`
8585
"bash"
8686
end
8787

@@ -112,7 +112,7 @@ def set_default_options!
112112
private
113113

114114
def help
115-
<<-HELP.gsub(/^ +/, "").gsub("\t", " " * 4)
115+
<<~HELP.gsub("\t", " " * 4)
116116
Usage: #{program_name} [options] [--] <command> [options]
117117
Examples:
118118
\t#{program_name} ./script.sh
@@ -141,8 +141,9 @@ def option_parser
141141

142142
options.bash_path = p
143143

144-
# Redefine `BASH_VERSION` constant with upated `bash_path`.
145-
# This is hacky, but a lot of code references that constant and this should only have to be done once.
144+
# redefine `BASH_VERSION` constant with updated `bash_path`, this is
145+
# hacky, but a lot of code references that constant and this should
146+
# only have to be done once
146147
send(:remove_const, "BASH_VERSION")
147148
const_set("BASH_VERSION", bash_version.freeze)
148149
end

lib/bashcov/detective.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def shellscript?(filename)
4343
# shebang
4444
# @note assumes that +filename+ is readable and refers to a regular file
4545
def shellscript_shebang?(filename)
46-
# Handle empty files that cause an immediate EOFError
46+
# handle empty files that cause an immediate EOFError
4747
begin
4848
shebang = File.open(filename) { |f| f.readline.chomp }
4949
rescue EOFError
@@ -67,8 +67,8 @@ def shellscript_shebang_line?(shebang)
6767

6868
args = scanner.skip(/\s+/).nil? ? [] : scanner.rest.split(/\s+/)
6969
rescue ArgumentError
70-
# Handle "invalid byte sequence in UTF-8" from `StringScanner`. Can
71-
# happen when trying to read binary data (e.g. .pngs).
70+
# handle "invalid byte sequence in UTF-8" from `StringScanner`, this can
71+
# happen when trying to read binary data (e.g. .png)
7272
return false
7373
end
7474

lib/bashcov/field_stream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Bashcov
4-
# Classes for streaming token-delimited fields
4+
# Class for streaming token-delimited fields
55
class FieldStream
66
attr_accessor :read
77

@@ -43,7 +43,7 @@ def each(delimiter, field_count, start_match, &block)
4343
(field_count - chunk.size).times { yield "" }
4444
end
4545

46-
# Skip junk that might appear before the first start-of-fields match
46+
# skip junk that might appear before the first start-of-fields match
4747
begin
4848
n, chunk = chunked.next
4949
yield_fields.call([n, chunk]) unless n.zero?

lib/bashcov/lexer.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,15 @@ def relevant?(line)
9999
line.sub!(/\s#.*\Z/, "") # remove comments
100100
line.strip!
101101

102-
relevant = true
102+
return false if line.empty? ||
103+
IGNORE_IS.include?(line) ||
104+
line.start_with?(*IGNORE_START_WITH) ||
105+
line.end_with?(*IGNORE_END_WITH)
103106

104-
relevant &= false if line.empty? ||
105-
IGNORE_IS.include?(line) ||
106-
line.start_with?(*IGNORE_START_WITH) ||
107-
line.end_with?(*IGNORE_END_WITH)
107+
return false if line =~ /\A[a-zA-Z_][a-zA-Z0-9_\-:]*\(\)/ # function declared without the `function` keyword
108+
return false if line =~ /\A[^)]+\)\Z/ # case statement selector, e.g. `--help)`
108109

109-
relevant &= false if line =~ /\A[a-zA-Z_][a-zA-Z0-9_\-:]*\(\)/ # function declared without the `function` keyword
110-
relevant &= false if line =~ /\A[^)]+\)\Z/ # case statement selector, e.g. `--help)`
111-
112-
relevant
110+
true
113111
end
114112
end
115113
end

lib/bashcov/line.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ module Bashcov
44
# {Line} represents a line of code.
55
module Line
66
# Uncovered line
7-
# @see http://ruby-doc.org/stdlib-2.3.0/libdoc/coverage/rdoc/Coverage.html
7+
# @see http://ruby-doc.org/stdlib-3.0.0/libdoc/coverage/rdoc/Coverage.html
88
UNCOVERED = 0
99

1010
# Ignored line
11-
# @see http://ruby-doc.org/stdlib-2.3.0/libdoc/coverage/rdoc/Coverage.html
11+
# @see http://ruby-doc.org/stdlib-3.0.0/libdoc/coverage/rdoc/Coverage.html
1212
IGNORED = nil
1313
end
1414
end

lib/bashcov/runner.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def initialize(command)
2323
# @note Binds Bashcov +stdin+ to the program being executed.
2424
# @return [Process::Status] Status of the executed command
2525
def run
26-
# Clear out previous run
27-
@result = nil
26+
@result = nil # clear out previous run
2827

2928
field_stream = FieldStream.new
3029
@xtrace = Xtrace.new(field_stream)

lib/bashcov/xtrace.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def read
114114
# @raise [XtraceError] when +lineno+ is not composed solely of digits,
115115
# indicating that something has gone wrong with parsing the +PS4+ fields
116116
def parse_hit!(lineno, *paths)
117-
# If +LINENO+ isn't a series of digits, something has gone wrong. Add
118-
# +@files+ to the exception in order to propagate the existing coverage
119-
# data back to the {Bashcov::Runner} instance.
117+
# if +LINENO+ isn't a series of digits, add +@files+ to the exception in
118+
# order to propagate the existing coverage data back to the
119+
# {Bashcov::Runner} instance
120120
if /\A\d+\z/.match?(lineno)
121121
lineno = lineno.to_i
122122
elsif lineno == "${LINENO-}"
@@ -128,15 +128,14 @@ def parse_hit!(lineno, *paths)
128128
)
129129
end
130130

131-
# The next three fields will be $BASH_SOURCE, $PWD, $OLDPWD, and $LINENO
132131
bash_source, pwd, oldpwd = paths.map { |p| Pathname.new(p) }
133132

134133
update_wd_stacks!(pwd, oldpwd)
135134

136135
script = find_script(bash_source)
137136

138-
# For one-liners, +LINENO+ == 0. Do this to avoid an +IndexError+;
139-
# one-liners will be culled from the coverage results later on.
137+
# for one-liners, +LINENO+ == 0, do this to avoid an +IndexError+
138+
# one-liners will be culled from the coverage results later on
140139
index = (lineno > 1 ? lineno - 1 : 0)
141140

142141
@files[script] ||= []
@@ -172,16 +171,16 @@ def update_wd_stacks!(pwd, oldpwd)
172171
@pwd_stack[0] ||= pwd
173172
@oldpwd_stack[0] ||= oldpwd unless oldpwd.to_s.empty?
174173

175-
# We haven't changed working directories; short-circuit.
174+
# return if we haven't changed working directories
176175
return if pwd == @pwd_stack[-1]
177176

178-
# If the current +pwd+ is identical to the top of the +@oldpwd_stack+ and
177+
# if the current +pwd+ is identical to the top of the +@oldpwd_stack+ and
179178
# the current +oldpwd+ is identical to the second-to-top entry, then a
180-
# previous cd/pushd has been undone.
179+
# previous cd/pushd has been undone
181180
if pwd == @oldpwd_stack[-1] && oldpwd == @oldpwd_stack[-2]
182181
@pwd_stack.pop
183182
@oldpwd_stack.pop
184-
else # New cd/pushd
183+
else # new cd/pushd
185184
@pwd_stack << pwd
186185
@oldpwd_stack << oldpwd
187186
end

0 commit comments

Comments
 (0)