This repository was archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdangerfile.ts
More file actions
47 lines (40 loc) · 1.4 KB
/
dangerfile.ts
File metadata and controls
47 lines (40 loc) · 1.4 KB
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
import { danger, warn, fail } from 'danger'
import { CLIEngine } from 'eslint'
import { lint as stylelint } from 'stylelint'
import * as eslintConfig from './.eslintrc'
import * as stylelintConfig from './stylelint.config'
const filesToCheck = [...danger.git.created_files, ...danger.git.modified_files]
const eslint = new CLIEngine(eslintConfig as CLIEngine.Options)
const isJsFile = (f: string) =>
f.endsWith('ts') || f.endsWith('tsx') || f.endsWith('js')
filesToCheck.filter(isJsFile).forEach(async f => {
const text = await danger.github.utils.fileContents(f)
const { results } = eslint.executeOnText(text)
results[0].messages.forEach(message => {
if (message.severity === 2) {
fail(message.message, f, message.line)
} else if (message.severity === 1) {
warn(message.message, f, message.line)
}
})
})
const isCssFile = (s: string) => s.endsWith('.css')
filesToCheck.filter(isCssFile).forEach(async f => {
const text = await danger.github.utils.fileContents(f)
const { results } = await stylelint({
code: text,
config: stylelintConfig
})
results[0].warnings.forEach(message => {
if (message.severity === 'error') {
fail(message.text, f, message.line)
} else if (message.severity === 'warning') {
warn(message.text, f, message.line)
}
})
})
if (filesToCheck.includes('package.json')) {
if (!filesToCheck.includes('yarn.lock')) {
fail('')
}
}