[pve-devel] [PATCH eslint] change from CLIEngine to ESLint

Dominik Csapak d.csapak at proxmox.com
Thu Dec 2 13:54:18 CET 2021


8.0 officialy removed CLIEngine (though it's still in git) so use
the current and supported API.

Necessary changes:
* use 'ESLint' instead of 'CLIEngine'
* use 'lintFiles' instead of 'executeOnFiles' (thats async now)
* adapt to the change of return value of 'lintFiles'

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
after appliying this, we have to 'make buildupstream' again, since the
included code changes (CLIEngine -> ESLint)

 patches/0001-adapt-webpack-config.patch |  2 +-
 src/bin/app.js                          |  4 ++--
 src/lib/worker.js                       | 12 +++++++-----
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/patches/0001-adapt-webpack-config.patch b/patches/0001-adapt-webpack-config.patch
index b0201e1..a1235d3 100644
--- a/patches/0001-adapt-webpack-config.patch
+++ b/patches/0001-adapt-webpack-config.patch
@@ -22,7 +22,7 @@ index a22c99b..9209159 100644
 +    target: "node",
      entry: {
 -        eslint: ["core-js/stable", "regenerator-runtime/runtime", "./lib/linter/linter.js"]
-+        eslint: ["core-js/stable", "regenerator-runtime/runtime", "./lib/linter/linter.js", "./lib/cli-engine/index.js"]
++        eslint: ["core-js/stable", "regenerator-runtime/runtime", "./lib/linter/linter.js", "./lib/eslint/index.js"]
      },
      output: {
          filename: "[name].js",
diff --git a/src/bin/app.js b/src/bin/app.js
index 10e7e6a..a1ba89f 100644
--- a/src/bin/app.js
+++ b/src/bin/app.js
@@ -313,7 +313,7 @@ promises.push(eslint.createWorker({
     files: paths
 }));
 
-let results = (await Promise.all(promises)).map(res => res.results).flat(1);
+let results = (await Promise.all(promises)).flat(1);
 
 let exitcode = 0;
 let files_err = [], files_warn = [], files_ok = [];
@@ -390,7 +390,7 @@ console.log('------------------------------------------------------------');
 if (program.fix) {
     if (fixes > 0) {
 	console.log(`Writing ${color.bold(fixes)} fixed files...`);
-	eslint.CLIEngine.outputFixes({ results });
+	eslint.ESLint.outputFixes({ results });
 	console.log('Done');
     } else {
 	console.log("No fixable Errors/Warnings found.");
diff --git a/src/lib/worker.js b/src/lib/worker.js
index 9a8c955..000209e 100644
--- a/src/lib/worker.js
+++ b/src/lib/worker.js
@@ -3,11 +3,13 @@
 const worker = require('worker_threads');
 
 if (!worker.isMainThread) {
-    const eslint = require('pve-eslint');
-    const data = worker.workerData;
-    const cli = new eslint.CLIEngine(data.cliOptions);
-    const report = cli.executeOnFiles(data.files);
-    worker.parentPort.postMessage(report);
+    (async function() {
+	const eslint = require('pve-eslint');
+	const data = worker.workerData;
+	const cli = new eslint.ESLint(data.cliOptions);
+	const report = await cli.lintFiles(data.files);
+	worker.parentPort.postMessage(report);
+    })();
 } else {
     module.exports = async function createWorker(workerData) {
 	return new Promise((resolve, reject) => {
-- 
2.30.2





More information about the pve-devel mailing list