From cce5d5c1abef54aaa17dda8e6ee904fb2263f240 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Fri, 9 Feb 2018 13:16:59 -0800 Subject: [PATCH] Add linter --- .travis.sh | 1 + composer.json | 3 +- composer.lock | 68 ++++++++++++++++++++++++++++- examples/BaseRouterExample.php | 3 +- examples/UriPatternsExample.php | 6 ++- hhast-lint.json | 4 ++ src/PatternParser/LiteralNode.php | 2 +- src/PatternParser/Node.php | 2 +- src/PatternParser/OptionalNode.php | 4 +- src/PatternParser/ParameterNode.php | 2 +- src/PatternParser/PatternNode.php | 4 +- tests/ParserTest.php | 2 +- tests/RouterTest.php | 7 ++- 13 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 hhast-lint.json diff --git a/.travis.sh b/.travis.sh index a03cc31..dac2f9b 100755 --- a/.travis.sh +++ b/.travis.sh @@ -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) diff --git a/composer.json b/composer.json index 7278836..9694b2e 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 95034e0..9bd7205 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "6e5c7426697148c0a6101682db652352", + "content-hash": "63432440f57aeb40257fe450b3b9fcc1", "packages": [ { "name": "fredemmott/hack-error-suppressor", @@ -78,6 +78,39 @@ ], "time": "2018-02-09T20:54:15+00:00" }, + { + "name": "hhvm/hhast", + "version": "v1.0", + "source": { + "type": "git", + "url": "https://github.com/hhvm/hhast.git", + "reference": "ddd9ec394375922e609d8c88a83142fd3cc89de2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hhvm/hhast/zipball/ddd9ec394375922e609d8c88a83142fd3cc89de2", + "reference": "ddd9ec394375922e609d8c88a83142fd3cc89de2", + "shasum": "" + }, + "require": { + "hhvm": "^3.24.0", + "hhvm/hsl": "^1.0.0", + "hhvm/type-assert": "^3.1" + }, + "require-dev": { + "91carriage/phpunit-hhi": "^5.7", + "facebook/fbexpect": "^0.4.0", + "facebook/hack-codegen": "~3.0.3", + "hhvm/hhvm-autoload": "^1.5", + "phpunit/phpunit": "^5.7" + }, + "bin": [ + "bin/hhast-lint" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "time": "2018-02-09T18:24:19+00:00" + }, { "name": "hhvm/hhvm-autoload", "version": "v1.6.1", @@ -156,6 +189,39 @@ "description": "The Hack Standard Library", "time": "2018-02-05T22:10:31+00:00" }, + { + "name": "hhvm/type-assert", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/hhvm/type-assert.git", + "reference": "8f70814c8268f50e2fa728893d3ad9cad73df398" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hhvm/type-assert/zipball/8f70814c8268f50e2fa728893d3ad9cad73df398", + "reference": "8f70814c8268f50e2fa728893d3ad9cad73df398", + "shasum": "" + }, + "require": { + "hhvm": "^3.23.0", + "hhvm/hhvm-autoload": "^1.4", + "hhvm/hsl": "^1.0" + }, + "require-dev": { + "91carriage/phpunit-hhi": "~5.1", + "facebook/fbexpect": "^0.2.0 | ^0.3.0 | ^0.4.0", + "phpunit/phpunit": "~5.1" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "description": "Convert untyped data to typed data", + "keywords": [ + "TypeAssert", + "hack" + ], + "time": "2018-02-09T17:05:23+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", diff --git a/examples/BaseRouterExample.php b/examples/BaseRouterExample.php index 9c0716e..6834ff0 100644 --- a/examples/BaseRouterExample.php +++ b/examples/BaseRouterExample.php @@ -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; @@ -27,6 +27,7 @@ type TResponder = (function(dict):string); final class BaseRouterExample extends BaseRouter { + <<__Override>> protected function getRoutes( ): ImmMap> { return ImmMap { diff --git a/examples/UriPatternsExample.php b/examples/UriPatternsExample.php index c808412..9ffc1b1 100644 --- a/examples/UriPatternsExample.php +++ b/examples/UriPatternsExample.php @@ -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, @@ -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'); } diff --git a/hhast-lint.json b/hhast-lint.json new file mode 100644 index 0000000..fcf38d4 --- /dev/null +++ b/hhast-lint.json @@ -0,0 +1,4 @@ +{ + "roots": [ "src/", "tests/", "examples/" ], + "builtinLinters": "all" +} diff --git a/src/PatternParser/LiteralNode.php b/src/PatternParser/LiteralNode.php index 2101aee..3749e1a 100644 --- a/src/PatternParser/LiteralNode.php +++ b/src/PatternParser/LiteralNode.php @@ -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); } diff --git a/src/PatternParser/Node.php b/src/PatternParser/Node.php index 32de05b..aaf2174 100644 --- a/src/PatternParser/Node.php +++ b/src/PatternParser/Node.php @@ -12,6 +12,6 @@ namespace Facebook\HackRouter\PatternParser; interface Node { - public function _toStringForDebug(): string; + public function toStringForDebug(): string; public function asRegexp(string $delimiter): string; } diff --git a/src/PatternParser/OptionalNode.php b/src/PatternParser/OptionalNode.php index 727780f..c53b39b 100644 --- a/src/PatternParser/OptionalNode.php +++ b/src/PatternParser/OptionalNode.php @@ -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 { diff --git a/src/PatternParser/ParameterNode.php b/src/PatternParser/ParameterNode.php index 264cef1..875358e 100644 --- a/src/PatternParser/ParameterNode.php +++ b/src/PatternParser/ParameterNode.php @@ -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().'}'; diff --git a/src/PatternParser/PatternNode.php b/src/PatternParser/PatternNode.php index 49d845b..4a5b66b 100644 --- a/src/PatternParser/PatternNode.php +++ b/src/PatternParser/PatternNode.php @@ -21,9 +21,9 @@ public function getChildren(): vec { 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($$, ', ') |> '['.$$.']'; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index db8bcf7..dd2a0e2 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -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); } } diff --git a/tests/RouterTest.php b/tests/RouterTest.php index b6c4a86..25fefaf 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -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 $_, BaseRouter $_): void {} + private function typecheckCovariantTResponder( + BaseRouter $_, + BaseRouter $_, + ): void {} private function getRouter(