Skip to content

Commit a877ce0

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

File tree

5 files changed

+701
-61
lines changed

5 files changed

+701
-61
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: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,69 @@ import { resolve } from 'path';
55
import tslint from 'danger-plugin-tslint';
66
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults';
77

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

1046
export default async () => {
1147
if (!danger.github) {
1248
return;
1349
}
1450

1551
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-
},
52+
const tsLintResult = (
53+
await Promise.all(
54+
packages.map(packageName => {
55+
return new Promise<string>(res => {
56+
tslint({
57+
lintResultsJsonPath: resolve(__dirname, 'packages', packageName, 'lint-results.json'),
58+
handleResults: results => {
59+
if (results.length > 0) {
60+
const formattedResults = prettyResults(results);
61+
res(`TSLint failed: **@sentry/${packageName}**\n\n${formattedResults}`);
62+
} else {
63+
res('');
64+
}
65+
},
66+
});
2967
});
30-
});
31-
}),
32-
)).filter(str => str.length);
68+
}),
69+
)
70+
).filter(str => str.length);
3371
if (tsLintResult.length) {
3472
tsLintResult.forEach(tsLintFail => {
3573
fail(`${tsLintFail}`);
@@ -39,6 +77,8 @@ export default async () => {
3977
}
4078
});
4179

80+
await eslint();
81+
4282
const hasChangelog = danger.git.modified_files.indexOf('CHANGELOG.md') !== -1;
4383
const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes('#trivial');
4484

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/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)