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

eslint-plugin-flowtype - npm Package Compare versions

Comparing version 2.6.1 to 2.6.3

dist/rules/validSyntax.js

10

dist/index.js

@@ -39,2 +39,6 @@ 'use strict';

var _validSyntax = require('./rules/validSyntax');
var _validSyntax2 = _interopRequireDefault(_validSyntax);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -51,3 +55,4 @@

'type-id-match': _typeIdMatch2.default,
'use-flow-type': _useFlowType2.default
'use-flow-type': _useFlowType2.default,
'valid-syntax': _validSyntax2.default
},

@@ -61,5 +66,6 @@ rulesConfig: {

'type-id-match': 0,
'use-flow-type': 0
'use-flow-type': 0,
'valid-syntax': 0
}
};
module.exports = exports['default'];

97

dist/rules/spaceAfterTypeColon.js

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _lodash = require('lodash');

@@ -16,26 +18,44 @@

exports.default = (0, _utilities.iterateFunctionNodes)(function (context) {
var always = (context.options[0] || 'always') === 'always';
var parseOptions = function parseOptions(context) {
return {
always: (context.options[0] || 'always') === 'always'
};
};
var propertyEvaluator = function propertyEvaluator(context, typeForMessage) {
var _parseOptions = parseOptions(context);
var always = _parseOptions.always;
var sourceCode = context.getSourceCode();
return function (functionNode) {
_lodash2.default.forEach(functionNode.params, function (identifierNode) {
var parameterName = (0, _utilities.getParameterName)(identifierNode, context);
var typeAnnotation = _lodash2.default.get(identifierNode, 'typeAnnotation') || _lodash2.default.get(identifierNode, 'left.typeAnnotation');
return function (node) {
var parameterName = (0, _utilities.getParameterName)(node, context);
var typeAnnotation = _lodash2.default.get(node, 'typeAnnotation') || _lodash2.default.get(node, 'left.typeAnnotation');
if (typeAnnotation) {
var token = sourceCode.getFirstToken(typeAnnotation, 1);
var spaceAfter = token.start - typeAnnotation.start - 1;
if (typeAnnotation) {
var token = sourceCode.getFirstToken(typeAnnotation, 1);
var spaceAfter = token.start - typeAnnotation.start - 1;
if (always && spaceAfter > 1) {
context.report(identifierNode, 'There must be 1 space after "' + parameterName + '" parameter type annotation colon.');
} else if (always && spaceAfter === 0) {
context.report(identifierNode, 'There must be a space after "' + parameterName + '" parameter type annotation colon.');
} else if (!always && spaceAfter > 0) {
context.report(identifierNode, 'There must be no space after "' + parameterName + '" parameter type annotation colon.');
}
if (always && spaceAfter > 1) {
context.report(node, 'There must be 1 space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.');
} else if (always && spaceAfter === 0) {
context.report(node, 'There must be a space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.');
} else if (!always && spaceAfter > 0) {
context.report(node, 'There must be no space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.');
}
});
}
};
};
var returnTypeEvaluator = function returnTypeEvaluator(context) {
var _parseOptions2 = parseOptions(context);
var always = _parseOptions2.always;
var sourceCode = context.getSourceCode();
return function (functionNode) {
if (functionNode.returnType) {

@@ -54,3 +74,46 @@ var token = sourceCode.getFirstToken(functionNode.returnType, 1);

};
};
var functionEvaluators = (0, _utilities.iterateFunctionNodes)(function (context) {
var checkParam = propertyEvaluator(context, 'parameter');
var checkReturnType = returnTypeEvaluator(context);
return function (functionNode) {
_lodash2.default.forEach(functionNode.params, checkParam);
checkReturnType(functionNode);
};
});
var objectTypePropertyEvaluator = function objectTypePropertyEvaluator(context) {
var _parseOptions3 = parseOptions(context);
var always = _parseOptions3.always;
var sourceCode = context.getSourceCode();
return function (objectTypeProperty) {
var colon = sourceCode.getFirstToken(objectTypeProperty, objectTypeProperty.optional ? 2 : 1);
var typeAnnotation = objectTypeProperty.value;
var name = (0, _utilities.getParameterName)(objectTypeProperty, context);
var spaceAfter = typeAnnotation.start - colon.end;
if (always && spaceAfter > 1) {
context.report(objectTypeProperty, 'There must be 1 space after "' + name + '" type annotation colon.');
} else if (always && spaceAfter === 0) {
context.report(objectTypeProperty, 'There must be a space after "' + name + '" type annotation colon.');
} else if (!always && spaceAfter > 0) {
context.report(objectTypeProperty, 'There must be no space after "' + name + '" type annotation colon.');
}
};
};
exports.default = function (context) {
return _extends({}, functionEvaluators(context), {
ClassProperty: propertyEvaluator(context, 'class property'),
ObjectTypeProperty: objectTypePropertyEvaluator(context)
});
};
module.exports = exports['default'];

@@ -7,2 +7,4 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _lodash = require('lodash');

@@ -16,27 +18,77 @@

exports.default = (0, _utilities.iterateFunctionNodes)(function (context) {
var always = context.options[0] === 'always';
var parseOptions = function parseOptions(context) {
return {
always: context.options[0] === 'always'
};
};
var propertyEvaluator = function propertyEvaluator(context, typeForMessage) {
var _parseOptions = parseOptions(context);
var always = _parseOptions.always;
var sourceCode = context.getSourceCode();
return function (functionNode) {
_lodash2.default.forEach(functionNode.params, function (identifierNode) {
var parameterName = (0, _utilities.getParameterName)(identifierNode, context);
var typeAnnotation = _lodash2.default.get(identifierNode, 'typeAnnotation') || _lodash2.default.get(identifierNode, 'left.typeAnnotation');
return function (node) {
var parameterName = (0, _utilities.getParameterName)(node, context);
var typeAnnotation = _lodash2.default.get(node, 'typeAnnotation') || _lodash2.default.get(node, 'left.typeAnnotation');
if (typeAnnotation) {
var tokenBeforeType = sourceCode.getTokenBefore(typeAnnotation, identifierNode.optional ? 1 : 0);
var spaceBefore = typeAnnotation.start - tokenBeforeType.end - (identifierNode.optional ? 1 : 0);
if (typeAnnotation) {
// tokenBeforeType can be the identifier or the closing } token of a destructuring
var tokenBeforeType = sourceCode.getTokenBefore(typeAnnotation, node.optional ? 1 : 0);
var spaceBefore = typeAnnotation.start - tokenBeforeType.end - (node.optional ? 1 : 0);
if (always && spaceBefore > 1) {
context.report(identifierNode, 'There must be 1 space before "' + parameterName + '" parameter type annotation colon.');
} else if (always && spaceBefore === 0) {
context.report(identifierNode, 'There must be a space before "' + parameterName + '" parameter type annotation colon.');
} else if (!always && spaceBefore > 0) {
context.report(identifierNode, 'There must be no space before "' + parameterName + '" parameter type annotation colon.');
}
if (always && spaceBefore > 1) {
context.report(node, 'There must be 1 space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.');
} else if (always && spaceBefore === 0) {
context.report(node, 'There must be a space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.');
} else if (!always && spaceBefore > 0) {
context.report(node, 'There must be no space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.');
}
});
}
};
};
var functionEvaluators = (0, _utilities.iterateFunctionNodes)(function (context) {
var checkParam = propertyEvaluator(context, 'parameter');
return function (functionNode) {
_lodash2.default.forEach(functionNode.params, checkParam);
};
});
var objectTypePropertyEvaluator = function objectTypePropertyEvaluator(context) {
var _parseOptions2 = parseOptions(context);
var always = _parseOptions2.always;
var sourceCode = context.getSourceCode();
return function (objectTypeProperty) {
// tokenBeforeColon can be identifier, or a ? token if is optional
var tokenBeforeColon = sourceCode.getFirstToken(objectTypeProperty, objectTypeProperty.optional ? 1 : 0);
var colon = sourceCode.getFirstToken(objectTypeProperty, objectTypeProperty.optional ? 2 : 1);
var name = (0, _utilities.getParameterName)(objectTypeProperty, context);
var spaceBefore = colon.start - tokenBeforeColon.end;
if (always && spaceBefore > 1) {
context.report(objectTypeProperty, 'There must be 1 space before "' + name + '" type annotation colon.');
} else if (always && spaceBefore === 0) {
context.report(objectTypeProperty, 'There must be a space before "' + name + '" type annotation colon.');
} else if (!always && spaceBefore > 0) {
context.report(objectTypeProperty, 'There must be no space before "' + name + '" type annotation colon.');
}
};
};
exports.default = function (context) {
return _extends({}, functionEvaluators(context), {
ClassProperty: propertyEvaluator(context, 'class property'),
ObjectTypeProperty: objectTypePropertyEvaluator(context)
});
};
module.exports = exports['default'];

@@ -22,2 +22,6 @@ 'use strict';

if (_lodash2.default.has(identifierNode, 'key.name')) {
return identifierNode.key.name;
}
if (identifierNode.type === 'RestElement') {

@@ -27,2 +31,6 @@ return identifierNode.argument.name;

if (identifierNode.type === 'ObjectTypeProperty') {
return context.getSourceCode().getFirstToken(identifierNode).value;
}
if (identifierNode.type === 'ObjectPattern' || identifierNode.type === 'ArrayPattern') {

@@ -29,0 +37,0 @@ return context.getSourceCode().getText(identifierNode);

{
"name": "eslint-plugin-flowtype",
"description": "Flowtype linting rules for ESLint.",
"version": "2.6.1",
"version": "2.6.3",
"main": "./dist/index.js",

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

@@ -23,2 +23,3 @@ <h1 id="eslint-plugin-flowtype">eslint-plugin-flowtype</h1>

* [`use-flow-type`](#eslint-plugin-flowtype-rules-use-flow-type)
* [`valid-syntax`](#eslint-plugin-flowtype-rules-valid-syntax)

@@ -76,3 +77,4 @@

],
"flowtype/use-flow-type": 1
"flowtype/use-flow-type": 1,
"flowtype/valid-syntax": 1
},

@@ -679,2 +681,43 @@ "settings": {

// Message: There must be a space after "[ a, b ]" parameter type annotation colon.
type X = { foo:string }
// Message: There must be a space after "foo" type annotation colon.
// Options: ["always"]
type X = { foo:string }
// Message: There must be a space after "foo" type annotation colon.
// Options: ["never"]
type X = { foo: string }
// Message: There must be no space after "foo" type annotation colon.
type X = { foo: string }
// Message: There must be 1 space after "foo" type annotation colon.
type X = { foo?:string }
// Message: There must be a space after "foo" type annotation colon.
// Options: ["never"]
type X = { foo?: string }
// Message: There must be no space after "foo" type annotation colon.
type X = { foo?:?string }
// Message: There must be a space after "foo" type annotation colon.
type X = { foo?: ?string }
// Message: There must be 1 space after "foo" type annotation colon.
class X { foo:string }
// Message: There must be a space after "foo" class property type annotation colon.
// Options: ["never"]
class X { foo: string }
// Message: There must be no space after "foo" class property type annotation colon.
class X { foo:?string }
// Message: There must be a space after "foo" class property type annotation colon.
// Options: ["never"]
class X { foo: ?string }
// Message: There must be no space after "foo" class property type annotation colon.
```

@@ -756,5 +799,31 @@

// Options: ["never"]
() :{ a: number, b: string } => {}
() :{ a:number, b:string } => {}
([ a, b ]: string[]) => {}
type X = { foo: string }
// Options: ["never"]
type X = { foo:string }
type X = { foo?: string }
type X = { foo?: ?string }
// Options: ["never"]
type X = { foo?:?string }
class Foo { bar }
class Foo { bar = 3 }
class Foo { bar: string }
class Foo { bar: ?string }
// Options: ["never"]
class Foo { bar:string }
// Options: ["never"]
class Foo { bar:?string }
```

@@ -832,2 +901,46 @@

// Message: There must be no space before "[ a, b ]" parameter type annotation colon.
type X = { foo : string }
// Message: There must be no space before "foo" type annotation colon.
// Options: ["never"]
type X = { foo : string }
// Message: There must be no space before "foo" type annotation colon.
// Options: ["always"]
type X = { foo: string }
// Message: There must be a space before "foo" type annotation colon.
// Options: ["always"]
type X = { foo : string }
// Message: There must be 1 space before "foo" type annotation colon.
type X = { foo? : string }
// Message: There must be no space before "foo" type annotation colon.
// Options: ["always"]
type X = { foo?: string }
// Message: There must be a space before "foo" type annotation colon.
// Options: ["always"]
type X = { foo? : string }
// Message: There must be 1 space before "foo" type annotation colon.
// Options: ["always"]
type X = { foo ?: string }
// Message: There must be a space before "foo" type annotation colon.
class X { foo :string }
// Message: There must be no space before "foo" class property type annotation colon.
// Options: ["always"]
class X { foo: string }
// Message: There must be a space before "foo" class property type annotation colon.
class X { foo :?string }
// Message: There must be no space before "foo" class property type annotation colon.
// Options: ["always"]
class X { foo: ?string }
// Message: There must be a space before "foo" class property type annotation colon.
```

@@ -881,5 +994,28 @@

// Options: ["always"]
() : { a: number, b: string } => {}
() : { a : number, b : string } => {}
([ a, b ]: string[]) => {}
type X = { foo: string }
// Options: ["always"]
type X = { foo : string }
type X = { foo?: string }
// Options: ["always"]
type X = { foo? : string }
class Foo { bar }
class Foo { bar = 3 }
class Foo { bar: string }
class Foo { bar: ?string }
class Foo { bar:?string }
// Options: ["always"]
class Foo { bar : string }
```

@@ -986,1 +1122,26 @@

<h3 id="eslint-plugin-flowtype-rules-valid-syntax"><code>valid-syntax</code></h3>
Checks for simple Flow syntax errors.
The following patterns are considered problems:
```js
function x(foo = "1": string) {}
// Message: "foo" parameter type annotation must be placed on left-hand side of assignment.
function x(foo = bar(): Type, baz = []: []) {}
// Message: "foo" parameter type annotation must be placed on left-hand side of assignment.
// Message: "baz" parameter type annotation must be placed on left-hand side of assignment.
```
The following patterns are not considered problems:
```js
function x(foo: string = "1") {}
function x(foo: Type = bar()) {}
```
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc