Skip to content

Commit

Permalink
feat: add Flow type checking
Browse files Browse the repository at this point in the history
Add `flow check` to check for type errors as additional
linting step.

The `.flowconfig` file in the root of AEgir is needed as else
the linting would fail (although AEgir doesn't define any Flow
types). This is intentional as this branch should only be used
with projects using Flow. There this error message is really
helpful.
  • Loading branch information
vmx committed May 3, 2018
1 parent 82a00b6 commit d590f4f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[ignore]
.*/node_modules/documentation/*

[libs]

[include]

[options]
suppress_comment= \\(.\\|\n\\)*\\@FlowIgnore
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"execa": "^0.8.0",
"filesize": "^3.5.11",
"findup-sync": "^2.0.0",
"flow-bin": "^0.71.0",
"fs-extra": "^4.0.3",
"gh-pages": "^1.1.0",
"glob": "^7.1.2",
Expand Down
22 changes: 21 additions & 1 deletion src/lint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict'

const util = require('util')
const execFile = util.promisify(require('child_process').execFile)

const CLIEngine = require('eslint').CLIEngine
const flow = require('flow-bin')
const path = require('path')
const formatter = CLIEngine.getFormatter()

Expand All @@ -18,7 +22,7 @@ const FILES = [
'!**/node_modules/**'
]

function lint (opts) {
const eslint = (opts) => {
return new Promise((resolve, reject) => {
const cli = new CLIEngine({
useEslintrc: true,
Expand All @@ -37,4 +41,20 @@ function lint (opts) {
})
}

const typecheck = async (_opts) => {
try {
const { stdout } = await execFile(flow, ['check', '--color=always'])
console.log(stdout)
} catch (err) {
console.error(err.stdout)
console.error(err.stderr)
throw new Error('Type check errors')
}
}

const lint = async (opts) => {
await eslint(opts)
await typecheck(opts)
}

module.exports = lint
2 changes: 1 addition & 1 deletion test/lint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const lint = require('../src/lint')
describe('lint', () => {
it('passes', function () {
// slow ci is slow, appveyor is even slower...
this.timeout(5000)
this.timeout(20000)
return lint({
fix: false
})
Expand Down

0 comments on commit d590f4f

Please sign in to comment.