Skip to content

Commit cf7a9f1

Browse files
committed
with eslint danger
1 parent 2df21da commit cf7a9f1

File tree

6 files changed

+751
-63
lines changed

6 files changed

+751
-63
lines changed

.eslintrc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ module.exports = {
2020
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
2121
plugins: ['@typescript-eslint'],
2222
parser: '@typescript-eslint/parser',
23-
parserOptions: {
24-
project: './tsconfig.json',
25-
},
2623
rules: {
2724
// We want to prevent async await usage in our files to prevent uncessary bundle size. Turned off in tests.
2825
'sentry-sdk/no-async-await': 'error',

dangerfile.ts

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,76 @@ 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', 'browser', 'core', 'hub', 'integrations', 'minimal', 'node', 'types', 'utils'];
9+
interface Options {
10+
baseConfig?: any;
11+
extensions?: string[];
12+
}
13+
14+
const packages = ['apm', 'core', 'hub', 'integrations', 'minimal', 'node', 'types', 'utils'];
15+
16+
/**
17+
* Eslint your code with Danger
18+
* Based on fork from: https://github.com/appcelerator/danger-plugin-eslint
19+
*/
20+
async function eslint(config: any, extensions?: string[]) {
21+
const allFiles = danger.git.created_files.concat(danger.git.modified_files);
22+
const options: Options = { baseConfig: config };
23+
if (extensions) {
24+
options.extensions = extensions;
25+
}
26+
const cli = new CLIEngine(options);
27+
// let eslint filter down to non-ignored, matching the extensions expected
28+
const filesToLint = allFiles.filter(f => {
29+
return !cli.isPathIgnored(f) && cli.options.extensions.some(ext => f.endsWith(ext));
30+
});
31+
return Promise.all(filesToLint.map(f => lintFile(cli, config, f)));
32+
}
33+
34+
async function lintFile(linter, config, path) {
35+
const contents = await danger.github.utils.fileContents(path);
36+
const report = linter.executeOnText(contents, path);
37+
38+
if (report.results.length !== 0) {
39+
report.results[0].messages.map(msg => {
40+
if (msg.fatal) {
41+
fail(`Fatal error linting ${path} with eslint.`);
42+
return;
43+
}
44+
45+
const fn = { 1: warn, 2: fail }[msg.severity];
46+
47+
fn(`${path} line ${msg.line}${msg.message} (${msg.ruleId})`, path, msg.line);
48+
});
49+
}
50+
}
951

1052
export default async () => {
1153
if (!danger.github) {
1254
return;
1355
}
1456

1557
schedule(async () => {
16-
const tsLintResult = (await Promise.all(
17-
packages.map(packageName => {
18-
return new Promise<string>(res => {
19-
tslint({
20-
lintResultsJsonPath: resolve(__dirname, 'packages', packageName, 'lint-results.json'),
21-
handleResults: results => {
22-
if (results.length > 0) {
23-
const formattedResults = prettyResults(results);
24-
res(`TSLint failed: **@sentry/${packageName}**\n\n${formattedResults}`);
25-
} else {
26-
res('');
27-
}
28-
},
58+
const tsLintResult = (
59+
await Promise.all(
60+
packages.map(packageName => {
61+
return new Promise<string>(res => {
62+
tslint({
63+
lintResultsJsonPath: resolve(__dirname, 'packages', packageName, 'lint-results.json'),
64+
handleResults: results => {
65+
if (results.length > 0) {
66+
const formattedResults = prettyResults(results);
67+
res(`TSLint failed: **@sentry/${packageName}**\n\n${formattedResults}`);
68+
} else {
69+
res('');
70+
}
71+
},
72+
});
2973
});
30-
});
31-
}),
32-
)).filter(str => str.length);
74+
}),
75+
)
76+
).filter(str => str.length);
3377
if (tsLintResult.length) {
3478
tsLintResult.forEach(tsLintFail => {
3579
fail(`${tsLintFail}`);
@@ -39,6 +83,8 @@ export default async () => {
3983
}
4084
});
4185

86+
await eslint();
87+
4288
const hasChangelog = danger.git.modified_files.indexOf('CHANGELOG.md') !== -1;
4389
const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes('#trivial');
4490

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"chai": "^4.1.2",
4949
"codecov": "^3.6.5",
5050
"danger": "^7.1.3",
51+
"danger-plugin-eslint": "^0.1.0",
5152
"danger-plugin-tslint": "^2.0.0",
5253
"eslint": "^7.5.0",
5354
"eslint-config-prettier": "^6.11.0",

packages/browser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"tslib": "^1.9.3"
2323
},
2424
"devDependencies": {
25+
"@types/eslint": "^7.2.0",
2526
"@types/md5": "2.1.33",
2627
"btoa": "^1.2.1",
2728
"chai": "^4.1.2",

packages/browser/src/backend.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export interface BrowserOptions extends Options {
3131
blacklistUrls?: Array<string | RegExp>;
3232
}
3333

34+
const lol = async () => {
35+
await new Promise();
36+
return 'hello';
37+
};
38+
3439
/**
3540
* The Sentry Browser SDK Backend.
3641
* @hidden

0 commit comments

Comments
 (0)