Last active
April 20, 2023 21:51
-
-
Save gabrielcsapo/7fc1f7533917d2f90266d9a3e068e5a3 to your computer and use it in GitHub Desktop.
removes all eslint-disable comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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