Sha256: 1a4d60d7519d477c39679d1e8c121a9f351c6fd826a911185b0f3dd3d1dab346

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

#!/usr/bin/env ruby
# Copyright (c) 2010-2017 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
require 'pathname'

bindir = Pathname.new(__FILE__).realpath.dirname
$LOAD_PATH.unshift((bindir + '../lib').realpath)
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
    @logger.warn "#{ln}: block #{new_block} started, but previous block #{block} didn't close yet." if block
    block = new_block
  elsif line =~ %r{\A//\}}
    @logger.warn "#{ln}: block ended, but not opened." if block.nil?
    block = nil
    maxcolcount = 0
    colcount = 0
  elsif line =~ /\A(\d+\.)\s+/
    # number
    @logger.warn "#{ln}: found '#{$1}' without the head space. Is it correct?" unless %w[list emlist listnum emlistnum cmd image table].include?(block)
  elsif line =~ /\A\*\s+/
    # itemize
    @logger.warn "#{ln}: found '*' without the head space. Is it correct?" unless %w[list emlist listnum emlistnum cmd image table].include?(block)
  elsif line =~ /\A\s+(\d+\.)\s+/ && line =~ /\A\s+\*\s+/
    @logger.warn "#{ln}: found itemized list or numbered list in #{block}. Is it correct?" unless Tw[list emlist listnum emlistnum cmd image table].include?(block)
  elsif block == 'table'
    next if line.start_with?('#@')
    if line !~ /\A\-\-\-\-\-/
      # table
      colcount = line.split("\t").size
      maxcolcount = colcount if maxcolcount == 0
      @logger.warn "#{ln}: the number of table columns seems mismatch. (#{maxcolcount} != #{colcount})" if colcount != maxcolcount
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
review-2.5.0 bin/review-validate
review-2.4.0 bin/review-validate