Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #68

Merged
merged 2 commits into from
Aug 17, 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ function foo (foo:string) {}
// Message: There must be 1 space after return type colon.

async function foo({ lorem, ipsum, dolor }:SomeType) {}
// Message: There must be a space after "{ lorem, ipsum, dolor }:SomeType" parameter type annotation colon.
// Message: There must be a space after "{ lorem, ipsum, dolor }" parameter type annotation colon.

({ lorem, ipsum, dolor } : SomeType) => {}
// Message: There must be 1 space after "{ lorem, ipsum, dolor }" parameter type annotation colon.
Expand Down Expand Up @@ -956,7 +956,7 @@ class Foo { constructor(foo: string ) {} }
// Message: There must be a space before "foo" parameter type annotation colon.

async function foo({ lorem, ipsum, dolor } : SomeType) {}
// Message: There must be no space before "{ lorem, ipsum, dolor } : SomeType" parameter type annotation colon.
// Message: There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.

({ lorem, ipsum, dolor } : SomeType) => {}
// Message: There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.
Expand Down Expand Up @@ -1103,6 +1103,8 @@ var x = function (foo: string) {}
// Options: ["always"]
var x = function (foo : string) {}

class X { foo({ bar }: Props = this.props) {} }

class Foo { constructor(foo: string ) {} }

// Options: ["always"]
Expand Down
8 changes: 7 additions & 1 deletion src/utilities/getParameterName.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export default (identifierNode, context) => {
}

if (identifierNode.type === 'ObjectPattern' || identifierNode.type === 'ArrayPattern') {
return context.getSourceCode().getText(identifierNode);
const text = context.getSourceCode().getText(identifierNode);

if (identifierNode.typeAnnotation) {
return text.replace(context.getSourceCode().getText(identifierNode.typeAnnotation), '').trim();
} else {
return text;
}
}
if (_.get(identifierNode, 'left.type') === 'ObjectPattern') {
return context.getSourceCode().getText(identifierNode.left);
Expand Down
4 changes: 1 addition & 3 deletions tests/rules/assertions/spaceAfterTypeColon.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default {
code: 'async function foo({ lorem, ipsum, dolor }:SomeType) {}',
errors: [
{
message: 'There must be a space after "{ lorem, ipsum, dolor }:SomeType" parameter type annotation colon.'
message: 'There must be a space after "{ lorem, ipsum, dolor }" parameter type annotation colon.'
}
],
output: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}'
Expand All @@ -186,8 +186,6 @@ export default {
code: '({ lorem, ipsum, dolor } : SomeType) => {}',
errors: [
{
// NOTE: this message is different because of a Babylon parser bug with arrow functions
// where the param ranges don't include the type annotation like other functions do
message: 'There must be 1 space after "{ lorem, ipsum, dolor }" parameter type annotation colon.'
}
],
Expand Down
4 changes: 1 addition & 3 deletions tests/rules/assertions/spaceBeforeTypeColon.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default {
code: 'async function foo({ lorem, ipsum, dolor } : SomeType) {}',
errors: [
{
message: 'There must be no space before "{ lorem, ipsum, dolor } : SomeType" parameter type annotation colon.'
message: 'There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.'
}
],
output: 'async function foo({ lorem, ipsum, dolor }: SomeType) {}'
Expand All @@ -160,8 +160,6 @@ export default {
code: '({ lorem, ipsum, dolor } : SomeType) => {}',
errors: [
{
// NOTE: this message is different because of a Babylon parser bug with arrow functions
// where the param ranges don't include the type annotation like other functions do
message: 'There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.'
}
],
Expand Down