Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Feb 9, 2018
1 parent cc7007a commit cce5d5c
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ composer install

hh_client
hhvm vendor/bin/phpunit
hhvm vendor/bin/hhast-lint

# Make sure we pass when a release is required
EXPORT_DIR=$(mktemp -d)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"hhvm": "^3.23.0",
"hack-psr/psr7-http-message-hhi": "^0.2.0|^1.0.0",
"hhvm/hsl": "^1.0.0",
"hhvm/hhvm-autoload": "^1.5.3"
"hhvm/hhvm-autoload": "^1.5.3",
"hhvm/hhast": "^1.0"
},
"extra": {
"branch-alias": {
Expand Down
68 changes: 67 additions & 1 deletion composer.lock

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

3 changes: 2 additions & 1 deletion examples/BaseRouterExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Facebook\HackRouter\Examples\BaseRouterExample;

require_once('../vendor/autoload.php');
require_once(__DIR__.'/../vendor/hh_autoload.php');

use Facebook\HackRouter\BaseRouter;
use Facebook\HackRouter\HttpMethod;
Expand All @@ -27,6 +27,7 @@
type TResponder = (function(dict<string, string>):string);

final class BaseRouterExample extends BaseRouter<TResponder> {
<<__Override>>
protected function getRoutes(
): ImmMap<HttpMethod, ImmMap<string, TResponder>> {
return ImmMap {
Expand Down
6 changes: 5 additions & 1 deletion examples/UriPatternsExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Facebook\HackRouter\Examples\UrlPatternsExample;

require_once('../vendor/autoload.php');
require_once(__DIR__.'/../vendor/hh_autoload.php');

use Facebook\HackRouter\{
BaseRouter,
Expand Down Expand Up @@ -52,22 +52,26 @@ public function __construct(
}

final class HomePageController extends WebController {
<<__Override>>
public static function getUriPattern(): UriPattern {
return (new UriPattern())->literal('/');
}

<<__Override>>
public function getResponse(): string {
return 'Hello, world';
}
}

final class UserPageController extends WebController {
<<__Override>>
public static function getUriPattern(): UriPattern {
return (new UriPattern())
->literal('/users/')
->string('user_name');
}

<<__Override>>
public function getResponse(): string {
return 'Hello, '.$this->getRequestParameters()->getString('user_name');
}
Expand Down
4 changes: 4 additions & 0 deletions hhast-lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"roots": [ "src/", "tests/", "examples/" ],
"builtinLinters": "all"
}
2 changes: 1 addition & 1 deletion src/PatternParser/LiteralNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getText(): string {
return $this->text;
}

public function _toStringForDebug(): string {
public function toStringForDebug(): string {
return \var_export($this->getText(), true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PatternParser/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
namespace Facebook\HackRouter\PatternParser;

interface Node {
public function _toStringForDebug(): string;
public function toStringForDebug(): string;
public function asRegexp(string $delimiter): string;
}
4 changes: 2 additions & 2 deletions src/PatternParser/OptionalNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function getPattern(): PatternNode {
return $this->pattern;
}

public function _toStringForDebug(): string {
return '?'.$this->pattern->_toStringForDebug();
public function toStringForDebug(): string {
return '?'.$this->pattern->toStringForDebug();
}

public function asRegexp(string $delimiter): string {
Expand Down
2 changes: 1 addition & 1 deletion src/PatternParser/ParameterNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getRegexp(): ?string {
return $this->regexp;
}

public function _toStringForDebug(): string {
public function toStringForDebug(): string {
$re = $this->getRegexp();
if ($re === null) {
return '{'.$this->getName().'}';
Expand Down
4 changes: 2 additions & 2 deletions src/PatternParser/PatternNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function getChildren(): vec<Node> {
return $this->children;
}

public function _toStringForDebug(): string {
public function toStringForDebug(): string {
return $this->children
|> Vec\map($$, $child ==> $child->_toStringForDebug())
|> Vec\map($$, $child ==> $child->toStringForDebug())
|> Str\join($$, ', ')
|> '['.$$.']';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getExamplePatterns(): array<(string, string)> {
* @dataProvider getExamplePatterns
*/
public function testPattern(string $pattern, string $expected): void {
expect(PatternParser\Parser::parse($pattern)->_toStringForDebug())
expect(PatternParser\Parser::parse($pattern)->toStringForDebug())
->toBeSame($expected);
}
}
7 changes: 5 additions & 2 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,13 @@ public function testMethodNotAllowed(): void {

public function testCovariantTResponder(): void {
$router = $this->getRouter();
$this->_testCovariantTResponder($router, $router);
$this->typecheckCovariantTResponder($router, $router);
}

public function _testCovariantTResponder(BaseRouter<arraykey> $_, BaseRouter<string> $_): void {}
private function typecheckCovariantTResponder(
BaseRouter<arraykey> $_,
BaseRouter<string> $_,
): void {}


private function getRouter(
Expand Down

0 comments on commit cce5d5c

Please sign in to comment.