From 625ac239028221a7666d22ed70dd45cd82317192 Mon Sep 17 00:00:00 2001 From: Thomas Brennetot Date: Sat, 23 Nov 2024 21:12:53 +0900 Subject: [PATCH 1/2] Remove unused variables or mark them as such And fix StandardRb's Lint/UselessAssignment rule. --- .standard_todo.yml | 5 ----- lib/csvlint/csvw/property_checker.rb | 6 +++--- lib/csvlint/schema.rb | 4 ++-- lib/csvlint/validate.rb | 8 +++----- spec/validator_spec.rb | 4 ++-- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.standard_todo.yml b/.standard_todo.yml index 559a4fc..9f2f38d 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -13,7 +13,6 @@ ignore: - Style/IdenticalConditionalBranches - lib/csvlint/csvw/property_checker.rb: - Performance/InefficientHashSearch - - Lint/UselessAssignment - Naming/VariableName - Style/SlicingWithRange - Security/Open @@ -24,17 +23,13 @@ ignore: - Naming/VariableName - lib/csvlint/schema.rb: - Security/Open - - Lint/UselessAssignment - Style/SlicingWithRange - lib/csvlint/validate.rb: - - Lint/UselessAssignment - Performance/Count - Lint/BooleanSymbol - Naming/VariableName - Security/Open - Lint/NonLocalExitFromIterator -- spec/validator_spec.rb: - - Lint/UselessAssignment - lib/csvlint/schema.rb: - Lint/UselessRescue - lib/csvlint/validate.rb: diff --git a/lib/csvlint/csvw/property_checker.rb b/lib/csvlint/csvw/property_checker.rb index c4d15bb..4ef0f2a 100644 --- a/lib/csvlint/csvw/property_checker.rb +++ b/lib/csvlint/csvw/property_checker.rb @@ -286,7 +286,7 @@ def column_reference_property(type) if value.instance_of? Hash if value["@id"] 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.values.include?(value["@id"]) - v, w, t = PROPERTIES["@id"].call(value["@id"], base_url, lang) + _, w, _ = PROPERTIES["@id"].call(value["@id"], base_url, lang) unless w.nil? warnings << w value.delete("@id") @@ -422,7 +422,7 @@ def column_reference_property(type) elsif p == "url" elsif p == "titles" else - v, warning, type = check_property(p, v, base_url, lang) + _, warning, type = check_property(p, v, base_url, lang) if type != :transformation && !(warning.nil? || warning.empty?) value.delete(p) warnings << :invalid_property unless type == :transformation @@ -555,7 +555,7 @@ def column_reference_property(type) warnings = [] value.each do |p, v| if ["resource", "schemaReference", "columnReference"].include? p - v, warning, type = check_property(p, v, base_url, lang) + v, warning, _ = check_property(p, v, base_url, lang) if warning.nil? || warning.empty? value[p] = v else diff --git a/lib/csvlint/schema.rb b/lib/csvlint/schema.rb index e6d841a..e0b08b7 100644 --- a/lib/csvlint/schema.rb +++ b/lib/csvlint/schema.rb @@ -48,7 +48,7 @@ def load_from_string(uri, string, output_errors = true) else Schema.from_json_table(uri, json) end - rescue TypeError => e + rescue TypeError # NO IDEA what this was even trying to do - SP 20160526 rescue Csvlint::Csvw::MetadataError => e raise e @@ -88,7 +88,7 @@ def validate_row(values, row = nil, all_errors = [], source_url = nil, validate fields.each_with_index do |field, i| value = values[i] || "" - result = field.validate_column(value, row, i + 1, all_errors) + field.validate_column(value, row, i + 1, all_errors) @errors += fields[i].errors @warnings += fields[i].warnings end diff --git a/lib/csvlint/validate.rb b/lib/csvlint/validate.rb index 1ddb289..e6290a3 100644 --- a/lib/csvlint/validate.rb +++ b/lib/csvlint/validate.rb @@ -157,7 +157,7 @@ def parse_line(line) # If it's not a full line, then prepare to add it to the beginning of the next chunk @leading = line end - rescue ArgumentError => ae + rescue ArgumentError build_errors(:invalid_encoding, :structure, @current_line, nil, @current_line) unless @reported_invalid_encoding @current_line += 1 @reported_invalid_encoding = true @@ -165,13 +165,12 @@ def parse_line(line) def validate_line(input = nil, index = nil) @input = input - single_col = false line = index.present? ? index : 0 @encoding = input.encoding.to_s report_line_breaks(line) parse_contents(input, line) @lambda&.call(self) - rescue ArgumentError => ae + rescue ArgumentError build_errors(:invalid_encoding, :structure, @current_line, nil, index) unless @reported_invalid_encoding @reported_invalid_encoding = true end @@ -205,7 +204,7 @@ def parse_contents(stream, line = nil) if @schema @schema.validate_row(row, current_line, all_errors, @source, @validate) @errors += @schema.errors - all_errors += @schema.errors + @schema.errors @warnings += @schema.warnings elsif !row.empty? && row.size != @expected_columns build_errors(:ragged_rows, :structure, current_line, nil, stream.to_s) @@ -277,7 +276,6 @@ def validate_metadata if schema.tables[@source_url] @schema = schema else - warn_if_unsuccessful = true build_warnings(:schema_mismatch, :context, nil, nil, @source_url, schema) end end diff --git a/spec/validator_spec.rb b/spec/validator_spec.rb index a3f3de7..6af2e85 100644 --- a/spec/validator_spec.rb +++ b/spec/validator_spec.rb @@ -573,14 +573,14 @@ it "should call a lambda for each line" do @count = 0 mylambda = lambda { |row| @count += 1 } - validator = Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda}) + Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda}) expect(@count).to eq(3) end it "reports back the status of each line" do @results = [] mylambda = lambda { |row| @results << row.current_line } - validator = Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda}) + Csvlint::Validator.new(File.new(File.join(File.dirname(__FILE__), "..", "features", "fixtures", "valid.csv")), {}, nil, {lambda: mylambda}) expect(@results.count).to eq(3) expect(@results[0]).to eq(1) expect(@results[1]).to eq(2) From 8838b0e99a4a3b504f6c8ca233f9ce073a348a97 Mon Sep 17 00:00:00 2001 From: Thomas Brennetot Date: Sat, 23 Nov 2024 21:19:04 +0900 Subject: [PATCH 2/2] Add new TODO to StandardRb --- .standard_todo.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.standard_todo.yml b/.standard_todo.yml index 9f2f38d..70c440c 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -34,3 +34,5 @@ ignore: - Lint/UselessRescue - lib/csvlint/validate.rb: - Lint/UselessRescue +- lib/csvlint/cli.rb: + - Style/SafeNavigation