eslint-plugin-flowtype
Advanced tools
Comparing version 2.35.0 to 2.35.1
@@ -9,2 +9,12 @@ 'use strict'; | ||
var hasLineBreak = function hasLineBreak(direction, colon, context) { | ||
var sourceCode = context.getSourceCode(); | ||
if (direction === 'before') { | ||
return colon.loc.start.line !== sourceCode.getTokenBefore(colon).loc.end.line; | ||
} else { | ||
return sourceCode.getTokenAfter(colon).loc.start.line !== colon.loc.end.line; | ||
} | ||
}; | ||
var getSpaces = function getSpaces(direction, colon, context) { | ||
@@ -32,3 +42,4 @@ var sourceCode = context.getSourceCode(); | ||
var spaces = void 0; | ||
var lineBreak = void 0, | ||
spaces = void 0; | ||
@@ -48,6 +59,9 @@ // Support optional names | ||
var charAfter = context.getSourceCode().getText(colon, 0, 1).slice(1); | ||
if (allowLineBreak && RegExp(/(\n|\r)+/).test(charAfter)) { | ||
spaces = 1; | ||
if (hasLineBreak(direction, colon, context)) { | ||
if (allowLineBreak) { | ||
spaces = 1; | ||
} else { | ||
lineBreak = true; | ||
spaces = getSpaces(direction, colon, context); | ||
} | ||
} else { | ||
@@ -57,5 +71,12 @@ spaces = getSpaces(direction, colon, context); | ||
if (always && spaces > 1) { | ||
if (always && lineBreak) { | ||
context.report({ | ||
data, | ||
fix: _utilities.spacingFixers.replaceWithSpace(direction, colon, spaces), | ||
message: 'There must not be a line break {{direction}} {{name}}{{type}} colon.', | ||
node | ||
}); | ||
} else if (always && spaces > 1) { | ||
context.report({ | ||
data, | ||
fix: _utilities.spacingFixers.stripSpaces(direction, colon, spaces - 1), | ||
@@ -62,0 +83,0 @@ message: 'There must be 1 space {{direction}} {{name}}{{type}} colon.', |
@@ -30,2 +30,14 @@ 'use strict'; | ||
var replaceWithSpaceBefore = exports.replaceWithSpaceBefore = function replaceWithSpaceBefore(node, spaces) { | ||
return function (fixer) { | ||
return fixer.replaceTextRange([node.start - spaces, node.start], ' '); | ||
}; | ||
}; | ||
var replaceWithSpaceAfter = exports.replaceWithSpaceAfter = function replaceWithSpaceAfter(node, spaces) { | ||
return function (fixer) { | ||
return fixer.replaceTextRange([node.end, node.end + spaces], ' '); | ||
}; | ||
}; | ||
var stripSpaces = exports.stripSpaces = function stripSpaces(direction, node, spaces) { | ||
@@ -45,2 +57,10 @@ if (direction === 'before') { | ||
} | ||
}; | ||
var replaceWithSpace = exports.replaceWithSpace = function replaceWithSpace(direction, node, spaces) { | ||
if (direction === 'before') { | ||
return replaceWithSpaceBefore(node, spaces); | ||
} else { | ||
return replaceWithSpaceAfter(node, spaces); | ||
} | ||
}; |
@@ -55,3 +55,3 @@ { | ||
}, | ||
"version": "2.35.0" | ||
"version": "2.35.1" | ||
} |
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
174240
2112