Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPDATE] Updated project to 0.19.1 #38

Merged
merged 2 commits into from
Jan 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
[ignore]
.*/node_modules/*
.*/test/*
[include]
.*/node_modules/babylon/lib/parser/*
.*/node_modules/babel-types/lib/*
.*/node_modules/babel-register/src/node.js
.*/node_modules/babel-generator/lib/*
.*/node_modules/babel-core/lib/util.js
.*/node_modules/babel-core/lib/transformation/*
.*/node_modules/babel-helper-regex/lib/index.js
[options]
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
47 changes: 14 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/* @flow weak */
'use strict';


var Q = require('q');
var fs = require('fs');
require('babel/polyfill');
require('babel-polyfill');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'require' is not defined.

var path = require('path');
var gutil = require('gulp-util');
var through = require('through2');
var flowBin = require('flow-bin');
var logSymbols = require('log-symbols');
var { execFile, spawn } = require('child_process');
var childProcess = require('child_process');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'require' is not defined.

var flowToJshint = require('flow-to-jshint');
var stylishReporter = require(require('jshint-stylish')).reporter;
var stylishReporter = require('jshint-stylish').reporter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'require' is not defined.


/**
* Flow check initialises a server per folder when run,
Expand Down Expand Up @@ -61,7 +63,7 @@ function executeFlow(_path, options) {

var opts = optsToArgs(options);

var command = opts.length ? (() => {
var command = opts.length || options.killFlow ? (() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use esnext option).

servers.push(path.dirname(_path));
return 'check';
})() : 'status';
Expand All @@ -73,7 +75,7 @@ function executeFlow(_path, options) {
'--json'
];

var stream = spawn(getFlowBin(), args);
var stream = childProcess.spawn(getFlowBin(), args);

stream.stdout.on('data', data => {
var parsed;
Expand All @@ -84,34 +86,13 @@ function executeFlow(_path, options) {
parsed = fatalError(data.toString());
}
var result = {};

// loop through errors in file
result.errors = parsed.errors.filter(function (error) {
error.message = error.message.filter(function (message, index) {
var isCurrentFile = message.path === _path;
var result = false;
/**
* If FlowType traces an issue to a method inside a file that is not
* the one being piped through, it adds a new element to the list
* of errors with a different file path to the current one. To detect
* whether this error is related to the current file we check the
* previous and next error to see if it ends with `found`, `in` or
* `with`, From this we can tell if the error should be shown or not.
*/
var lineEnding = /(with|found|in)$/;

var previous = error.message[index - 1];
if (previous && lineEnding.test(previous.descr)) {
result = previous.path === _path;
}

var nextMessage = error.message[index + 1];
if (nextMessage && lineEnding.test(message.descr)) {
result = nextMessage.path === _path;
}

var generalError = (/(Fatal)/.test(message.descr));
return isCurrentFile || result || generalError;
});
return error.message.length > 0;
let isCurrentFile = error.message[0].path === _path;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).

let generalError = (/(Fatal)/.test(error.message[0].descr));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'let' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).


return isCurrentFile || generalError;
});

if (result.errors.length) {
Expand Down Expand Up @@ -176,7 +157,7 @@ function isFileSuitable(file) {
function killServers() {
var defers = servers.map(function(_path) {
var deferred = Q.defer();
execFile(getFlowBin(), ['stop'], {
childProcess.execFile(getFlowBin(), ['stop'], {
cwd: _path
}, deferred.resolve);
return deferred;
Expand Down
36 changes: 24 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-flowtype",
"version": "0.4.8",
"version": "0.4.9",
"description": "Run Facebook's Flow in your gulp pipeline",
"keywords": [
"gulp",
Expand All @@ -13,33 +13,45 @@
},
"repository": "charliedowler/gulp-flowtype",
"scripts": {
"lint": "./node_modules/.bin/jshint **.js && flow check --lib ./declarations/",
"lint": "npm run lint:js && npm run lint:flow",
"lint:js": "jshint **.js",
"lint:flow": "flow check --lib ./declarations/",
"test": "babel -d lib index.js; istanbul test _mocha --report html -- test/*.js --reporter spec",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"prepublish": "babel -d lib index.js"
},
"dependencies": {
"babel": "^5.0.12",
"babel-cli": "^6.3.15",
"babel-polyfill": "^6.3.14",
"babel-types": "^6.3.14",
"event-stream": "~3.3.0",
"flow-bin": "^0.20.1",
"flow-to-jshint": "~0.2.0",
"gulp-util": "~3.0.1",
"jshint": "^2.5.10",
"jshint-stylish": "~1.0.0",
"jshint": "^2.8.0",
"jshint-stylish": "~2.1.0",
"log-symbols": "^1.0.1",
"q": "^1.1.2",
"through2": "~0.6.3",
"flow-bin": "~0.13.1"
"through2": "~2.0.0"
},
"devDependencies": {
"coveralls": "~2.11.2",
"istanbul": "~0.3.2",
"mocha": "~2.2.4",
"mocha-lcov-reporter": "~0.0.1",
"should": "~5.2.0"
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-2": "^6.3.13",
"coveralls": "~2.11.5",
"istanbul": "~0.4.1",
"mocha": "~2.3.4",
"mocha-lcov-reporter": "~1.0.0",
"should": "~8.0.0"
},
"engines": {
"node": ">=0.8.0",
"npm": ">=1.2.10"
},
"babel": {
"presets": [
"es2015",
"stage-2"
]
},
"license": "MIT"
}
19 changes: 16 additions & 3 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('gulp-flow', function () {
stream.end();
});

it('should able to check with declarations', function (done) {
it('should be able to check with declarations', function (done) {
assertFile(getFixture('declaration.js'), {
beep: false
}, function () {
Expand Down Expand Up @@ -129,12 +129,19 @@ describe('gulp-flow', function () {
execFile(flowBin, ['status', '--no-auto-start'], {
cwd: 'test'
}, function(err, stdout, stderr) {
should.equal(/no flow server running/.test(stderr), true);
should.equal(/no flow server running/.test(stderr.toLowerCase()), true);
done();
});
});
});

/**
* Get file from fixtures
*
* @param {string} name fixture file name
*
* @return {Vinyl} file object
*/
function getFixture(name) {
var _path = '/' + path.relative('/', 'test/fixtures/' + name);
return new gutil.File({
Expand All @@ -145,6 +152,13 @@ describe('gulp-flow', function () {
});
}

/**
* Test file with flow
*
* @param {Vinyl} srcFile file object
* @param {Object} flowOptions flow options
* @param {Function} callback execution callback
*/
function assertFile(srcFile, flowOptions, callback) {
var stream = flow(flowOptions);
stream.on('error', function (err) {
Expand All @@ -165,5 +179,4 @@ describe('gulp-flow', function () {
stream.write(srcFile);
stream.end();
}

});