@@ -4,8 +4,42 @@ import { promisify } from 'util';
4
4
import { resolve } from 'path' ;
5
5
import tslint from 'danger-plugin-tslint' ;
6
6
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults' ;
7
+ import { CLIEngine } from 'eslint' ;
7
8
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
+ }
9
43
10
44
export default async ( ) : Promise < void > => {
11
45
if ( ! danger . github ) {
@@ -15,7 +49,7 @@ export default async (): Promise<void> => {
15
49
schedule ( async ( ) => {
16
50
const tsLintResult = (
17
51
await Promise . all (
18
- packages . map ( packageName => {
52
+ PACKAGES . map ( packageName => {
19
53
return new Promise < string > ( res => {
20
54
tslint ( {
21
55
lintResultsJsonPath : resolve ( __dirname , 'packages' , packageName , 'lint-results.json' ) ,
@@ -41,6 +75,8 @@ export default async (): Promise<void> => {
41
75
}
42
76
} ) ;
43
77
78
+ await eslint ( ) ;
79
+
44
80
const hasChangelog = danger . git . modified_files . indexOf ( 'CHANGELOG.md' ) !== - 1 ;
45
81
const isTrivial = ( danger . github . pr . body + danger . github . pr . title ) . includes ( '#trivial' ) ;
46
82
0 commit comments