checkPlugin: Config ESLint via `.eslintrc.cjs`

pull/5425/head
Richard Hansen 2022-02-21 14:13:40 -05:00
parent f046f0ab81
commit d5db979c93
2 changed files with 30 additions and 7 deletions

View File

@ -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: {

View File

@ -0,0 +1,6 @@
'use strict';
module.exports = {
root: true,
extends: 'etherpad/plugin',
};