forked from eth-infinitism/bundler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckRulesCoverage
executable file
·76 lines (62 loc) · 2.12 KB
/
checkRulesCoverage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
const fs = require('fs')
const {execSync} = require( 'child_process')
args = process.argv.slice(2)
let showRev=true;
let showMatch=true;
let rulesFile = args[0]
let folder = args[1]
let rules = {}
let unmatched = {}
let totMatched = 0
let totUnmatched = 0
function usage(msg="") {
if (msg) console.error("FATAL:",msg)
console.error("usage: checkValidationRules {ruleFile.md} {folder}")
console.error("find rules in the format [www-###] in rulesFile and in folder. report matched (and missing) rules in source folder")
console.error("(unfortunately, the tool can only highlight the IDs in the source code, not their actual impelmentation....)")
console.error('e.g: ./scripts/checkRulesCoverage ../account-abstraction/eip/EIPS/eip-aa-rules.md packages/bundler/src/' )
process.exit(1)
}
if ( !folder ) usage()
if ( !fs.existsSync(rulesFile) ) usage( "unknown rulesfile "+rulesFile )
if ( !fs.existsSync(folder) ) usage( "unknown folder "+folder )
//use separator: /(?<!\\)\n/ to unwrap backslash
const fileData = fs.readFileSync(rulesFile, "ascii")
for( let line of fileData.split(/\n/) ) {
//wrap backslash
//$line=~s/\s*\\\s*\n\s*/; /g;
line = line.replaceAll( /\*\*(.*?)\*\*/g, '$1' )
const match = line.match(/\[(\w+-\d+)\][\s-:]+\s*([\s\S]*)/);
if ( !match )
continue;
const [_, rule, rest] = match
rules[rule] = rest
unmatched[rule] = rest
}
rules["STO-000"] = "== placehodler rule";
function foundRule(r) {
if (r.match(/UTF|eip|erc|gpl/i)) return ;
if ( !rules[r]) {
console.log("UNKNOWN:", r)
rules[r] = "==unknown=="
} else if ( unmatched[r]) {
if ( showMatch )
console.log("matched:",r) // ${rules[r]})
totMatched++;
delete unmatched[r]
}
}
const grepCmd = execSync( `grep -r . ${folder}`, { maxBuffer: 3e6}).toString()
for ( const line of grepCmd.split(/\n/) ) {
const mm = line.replaceAll( /\b(\w{2,3}-\d+)\b/g, rule=>foundRule(rule))
}
let unmatchedKeys = Object.keys(unmatched)
unmatchedKeys.sort()
for ( const r of unmatchedKeys ) {
if (showRev) {
console.log(`unmatched: ${r} ${rules[r]}`)
}
totUnmatched++;
}
console.log("total",totMatched,"matched,", totUnmatched,"unmatched");