Skip to content

Commit 9dca0d8

Browse files
committed
never mind
1 parent 269c81c commit 9dca0d8

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

dangerfile.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,42 @@ import { promisify } from 'util';
44
import { resolve } from 'path';
55
import tslint from 'danger-plugin-tslint';
66
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults';
7+
import { CLIEngine } from 'eslint';
78

8-
const packages = ['apm', 'core', 'hub', 'integrations', 'minimal', 'node', 'types', 'utils'];
9+
const PACKAGES = ['apm', 'core', 'hub', 'integrations', 'minimal', 'node', 'types', 'utils'];
10+
const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];
11+
12+
/**
13+
* Eslint your code with Danger
14+
* Based on fork from: https://github.com/appcelerator/danger-plugin-eslint
15+
*/
16+
async function eslint(): Promise<void[]> {
17+
const allFiles = danger.git.created_files.concat(danger.git.modified_files);
18+
const cli = new CLIEngine({});
19+
// let eslint filter down to non-ignored, matching the extensions expected
20+
const filesToLint = allFiles.filter(f => !cli.isPathIgnored(f) && EXTENSIONS.some(ext => f.endsWith(ext)));
21+
return Promise.all(filesToLint.map(f => lintFile(cli, f)));
22+
}
23+
24+
/** JSDoc */
25+
async function lintFile(linter: CLIEngine, path: string): Promise<void> {
26+
const contents = await danger.github.utils.fileContents(path);
27+
const report = linter.executeOnText(contents, path);
28+
29+
if (report.results.length !== 0) {
30+
report.results[0].messages.map(msg => {
31+
if (msg.fatal) {
32+
fail(`Fatal error linting ${path} with eslint.`);
33+
return;
34+
}
35+
36+
const noop = (): void => undefined;
37+
const fn = { 0: noop, 1: warn, 2: fail }[msg.severity];
38+
39+
fn(`${path} line ${msg.line}${msg.message} (${msg.ruleId})`, path, msg.line);
40+
});
41+
}
42+
}
943

1044
export default async (): Promise<void> => {
1145
if (!danger.github) {
@@ -15,7 +49,7 @@ export default async (): Promise<void> => {
1549
schedule(async () => {
1650
const tsLintResult = (
1751
await Promise.all(
18-
packages.map(packageName => {
52+
PACKAGES.map(packageName => {
1953
return new Promise<string>(res => {
2054
tslint({
2155
lintResultsJsonPath: resolve(__dirname, 'packages', packageName, 'lint-results.json'),
@@ -41,6 +75,8 @@ export default async (): Promise<void> => {
4175
}
4276
});
4377

78+
await eslint();
79+
4480
const hasChangelog = danger.git.modified_files.indexOf('CHANGELOG.md') !== -1;
4581
const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes('#trivial');
4682

0 commit comments

Comments
 (0)