From ff79a434f0d4e816dcbb7dae7bcde53d68ba3efc Mon Sep 17 00:00:00 2001 From: Serhii Bodnaruk Date: Tue, 30 Jun 2026 17:07:02 +0300 Subject: [PATCH] Fix trailing whitespace and line-length in generated column annotations ColumnFormatter was emitting trailing spaces on column lines because the left-hand side was built with %-width padding and only stripped on the final joined line, not before passing through the wrapping branch. This produced: # trailing whitespace offense (padded left with no options) # line-too-long offense (continuation line included deep indent) Fix: rstrip left immediately after formatting, before any output path. indent_size is now derived from the stripped left length, keeping multiline default values visually aligned under their opening token. --- Gemfile.lock | 2 +- lib/annotato/column_formatter.rb | 12 ++++++------ lib/annotato/version.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5c92b5a..d0f7222 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - annotato (0.2.2) + annotato (0.2.3) rails (>= 6.0) GEM diff --git a/lib/annotato/column_formatter.rb b/lib/annotato/column_formatter.rb index bc9823f..9ca504a 100644 --- a/lib/annotato/column_formatter.rb +++ b/lib/annotato/column_formatter.rb @@ -26,11 +26,12 @@ def self.format(model, connection) type = col.sql_type # Build the left-hand side and calculate indent. - left = "# %-#{name_width}s :%-#{type_width}s" % [name, type] - # " default(" is 9 chars; +2 gives the extra gap. + # Strip trailing padding spaces immediately — output must never have trailing whitespace. + left = ("# %-#{name_width}s :%-#{type_width}s" % [name, type]).rstrip + # indent_size aligns multiline default content under the opening "default(" token. indent_size = left.length + 1 indent_str = " " * indent_size - closing_indent_str = " " * (indent_size - 2) + closing_indent_str = " " * (indent_size - 2) # Gather all options, pulling out default_lines if multiline. opts = [] @@ -64,10 +65,9 @@ def self.format(model, connection) opts_str = opts.join(", ") line = opts_str.empty? ? left : "#{left} #{opts_str}" if line.length > WrapHelper::MAX_LINE && !opts_str.empty? - cont_indent = " " * (left.length + 1) - [left, "# #{cont_indent}#{opts_str}"] + [left, "# #{opts_str}"] else - [line.rstrip] + [line] end end end diff --git a/lib/annotato/version.rb b/lib/annotato/version.rb index 8f3ae77..5ec7b83 100644 --- a/lib/annotato/version.rb +++ b/lib/annotato/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Annotato - VERSION = "0.2.2" + VERSION = "0.2.3" end