Skip to content

Commit 79de6e3

Browse files
committed
Fix shifted when format_markdown option enabled and used non-ascii
1 parent e43ab40 commit 79de6e3

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Lint/ShadowingOuterLocalVariable:
408408

409409
# Offense count: 20
410410
Metrics/AbcSize:
411-
Max: 138
411+
Max: 139
412412

413413
# Offense count: 28
414414
# Configuration parameters: CountComments, ExcludedMethods.

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def get_schema_info(klass, header, options = {})
305305
if options[:format_rdoc]
306306
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
307307
elsif options[:format_markdown]
308-
name_remainder = max_size - col_name.length
308+
name_remainder = max_size - col_name.length - non_ascii_length(col_name)
309309
type_remainder = (md_type_allowance - 2) - col_type.length
310310
info << (sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n"
311311
else
@@ -932,6 +932,10 @@ def mb_chars_ljust(string, length)
932932
string[0..length-1]
933933
end
934934
end
935+
936+
def non_ascii_length(string)
937+
string.to_s.chars.reject(&:ascii_only?).length
938+
end
935939
end
936940

937941
class BadModelFileError < LoadError

0 commit comments

Comments
 (0)