Sha256: 1a8dbc34aaffa3be3e985546da94148767572c25ce02b5d6d1ff049c363f9cc6

Contents?: true

Size: 1.9 KB

Versions: 7

Compression:

Stored size: 1.9 KB

Contents

#!/usr/bin/env ruby
# Copyright (c) 2010-2019 Kenshi Muto
#
# This program is free software
# You can distribute or modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
# For details of the GNU LGPL, see the file "COPYING".
#

# simple validator for Re:VIEW

$LOAD_PATH.unshift(File.realpath('../lib', __dir__))

require 'review/logger'

block = nil
maxcolcount = 0
colcount = 0
ln = 0

@logger = ReVIEW.logger

ARGF.each do |line|
  ln += 1
  if line =~ %r{\A//([a-z]+)\{\s*\Z} || line =~ %r{\A//([a-z]+)\[.+?\{\s*\Z}
    # block
    new_block = $1
    if block
      @logger.warn "#{ln}: block #{new_block} started, but previous block #{block} didn't close yet."
    end
    block = new_block
  elsif line.start_with?('//}')
    if block.nil?
      @logger.warn "#{ln}: block ended, but not opened."
    end
    block = nil
    maxcolcount = 0
    colcount = 0
  elsif line =~ /\A(\d+\.)\s+/
    # number
    unless %w[list emlist listnum emlistnum cmd image table].include?(block)
      @logger.warn "#{ln}: found '#{$1}' without the head space. Is it correct?"
    end
  elsif /\A\*\s+/.match?(line)
    # itemize
    unless %w[list emlist listnum emlistnum cmd image table].include?(block)
      @logger.warn "#{ln}: found '*' without the head space. Is it correct?"
    end
  elsif line =~ /\A\s+(\d+\.)\s+/ && line =~ /\A\s+\*\s+/
    unless %w[list emlist listnum emlistnum cmd image table].include?(block)
      @logger.warn "#{ln}: found itemized list or numbered list in #{block}. Is it correct?"
    end
  elsif block == 'table'
    next if line.start_with?('#@')

    unless line.start_with?('-----')
      # table
      colcount = line.split("\t").size
      if maxcolcount == 0
        maxcolcount = colcount
      end
      if colcount != maxcolcount
        @logger.warn "#{ln}: the number of table columns seems mismatch. (#{maxcolcount} != #{colcount})"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
review-5.10.0 bin/review-validate
review-5.9.0 bin/review-validate
review-5.8.0 bin/review-validate
review-5.7.0 bin/review-validate
review-5.6.0 bin/review-validate
review-5.5.0 bin/review-validate
review-5.4.0 bin/review-validate