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

Amend regex to prevent incorrect boolean return type #129

Merged
merged 6 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
51 changes: 0 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/block/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class FunctionBlock extends Block
*/
public getReturnFromName(name:string):string
{
if (/^(is|has|can)/.test(name)) {
if (/^(is|has|can|should)(?:[A-Z0-9_]|$)/.test(name)) {
return TypeUtil.instance.getFormattedTypeByName('bool');
}

Expand Down
47 changes: 46 additions & 1 deletion test/fixtures/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,61 @@ public function isSomething()
{
}

////=> is-void
public function isotope()
{
}

////=> is-only
public function is()
{
}

////=> has
public function hasValue()
{
}


////=> has-void
public function hashed()
{
}

////=> has-only
public function has()
{
}

////=> can
public function canValue()
{
}

////=> can-void
public function cancel()
{
}

////=> can-only
public function can()
{
}

////=> should
public function shouldDoSomething()
{
}

////=> should-void
public function shouldasdf()
{
}

////=> should-only
public function should()
{
}

////=> debug-info
public function __debugInfo()
{
Expand Down
72 changes: 72 additions & 0 deletions test/fixtures/functions.php.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,22 @@
"params": []
}
},
{
"key": "is-void",
"name": "Check is prefix - void",
"result": {
"return": "void",
"params": []
}
},
{
"key": "is-only",
"name": "Check is prefix - only",
"result": {
"return": "boolean",
"params": []
}
},
{
"key": "has",
"name": "Check has prefix",
Expand All @@ -429,6 +445,22 @@
"params": []
}
},
{
"key": "has-void",
"name": "Check has prefix - void",
"result": {
"return": "void",
"params": []
}
},
{
"key": "has-only",
"name": "Check has prefix - only",
"result": {
"return": "boolean",
"params": []
}
},
{
"key": "can",
"name": "Check can prefix",
Expand All @@ -437,6 +469,46 @@
"params": []
}
},
{
"key": "can-void",
"name": "Check can prefix - void",
"result": {
"return": "void",
"params": []
}
},
{
"key": "can-only",
"name": "Check can prefix - only",
"result": {
"return": "boolean",
"params": []
}
},
{
"key": "should",
"name": "Check should prefix",
"result": {
"return": "boolean",
"params": []
}
},
{
"key": "should-void",
"name": "Check should prefix - void",
"result": {
"return": "void",
"params": []
}
},
{
"key": "should-only",
"name": "Check should prefix - only",
"result": {
"return": "boolean",
"params": []
}
},
{
"key": "debug-info",
"name": "Debug info return type",
Expand Down