-
Notifications
You must be signed in to change notification settings - Fork 1
/
dangerfile.js
97 lines (79 loc) · 2.76 KB
/
dangerfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const {
committedFilesGrep,
commonChangelog,
commonContributingGuide,
commonFileContains,
commonFileWarnings,
commonPrDescriptionContribution,
commonValidJson,
inCommit,
inCommitGrep,
jsConsoleCommands,
jsGlobalEslintChange,
jsLocalEslintChange,
jsLockfile,
jsOutOfSyncDeps,
jsTestShortcuts,
linkToTargetRepo,
prAuthor,
prTitle,
} = require('prod-danger-plugin-toolbox'); // eslint-disable-line import/no-extraneous-dependencies -- This is only needed in CI
const prAuthorIsBot = [
'snyk-bot',
'dependabot-preview[bot]',
'dependabot[bot]',
].includes(prAuthor);
commonPrDescriptionContribution();
commonContributingGuide();
// Do not require "CHANGELOG.md" to be updated when:
// - The PR is created by a bot (Snyk...)
// - The PR title is "Update dependencies" (just bumping devDependencies)
if (!(prAuthorIsBot || prTitle === 'Update dependencies')) {
commonChangelog();
}
commonValidJson();
commonFileWarnings('lint.log');
commonFileWarnings('test.log');
jsConsoleCommands({ inline: true });
jsGlobalEslintChange();
jsLocalEslintChange({ inline: true });
jsLockfile();
jsOutOfSyncDeps({ logType: 'fail' });
jsTestShortcuts({ logTypeFocused: 'fail', inline: true });
const noUnreleasedSection = () =>
'CHANGELOG.md is missing the "Unreleased" section.';
commonFileContains('CHANGELOG.md', /^## \[Unreleased\]$/m, {
buildMessage: noUnreleasedSection,
});
// Make sure documentation has been added/updated when a validation/helper is added/updated
const validationsMd = 'docs/validations.md';
const utilitiesMd = 'docs/utilities.md';
const changedValidations = inCommitGrep(/^src\/rules\/\w+\/\w+\.js$/);
const changedValidationsDoc = inCommit(validationsMd);
if (changedValidations && !changedValidationsDoc) {
const validationsLink = linkToTargetRepo(validationsMd, 'documentation');
warn(
`Seems like a validation has been added or modified, make sure the ${validationsLink} is up to date.`,
);
}
const changedUtilities = inCommit('src/rules/helpers.js');
const changedUtilitiesDoc = inCommit(utilitiesMd);
if (changedUtilities && !changedUtilitiesDoc) {
const utilitiesLink = linkToTargetRepo(utilitiesMd, 'documentation');
warn(
`Seems like a utility (helper) has been added or modified, make sure the ${utilitiesLink} is up to date.`,
);
}
// Make sure tests are added/updated when adding/updating validations or utilities
const changedRules = committedFilesGrep(/^src\/rules\/(\w+\/)?\w+\.js$/);
changedRules.forEach((curChange) => {
const curChangeTest = curChange.replace(
/^(src\/rules\/(\w+\/)?)(\w+)(\.js)$/,
'$1__tests__/$3.test$4',
);
if (!inCommit(curChangeTest)) {
warn(
`The file \`${curChange}\` has been added or modified but the corresponding test (\`${curChangeTest}\`) hasn't.`,
);
}
});