2020-04-22 02:42:25 -04:00
|
|
|
"use strict";
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
import fs from "fs";
|
|
|
|
import { resolve } from "path";
|
|
|
|
import ts from "typescript";
|
2020-04-22 02:42:25 -04:00
|
|
|
|
2020-09-22 22:54:48 -04:00
|
|
|
import { colorify } from "../log";
|
|
|
|
|
2020-04-22 02:42:25 -04:00
|
|
|
const Words = fs.readFileSync("/usr/share/dict/words").toString().split("\n").reduce((accum, word) => {
|
|
|
|
accum[word.toLowerCase()] = true;
|
|
|
|
return accum;
|
2020-09-21 01:14:06 -04:00
|
|
|
}, <Record<string, boolean>>{ });
|
2020-04-22 02:42:25 -04:00
|
|
|
|
|
|
|
`
|
|
|
|
// Words missing from the dictionary
|
2023-02-02 20:54:33 -05:00
|
|
|
accessing addresses aligned allowed autofill avatar called cancelled changed censored
|
2022-03-09 02:56:46 -05:00
|
|
|
clamping compiled computed configured consumed contained creating decoded decoding
|
2020-09-16 19:44:55 -04:00
|
|
|
decreased decrypt decrypted decrypting deployed deploying deprecated detected
|
2022-03-09 02:56:46 -05:00
|
|
|
discontinued earliest email emitted enabled encoded encoder encoding encountered
|
|
|
|
encrypt encrypted encrypting entries euro exceeded existing expected
|
2023-02-02 20:54:33 -05:00
|
|
|
expired failed fetches finalized formatted formatting funding generated
|
2020-08-23 16:37:24 -04:00
|
|
|
hardened has highly ignoring implemented implementer imported including instantiate
|
2020-07-13 08:50:41 -04:00
|
|
|
joined keyword labelled larger lookup matches mined modified modifies multi
|
2020-06-01 05:04:12 -04:00
|
|
|
named needed nested neutered numeric offline optimizer overriding owned packed
|
2021-03-30 19:54:52 -04:00
|
|
|
padded parsed parsing passed payload placeholder processing properties prototyping reached
|
2023-02-02 20:54:33 -05:00
|
|
|
recommended recovered recursively redacted rejected remaining replaced repriced required reverted
|
2021-05-18 15:53:15 -04:00
|
|
|
serializes shared signed signing skipped stats stored supported tagging targetted
|
2021-04-17 22:37:04 -04:00
|
|
|
throttled transactions typed uninstall unstake unsubscribe untyped
|
|
|
|
using verifies verifying website
|
2020-04-22 02:42:25 -04:00
|
|
|
|
|
|
|
// Overly Specific Words
|
2020-09-04 01:37:14 -04:00
|
|
|
bech BIP BIP39 BIP44 btc bzz crypto eip etc hashes hmac icap
|
|
|
|
keccak ltc namehash ripemd RLP scrypt secp sha xdai
|
2020-04-22 02:42:25 -04:00
|
|
|
|
2021-05-18 15:53:15 -04:00
|
|
|
blockhash bnb bnbt ethprice matic txlist
|
2020-04-22 02:42:25 -04:00
|
|
|
|
|
|
|
bitcoin ethereum finney gwei kwei mwei satoshi szabo wei weth
|
|
|
|
|
|
|
|
crowdsale hexlify hd hdnode underpriced
|
|
|
|
|
|
|
|
boolean int struct tuple uint
|
|
|
|
nonpayable
|
|
|
|
jumpdest mstore shr shl xor
|
|
|
|
|
|
|
|
// Classes
|
|
|
|
ABIEncoder testcase numberish Wordlist
|
|
|
|
|
|
|
|
// Common Code Strings
|
2021-03-30 19:54:52 -04:00
|
|
|
abi addr api app arg arrayify asm backend basex bigint bignumber bn byte
|
2022-03-09 02:56:46 -05:00
|
|
|
bytecode callback calldata ccip charset checksum ciphertext cli codepoint
|
2020-10-22 20:01:57 -04:00
|
|
|
commify config
|
2023-02-02 20:54:33 -05:00
|
|
|
contenthash ctr ctrl debug dd disallowed dklen dns eexist encseed eof eq erc ethaddr
|
2020-10-07 20:11:34 -04:00
|
|
|
ethseed ethers eval exec filename func gz gzip hid http https hw iv
|
2021-10-19 00:01:37 -04:00
|
|
|
info init ipc json kdf kdfparams labelhash lang lib metadata mm multihash nfc
|
2022-03-09 02:56:46 -05:00
|
|
|
nfkc nfd nfkd nodehash notok nowait nullish offchain oob opcode org pbkdf pc plugin
|
2023-02-02 20:54:33 -05:00
|
|
|
pragma pre prf punycode recid repl rpc sighash topichash solc stderr stdin stdout subclasses
|
2021-03-30 19:54:52 -04:00
|
|
|
subnode timeout todo txt typeof ufixed utc utf util url urlencoded uuid vm
|
2022-05-20 19:13:34 -04:00
|
|
|
vs websocket wikipedia wildcard wildcards wss www wx xe xpriv xpub xx yyyy zlib
|
2020-04-22 02:42:25 -04:00
|
|
|
|
|
|
|
// AbiV2
|
|
|
|
abiv
|
|
|
|
|
|
|
|
// Query parameters
|
|
|
|
apikey asc endblock startblock
|
|
|
|
|
2024-02-22 17:54:01 -05:00
|
|
|
alchemyapi ankr arbitrum Cloudflare com Etherscan INFURA IPFS IPNS MetaMask Nodesmith quiknode
|
2020-07-05 00:03:50 -04:00
|
|
|
Trezor ledgerhq axic bitcoinjs browserify easyseed ethereumjs
|
2024-02-22 17:54:01 -05:00
|
|
|
goerli holesky homestead kotti kovan mainnet morden mordor rinkeby kintsugi
|
2023-02-02 20:54:33 -05:00
|
|
|
ropsten sepolia skynet testnet lb maticmum
|
2020-04-22 02:42:25 -04:00
|
|
|
|
|
|
|
// Demo words
|
|
|
|
args foo eth foo foobar ll localhost passwd ricmoo tx xxx yna
|
2022-03-09 02:56:46 -05:00
|
|
|
brantly ricmoose
|
2020-04-22 02:42:25 -04:00
|
|
|
|
|
|
|
// nameprep tags
|
|
|
|
ALCat BiDi LCat nameprep
|
|
|
|
|
|
|
|
// Lanauge Codes (and short binary data)
|
|
|
|
cn cz en es fr it ja tw zh zh_cn zh_tw
|
|
|
|
OYAa IJBEJqXZJ
|
|
|
|
|
2020-10-20 00:17:02 -04:00
|
|
|
// Encoded data
|
|
|
|
Jx Trw BMd
|
|
|
|
lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
|
|
|
|
|
|
|
2020-04-22 02:42:25 -04:00
|
|
|
`.split("\n").filter((l) => (l.substring(0, 2) != "/\/")).join("\n").split(/\s+/g,).forEach((word) => {
|
|
|
|
word = word.trim();
|
|
|
|
if (word === "") { return; }
|
|
|
|
Words[word.toLowerCase()] = true;
|
|
|
|
});
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
type Bar = {
|
|
|
|
value: string;
|
|
|
|
lineNo: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
type Foo = {
|
|
|
|
filename: string;
|
|
|
|
values: Array<Bar>;
|
|
|
|
};
|
2020-04-22 02:42:25 -04:00
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
function getStrings(source: string): Array<Bar> {
|
|
|
|
const sourceFile = ts.createSourceFile("filename.ts", source, ts.ScriptTarget.Latest);
|
2020-04-22 02:42:25 -04:00
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
const result: Array<Bar> = [ ];
|
2020-04-22 02:42:25 -04:00
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
function add(value: string, pos: number): void {
|
2020-04-22 02:42:25 -04:00
|
|
|
const lineNo = sourceFile.getLineAndCharacterOfPosition(pos).line + 1;
|
|
|
|
result.push({ value, lineNo });
|
|
|
|
}
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
//let lastClass = null, lastEnum = null;
|
|
|
|
function visit(node: ts.Node, depth: number): void {
|
2020-04-22 02:42:25 -04:00
|
|
|
switch (node.kind) {
|
|
|
|
//case ts.SyntaxKind.TemplateExpression:
|
|
|
|
// if (node.head) { visit(node.head); }
|
|
|
|
// console.dir(node, { depth: null });
|
|
|
|
// break;
|
|
|
|
case ts.SyntaxKind.TemplateHead:
|
|
|
|
case ts.SyntaxKind.TemplateMiddle:
|
|
|
|
case ts.SyntaxKind.TemplateTail:
|
|
|
|
case ts.SyntaxKind.StringLiteral:
|
|
|
|
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
|
2020-09-21 01:14:06 -04:00
|
|
|
add((<ts.LiteralLikeNode>node).text, node.pos);
|
2020-04-22 02:42:25 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts.forEachChild(node, (node) => { return visit(node, depth + 1); });
|
|
|
|
}
|
|
|
|
|
|
|
|
visit(sourceFile, 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Include = new RegExp("packages/.*/src.ts/.*\.ts$");
|
|
|
|
const Exclude = new RegExp("/node_modules/|src.ts/.*browser.*");
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
|
|
|
|
function getAllStrings(path: string): Array<Foo> {
|
2020-04-22 02:42:25 -04:00
|
|
|
const Root = resolve(__dirname, path);
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
const readdir = function(path: string): Array<Foo> {
|
2020-04-22 02:42:25 -04:00
|
|
|
if (path.match(Exclude)) { return [ ]; }
|
|
|
|
|
|
|
|
const stat = fs.statSync(path);
|
|
|
|
if (stat.isDirectory()) {
|
|
|
|
return fs.readdirSync(path).reduce((result, filename) => {
|
|
|
|
readdir(resolve(path, filename)).forEach((file) => {
|
|
|
|
result.push(file);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}, [ ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.match(Include)) {
|
|
|
|
const source = fs.readFileSync(path).toString();
|
|
|
|
return [ { filename: path.substring(Root.length), values: getStrings(source) } ]
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return readdir(Root);
|
|
|
|
}
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
function checkWord(word: string): boolean {
|
2020-04-22 02:42:25 -04:00
|
|
|
word = word.toLowerCase();
|
|
|
|
|
|
|
|
// A word
|
|
|
|
if (Words[word]) { return true; }
|
|
|
|
|
|
|
|
// Simple Plural
|
|
|
|
if (word.match(/.*s$/) && Words[word.substring(0, word.length - 1)]) { return true; }
|
|
|
|
|
|
|
|
// Hex string
|
|
|
|
if (word.match(/^(0x)?[0-9a-f]*$/i)) { return true; }
|
2020-09-21 01:14:06 -04:00
|
|
|
|
|
|
|
return false;
|
2020-04-22 02:42:25 -04:00
|
|
|
}
|
|
|
|
|
2020-09-21 01:14:06 -04:00
|
|
|
function starts(text: string, prefix: string): boolean {
|
2020-04-22 02:42:25 -04:00
|
|
|
return (text.substring(0, prefix.length) === prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
(async function() {
|
2020-09-22 22:54:48 -04:00
|
|
|
console.log(colorify.bold("Spell checking source code strings..."));
|
|
|
|
|
2020-04-22 02:42:25 -04:00
|
|
|
let count = 0;
|
2020-09-21 01:14:06 -04:00
|
|
|
getAllStrings(resolve(__dirname, "../../../../packages")).forEach((file: Foo) => {
|
2020-04-22 02:42:25 -04:00
|
|
|
if (starts(file.filename, "/testcases/src.ts/generation-scripts")) { return; }
|
|
|
|
if (starts(file.filename, "/asm/src.ts/opcodes.ts")) { return; }
|
|
|
|
|
|
|
|
file.values.forEach((entry) => {
|
2020-09-21 01:14:06 -04:00
|
|
|
function problem(word: string): void {
|
2020-04-22 02:42:25 -04:00
|
|
|
count++;
|
|
|
|
console.log({
|
|
|
|
filename: file.filename,
|
|
|
|
word: JSON.stringify(word),
|
|
|
|
sentence: JSON.stringify(entry.value.substring(0, 80)),
|
|
|
|
line: entry.lineNo
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const value = entry.value.trim();
|
|
|
|
|
|
|
|
// Emptry space
|
|
|
|
if (value === "") { return; }
|
|
|
|
|
|
|
|
// Prolly a require
|
|
|
|
if (value.match(/^@ethersproject\/[a-z0-9-]+$/)) { return; }
|
|
|
|
if (value.substring(0, 2) === "./") { return; }
|
|
|
|
|
|
|
|
// Prolly encoded binary data
|
|
|
|
if (value.indexOf(" ") === -1 && value.length > 20) { return; }
|
|
|
|
|
|
|
|
if (checkWord(value)) { return; }
|
|
|
|
|
|
|
|
value.replace(/([a-z+])([A-Z])/g, (all, first, secondLetter) => {
|
|
|
|
return first + " " + secondLetter;
|
|
|
|
}).replace(/((?:0x)?[A-Za-z]+)/gi, (all, word) => {
|
2020-09-21 01:14:06 -04:00
|
|
|
if (checkWord(word)) { return ""; }
|
2020-04-22 02:42:25 -04:00
|
|
|
problem(word);
|
|
|
|
return "";
|
|
|
|
});;
|
|
|
|
});
|
|
|
|
});
|
2020-09-21 01:14:06 -04:00
|
|
|
|
2020-04-22 02:42:25 -04:00
|
|
|
if (count) {
|
|
|
|
console.log(`Found ${ count } typos.`);
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2020-09-21 01:14:06 -04:00
|
|
|
|
|
|
|
|
2020-04-22 02:42:25 -04:00
|
|
|
process.exit(0)
|
2020-09-21 01:14:06 -04:00
|
|
|
})().catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
2020-04-22 02:42:25 -04:00
|
|
|
|