Init Danger/Endanger with Backbone/package.json versions rules

This commit is contained in:
Jamie Kyle 2022-09-16 11:32:28 -07:00 committed by GitHub
parent c6819a5438
commit bbf4e74239
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 2431 additions and 131 deletions

View file

@ -0,0 +1,54 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { Line, Rule } from 'endanger';
export default function migrateBackboneToRedux() {
return new Rule({
match: {
files: ['**/*.{js,jsx,ts,tsx}'],
},
messages: {
foundNewBackboneFile: `
**Prefer Redux**
Don't create new Backbone files, use Redux
`,
foundBackboneFileWithManyChanges: `
**Prefer Redux**
Migrate Backbone files to Redux when making major changes
`,
},
async run({ files, context }) {
for (let file of files.touched) {
let lines = await file.lines();
let matchedLine: Line | null = null;
for (let line of lines) {
// Check for the most stable part of the backbone `import`
if (
(await line.contains("from 'backbone'")) ||
(await line.contains('window.Backbone'))
) {
matchedLine = line;
break;
}
}
if (!matchedLine) {
continue;
}
if (file.created) {
context.warn('foundNewBackboneFile', { file, line: matchedLine });
} else if (file.modifiedOnly) {
if (await file.diff().changedBy({ added: 0.1 })) {
context.warn('foundBackboneFileWithManyChanges', {
file,
line: matchedLine,
});
}
}
}
},
});
}