Init Danger/Endanger with Backbone/package.json versions rules
This commit is contained in:
parent
c6819a5438
commit
bbf4e74239
13 changed files with 2431 additions and 131 deletions
54
danger/rules/migrateBackboneToRedux.ts
Normal file
54
danger/rules/migrateBackboneToRedux.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue