mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
checkPlugin: Config ESLint via .eslintrc.cjs
This commit is contained in:
parent
f046f0ab81
commit
d5db979c93
2 changed files with 30 additions and 7 deletions
|
@ -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 outFn = path.join(pluginPath, dstFn);
|
||||||
const wantContents = await fsp.readFile(srcFn, {encoding: 'utf8'});
|
const wantContents = await fsp.readFile(srcFn, {encoding: 'utf8'});
|
||||||
let gotContents = null;
|
let gotContents = null;
|
||||||
|
@ -127,8 +127,12 @@ const path = require('path');
|
||||||
try {
|
try {
|
||||||
assert.equal(gotContents, wantContents);
|
assert.equal(gotContents, wantContents);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`File ${dstFn} is out of date`);
|
console.warn(`File ${dstFn} does not match the default`);
|
||||||
console.warn(err.message);
|
console.warn(err.message);
|
||||||
|
if (!overwrite && gotContents != null) {
|
||||||
|
console.warn('Leaving existing contents alone.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (autoFix) {
|
if (autoFix) {
|
||||||
await fsp.mkdir(path.dirname(outFn), {recursive: true});
|
await fsp.mkdir(path.dirname(outFn), {recursive: true});
|
||||||
await fsp.writeFile(outFn, wantContents);
|
await fsp.writeFile(outFn, wantContents);
|
||||||
|
@ -182,11 +186,24 @@ const path = require('path');
|
||||||
node: '>=12.17.0',
|
node: '>=12.17.0',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parsedPackageJSON.eslintConfig == null) parsedPackageJSON.eslintConfig = {};
|
if (parsedPackageJSON.eslintConfig != null && autoFix) {
|
||||||
if (checkEntries(parsedPackageJSON.eslintConfig, {
|
delete parsedPackageJSON.eslintConfig;
|
||||||
root: true,
|
await writePackageJson(parsedPackageJSON);
|
||||||
extends: 'etherpad/plugin',
|
}
|
||||||
})) 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, {
|
if (checkEntries(parsedPackageJSON, {
|
||||||
funding: {
|
funding: {
|
||||||
|
|
6
src/bin/plugins/lib/eslintrc.cjs
Normal file
6
src/bin/plugins/lib/eslintrc.cjs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
extends: 'etherpad/plugin',
|
||||||
|
};
|
Loading…
Reference in a new issue