From d5db979c93b9f62a8998b971dafed4de67b7fbdc Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 21 Feb 2022 14:13:40 -0500 Subject: [PATCH] checkPlugin: Config ESLint via `.eslintrc.cjs` --- src/bin/plugins/checkPlugin.js | 31 ++++++++++++++++++++++++------- src/bin/plugins/lib/eslintrc.cjs | 6 ++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 src/bin/plugins/lib/eslintrc.cjs diff --git a/src/bin/plugins/checkPlugin.js b/src/bin/plugins/checkPlugin.js index 8be9316cb..026420713 100755 --- a/src/bin/plugins/checkPlugin.js +++ b/src/bin/plugins/checkPlugin.js @@ -117,7 +117,7 @@ const path = require('path'); } }; - const checkFile = async (srcFn, dstFn) => { + const checkFile = async (srcFn, dstFn, overwrite = true) => { const outFn = path.join(pluginPath, dstFn); const wantContents = await fsp.readFile(srcFn, {encoding: 'utf8'}); let gotContents = null; @@ -127,8 +127,12 @@ const path = require('path'); try { assert.equal(gotContents, wantContents); } catch (err) { - console.warn(`File ${dstFn} is out of date`); + console.warn(`File ${dstFn} does not match the default`); console.warn(err.message); + if (!overwrite && gotContents != null) { + console.warn('Leaving existing contents alone.'); + return; + } if (autoFix) { await fsp.mkdir(path.dirname(outFn), {recursive: true}); await fsp.writeFile(outFn, wantContents); @@ -182,11 +186,24 @@ const path = require('path'); node: '>=12.17.0', }); - if (parsedPackageJSON.eslintConfig == null) parsedPackageJSON.eslintConfig = {}; - if (checkEntries(parsedPackageJSON.eslintConfig, { - root: true, - extends: 'etherpad/plugin', - })) await writePackageJson(parsedPackageJSON); + if (parsedPackageJSON.eslintConfig != null && autoFix) { + delete parsedPackageJSON.eslintConfig; + await writePackageJson(parsedPackageJSON); + } + if (files.includes('.eslintrc.js')) { + const [from, to] = [`${pluginPath}/.eslintrc.js`, `${pluginPath}/.eslintrc.cjs`]; + if (!files.includes('.eslintrc.cjs')) { + if (autoFix) { + await fsp.rename(from, to); + } else { + console.warn(`please rename ${from} to ${to}`); + } + } else { + console.error(`both ${from} and ${to} exist; delete ${from}`); + } + } else { + checkFile('src/bin/plugins/lib/eslintrc.cjs', '.eslintrc.cjs', false); + } if (checkEntries(parsedPackageJSON, { funding: { diff --git a/src/bin/plugins/lib/eslintrc.cjs b/src/bin/plugins/lib/eslintrc.cjs new file mode 100644 index 000000000..88c72d3d2 --- /dev/null +++ b/src/bin/plugins/lib/eslintrc.cjs @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = { + root: true, + extends: 'etherpad/plugin', +};