Commit 111640d0 by Andrew W. Lee

Merge branch 'develop'

parents 0ef095dc 5ac56e47
inherit_from: ./.rubocop_todo.yml inherit_from:
- .rubocop_todo.yml
AllCops: AllCops:
Exclude: Exclude:
......
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2019-03-07 18:25:02 -0800 using RuboCop version 0.65.0. # on 2019-06-16 12:01:03 -0700 using RuboCop version 0.68.1.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
...@@ -51,7 +51,7 @@ Layout/AlignArray: ...@@ -51,7 +51,7 @@ Layout/AlignArray:
Exclude: Exclude:
- 'spec/annotate/annotate_models_spec.rb' - 'spec/annotate/annotate_models_spec.rb'
# Offense count: 103 # Offense count: 104
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table # SupportedHashRocketStyles: key, separator, table
...@@ -149,7 +149,7 @@ Layout/EmptyLinesAroundExceptionHandlingKeywords: ...@@ -149,7 +149,7 @@ Layout/EmptyLinesAroundExceptionHandlingKeywords:
# Offense count: 24 # Offense count: 24
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing: Layout/ExtraSpacing:
Exclude: Exclude:
- 'Guardfile' - 'Guardfile'
...@@ -170,7 +170,7 @@ Layout/ExtraSpacing: ...@@ -170,7 +170,7 @@ Layout/ExtraSpacing:
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: IndentationWidth. # Configuration parameters: IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces # SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/IndentHash: Layout/IndentFirstHashElement:
EnforcedStyle: consistent EnforcedStyle: consistent
# Offense count: 54 # Offense count: 54
...@@ -247,7 +247,7 @@ Layout/SpaceAroundKeyword: ...@@ -247,7 +247,7 @@ Layout/SpaceAroundKeyword:
- 'spec/integration/rails_4.2.0/Gemfile' - 'spec/integration/rails_4.2.0/Gemfile'
- 'spec/integration/standalone/Gemfile' - 'spec/integration/standalone/Gemfile'
# Offense count: 4 # Offense count: 5
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment. # Configuration parameters: AllowForAlignment.
Layout/SpaceAroundOperators: Layout/SpaceAroundOperators:
...@@ -419,15 +419,15 @@ Lint/UnusedBlockArgument: ...@@ -419,15 +419,15 @@ Lint/UnusedBlockArgument:
Exclude: Exclude:
- 'bin/annotate' - 'bin/annotate'
# Offense count: 18 # Offense count: 19
Metrics/AbcSize: Metrics/AbcSize:
Max: 139 Max: 138
# Offense count: 29 # Offense count: 27
# Configuration parameters: CountComments, ExcludedMethods. # Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine # ExcludedMethods: refine
Metrics/BlockLength: Metrics/BlockLength:
Max: 1140 Max: 244
# Offense count: 1 # Offense count: 1
# Configuration parameters: CountBlocks. # Configuration parameters: CountBlocks.
...@@ -475,14 +475,6 @@ Naming/UncommunicativeMethodParamName: ...@@ -475,14 +475,6 @@ Naming/UncommunicativeMethodParamName:
Exclude: Exclude:
- 'Rakefile' - 'Rakefile'
# Offense count: 4
# Cop supports --auto-correct.
Performance/RegexpMatch:
Exclude:
- 'lib/annotate/annotate_models.rb'
- 'lib/annotate/annotate_routes.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 1 # Offense count: 1
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.
# SupportedStyles: inline, group # SupportedStyles: inline, group
...@@ -688,7 +680,7 @@ Style/NestedParenthesizedCalls: ...@@ -688,7 +680,7 @@ Style/NestedParenthesizedCalls:
Style/NumericLiterals: Style/NumericLiterals:
MinDigits: 15 MinDigits: 15
# Offense count: 2 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison # SupportedStyles: predicate, comparison
...@@ -809,7 +801,7 @@ Style/StderrPuts: ...@@ -809,7 +801,7 @@ Style/StderrPuts:
- 'lib/annotate/annotate_models.rb' - 'lib/annotate/annotate_models.rb'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 240 # Offense count: 243
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes # SupportedStyles: single_quotes, double_quotes
...@@ -867,8 +859,9 @@ Style/UnneededPercentQ: ...@@ -867,8 +859,9 @@ Style/UnneededPercentQ:
- 'annotate.gemspec' - 'annotate.gemspec'
- 'spec/integration/rails_2.3_with_bundler/config/boot.rb' - 'spec/integration/rails_2.3_with_bundler/config/boot.rb'
# Offense count: 424 # Offense count: 431
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https # URISchemes: http, https
Metrics/LineLength: Metrics/LineLength:
Max: 276 Max: 276
sudo: false sudo: false
language: ruby language: ruby
rvm: rvm:
- 2.2.7 - 2.2.10
- 2.3.4 - 2.3.8
- 2.4.1 - 2.4.6
- 2.5.5
- 2.6.0 - 2.6.0
- 2.6.1
- 2.6.2
- 2.6.3
- ruby-head - ruby-head
matrix: matrix:
allow_failures: allow_failures:
- rvm: ruby-head - rvm: ruby-head
before_install: before_install:
- gem update --system - gem update --system || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)
- gem update bundler - gem update bundler
script: script:
- bundle exec rubocop && bundle exec rspec - bundle exec rubocop && bundle exec rspec
deploy:
jobs:
include:
- stage: gem release
if: tag =~ ^v
rvm: 2.6.0
script: echo "Deploying to rubygems.org ..."
deploy:
provider: rubygems provider: rubygems
api_key: api_key: $RUBYGEMS_API_KEY
secure: Y7DUitak26kcRAAkgph/7m6Y1wHeObD0BelSSJbmCfjkRd/qaVy7fz9VvHL9zxlRJtLGVHInyCnwcfzinibY6OFd3MoMYHKv8GFa2LxLJNEVSY46KQYFxfH5JTg1ejh6ldoJRRBoeOx9dcWS80pRNjYMKPGnpSz7yDBl1azibFs=
gem: annotate gem: annotate
on: on:
tags: true tags: true
......
...@@ -19,7 +19,7 @@ group :development, :test do ...@@ -19,7 +19,7 @@ group :development, :test do
gem 'guard-rspec', require: false gem 'guard-rspec', require: false
gem 'rspec', require: false gem 'rspec', require: false
gem 'rubocop', '~> 0.67.2', require: false unless RUBY_VERSION =~ /^1.8/ gem 'rubocop', '~> 0.68.1', require: false unless RUBY_VERSION =~ /^1.8/
gem 'simplecov', require: false gem 'simplecov', require: false
gem 'terminal-notifier-guard', require: false gem 'terminal-notifier-guard', require: false
...@@ -27,7 +27,7 @@ group :development, :test do ...@@ -27,7 +27,7 @@ group :development, :test do
gem 'coveralls' gem 'coveralls'
gem 'overcommit' gem 'overcommit'
gem 'ruby_dep', '1.3.1' gem 'ruby_dep', '1.5.0'
platforms :mri, :mingw do platforms :mri, :mingw do
gem 'pry', require: false gem 'pry', require: false
......
...@@ -910,7 +910,11 @@ module AnnotateModels ...@@ -910,7 +910,11 @@ module AnnotateModels
def mb_chars_ljust(string, length) def mb_chars_ljust(string, length)
string = string.to_s string = string.to_s
padding = length - width(string) padding = length - width(string)
if padding > 0
string + (' ' * padding) string + (' ' * padding)
else
string[0..length-1]
end
end end
end end
......
...@@ -25,14 +25,53 @@ module AnnotateRoutes ...@@ -25,14 +25,53 @@ module AnnotateRoutes
HEADER_ROW = ['Prefix', 'Verb', 'URI Pattern', 'Controller#Action'] HEADER_ROW = ['Prefix', 'Verb', 'URI Pattern', 'Controller#Action']
class << self class << self
def content(line, maxs, options = {}) def do_annotations(options = {})
return line.rstrip unless options[:format_markdown] return unless routes_exists?
existing_text = File.read(routes_file)
line.each_with_index.map do |elem, index| if rewrite_contents_with_header(existing_text, header(options), options)
min_length = maxs.map { |arr| arr[index] }.max || 0 puts "#{routes_file} annotated."
end
end
sprintf("%-#{min_length}.#{min_length}s", elem.tr('|', '-')) def remove_annotations(_options={})
end.join(' | ') return unless routes_exists?
existing_text = File.read(routes_file)
content, where_header_found = strip_annotations(existing_text)
new_content = strip_on_removal(content, where_header_found)
if rewrite_contents(existing_text, new_content)
puts "Removed annotations from #{routes_file}."
end
end
private
def routes_exists?
routes_exists = File.exists?(routes_file)
puts "Can't find routes.rb" unless routes_exists
routes_exists
end
def routes_file
@routes_rb ||= File.join('config', 'routes.rb')
end
def rewrite_contents_with_header(existing_text, header, options = {})
content, where_header_found = strip_annotations(existing_text)
new_content = annotate_routes(header, content, where_header_found, options)
# Make sure we end on a trailing newline.
new_content << '' unless new_content.last == ''
new_text = new_content.join("\n")
if existing_text == new_text
puts "#{routes_file} unchanged."
false
else
File.open(routes_file, 'wb') { |f| f.puts(new_text) }
true
end
end end
def header(options = {}) def header(options = {})
...@@ -70,95 +109,49 @@ module AnnotateRoutes ...@@ -70,95 +109,49 @@ module AnnotateRoutes
out out
end end
def do_annotations(options = {}) # TODO: write the method doc using ruby rdoc formats
return unless routes_exists? # where_header_found => This will either be :before, :after, or
existing_text = File.read(routes_file) # a number. If the number is > 0, the
# annotation was found somewhere in the
if rewrite_contents_with_header(existing_text, header(options), options) # middle of the file. If the number is
puts "#{routes_file} annotated." # zero, no annotation was found.
end def strip_annotations(content)
end real_content = []
mode = :content
def remove_annotations(_options={}) header_found_at = 0
return unless routes_exists?
existing_text = File.read(routes_file)
content, where_header_found = strip_annotations(existing_text)
new_content = strip_on_removal(content, where_header_found)
if rewrite_contents(existing_text, new_content)
puts "Removed annotations from #{routes_file}."
end
end
end
def self.magic_comment_matcher
Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/)
end
# @param [Array<String>] content
# @return [Array<String>] all found magic comments
# @return [Array<String>] content without magic comments
def self.extract_magic_comments_from_array(content_array)
magic_comments = []
new_content = []
content_array.map do |row| content.split(/\n/, -1).each_with_index do |line, line_number|
if row =~ magic_comment_matcher if mode == :header && line !~ /\s*#/
magic_comments << row.strip mode = :content
real_content << line unless line.blank?
elsif mode == :content
if line =~ /^\s*#\s*== Route.*$/
header_found_at = line_number + 1 # index start's at 0
mode = :header
else else
new_content << row real_content << line
end end
end end
[magic_comments, new_content]
end end
def self.app_routes_map(options) where_header_found(real_content, header_found_at)
routes_map = `rake routes`.chomp("\n").split(/\n/, -1)
# In old versions of Rake, the first line of output was the cwd. Not so
# much in newer ones. We ditch that line if it exists, and if not, we
# keep the line around.
routes_map.shift if routes_map.first =~ /^\(in \//
# Skip routes which match given regex
# Note: it matches the complete line (route_name, path, controller/action)
if options[:ignore_routes]
routes_map.reject! { |line| line =~ /#{options[:ignore_routes]}/ }
end
routes_map
end end
def self.routes_file def strip_on_removal(content, where_header_found)
@routes_rb ||= File.join('config', 'routes.rb') if where_header_found == :before
content.shift while content.first == ''
elsif where_header_found == :after
content.pop while content.last == ''
end end
def self.routes_exists? # TODO: If the user buried it in the middle, we should probably see about
routes_exists = File.exists?(routes_file) # TODO: preserving a single line of space between the content above and
puts "Can't find routes.rb" unless routes_exists # TODO: below...
content
routes_exists
end end
# @param [String, Array<String>] # @param [String, Array<String>]
def self.rewrite_contents(existing_text, new_content) def rewrite_contents(existing_text, new_content)
# Make sure we end on a trailing newline.
new_content << '' unless new_content.last == ''
new_text = new_content.join("\n")
if existing_text == new_text
puts "#{routes_file} unchanged."
false
else
File.open(routes_file, 'wb') { |f| f.puts(new_text) }
true
end
end
def self.rewrite_contents_with_header(existing_text, header, options = {})
content, where_header_found = strip_annotations(existing_text)
new_content = annotate_routes(header, content, where_header_found, options)
# Make sure we end on a trailing newline. # Make sure we end on a trailing newline.
new_content << '' unless new_content.last == '' new_content << '' unless new_content.last == ''
new_text = new_content.join("\n") new_text = new_content.join("\n")
...@@ -172,7 +165,7 @@ module AnnotateRoutes ...@@ -172,7 +165,7 @@ module AnnotateRoutes
end end
end end
def self.annotate_routes(header, content, where_header_found, options = {}) def annotate_routes(header, content, where_header_found, options = {})
magic_comments_map, content = extract_magic_comments_from_array(content) magic_comments_map, content = extract_magic_comments_from_array(content)
if %w(before top).include?(options[:position_in_routes]) if %w(before top).include?(options[:position_in_routes])
header = header << '' if content.first != '' header = header << '' if content.first != ''
...@@ -193,35 +186,52 @@ module AnnotateRoutes ...@@ -193,35 +186,52 @@ module AnnotateRoutes
new_content new_content
end end
# TODO: write the method doc using ruby rdoc formats def app_routes_map(options)
# where_header_found => This will either be :before, :after, or routes_map = `rake routes`.chomp("\n").split(/\n/, -1)
# a number. If the number is > 0, the
# annotation was found somewhere in the
# middle of the file. If the number is
# zero, no annotation was found.
def self.strip_annotations(content)
real_content = []
mode = :content
header_found_at = 0
content.split(/\n/, -1).each_with_index do |line, line_number| # In old versions of Rake, the first line of output was the cwd. Not so
if mode == :header && line !~ /\s*#/ # much in newer ones. We ditch that line if it exists, and if not, we
mode = :content # keep the line around.
real_content << line unless line.blank? routes_map.shift if routes_map.first =~ /^\(in \//
elsif mode == :content
if line =~ /^\s*#\s*== Route.*$/ # Skip routes which match given regex
header_found_at = line_number + 1 # index start's at 0 # Note: it matches the complete line (route_name, path, controller/action)
mode = :header if options[:ignore_routes]
routes_map.reject! { |line| line =~ /#{options[:ignore_routes]}/ }
end
routes_map
end
# @param [Array<String>] content
# @return [Array<String>] all found magic comments
# @return [Array<String>] content without magic comments
def extract_magic_comments_from_array(content_array)
magic_comments = []
new_content = []
content_array.map do |row|
if row =~ magic_comment_matcher
magic_comments << row.strip
else else
real_content << line new_content << row
end end
end end
[magic_comments, new_content]
end end
where_header_found(real_content, header_found_at) def content(line, maxs, options = {})
return line.rstrip unless options[:format_markdown]
line.each_with_index.map do |elem, index|
min_length = maxs.map { |arr| arr[index] }.max || 0
sprintf("%-#{min_length}.#{min_length}s", elem.tr('|', '-'))
end.join(' | ')
end end
def self.where_header_found(real_content, header_found_at) def where_header_found(real_content, header_found_at)
# By default assume the annotation was found in the middle of the file # By default assume the annotation was found in the middle of the file
# ... unless we have evidence it was at the beginning ... # ... unless we have evidence it was at the beginning ...
...@@ -234,16 +244,8 @@ module AnnotateRoutes ...@@ -234,16 +244,8 @@ module AnnotateRoutes
return real_content, header_found_at return real_content, header_found_at
end end
def self.strip_on_removal(content, where_header_found) def magic_comment_matcher
if where_header_found == :before Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/)
content.shift while content.first == ''
elsif where_header_found == :after
content.pop while content.last == ''
end end
# TODO: If the user buried it in the middle, we should probably see about
# TODO: preserving a single line of space between the content above and
# TODO: below...
content
end end
end end
...@@ -943,7 +943,8 @@ EOS ...@@ -943,7 +943,8 @@ EOS
[:active, :boolean, { limit: 1, comment: 'ACTIVE' }], [:active, :boolean, { limit: 1, comment: 'ACTIVE' }],
[:name, :string, { limit: 50, comment: 'NAME' }], [:name, :string, { limit: 50, comment: 'NAME' }],
[:notes, :text, { limit: 55, comment: 'NOTES' }], [:notes, :text, { limit: 55, comment: 'NOTES' }],
[:no_comment, :text, { limit: 20, comment: nil }] [:no_comment, :text, { limit: 20, comment: nil }],
[:location, :geometry_collection, { limit: nil, comment: nil }]
] ]
when_called_with with_comment: 'yes', when_called_with with_comment: 'yes',
...@@ -958,6 +959,7 @@ EOS ...@@ -958,6 +959,7 @@ EOS
# name(NAME) :string(50) not null # name(NAME) :string(50) not null
# notes(NOTES) :text(55) not null # notes(NOTES) :text(55) not null
# no_comment :text(20) not null # no_comment :text(20) not null
# location :geometry_collect not null
# #
EOS EOS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment