Skip to content

Commit

Permalink
Fix shifted when format_markdown option enabled and used non-ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
hasimoto1009 committed Oct 3, 2019
1 parent e43ab40 commit c0eb433
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ Lint/ShadowingOuterLocalVariable:

# Offense count: 20
Metrics/AbcSize:
Max: 138
Max: 139

# Offense count: 28
# Configuration parameters: CountComments, ExcludedMethods.
Expand Down
6 changes: 5 additions & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def get_schema_info(klass, header, options = {})
if options[:format_rdoc]
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
elsif options[:format_markdown]
name_remainder = max_size - col_name.length
name_remainder = max_size - col_name.length - non_ascii_length(col_name)
type_remainder = (md_type_allowance - 2) - col_type.length
info << (sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n"
else
Expand Down Expand Up @@ -932,6 +932,10 @@ def mb_chars_ljust(string, length)
string[0..length-1]
end
end

def non_ascii_length(string)
string.to_s.chars.reject(&:ascii_only?).length
end
end

class BadModelFileError < LoadError
Expand Down

0 comments on commit c0eb433

Please sign in to comment.