Skip to content

Commit 34ae640

Browse files
authored
Merge branch 'main' into standardrb-fix-performance_inefficient_hash_search
2 parents d1d2bb2 + 4d8a9b6 commit 34ae640

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

.standard_todo.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ignore:
1313
- Style/IdenticalConditionalBranches
1414
- lib/csvlint/csvw/property_checker.rb:
1515
- Lint/UselessAssignment
16+
- Performance/InefficientHashSearch
1617
- Naming/VariableName
1718
- Style/SlicingWithRange
1819
- Security/Open
@@ -23,17 +24,13 @@ ignore:
2324
- Naming/VariableName
2425
- lib/csvlint/schema.rb:
2526
- Security/Open
26-
- Lint/UselessAssignment
2727
- Style/SlicingWithRange
2828
- lib/csvlint/validate.rb:
29-
- Lint/UselessAssignment
3029
- Performance/Count
3130
- Lint/BooleanSymbol
3231
- Naming/VariableName
3332
- Security/Open
3433
- Lint/NonLocalExitFromIterator
35-
- spec/validator_spec.rb:
36-
- Lint/UselessAssignment
3734
- lib/csvlint/schema.rb:
3835
- Lint/UselessRescue
3936
- lib/csvlint/validate.rb:

lib/csvlint/csvw/property_checker.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def column_reference_property(type)
286286
if value.instance_of? Hash
287287
if value["@id"]
288288
raise Csvlint::Csvw::MetadataError.new("datatype.@id"), "datatype @id must not be the id of a built-in datatype (#{value["@id"]})" if BUILT_IN_DATATYPES.value?(value["@id"])
289-
v, w, t = PROPERTIES["@id"].call(value["@id"], base_url, lang)
289+
_, w, _ = PROPERTIES["@id"].call(value["@id"], base_url, lang)
290290
unless w.nil?
291291
warnings << w
292292
value.delete("@id")
@@ -422,7 +422,7 @@ def column_reference_property(type)
422422
elsif p == "url"
423423
elsif p == "titles"
424424
else
425-
v, warning, type = check_property(p, v, base_url, lang)
425+
_, warning, type = check_property(p, v, base_url, lang)
426426
if type != :transformation && !(warning.nil? || warning.empty?)
427427
value.delete(p)
428428
warnings << :invalid_property unless type == :transformation
@@ -555,7 +555,7 @@ def column_reference_property(type)
555555
warnings = []
556556
value.each do |p, v|
557557
if ["resource", "schemaReference", "columnReference"].include? p
558-
v, warning, type = check_property(p, v, base_url, lang)
558+
v, warning, _ = check_property(p, v, base_url, lang)
559559
if warning.nil? || warning.empty?
560560
value[p] = v
561561
else

lib/csvlint/schema.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def load_from_string(uri, string, output_errors = true)
4848
else
4949
Schema.from_json_table(uri, json)
5050
end
51-
rescue TypeError => e
51+
rescue TypeError
5252
# NO IDEA what this was even trying to do - SP 20160526
5353
rescue Csvlint::Csvw::MetadataError => e
5454
raise e
@@ -88,7 +88,7 @@ def validate_row(values, row = nil, all_errors = [], source_url = nil, validate
8888

8989
fields.each_with_index do |field, i|
9090
value = values[i] || ""
91-
result = field.validate_column(value, row, i + 1, all_errors)
91+
field.validate_column(value, row, i + 1, all_errors)
9292
@errors += fields[i].errors
9393
@warnings += fields[i].warnings
9494
end

lib/csvlint/validate.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,20 @@ def parse_line(line)
157157
# If it's not a full line, then prepare to add it to the beginning of the next chunk
158158
@leading = line
159159
end
160-
rescue ArgumentError => ae
160+
rescue ArgumentError
161161
build_errors(:invalid_encoding, :structure, @current_line, nil, @current_line) unless @reported_invalid_encoding
162162
@current_line += 1
163163
@reported_invalid_encoding = true
164164
end
165165

166166
def validate_line(input = nil, index = nil)
167167
@input = input
168-
single_col = false
169168
line = index.present? ? index : 0
170169
@encoding = input.encoding.to_s
171170
report_line_breaks(line)
172171
parse_contents(input, line)
173172
@lambda&.call(self)
174-
rescue ArgumentError => ae
173+
rescue ArgumentError
175174
build_errors(:invalid_encoding, :structure, @current_line, nil, index) unless @reported_invalid_encoding
176175
@reported_invalid_encoding = true
177176
end
@@ -205,7 +204,7 @@ def parse_contents(stream, line = nil)
205204
if @schema
206205
@schema.validate_row(row, current_line, all_errors, @source, @validate)
207206
@errors += @schema.errors
208-
all_errors += @schema.errors
207+
@schema.errors
209208
@warnings += @schema.warnings
210209
elsif !row.empty? && row.size != @expected_columns
211210
build_errors(:ragged_rows, :structure, current_line, nil, stream.to_s)
@@ -277,7 +276,6 @@ def validate_metadata
277276
if schema.tables[@source_url]
278277
@schema = schema
279278
else
280-
warn_if_unsuccessful = true
281279
build_warnings(:schema_mismatch, :context, nil, nil, @source_url, schema)
282280
end
283281
end

spec/validator_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,14 @@
573573
it "should call a lambda for each line" do
574574
@count = 0
575575
mylambda = lambda { |row| @count += 1 }
576-
validator = Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda})
576+
Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda})
577577
expect(@count).to eq(3)
578578
end
579579

580580
it "reports back the status of each line" do
581581
@results = []
582582
mylambda = lambda { |row| @results << row.current_line }
583-
validator = Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda})
583+
Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda})
584584
expect(@results.count).to eq(3)
585585
expect(@results[0]).to eq(1)
586586
expect(@results[1]).to eq(2)

0 commit comments

Comments
 (0)