mirror of
https://github.com/benjaminion/upgrading-ethereum-book.git
synced 2026-01-09 22:47:55 -05:00
Make some of the checks read from stdin as well as file
This commit is contained in:
@@ -10,14 +10,9 @@ $\ = "\n"; # set output record separator
|
||||
my @html_entities = ('ndash', 'nbsp', 'trade', 'ldquo', 'rdquo');
|
||||
my %entities = map { $_ => 1 } @html_entities;
|
||||
|
||||
my $fh = *STDIN;
|
||||
if (my $file = shift) {
|
||||
open $fh, '<', $file or die "Can't open $file: $!";
|
||||
}
|
||||
|
||||
my @tags = ();
|
||||
|
||||
while(<$fh>) {
|
||||
while(<>) {
|
||||
|
||||
while (/<(\/{0,1})([a-z]+).*?(\/{0,1})>/g) {
|
||||
my $thisTag = $2;
|
||||
|
||||
@@ -10,11 +10,6 @@ use IPC::Run3;
|
||||
|
||||
$\ = "\n"; # set output record separator
|
||||
|
||||
my $fh = *STDIN;
|
||||
if (my $file = shift) {
|
||||
open $fh, '<', $file or die "Can't open $file: $!";
|
||||
}
|
||||
|
||||
# Add any exclusions here by adding "-n#" where # is the warning number
|
||||
my @command = ["chktex", "-q"];
|
||||
|
||||
@@ -23,7 +18,7 @@ my $ignore = qr/\$(\[1,r\))\$/;
|
||||
|
||||
my $latex = '';
|
||||
my $inMath = 0;
|
||||
while(<$fh>) {
|
||||
while(<>) {
|
||||
|
||||
chomp;
|
||||
|
||||
|
||||
@@ -7,12 +7,7 @@ use warnings;
|
||||
|
||||
$\ = "\n"; # set output record separator
|
||||
|
||||
my $fh = *STDIN;
|
||||
if (my $file = shift) {
|
||||
open $fh, '<', $file or die "Can't open $file: $!";
|
||||
}
|
||||
|
||||
while(<$fh>) {
|
||||
while(<>) {
|
||||
while (/\b([_[:alpha:]]+)\s+(\1)\b/g) {
|
||||
print "Line $.: $1 $2";
|
||||
}
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Spell check the book source, supplied as $1, exceptions are in the file $2.
|
||||
# Spell check the book source, supplied as $1 (or stdin), exceptions are in the file $2.
|
||||
#
|
||||
# Aspell has input filters for markdown etc, but it's honestly easier just to preprocess stuff
|
||||
# with the spellcheck_prep.pl script.
|
||||
|
||||
if [ "$#" -eq 1 ]; then
|
||||
input=/dev/stdin
|
||||
exceptions=$1
|
||||
elif [ "$#" -eq 2 ]; then
|
||||
input=$1
|
||||
exceptions=$2
|
||||
else
|
||||
echo "Usage: spellcheck.sh [markdown_file] exceptions_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export LANG=en_GB.UTF-8
|
||||
here=$(cd $(dirname "$0") && pwd)
|
||||
|
||||
$here/spellcheck_prep.pl $1 \
|
||||
| aspell --home-dir . -p $2 --dont-suggest pipe --dict-dir=$here/../dicts -d en_GB-ise-w_accents \
|
||||
$here/spellcheck_prep.pl $input \
|
||||
| aspell --home-dir . -p $exceptions --dont-suggest pipe --dict-dir=$here/../dicts -d en_GB-ise-w_accents \
|
||||
| tail -n +2 \
|
||||
| awk 'BEGIN {n=1} /^$/{n++} /^..+$/{print "Line " n ": "$2}'
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $fh = *STDIN;
|
||||
if (my $file = shift) {
|
||||
open $fh, '<', $file or die "Can't open $file: $!";
|
||||
}
|
||||
|
||||
while(<$fh>) {
|
||||
while(<>) {
|
||||
print "Line $." if /\h$/;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,11 @@ const colour = {
|
||||
green: (s) => '\x1b[38;5;34m' + s + '\x1b[0m',
|
||||
};
|
||||
|
||||
const chars = {
|
||||
tick: colour.green('\u2713'),
|
||||
cross: colour.orange('\u2717'),
|
||||
};
|
||||
|
||||
const myLogger = {
|
||||
info: (m) => {
|
||||
console.log(colour.blue('info ') + m);
|
||||
@@ -98,14 +103,14 @@ async function runCheck({ name, enabled, checker }, logger) {
|
||||
try {
|
||||
const out = await checker();
|
||||
if (out === '' || out === null) {
|
||||
logger.info(colour.green('\u2713') + ` Passed ${name} check`);
|
||||
logger.info(chars.tick + ` Passed ${name} check`);
|
||||
} else {
|
||||
logger.warn(`Issues were found by ${name} check:`);
|
||||
logger.warn(chars.cross + ` Issues were found by ${name} check:`);
|
||||
printLines(out, logger);
|
||||
success = false;
|
||||
}
|
||||
} catch (err) {
|
||||
logger.warn(`An error occurred during ${name} check:`);
|
||||
logger.warn(chars.cross + ` An error occurred during ${name} check:`);
|
||||
printLines(err.toString(), logger);
|
||||
success = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user