eslint-plugin-flowtype
Advanced tools
Comparing version 2.6.3 to 2.6.4
@@ -31,2 +31,14 @@ 'use strict'; | ||
var getSpacesAfterColon = function getSpacesAfterColon(node, typeAnnotation) { | ||
if (node.type === 'FunctionTypeParam') { | ||
var colon = sourceCode.getTokenBefore(typeAnnotation); | ||
return typeAnnotation.start - colon.end; | ||
} else { | ||
var token = sourceCode.getFirstToken(typeAnnotation, 1); | ||
return token.start - typeAnnotation.start - 1; | ||
} | ||
}; | ||
return function (node) { | ||
@@ -37,4 +49,3 @@ var parameterName = (0, _utilities.getParameterName)(node, context); | ||
if (typeAnnotation) { | ||
var token = sourceCode.getFirstToken(typeAnnotation, 1); | ||
var spaceAfter = token.start - typeAnnotation.start - 1; | ||
var spaceAfter = getSpacesAfterColon(node, typeAnnotation); | ||
@@ -61,3 +72,6 @@ if (always && spaceAfter > 1) { | ||
return function (functionNode) { | ||
if (functionNode.returnType) { | ||
// skip FunctionTypeAnnotation, possibly another rule as it's an arrow, not a colon? | ||
// (foo: number) => string | ||
// ^^^^ | ||
if (functionNode.returnType && functionNode.type !== 'FunctionTypeAnnotation') { | ||
var token = sourceCode.getFirstToken(functionNode.returnType, 1); | ||
@@ -64,0 +78,0 @@ var spaceAfter = token.start - functionNode.returnType.start - 1; |
@@ -31,2 +31,17 @@ 'use strict'; | ||
var getSpacesBeforeColon = function getSpacesBeforeColon(node, typeAnnotation) { | ||
if (node.type === 'FunctionTypeParam') { | ||
// the colon isn't included in the typeAnnotation node here... | ||
var colon = sourceCode.getTokenBefore(typeAnnotation); | ||
var tokenBeforeColon = sourceCode.getTokenBefore(colon); | ||
return colon.start - tokenBeforeColon.end; | ||
} else { | ||
// tokenBeforeColon can be the identifier or the closing } token of a destructuring | ||
var _tokenBeforeColon = sourceCode.getTokenBefore(typeAnnotation, node.optional ? 1 : 0); | ||
return typeAnnotation.start - _tokenBeforeColon.end - (node.optional ? 1 : 0); | ||
} | ||
}; | ||
return function (node) { | ||
@@ -37,5 +52,3 @@ var parameterName = (0, _utilities.getParameterName)(node, context); | ||
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); | ||
var spaceBefore = getSpacesBeforeColon(node, typeAnnotation); | ||
@@ -42,0 +55,0 @@ if (always && spaceBefore > 1) { |
@@ -30,3 +30,3 @@ 'use strict'; | ||
if (identifierNode.type === 'ObjectTypeProperty') { | ||
if (identifierNode.type === 'ObjectTypeProperty' || identifierNode.type === 'FunctionTypeParam') { | ||
return context.getSourceCode().getFirstToken(identifierNode).value; | ||
@@ -33,0 +33,0 @@ } |
@@ -14,3 +14,4 @@ "use strict"; | ||
FunctionDeclaration: nodeIterator, | ||
FunctionExpression: nodeIterator | ||
FunctionExpression: nodeIterator, | ||
FunctionTypeAnnotation: nodeIterator | ||
}; | ||
@@ -17,0 +18,0 @@ }; |
{ | ||
"name": "eslint-plugin-flowtype", | ||
"description": "Flowtype linting rules for ESLint.", | ||
"version": "2.6.3", | ||
"version": "2.6.4", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -511,6 +511,6 @@ <h1 id="eslint-plugin-flowtype">eslint-plugin-flowtype</h1> | ||
// Options: ["always",{"excludeArrowFunctions":true,"annotateUndefined":"always"}] | ||
// Options: ["always",{"annotateUndefined":"always","excludeArrowFunctions":true}] | ||
() => undefined | ||
// Options: ["always",{"excludeArrowFunctions":true,"annotateUndefined":"always"}] | ||
// Options: ["always",{"annotateUndefined":"always","excludeArrowFunctions":true}] | ||
() => { return undefined; } | ||
@@ -721,2 +721,15 @@ | ||
// Message: There must be no space after "foo" class property type annotation colon. | ||
type X = (foo:number) => string | ||
// Message: There must be a space after "foo" parameter type annotation colon. | ||
// Options: ["never"] | ||
type X = (foo: number) => string | ||
// Message: There must be no space after "foo" parameter type annotation colon. | ||
type X = (foo: number) => string | ||
// Message: There must be 1 space after "foo" parameter type annotation colon. | ||
type X = (foo:?number) => string | ||
// Message: There must be a space after "foo" parameter type annotation colon. | ||
``` | ||
@@ -827,2 +840,18 @@ | ||
class Foo { bar:?string } | ||
type X = (foo: number) => string; | ||
type X = (foo : number) => string; | ||
type X = (foo: ?number) => string; | ||
type X = (foo? : ?number) => string; | ||
type X = (foo: ?{ x: number }) => string; | ||
// Options: ["never"] | ||
type X = (foo:number) => string; | ||
// Options: ["never"] | ||
type X = (foo:?{ x:number }) => string; | ||
``` | ||
@@ -944,2 +973,23 @@ | ||
// Message: There must be a space before "foo" class property type annotation colon. | ||
type X = (foo :string) => string; | ||
// Message: There must be no space before "foo" parameter type annotation colon. | ||
// Options: ["always"] | ||
type X = (foo:string) => string; | ||
// Message: There must be a space before "foo" parameter type annotation colon. | ||
// Options: ["always"] | ||
type X = (foo :string) => string; | ||
// Message: There must be 1 space before "foo" parameter type annotation colon. | ||
type X = (foo? :string) => string; | ||
// Message: There must be no space before "foo" parameter type annotation colon. | ||
// Options: ["always"] | ||
type X = (foo?:string) => string; | ||
// Message: There must be a space before "foo" parameter type annotation colon. | ||
type X = (foo? :?string) => string; | ||
// Message: There must be no space before "foo" parameter type annotation colon. | ||
``` | ||
@@ -1019,2 +1069,18 @@ | ||
class Foo { bar : string } | ||
type X = (foo:string) => number; | ||
type X = (foo: string) => number; | ||
type X = (foo: ?string) => number; | ||
type X = (foo?: string) => number; | ||
type X = (foo?: ?string) => number; | ||
// Options: ["always"] | ||
type X = (foo? : string) => number | ||
// Options: ["always"] | ||
type X = (foo? : ?string) => number | ||
``` | ||
@@ -1021,0 +1087,0 @@ |
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
85004
642
1207