Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Add type annotations to arrow-parens "as-needed" #44

Merged
merged 1 commit into from
Jan 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rules/arrow-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = function(context) {
if (node.async) token = context.getTokenAfter(token);

// as-needed: x => x
if (asNeeded && node.params.length === 1 && node.params[0].type === "Identifier") {
if (asNeeded && node.params.length === 1
&& node.params[0].type === "Identifier"
&& node.params[0].typeAnnotation === undefined) {
if (token.type === "Punctuator" && token.value === "(") {
context.report(node, asNeededMessage);
}
Expand All @@ -50,4 +52,4 @@ module.exports.schema = [
{
"enum": ["always", "as-needed"]
}
];
];
3 changes: 2 additions & 1 deletion tests/arrow-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var valid = [
{ code: "(a = 10) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true, destructuring: true, defaultParams: true } },
{ code: "(...a) => a[0]", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true, restParams: true } },
{ code: "(a, b) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true } },
ok("(a: string) => a", ["as-needed"]),

// async
ok("async () => {}"),
Expand Down Expand Up @@ -174,4 +175,4 @@ var invalid = [
ruleTester.run("arrow-parens", rule, {
valid: valid,
invalid: invalid
});
});