eslint-plugin-flowtype
Advanced tools
Comparing version 2.6.4 to 2.7.0
@@ -9,2 +9,4 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _lodash = require('lodash'); | ||
@@ -36,7 +38,19 @@ | ||
return typeAnnotation.start - colon.end; | ||
return { | ||
colon: colon, | ||
spaceAfter: typeAnnotation.start - colon.end | ||
}; | ||
} else { | ||
var token = sourceCode.getFirstToken(typeAnnotation, 1); | ||
var _sourceCode$getFirstT = sourceCode.getFirstTokens(typeAnnotation, 2); | ||
return token.start - typeAnnotation.start - 1; | ||
var _sourceCode$getFirstT2 = _slicedToArray(_sourceCode$getFirstT, 2); | ||
var _colon = _sourceCode$getFirstT2[0]; | ||
var token = _sourceCode$getFirstT2[1]; | ||
return { | ||
colon: _colon, | ||
spaceAfter: token.start - typeAnnotation.start - 1 | ||
}; | ||
} | ||
@@ -50,10 +64,26 @@ }; | ||
if (typeAnnotation) { | ||
var spaceAfter = getSpacesAfterColon(node, typeAnnotation); | ||
var _getSpacesAfterColon = getSpacesAfterColon(node, typeAnnotation); | ||
var colon = _getSpacesAfterColon.colon; | ||
var spaceAfter = _getSpacesAfterColon.spaceAfter; | ||
if (always && spaceAfter > 1) { | ||
context.report(node, 'There must be 1 space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.'); | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaceAfter - 1), | ||
message: 'There must be 1 space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.', | ||
node: node | ||
}); | ||
} else if (always && spaceAfter === 0) { | ||
context.report(node, 'There must be a space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.'); | ||
context.report({ | ||
fix: _utilities.spacingFixers.addSpaceAfter(colon), | ||
message: 'There must be a space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.', | ||
node: node | ||
}); | ||
} else if (!always && spaceAfter > 0) { | ||
context.report(node, 'There must be no space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.'); | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaceAfter), | ||
message: 'There must be no space after "' + parameterName + '" ' + typeForMessage + ' type annotation colon.', | ||
node: node | ||
}); | ||
} | ||
@@ -77,11 +107,29 @@ } | ||
if (functionNode.returnType && functionNode.type !== 'FunctionTypeAnnotation') { | ||
var token = sourceCode.getFirstToken(functionNode.returnType, 1); | ||
var spaceAfter = token.start - functionNode.returnType.start - 1; | ||
var _sourceCode$getFirstT3 = sourceCode.getFirstTokens(functionNode.returnType, 2); | ||
if (always && spaceAfter > 1) { | ||
context.report(functionNode, 'There must be 1 space after return type colon.'); | ||
} else if (always && spaceAfter === 0) { | ||
context.report(functionNode, 'There must be a space after return type colon.'); | ||
} else if (!always && spaceAfter > 0) { | ||
context.report(functionNode, 'There must be no space after return type colon.'); | ||
var _sourceCode$getFirstT4 = _slicedToArray(_sourceCode$getFirstT3, 2); | ||
var colon = _sourceCode$getFirstT4[0]; | ||
var token = _sourceCode$getFirstT4[1]; | ||
var spaces = token.start - functionNode.returnType.start - 1; | ||
if (always && spaces > 1) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaces - 1), | ||
message: 'There must be 1 space after return type colon.', | ||
node: functionNode | ||
}); | ||
} else if (always && spaces === 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.addSpaceAfter(colon), | ||
message: 'There must be a space after return type colon.', | ||
node: functionNode | ||
}); | ||
} else if (!always && spaces > 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaces), | ||
message: 'There must be no space after return type colon.', | ||
node: functionNode | ||
}); | ||
} | ||
@@ -115,10 +163,22 @@ } | ||
var spaceAfter = typeAnnotation.start - colon.end; | ||
var spaces = 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.'); | ||
if (always && spaces > 1) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaces - 1), | ||
message: 'There must be 1 space after "' + name + '" type annotation colon.', | ||
node: objectTypeProperty | ||
}); | ||
} else if (always && spaces === 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.addSpaceAfter(colon), | ||
message: 'There must be a space after "' + name + '" type annotation colon.', | ||
node: objectTypeProperty | ||
}); | ||
} else if (!always && spaces > 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(colon, spaces), | ||
message: 'There must be no space after "' + name + '" type annotation colon.', | ||
node: objectTypeProperty | ||
}); | ||
} | ||
@@ -125,0 +185,0 @@ }; |
@@ -9,2 +9,4 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _lodash = require('lodash'); | ||
@@ -38,8 +40,14 @@ | ||
return colon.start - tokenBeforeColon.end; | ||
return { | ||
spaces: colon.start - tokenBeforeColon.end, | ||
tokenBeforeType: tokenBeforeColon | ||
}; | ||
} else { | ||
// tokenBeforeColon can be the identifier or the closing } token of a destructuring | ||
var _tokenBeforeColon = sourceCode.getTokenBefore(typeAnnotation, node.optional ? 1 : 0); | ||
var _tokenBeforeColon = sourceCode.getTokenBefore(typeAnnotation); | ||
return typeAnnotation.start - _tokenBeforeColon.end - (node.optional ? 1 : 0); | ||
return { | ||
spaces: typeAnnotation.start - _tokenBeforeColon.end, | ||
tokenBeforeType: _tokenBeforeColon | ||
}; | ||
} | ||
@@ -53,10 +61,28 @@ }; | ||
if (typeAnnotation) { | ||
var spaceBefore = getSpacesBeforeColon(node, typeAnnotation); | ||
// tokenBeforeType can be the identifier or the closing } token of a destructuring | ||
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 _getSpacesBeforeColon = getSpacesBeforeColon(node, typeAnnotation); | ||
var spaces = _getSpacesBeforeColon.spaces; | ||
var tokenBeforeType = _getSpacesBeforeColon.tokenBeforeType; | ||
if (always && spaces > 1) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeType, spaces - 1), | ||
message: 'There must be 1 space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.', | ||
node: node | ||
}); | ||
} else if (always && spaces === 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.addSpaceAfter(tokenBeforeType), | ||
message: 'There must be a space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.', | ||
node: node | ||
}); | ||
} else if (!always && spaces > 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeType, spaces), | ||
message: 'There must be no space before "' + parameterName + '" ' + typeForMessage + ' type annotation colon.', | ||
node: node | ||
}); | ||
} | ||
@@ -83,16 +109,44 @@ } | ||
var getFirstTokens = function getFirstTokens(objectTypeProperty) { | ||
var tokens = sourceCode.getFirstTokens(objectTypeProperty, 3); | ||
if (objectTypeProperty.optional) { | ||
return [tokens[1], tokens[2]]; | ||
} else { | ||
return [tokens[0], tokens[1]]; | ||
} | ||
}; | ||
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 _getFirstTokens = getFirstTokens(objectTypeProperty); | ||
var _getFirstTokens2 = _slicedToArray(_getFirstTokens, 2); | ||
var tokenBeforeColon = _getFirstTokens2[0]; | ||
var colon = _getFirstTokens2[1]; | ||
var name = (0, _utilities.getParameterName)(objectTypeProperty, context); | ||
var spaceBefore = colon.start - tokenBeforeColon.end; | ||
var spaces = 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.'); | ||
if (always && spaces > 1) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeColon, spaces - 1), | ||
message: 'There must be 1 space before "' + name + '" type annotation colon.', | ||
node: objectTypeProperty | ||
}); | ||
} else if (always && spaces === 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.addSpaceAfter(tokenBeforeColon), | ||
message: 'There must be a space before "' + name + '" type annotation colon.', | ||
node: objectTypeProperty | ||
}); | ||
} else if (!always && spaces > 0) { | ||
context.report({ | ||
fix: _utilities.spacingFixers.stripSpacesAfter(tokenBeforeColon, spaces), | ||
message: 'There must be no space before "' + name + '" type annotation colon.', | ||
node: objectTypeProperty | ||
}); | ||
} | ||
@@ -99,0 +153,0 @@ }; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
}); | ||
exports.iterateFunctionNodes = exports.isFlowFileAnnotation = exports.isFlowFile = exports.getParameterName = undefined; | ||
exports.spacingFixers = exports.iterateFunctionNodes = exports.isFlowFileAnnotation = exports.isFlowFile = exports.getParameterName = undefined; | ||
@@ -26,2 +26,8 @@ var _getParameterName2 = require('./getParameterName.js'); | ||
var _spacingFixers2 = require('./spacingFixers'); | ||
var _spacingFixers = _interopRequireWildcard(_spacingFixers2); | ||
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; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -32,2 +38,3 @@ | ||
exports.isFlowFileAnnotation = _isFlowFileAnnotation3.default; | ||
exports.iterateFunctionNodes = _iterateFunctionNodes3.default; | ||
exports.iterateFunctionNodes = _iterateFunctionNodes3.default; | ||
exports.spacingFixers = _spacingFixers; |
{ | ||
"name": "eslint-plugin-flowtype", | ||
"description": "Flowtype linting rules for ESLint.", | ||
"version": "2.6.4", | ||
"version": "2.7.0", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -599,2 +599,4 @@ <h1 id="eslint-plugin-flowtype">eslint-plugin-flowtype</h1> | ||
_The `--fix` option on the command line automatically fixes problems reported by this rule._ | ||
Enforces consistent spacing after the type annotation colon. | ||
@@ -861,2 +863,4 @@ | ||
_The `--fix` option on the command line automatically fixes problems reported by this rule._ | ||
Enforces consistent spacing before the type annotation colon. | ||
@@ -874,3 +878,3 @@ | ||
// Options: ["never"] | ||
(foo ?: string) => {} | ||
(foo ? : string) => {} | ||
// Message: There must be no space before "foo" parameter type annotation colon. | ||
@@ -891,5 +895,9 @@ | ||
// Options: ["always"] | ||
(foo ?: string) => {} | ||
(foo ? : string) => {} | ||
// Message: There must be 1 space before "foo" parameter type annotation colon. | ||
// Options: ["always"] | ||
(foo ?: string) => {} | ||
// Message: There must be a space before "foo" parameter type annotation colon. | ||
function x(foo : string) {} | ||
@@ -989,2 +997,5 @@ // Message: There must be no 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"] | ||
@@ -1007,2 +1018,4 @@ type X = (foo?:string) => string; | ||
(foo ?: string) => {} | ||
// Options: ["never"] | ||
@@ -1015,4 +1028,10 @@ (foo: string) => {} | ||
// Options: ["always"] | ||
(foo ?: string) => {} | ||
(foo? : string) => {} | ||
// Options: ["always"] | ||
(foo ? : string) => {} | ||
// Options: ["always"] | ||
(foo ? : string) => {} | ||
function x(foo: string) {} | ||
@@ -1057,2 +1076,4 @@ | ||
type X = { foo ?: string } | ||
// Options: ["always"] | ||
@@ -1084,2 +1105,4 @@ type X = { foo? : string } | ||
type X = (foo ?: string) => number; | ||
// Options: ["always"] | ||
@@ -1086,0 +1109,0 @@ type X = (foo? : string) => number |
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
91475
31
758
1230