eslint-plugin-flowtype-errors
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _flowBin = require('flow-bin'); | ||
@@ -31,3 +35,6 @@ | ||
* Run Flow and collect errors in JSON format | ||
* Reference https://github.com/facebook/nuclide/blob/master/pkg/nuclide-flow-rpc/lib/FlowRoot.js | ||
* | ||
* Reference the following links for possible bug fixes and optimizations | ||
* https://github.com/facebook/nuclide/blob/master/pkg/nuclide-flow-rpc/lib/FlowRoot.js | ||
* https://github.com/ptmt/tryflow/blob/gh-pages/js/worker.js | ||
*/ | ||
@@ -81,34 +88,34 @@ function fatalError(stderr) { | ||
// Loop through errors in the file | ||
var output = parsedJSONArray.errors.map(function (error) { | ||
return error.message.map(function (message, i, whole) { | ||
if (message.type === 'Comment' || !message.loc) { | ||
return false; | ||
} | ||
var output = parsedJSONArray.errors.map(function (_ref) { | ||
var message = _ref.message; | ||
var comments = whole.find(function (_) { | ||
return _.type === 'Comment'; | ||
}); | ||
var messageDescr = (comments ? comments.descr : '') + ' ' + message.descr; | ||
var _message = (0, _slicedToArray3.default)(message, 1); | ||
if (process.env.DEBUG_FLOWTYPE_ERRRORS === 'true') { | ||
return { | ||
message: messageDescr, | ||
path: message.path, | ||
start: message.loc.start.line, | ||
end: message.loc.end.line, | ||
parsedJSONArray: parsedJSONArray | ||
}; | ||
} | ||
var firstMessage = _message[0]; | ||
var entireMessage = message.reduce(function (previous, current) { | ||
return previous + (current.type === 'Blame' ? ' \'' + current.descr + '\' ' : current.descr); | ||
}, ''); | ||
if (process.env.DEBUG_FLOWTYPE_ERRRORS === 'true') { | ||
return { | ||
message: messageDescr, | ||
path: message.path, | ||
start: message.loc.start.line, | ||
end: message.loc.end.line | ||
message: entireMessage, | ||
path: firstMessage.path, | ||
start: firstMessage.loc.start.line, | ||
end: firstMessage.loc.end.line, | ||
loc: firstMessage.loc, | ||
parsedJSONArray: parsedJSONArray | ||
}; | ||
}); | ||
}).reduce(function (p, c) { | ||
return p.concat(c); | ||
}, []); | ||
} | ||
return { | ||
message: entireMessage, | ||
path: firstMessage.path, | ||
start: firstMessage.loc.start.line, | ||
end: firstMessage.loc.end.line, | ||
loc: firstMessage.loc | ||
}; | ||
}); | ||
return output.length ? (0, _filter2.default)(output) : true; | ||
@@ -115,0 +122,0 @@ } |
@@ -0,1 +1,15 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
exports.default = filter; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -6,2 +20,18 @@ * This module is responsible for formatting flowtype errors to be more friendly and understandable | ||
*/ | ||
"use strict"; | ||
function fomatMessage(description) { | ||
if (description.toLowerCase().includes("' This type")) { | ||
return description.replace('This type', 'type'); | ||
} | ||
return description; | ||
} | ||
function filter(messages) { | ||
return messages.map(function (e) { | ||
return (0, _extends3.default)({}, e, { | ||
message: fomatMessage(e.message) | ||
}); | ||
}); | ||
} | ||
module.exports = exports['default']; |
103
index.js
@@ -44,9 +44,20 @@ const { execSync } = require('child_process'); | ||
try { | ||
const foundASTNodeError = parsedJSONArray.find(each => ( | ||
each.start === node.loc.start.line && | ||
each.path === context.getFilename() | ||
)); | ||
const foundASTNodeError = parsedJSONArray | ||
.filter(each => each.path === context.getFilename()) | ||
// ESLint uses a 'zero-based' column mechanisim. That means that they count columns | ||
// starting from 0. Weird... Flow's columns start at 1. Ughh | ||
.find(each => | ||
each.start === node.loc.start.line && | ||
each.loc.start.column === node.loc.start.column + 1 | ||
); | ||
if (foundASTNodeError) { | ||
return context.report(node, foundASTNodeError.message); | ||
const { message, loc } = foundASTNodeError; | ||
return context.report({ | ||
node, | ||
message, | ||
loc | ||
}); | ||
} | ||
@@ -63,20 +74,80 @@ } catch (err) { | ||
return { | ||
Program: collectFlowErrors, | ||
ArrayExpression: collectFlowErrors, | ||
ArrayPattern: collectFlowErrors, | ||
ArrowFunctionExpression: collectFlowErrors, | ||
AssignmentExpression: collectFlowErrors, | ||
AssignmentPattern: collectFlowErrors, | ||
BinaryExpression: collectFlowErrors, | ||
BlockStatement: collectFlowErrors, | ||
BreakStatement: collectFlowErrors, | ||
CallExpression: collectFlowErrors, | ||
CatchClause: collectFlowErrors, | ||
Class: collectFlowErrors, | ||
ClassBody: collectFlowErrors, | ||
BlockStatement: collectFlowErrors, | ||
WhileStatement: collectFlowErrors, | ||
ForStatement: collectFlowErrors, | ||
ClassDeclaration: collectFlowErrors, | ||
ClassExpression: collectFlowErrors, | ||
ConditionalStatement: collectFlowErrors, | ||
ContinueStatement: collectFlowErrors, | ||
DebuggerStatement: collectFlowErrors, | ||
Declaration: collectFlowErrors, | ||
DoWhileStatement: collectFlowErrors, | ||
EmptyExpression: collectFlowErrors, | ||
EmptyStatement: collectFlowErrors, | ||
ExportAllDeclaration: collectFlowErrors, | ||
ExportDeclaration: collectFlowErrors, | ||
ExportDefaultDeclaration: collectFlowErrors, | ||
ExportNamedDeclaration: collectFlowErrors, | ||
ExportSpecifier: collectFlowErrors, | ||
Expression: collectFlowErrors, | ||
ExpressionStatement: collectFlowErrors, | ||
ForInStatement: collectFlowErrors, | ||
ForOfStatement: collectFlowErrors, | ||
DoWhileStatement: collectFlowErrors, | ||
ForStatement: collectFlowErrors, | ||
Function: collectFlowErrors, | ||
FunctionDeclaration: collectFlowErrors, | ||
FunctionExpression: collectFlowErrors, | ||
Identifier: collectFlowErrors, | ||
IfStatement: collectFlowErrors, | ||
Identifier: collectFlowErrors, | ||
FunctionDeclaration: collectFlowErrors, | ||
VariableDeclaration: collectFlowErrors, | ||
ImportDeclaration: collectFlowErrors, | ||
ImportDefaultSpecifier: collectFlowErrors, | ||
ImportNamespaceSpecifier: collectFlowErrors, | ||
ImportSpecifier: collectFlowErrors, | ||
LabeledStatement: collectFlowErrors, | ||
Literal: collectFlowErrors, | ||
LogicalExpression: collectFlowErrors, | ||
MemberExpression: collectFlowErrors, | ||
MetaProperty: collectFlowErrors, | ||
MethodDefinition: collectFlowErrors, | ||
NewExpression: collectFlowErrors, | ||
Node: collectFlowErrors, | ||
ObjectExpression: collectFlowErrors, | ||
ArrayExpression: collectFlowErrors, | ||
MemberExpression: collectFlowErrors, | ||
ObjectPattern: collectFlowErrors, | ||
Pattern: collectFlowErrors, | ||
Position: collectFlowErrors, | ||
Program: collectFlowErrors, | ||
Property: collectFlowErrors, | ||
Regex: collectFlowErrors, | ||
RestElement: collectFlowErrors, | ||
ReturnStatement: collectFlowErrors, | ||
SequenceExpression: collectFlowErrors, | ||
SourceLocation: collectFlowErrors, | ||
SpreadElement: collectFlowErrors, | ||
Statement: collectFlowErrors, | ||
Super: collectFlowErrors, | ||
SwitchCase: collectFlowErrors, | ||
SwitchStatement: collectFlowErrors, | ||
SwitchCase: collectFlowErrors | ||
TaggedTemplateExpression: collectFlowErrors, | ||
TemplateElement: collectFlowErrors, | ||
TemplateLiteral: collectFlowErrors, | ||
ThisExpression: collectFlowErrors, | ||
ThrowStatement: collectFlowErrors, | ||
Tools: collectFlowErrors, | ||
TryStatement: collectFlowErrors, | ||
UnaryExpression: collectFlowErrors, | ||
UpdateExpression: collectFlowErrors, | ||
VariableDeclaration: collectFlowErrors, | ||
VariableDeclarator: collectFlowErrors, | ||
WhileStatement: collectFlowErrors, | ||
WithStatement: collectFlowErrors, | ||
YieldExpression: collectFlowErrors | ||
}; | ||
@@ -83,0 +154,0 @@ } |
{ | ||
"name": "eslint-plugin-flowtype-errors", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Retrieve Flow errors as ESLint errors.", | ||
@@ -5,0 +5,0 @@ "author": "Amila Welihinda", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1410975
297