Skip to content

Instantly share code, notes, and snippets.

@gabrielcsapo
Last active April 20, 2023 21:51
Show Gist options
  • Save gabrielcsapo/7fc1f7533917d2f90266d9a3e068e5a3 to your computer and use it in GitHub Desktop.
Save gabrielcsapo/7fc1f7533917d2f90266d9a3e068e5a3 to your computer and use it in GitHub Desktop.
removes all eslint-disable comments
const fs = require('fs');
const walkSync = require('walk-sync');
const workerpool = require('workerpool');
const os = require('os');
const chalk = require('chalk');
const maxWorkers = Math.ceil(os.cpus().length / 3);
const pool = workerpool.pool(`${__dirname}/worker.js`, {
maxWorkers,
workerType: 'thread',
});
const paths = walkSync(process.cwd(), { directories: false, includeBasePath: true, globs: ['**/*.js'], ignore: ['**/node_modules/**/*', 'dist/**/*', 'build/**/*', 'blueprints/**/*', 'docs/**/*', 'ember-backstop/**/*', 'extended/node_modules/**/*'] });
const start = process.hrtime();
let totalInstancesFound = 0;
const allFilePromisesForAddon = paths.map((filePath) =>
pool.exec('removeEslintStatements', [filePath]).then((instancesFound) => {
totalInstancesFound += instancesFound;
return;
}).catch((ex) => {
console.log(`error happening on ${filePath} \n ${ex.message}`);
})
);
Promise.all(allFilePromisesForAddon).then(() => {
const end = process.hrtime(start);
const seconds = ((end[0] * 1e9) + end[1]) / 1e9;
console.log(chalk.bold(`${paths.length.toLocaleString()} files process. ${chalk.green(totalInstancesFound.toLocaleString())} eslint disable statements removed. (${seconds}s)`))
process.exit();
})
{
"name": "remove-eslint-statements",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"chalk": "^4.1.0",
"walk-sync": "^2.2.0",
"workerpool": "^6.0.0"
}
}
const workerpool = require('workerpool');
const fs = require('fs');
function removeEslintStatements(filePath) {
return new Promise((resolve, reject) => {
try {
let matches = 0;
let content = fs.readFileSync(filePath, 'utf8')
content = content
.replace(/(\/\/ eslint-disable(.+?)$)/gm, function(match, p1, p2, offset, string) {
matches += 1;
return '';
})
.replace(/(\/\* eslint-disable(.+?)$)/gm, function(match, p1, p2, offset, string) {
matches += 1;
return '';
});
fs.writeFileSync(filePath, content);
return resolve(matches);
} catch(ex) {
return reject(ex);
}
});
}
workerpool.worker({
removeEslintStatements
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment