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.7.0 to 2.7.1

dist/utilities/quoteName.js

9

dist/rules/requireParameterType.js

@@ -26,3 +26,2 @@ 'use strict';

_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');

@@ -38,3 +37,9 @@

if (!typeAnnotation) {
context.report(identifierNode, 'Missing "' + parameterName + '" parameter type annotation.');
context.report({
data: {
name: (0, _utilities.quoteName)((0, _utilities.getParameterName)(identifierNode, context))
},
message: 'Missing {{name}}parameter type annotation.',
node: identifierNode
});
}

@@ -41,0 +46,0 @@ });

@@ -58,3 +58,2 @@ 'use strict';

return function (node) {
var parameterName = (0, _utilities.getParameterName)(node, context);
var typeAnnotation = _lodash2.default.get(node, 'typeAnnotation') || _lodash2.default.get(node, 'left.typeAnnotation');

@@ -69,6 +68,12 @@

var data = {
name: (0, _utilities.quoteName)((0, _utilities.getParameterName)(node, context)),
type: typeForMessage
};
if (always && spaceAfter > 1) {
context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaceAfter - 1),
message: 'There must be 1 space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.',
message: 'There must be 1 space after {{name}}{{type}} type annotation colon.',
node: node

@@ -78,4 +83,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.addSpaceAfter(colon),
message: 'There must be a space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.',
message: 'There must be a space after {{name}}{{type}} type annotation colon.',
node: node

@@ -85,4 +91,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaceAfter),
message: 'There must be no space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.',
message: 'There must be no space after {{name}}{{type}} type annotation colon.',
node: node

@@ -158,13 +165,25 @@ });

var getColon = function getColon(objectTypeProperty) {
if (objectTypeProperty.optional || objectTypeProperty.static) {
return sourceCode.getFirstToken(objectTypeProperty, 2);
} else {
return sourceCode.getFirstToken(objectTypeProperty, 1);
}
};
return function (objectTypeProperty) {
var colon = sourceCode.getFirstToken(objectTypeProperty, objectTypeProperty.optional ? 2 : 1);
var colon = getColon(objectTypeProperty);
var typeAnnotation = objectTypeProperty.value;
var name = (0, _utilities.getParameterName)(objectTypeProperty, context);
var spaces = typeAnnotation.start - colon.end;
var data = {
name: (0, _utilities.quoteName)((0, _utilities.getParameterName)(objectTypeProperty, context))
};
if (always && spaces > 1) {
context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaces - 1),
message: 'There must be 1 space after "' + name + '" type annotation colon.',
message: 'There must be 1 space after {{name}}type annotation colon.',
node: objectTypeProperty

@@ -174,4 +193,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.addSpaceAfter(colon),
message: 'There must be a space after "' + name + '" type annotation colon.',
message: 'There must be a space after {{name}}type annotation colon.',
node: objectTypeProperty

@@ -181,4 +201,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaces),
message: 'There must be no space after "' + name + '" type annotation colon.',
message: 'There must be no space after {{name}}type annotation colon.',
node: objectTypeProperty

@@ -185,0 +206,0 @@ });

@@ -55,3 +55,2 @@ 'use strict';

return function (node) {
var parameterName = (0, _utilities.getParameterName)(node, context);
var typeAnnotation = _lodash2.default.get(node, 'typeAnnotation') || _lodash2.default.get(node, 'left.typeAnnotation');

@@ -61,3 +60,2 @@

// tokenBeforeType can be the identifier or the closing } token of a destructuring
var _getSpacesBeforeColon = getSpacesBeforeColon(node, typeAnnotation);

@@ -69,6 +67,12 @@

var data = {
name: (0, _utilities.quoteName)((0, _utilities.getParameterName)(node, context)),
type: typeForMessage
};
if (always && spaces > 1) {
context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeType, spaces - 1),
message: 'There must be 1 space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.',
message: 'There must be 1 space before {{name}}{{type}} type annotation colon.',
node: node

@@ -78,4 +82,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.addSpaceAfter(tokenBeforeType),
message: 'There must be a space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.',
message: 'There must be a space before {{name}}{{type}} type annotation colon.',
node: node

@@ -85,4 +90,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeType, spaces),
message: 'There must be no space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.',
message: 'There must be no space before {{name}}{{type}} type annotation colon.',
node: node

@@ -114,3 +120,3 @@ });

if (objectTypeProperty.optional) {
if (objectTypeProperty.optional || objectTypeProperty.static) {
return [tokens[1], tokens[2]];

@@ -124,3 +130,2 @@ } else {

// tokenBeforeColon can be identifier, or a ? token if is optional
var _getFirstTokens = getFirstTokens(objectTypeProperty);

@@ -133,10 +138,13 @@

var name = (0, _utilities.getParameterName)(objectTypeProperty, context);
var spaces = colon.start - tokenBeforeColon.end;
var data = {
name: (0, _utilities.quoteName)((0, _utilities.getParameterName)(objectTypeProperty, context))
};
if (always && spaces > 1) {
context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeColon, spaces - 1),
message: 'There must be 1 space before "' + name + '" type annotation colon.',
message: 'There must be 1 space before {{name}}type annotation colon.',
node: objectTypeProperty

@@ -146,4 +154,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.addSpaceAfter(tokenBeforeColon),
message: 'There must be a space before "' + name + '" type annotation colon.',
message: 'There must be a space before {{name}}type annotation colon.',
node: objectTypeProperty

@@ -153,4 +162,5 @@ });

context.report({
data: data,
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeColon, spaces),
message: 'There must be no space before "' + name + '" type annotation colon.',
message: 'There must be no space before {{name}}type annotation colon.',
node: objectTypeProperty

@@ -157,0 +167,0 @@ });

@@ -18,3 +18,2 @@ 'use strict';

_lodash2.default.forEach(functionNode.params, function (identifierNode) {
var parameterName = (0, _utilities.getParameterName)(identifierNode, context);
var nodeType = _lodash2.default.get(identifierNode, 'type');

@@ -26,3 +25,9 @@ var isAssignmentPattern = nodeType === 'AssignmentPattern';

if (isAssignmentPattern && hasTypeAnnotation && !leftAnnotated) {
context.report(identifierNode, '"' + parameterName + '" parameter type annotation must be placed on left-hand side of assignment.');
context.report({
data: {
name: (0, _utilities.quoteName)((0, _utilities.getParameterName)(identifierNode, context))
},
message: '{{name}}parameter type annotation must be placed on left-hand side of assignment.',
node: identifierNode
});
}

@@ -29,0 +34,0 @@ });

@@ -30,3 +30,7 @@ 'use strict';

if (identifierNode.type === 'ObjectTypeProperty' || identifierNode.type === 'FunctionTypeParam') {
if (identifierNode.type === 'ObjectTypeProperty') {
return context.getSourceCode().getFirstToken(identifierNode, identifierNode.static ? 1 : 0).value;
}
if (identifierNode.type === 'FunctionTypeParam') {
return context.getSourceCode().getFirstToken(identifierNode).value;

@@ -36,11 +40,17 @@ }

if (identifierNode.type === 'ObjectPattern' || identifierNode.type === 'ArrayPattern') {
return context.getSourceCode().getText(identifierNode);
var text = context.getSourceCode().getText(identifierNode);
if (identifierNode.typeAnnotation) {
return text.replace(context.getSourceCode().getText(identifierNode.typeAnnotation), '').trim();
} else {
return text;
}
}
if (_lodash2.default.get(identifierNode, 'left.type') === 'ObjectPattern' && _lodash2.default.get(identifierNode, 'right.type') === 'ObjectExpression') {
if (_lodash2.default.get(identifierNode, 'left.type') === 'ObjectPattern') {
return context.getSourceCode().getText(identifierNode.left);
}
throw new Error('Unsupported function signature.');
return null;
};
module.exports = exports['default'];

@@ -7,3 +7,3 @@ 'use strict';

});
exports.spacingFixers = exports.iterateFunctionNodes = exports.isFlowFileAnnotation = exports.isFlowFile = exports.getParameterName = undefined;
exports.quoteName = exports.spacingFixers = exports.iterateFunctionNodes = exports.isFlowFileAnnotation = exports.isFlowFile = exports.getParameterName = undefined;

@@ -30,2 +30,6 @@ var _getParameterName2 = require('./getParameterName.js');

var _quoteName2 = require('./quoteName');
var _quoteName3 = _interopRequireDefault(_quoteName2);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -39,2 +43,3 @@

exports.iterateFunctionNodes = _iterateFunctionNodes3.default;
exports.spacingFixers = _spacingFixers;
exports.spacingFixers = _spacingFixers;
exports.quoteName = _quoteName3.default;
{
"name": "eslint-plugin-flowtype",
"description": "Flowtype linting rules for ESLint.",
"version": "2.7.0",
"version": "2.7.1",
"main": "./dist/index.js",

@@ -45,3 +45,3 @@ "repository": {

"eslint": "^2.13.1",
"eslint-config-canonical": "^1.7.12",
"eslint-config-canonical": "1.7.12",
"gitdown": "^2.4.8",

@@ -48,0 +48,0 @@ "mocha": "^2.5.3"

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

async function foo({ lorem, ipsum, dolor }:SomeType) {}
// Message: There must be a space after "{ lorem, ipsum, dolor }:SomeType" parameter type annotation colon.
// Message: There must be a space after "{ lorem, ipsum, dolor }" parameter type annotation colon.

@@ -736,2 +736,30 @@ ({ lorem, ipsum, dolor } : SomeType) => {}

// Message: There must be a space after "foo" parameter type annotation colon.
class X { static foo:number }
// Message: There must be a space after "foo" class property type annotation colon.
// Options: ["never"]
class X { static foo: number }
// Message: There must be no space after "foo" class property type annotation colon.
class X { static foo :number }
// Message: There must be a space after "foo" class property type annotation colon.
// Options: ["never"]
class X { static foo : number }
// Message: There must be no space after "foo" class property type annotation colon.
declare class X { static foo:number }
// Message: There must be a space after "foo" type annotation colon.
// Options: ["never"]
declare class X { static foo: number }
// Message: There must be no space after "foo" type annotation colon.
declare class X { static foo :number }
// Message: There must be a space after "foo" type annotation colon.
// Options: ["never"]
declare class X { static foo : number }
// Message: There must be no space after "foo" type annotation colon.
```

@@ -858,2 +886,12 @@

type X = (foo:?{ x:number }) => string;
class X { static foo : number }
// Options: ["never"]
class X { static foo :number }
declare class X { static foo : number }
// Options: ["never"]
declare class X { static foo :number }
```

@@ -924,3 +962,3 @@

async function foo({ lorem, ipsum, dolor } : SomeType) {}
// Message: There must be no space before "{ lorem, ipsum, dolor } : SomeType" parameter type annotation colon.
// Message: There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.

@@ -1006,2 +1044,30 @@ ({ lorem, ipsum, dolor } : SomeType) => {}

// Message: There must be no space before "foo" parameter type annotation colon.
class X { static foo : number }
// Message: There must be no space before "foo" class property type annotation colon.
class X { static foo :number }
// Message: There must be no space before "foo" class property type annotation colon.
// Options: ["always"]
class X { static foo: number }
// Message: There must be a space before "foo" class property type annotation colon.
// Options: ["always"]
class X { static foo:number }
// Message: There must be a space before "foo" class property type annotation colon.
declare class Foo { static bar :number; }
// Message: There must be no space before "bar" type annotation colon.
declare class Foo { static bar : number; }
// Message: There must be no space before "bar" type annotation colon.
// Options: ["always"]
declare class Foo { static bar:number; }
// Message: There must be a space before "bar" type annotation colon.
// Options: ["always"]
declare class Foo { static bar: number; }
// Message: There must be a space before "bar" type annotation colon.
```

@@ -1045,2 +1111,4 @@

class X { foo({ bar }: Props = this.props) {} }
class Foo { constructor(foo: string ) {} }

@@ -1110,2 +1178,22 @@

type X = (foo? : ?string) => number
class X { static foo:number }
class X { static foo: number }
// Options: ["always"]
class X { static foo :number }
// Options: ["always"]
class X { static foo : number }
declare class Foo { static bar:number; }
// Options: ["always"]
declare class Foo { static bar :number; }
declare class Foo { static bar: number; }
// Options: ["always"]
declare class Foo { static bar : number; }
```

@@ -1112,0 +1200,0 @@

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