Report per-ruleset stats for filters-to-rules conversion

This commit is contained in:
Raymond Hill 2022-09-07 13:45:55 -04:00
parent f7205fe2e4
commit 41d66a78ba
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 20 additions and 10 deletions

View File

@ -1,6 +1,6 @@
'use strict';
import regexRulesets from '/rulesets/regexes.js';
import rulesetDetails from '/rulesets/ruleset-details.js';
/******************************************************************************/
@ -13,9 +13,9 @@ const dynamicRuleMap = new Map();
async function updateRegexRules() {
const allRules = [];
const toCheck = [];
for ( const regexRuleset of regexRulesets ) {
if ( regexRuleset.enabled !== true ) { continue; }
for ( const rule of regexRuleset.rules ) {
for ( const details of rulesetDetails ) {
if ( details.enabled !== true ) { continue; }
for ( const rule of details.ruleDetails.regexes ) {
const regex = rule.condition.regexFilter;
const isCaseSensitive = rule.condition.isUrlFilterCaseSensitive === true;
allRules.push(rule);

View File

@ -55,7 +55,7 @@ async function main() {
const writeOps = [];
const ruleResources = [];
const regexRuleResources = [];
const rulesetDetails = [];
const outputDir = commandLineArgs.get('output') || '.';
let goodTotalCount = 0;
@ -202,10 +202,21 @@ async function main() {
)
);
regexRuleResources.push({
rulesetDetails.push({
id: ruleset.id,
enabled: ruleset.enabled,
rules: regexes
filterDetails: {
total: details.filterCount,
accepted: details.acceptedFilterCount,
rejected: details.rejectedFilterCount,
},
ruleDetails: {
total: rules.length,
accepted: good.length,
discarded: redirects.length + headers.length + removeparams.length,
rejected: bad.length,
regexes,
},
});
ruleResources.push({
@ -220,8 +231,8 @@ async function main() {
writeOps.push(
writeFile(
`${rulesetDir}/regexes.js`,
`export default ${JSON.stringify(regexRuleResources, replacer, 2)};\n`
`${rulesetDir}/ruleset-details.js`,
`export default ${JSON.stringify(rulesetDetails, replacer, 2)};\n`
)
);

View File

@ -40,7 +40,6 @@ export default [
'https://ublockorigin.github.io/uAssets/filters/unbreak.txt',
'https://easylist.to/easylist/easylist.txt',
'https://easylist.to/easylist/easyprivacy.txt',
'https://malware-filter.gitlab.io/malware-filter/urlhaus-filter-online.txt',
'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=1&mimetype=plaintext',
]
},