tools: fix eslint errors
This commit is contained in:
parent
b5356bac0f
commit
3fd1466c56
@ -1,19 +1,19 @@
|
||||
// This is a mess. I know.
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Parse command line options.
|
||||
|
||||
var files = [];
|
||||
var includeDirs = [];
|
||||
var stripGuardsEnabled = false;
|
||||
const files = [];
|
||||
const includeDirs = [];
|
||||
let stripGuardsEnabled = false;
|
||||
|
||||
process.argv
|
||||
.slice(2)
|
||||
.forEach((arg) => {
|
||||
let match;
|
||||
if (match = /^-I(.*)$/.exec(arg))
|
||||
if ((match = /^-I(.*)$/.exec(arg)))
|
||||
includeDirs.push(match[1]);
|
||||
else if (arg === '--strip-guards')
|
||||
stripGuardsEnabled = true;
|
||||
@ -21,14 +21,14 @@ process.argv
|
||||
files.push(arg);
|
||||
});
|
||||
|
||||
var included = {};
|
||||
const included = {};
|
||||
|
||||
function readFileWithPath(fileName, dirs) {
|
||||
if (/[/\\]/.test(fileName))
|
||||
return fs.readFileSync(fileName, 'utf8');
|
||||
|
||||
for (let i = 0; i < dirs.length; i++) {
|
||||
var filePath = path.resolve(dirs[i], fileName);
|
||||
const filePath = path.resolve(dirs[i], fileName);
|
||||
try {
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
} catch (e) {
|
||||
@ -36,24 +36,24 @@ function readFileWithPath(fileName, dirs) {
|
||||
}
|
||||
}
|
||||
|
||||
var err = new Error('file not found: ' + fileName);
|
||||
err.code = 'ENOENT'
|
||||
const err = new Error('file not found: ' + fileName);
|
||||
err.code = 'ENOENT';
|
||||
throw err;
|
||||
}
|
||||
|
||||
function strip_guards(filename, source) {
|
||||
var lead_comments_re = /^(\s*\/\*((?!\*\/)[\s\S])*\*\/)*\s*/;
|
||||
var trail_comments_re = /(\s*\/\*((?!\*\/)[\s\S])*\*\/)*\s*$/;
|
||||
var lead_guards_re = /^#ifndef\s+(\w+)\s+#define\s+(\w+)\s+/;
|
||||
var trail_guards_re = /#endif$/;
|
||||
const lead_comments_re = /^(\s*\/\*((?!\*\/)[\s\S])*\*\/)*\s*/;
|
||||
const trail_comments_re = /(\s*\/\*((?!\*\/)[\s\S])*\*\/)*\s*$/;
|
||||
const lead_guards_re = /^#ifndef\s+(\w+)\s+#define\s+(\w+)\s+/;
|
||||
const trail_guards_re = /#endif$/;
|
||||
|
||||
// Strip leading and trailing comments and whitespace.
|
||||
source = source.replace(lead_comments_re, '');
|
||||
source = source.replace(trail_comments_re, '');
|
||||
|
||||
// Find include guards.
|
||||
var lead_guards = lead_guards_re.exec(source);
|
||||
var trail_guards = trail_guards_re.exec(source);
|
||||
const lead_guards = lead_guards_re.exec(source);
|
||||
const trail_guards = trail_guards_re.exec(source);
|
||||
|
||||
// Remove include guards, if found.
|
||||
if (lead_guards && trail_guards && lead_guards[1] == lead_guards[2]) {
|
||||
@ -69,41 +69,37 @@ function strip_guards(filename, source) {
|
||||
}
|
||||
|
||||
function lines(filename, strip) {
|
||||
var source = readFileWithPath(filename, ['.'].concat(includeDirs));
|
||||
let source = readFileWithPath(filename, ['.'].concat(includeDirs));
|
||||
if (strip) source = strip_guards(filename, source);
|
||||
return source.split(/\r?\n/g);
|
||||
}
|
||||
|
||||
function comment(s) {
|
||||
return ''; //'/* ' + s + '*/'
|
||||
}
|
||||
|
||||
function include(line, filename) {
|
||||
var key = path.basename(filename).toLowerCase();
|
||||
const key = path.basename(filename).toLowerCase();
|
||||
if (included[key])
|
||||
return comment(line);
|
||||
return ''; // Included earlier.
|
||||
console.error('Including: ' + key);
|
||||
included[key] = true;
|
||||
return lines(filename, true);
|
||||
}
|
||||
|
||||
function add(filename) {
|
||||
var key = path.basename(filename).toLowerCase();
|
||||
const key = path.basename(filename).toLowerCase();
|
||||
console.error('Adding: ' + key);
|
||||
included[key] = true;
|
||||
return lines(filename, stripGuardsEnabled);
|
||||
}
|
||||
|
||||
var sys_included = {};
|
||||
const sys_included = {};
|
||||
function include_sys(line, filename) {
|
||||
var key = path.basename(filename).toLowerCase();
|
||||
const key = path.basename(filename).toLowerCase();
|
||||
if (sys_included[key])
|
||||
return comment(line);
|
||||
return ''; // Included earlier.
|
||||
|
||||
sys_included[key] = true;
|
||||
}
|
||||
|
||||
var source = [];
|
||||
let source = [];
|
||||
|
||||
source = source.concat('/*')
|
||||
.concat(fs.readFileSync('LICENSE', 'utf8')
|
||||
@ -118,23 +114,23 @@ source = source.concat('/*')
|
||||
.concat(' */')
|
||||
.concat('');
|
||||
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var filename = files[i];
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const filename = files[i];
|
||||
source = source.concat(add(filename));
|
||||
}
|
||||
|
||||
var patterns = [
|
||||
const patterns = [
|
||||
{ re: /^\s*#include\s*"([^"]*)".*$/, fn: include },
|
||||
{ re: /^\s*#include\s*<([^"]*)>.*$/, fn: include_sys }
|
||||
]
|
||||
];
|
||||
|
||||
restart: for (var lno = 0; lno < source.length;) {
|
||||
for (var i in patterns) {
|
||||
var line = source[lno];
|
||||
var pattern = patterns[i];
|
||||
var match = pattern.re.exec(line);
|
||||
restart: for (let lno = 0; lno < source.length;) {
|
||||
for (const i in patterns) {
|
||||
const line = source[lno];
|
||||
const pattern = patterns[i];
|
||||
const match = pattern.re.exec(line);
|
||||
if (match) {
|
||||
var repl = pattern.fn.apply(null, match);
|
||||
const repl = pattern.fn.apply(null, match);
|
||||
if (repl != null && repl !== line) {
|
||||
source.splice.apply(source, [lno, 1].concat(repl));
|
||||
continue restart;
|
||||
|
||||
@ -22,7 +22,7 @@ function run_tests(test_exes, num = 0, fail_count = 0) {
|
||||
|
||||
child.on('exit', (code) => {
|
||||
if (code === 0) {
|
||||
console.log(' PASS')
|
||||
console.log(' PASS');
|
||||
} else {
|
||||
console.log(' FAIL\n' + out);
|
||||
fail_count++;
|
||||
@ -33,7 +33,7 @@ function run_tests(test_exes, num = 0, fail_count = 0) {
|
||||
}
|
||||
|
||||
function done(test_exes, fail_count) {
|
||||
let pass_count = test_exes.length - fail_count;
|
||||
const pass_count = test_exes.length - fail_count;
|
||||
console.log(' DONE - %d PASSED, %d FAILED', pass_count, fail_count);
|
||||
|
||||
process.exit(fail_count == 0 ? 0 : 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user