You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

eslint-plugin-flowtype

Package Overview
Dependencies
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.1.0

67

dist/rules/requireReturnType.js

@@ -7,12 +7,69 @@ 'use strict';

var _get2 = require('lodash/get');
var _get3 = _interopRequireDefault(_get2);
var _utilities = require('./../utilities');
exports.default = (0, _utilities.iterateFunctionNodes)(function (context) {
return function (functionNode) {
if (!functionNode.returnType) {
context.report(functionNode, 'Missing return type annotation.');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function (context) {
var annotateReturn = ((0, _get3.default)(context, 'options[0]') || 'always') === 'always';
var annotateUndefined = ((0, _get3.default)(context, 'options[1].annotateUndefined') || 'never') === 'always';
var targetNodes = [];
var registerFunction = function registerFunction(functionNode) {
targetNodes.push({
functionNode: functionNode
});
};
var isUndefinedReturnType = function isUndefinedReturnType(returnNode) {
return returnNode.argument === null || returnNode.argument.name === 'undefined';
};
var evaluateFunction = function evaluateFunction(functionNode) {
var targetNode = targetNodes.pop();
if (functionNode !== targetNode.functionNode) {
throw new Error('Mismatch.');
}
var isFunctionReturnUndefined = !targetNode.returnStatementNode || isUndefinedReturnType(targetNode.returnStatementNode);
var isReturnTypeAnnotationUndefined = (0, _get3.default)(targetNode, 'functionNode.returnType.typeAnnotation.type') === 'GenericTypeAnnotation';
if (isFunctionReturnUndefined && isReturnTypeAnnotationUndefined && !annotateUndefined) {
context.report(functionNode, 'Must not annotate undefined return type.');
} else if (isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined && annotateUndefined) {
context.report(functionNode, 'Must annotate undefined return type.');
} else if (!isFunctionReturnUndefined && !isReturnTypeAnnotationUndefined) {
if (annotateReturn && !functionNode.returnType) {
context.report(functionNode, 'Missing return type annotation.');
}
}
};
});
var evaluateNoise = function evaluateNoise() {
targetNodes.pop();
};
return {
ArrowFunctionExpression: registerFunction,
'ArrowFunctionExpression:exit': evaluateFunction,
ClassDeclaration: registerFunction,
'ClassDeclaration:exit': evaluateNoise,
ClassExpression: registerFunction,
'ClassExpression:exit': evaluateNoise,
FunctionDeclaration: registerFunction,
'FunctionDeclaration:exit': evaluateFunction,
FunctionExpression: registerFunction,
'FunctionExpression:exit': evaluateFunction,
ReturnStatement: function ReturnStatement(node) {
targetNodes[targetNodes.length - 1].returnStatementNode = node;
}
};
};
module.exports = exports['default'];
//# sourceMappingURL=requireReturnType.js.map

2

package.json
{
"name": "eslint-plugin-flowtype",
"description": "Flowtype linting rules for ESLint.",
"version": "2.0.1",
"version": "2.1.0",
"main": "./dist/index.js",

@@ -6,0 +6,0 @@ "repository": {

@@ -51,4 +51,10 @@ <h1 id="eslint-plugin-flowtype">eslint-plugin-flowtype</h1>

"flowtype/require-return-type": 1,
"flowtype/space-after-type-colon": 1,
"flowtype/space-before-type-colon": 1
"flowtype/space-after-type-colon": [
1,
"always"
],
"flowtype/space-before-type-colon": [
1,
"never"
]
}

@@ -100,4 +106,30 @@ }

```js
(foo) => {}
(foo) => { return "foo"; }
// Message: Missing return type annotation.
// Options: ["always"]
(foo) => { return "foo"; }
// Message: Missing return type annotation.
(foo): undefined => { return; }
// Message: Must not annotate undefined return type.
(foo): undefined => { return undefined; }
// Message: Must not annotate undefined return type.
// Options: ["always",{"annotateUndefined":"never"}]
(foo): undefined => { return; }
// Message: Must not annotate undefined return type.
// Options: ["always",{"annotateUndefined":"always"}]
(foo) => { return; }
// Message: Must annotate undefined return type.
// Options: ["always",{"annotateUndefined":"never"}]
(foo): undefined => { return undefined; }
// Message: Must not annotate undefined return type.
// Options: ["always",{"annotateUndefined":"always"}]
(foo) => { return undefined; }
// Message: Must annotate undefined return type.
```

@@ -109,2 +141,21 @@

(foo): string => {}
// Options: ["always"]
(foo): string => {}
(foo) => { return; }
(foo) => { return undefined; }
// Options: ["always",{"annotateUndefined":"always"}]
(foo): undefined => { return; }
// Options: ["always",{"annotateUndefined":"never"}]
(foo) => { return; }
// Options: ["always",{"annotateUndefined":"never"}]
(foo) => { return undefined; }
// Options: ["always",{"annotateUndefined":"always"}]
(foo): undefined => { return undefined; }
```

@@ -111,0 +162,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc