Skip to content

Commit 657495d

Browse files
author
Will Johnson
committed
- removed format and reverted back to string concatenation
1 parent a98e30a commit 657495d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/rules/spaceAfterTypeColon.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import _ from 'lodash';
2-
import {format} from 'util';
32
import {
43
getParameterName,
54
iterateFunctionNodes
@@ -8,34 +7,34 @@ import {
87
export default iterateFunctionNodes((context) => {
98
const always = (context.options[0] || 'always') === 'always';
109

11-
const processNode = (node, spaceAfter, reportMessage) => {
12-
if (always && spaceAfter > 1) {
13-
context.report(node, reportMessage('1'));
14-
} else if (always && spaceAfter === 0) {
15-
context.report(node, reportMessage('a'));
16-
} else if (!always && spaceAfter > 0) {
17-
context.report(node, reportMessage('no'));
18-
}
19-
};
20-
2110
return (functionNode) => {
2211
_.forEach(functionNode.params, (identifierNode) => {
2312
const parameterName = getParameterName(identifierNode, context);
2413
const typeAnnotation = _.get(identifierNode, 'typeAnnotation') || _.get(identifierNode, 'left.typeAnnotation');
2514

2615
if (typeAnnotation) {
2716
const spaceAfter = typeAnnotation.typeAnnotation.start - typeAnnotation.start - 1;
28-
const reportMessage = _.curry(format, 3)('There must be %s space after "%s" parameter type annotation colon.', _.curry.placeholder, parameterName);
2917

30-
processNode(identifierNode, spaceAfter, reportMessage);
18+
if (always && spaceAfter > 1) {
19+
context.report(identifierNode, 'There must be 1 space after "' + parameterName + '" parameter type annotation colon.');
20+
} else if (always && spaceAfter === 0) {
21+
context.report(identifierNode, 'There must be a space after "' + parameterName + '" parameter type annotation colon.');
22+
} else if (!always && spaceAfter > 0) {
23+
context.report(identifierNode, 'There must be no space after "' + parameterName + '" parameter type annotation colon.');
24+
}
3125
}
3226
});
3327

3428
if (functionNode.returnType) {
3529
const spaceAfter = functionNode.returnType.typeAnnotation.start - functionNode.returnType.start - 1;
36-
const reportMessage = format.bind(null, 'There must be %s space after return type colon.');
3730

38-
processNode(functionNode, spaceAfter, reportMessage);
31+
if (always && spaceAfter > 1) {
32+
context.report(functionNode, 'There must be 1 space after return type colon.');
33+
} else if (always && spaceAfter === 0) {
34+
context.report(functionNode, 'There must be a space after return type colon.');
35+
} else if (!always && spaceAfter > 0) {
36+
context.report(functionNode, 'There must be no space after return type colon.');
37+
}
3938
}
4039
};
4140
});

0 commit comments

Comments
 (0)