Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax: Remove unused variables or mark them as such #302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .standard_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ignore:
- Style/IdenticalConditionalBranches
- lib/csvlint/csvw/property_checker.rb:
- Performance/InefficientHashSearch
- Lint/UselessAssignment
- Naming/VariableName
- Style/SlicingWithRange
- Security/Open
Expand All @@ -24,18 +23,16 @@ 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:
- Lint/UselessRescue
- lib/csvlint/cli.rb:
- Style/SafeNavigation
6 changes: 3 additions & 3 deletions lib/csvlint/csvw/property_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/csvlint/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions lib/csvlint/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,20 @@ 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
end

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down