зеркало из https://github.com/electron/electron.git
chore: fixup patches linting (#26595)
This commit is contained in:
Родитель
fadd513739
Коммит
c8c41fb727
|
@ -164,16 +164,16 @@ const LINTERS = [{
|
|||
}, {
|
||||
key: 'patches',
|
||||
roots: ['patches'],
|
||||
test: () => true,
|
||||
test: filename => filename.endsWith('.patch'),
|
||||
run: (opts, filenames) => {
|
||||
const patchesDir = path.resolve(__dirname, '../patches');
|
||||
for (const patchTarget of fs.readdirSync(patchesDir)) {
|
||||
const targetDir = path.resolve(patchesDir, patchTarget);
|
||||
// If the config does not exist that is OK, we just skip this dir
|
||||
const targetConfig = path.resolve(targetDir, 'config.json');
|
||||
if (!fs.existsSync(targetConfig)) continue;
|
||||
const patchesConfig = path.resolve(patchesDir, 'config.json');
|
||||
// If the config does not exist, that's a proiblem
|
||||
if (!fs.existsSync(patchesConfig)) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const config = JSON.parse(fs.readFileSync(targetConfig, 'utf8'));
|
||||
const config = JSON.parse(fs.readFileSync(patchesConfig, 'utf8'));
|
||||
for (const key of Object.keys(config)) {
|
||||
// The directory the config points to should exist
|
||||
const targetPatchesDir = path.resolve(__dirname, '../../..', key);
|
||||
|
@ -207,22 +207,22 @@ const LINTERS = [{
|
|||
throw new Error(`Expected all the patch files listed in the .patches file at "${dotPatchesPath}" to exist but some did not:\n${JSON.stringify([...patchFileSet.values()], null, 2)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let ok = true;
|
||||
filenames.filter(f => f.endsWith('.patch')).forEach(f => {
|
||||
const allOk = filenames.length > 0 && filenames.map(f => {
|
||||
const patchText = fs.readFileSync(f, 'utf8');
|
||||
if (/^Subject: .*$\s+^diff/m.test(patchText)) {
|
||||
const subjectAndDescription = /Subject: (.*?)\n\n([\s\S]*?)\s*(?=diff)/ms.exec(patchText);
|
||||
if (!subjectAndDescription[2]) {
|
||||
console.warn(`Patch file '${f}' has no description. Every patch must contain a justification for why the patch exists and the plan for its removal.`);
|
||||
ok = false;
|
||||
return false;
|
||||
}
|
||||
const trailingWhitespace = patchText.split('\n').filter(line => line.startsWith('+')).some(line => /\s+$/.test(line));
|
||||
if (trailingWhitespace) {
|
||||
console.warn(`Patch file '${f}' has trailing whitespace on some lines.`);
|
||||
ok = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (!ok) {
|
||||
return true;
|
||||
}).every(x => x);
|
||||
if (!allOk) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче