From b3e72837e56d76d0ae780a2e06c30886de13f7e8 Mon Sep 17 00:00:00 2001 From: Thomas Brennetot Date: Sat, 23 Nov 2024 21:19:04 +0900 Subject: [PATCH 1/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 559a4fc..79f2be0 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -39,3 +39,5 @@ ignore: - Lint/UselessRescue - lib/csvlint/validate.rb: - Lint/UselessRescue +- lib/csvlint/cli.rb: + - Style/SafeNavigation From d2739cfa470b18e91da13e01b5f83bfd0451934e Mon Sep 17 00:00:00 2001 From: Thomas Brennetot Date: Sat, 23 Nov 2024 21:24:38 +0900 Subject: [PATCH 2/2] Fix Style/SafeNavigation --- .standard_todo.yml | 2 -- lib/csvlint/cli.rb | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.standard_todo.yml b/.standard_todo.yml index 79f2be0..559a4fc 100644 --- a/.standard_todo.yml +++ b/.standard_todo.yml @@ -39,5 +39,3 @@ ignore: - Lint/UselessRescue - lib/csvlint/validate.rb: - Lint/UselessRescue -- lib/csvlint/cli.rb: - - Style/SafeNavigation diff --git a/lib/csvlint/cli.rb b/lib/csvlint/cli.rb index 03694db..7d4edef 100644 --- a/lib/csvlint/cli.rb +++ b/lib/csvlint/cli.rb @@ -104,7 +104,7 @@ def print_error(index, error, dump, color) location = "#{error.row ? "Row" : "Column"}: #{location}" end output_string = "#{index + 1}. " - if error.column && @schema && @schema.instance_of?(Csvlint::Schema) + if error.column && @schema&.instance_of?(Csvlint::Schema) unless @schema.fields[error.column - 1].nil? output_string += "#{@schema.fields[error.column - 1].name}: " end @@ -176,7 +176,7 @@ def hashify(error) col: error.column } - if error.column && @schema && @schema.instance_of?(Csvlint::Schema) && !@schema.fields[error.column - 1].nil? + if error.column && @schema&.instance_of?(Csvlint::Schema) && !@schema.fields[error.column - 1].nil? field = @schema.fields[error.column - 1] h[:header] = field.name h[:constraints] = field.constraints.map { |k, v| [k.underscore, v] }.to_h