Skip to content

Commit

Permalink
Update forward compatibility level, fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kmeht committed Aug 28, 2018
1 parent b897ada commit f753113
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .hhconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ enable_experimental_tc_features=shape_field_check,sealed_classes
# - otherwise, we get a circular dependency
# - we don't use anything other than executables from it
ignored_paths = [ "vendor/.+/tests/.+", "vendor/hhvm/hhast/.+" ]
forward_compatibility_level=20180704
forward_compatibility_level=3.28
2 changes: 1 addition & 1 deletion examples/dorm/CodegenDorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function getLoad(): CodegenMethod {
$body = $this->codegen->codegenHackBuilder()
->addLinef('$conn = new PDO(\'%s\');', $this->schema->getDsn())
->add('$cursor = ')
->addMultilineCall('$conn->query', Vector {"\"$sql\""}, true)
->addMultilineCall('$conn->query', Vector {"\"".$sql."\""}, true)
->addLine('$result = $cursor->fetch(PDO::FETCH_ASSOC);')
->startIfBlock('!$result')
->addReturnf('null')
Expand Down
8 changes: 4 additions & 4 deletions examples/dorm/codegen.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?hh
<?hh // strict
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand All @@ -12,13 +12,13 @@

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

if ($argc == 1) {
if ($argc === 1) {
echo " Usage: ".$argv[0]." file_name.php\n\n";
exit(1);
}
$fname = $argv[1];
if (!file_exists($fname)) {
echo " File doesn't exist: $fname\n\n";
echo " File doesn't exist: ".$fname."\n\n";
exit(1);
}

Expand All @@ -36,7 +36,7 @@
if (!$instance instanceof DormSchema) {
continue;
}
echo "Generating code for $class_name\n";
echo "Generating code for ".$class_name."\n";
(new CodegenDorm($instance))->generate();
(new CodegenMutator($instance))->generate();
}
4 changes: 2 additions & 2 deletions examples/dorm/demo/demo_usage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?hh
<?hh // strict
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
Expand Down Expand Up @@ -40,7 +40,7 @@
->setIsActive(true)
->save();

echo "Created user with id $id\n";
echo "Created user with id ".$id."\n";

$user = DormUser::load($id);
echo "Loaded: ".$user->getFirstName()." ".$user->getLastName()."\n";
Expand Down
2 changes: 1 addition & 1 deletion src/CodegenClassBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected function buildGenericsDeclaration(): string {
return '';
}

if ($generics_count == 1) {
if ($generics_count === 1) {
return '<'.C\onlyx($this->genericsDecl).'>';
}

Expand Down
8 changes: 4 additions & 4 deletions src/CodegenFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ final public function codegenGeneratedFromClass(
string $class,
): CodegenGeneratedFrom {
return
new CodegenGeneratedFrom($this->getConfig(), "Generated from $class");
new CodegenGeneratedFrom($this->getConfig(), "Generated from ".$class);
}

final public function codegenGeneratedFromMethod(
Expand All @@ -128,7 +128,7 @@ final public function codegenGeneratedFromMethod(
): CodegenGeneratedFrom {
return new CodegenGeneratedFrom(
$this->getConfig(),
"Generated from $class::$method()",
"Generated from ".$class."::".$method."()",
);
}

Expand All @@ -139,7 +139,7 @@ final public function codegenGeneratedFromMethodWithKey(
): CodegenGeneratedFrom {
return new CodegenGeneratedFrom(
$this->getConfig(),
"Generated from $class::$method()['$key']",
"Generated from ".$class."::".$method."()['".$key."']",
);
}

Expand All @@ -158,7 +158,7 @@ final public function codegenGeneratedFromScript(
}
return new CodegenGeneratedFrom(
$this->getConfig(),
"To re-generate this file run $script",
"To re-generate this file run ".$script,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/CodegenFunctionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function getFunctionDeclarationBase(

$multi_line_builder = (new HackBuilder($this->config))
->add($keywords)
->addLine("$this->name(")
->addLine($this->name."(")
->indent()
->addLines($parameter_lines)
->unindent()
Expand Down
2 changes: 1 addition & 1 deletion src/CodegenProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function appendToBuilder(HackBuilder $builder): HackBuilder {
->addIf($this->isStatic, 'static ')
->addIf($this->type !== null, $this->type.' ')
->add('$'.$this->name)
->addIf($this->value != self::UNSET_VALUE, ' = '.$this->value)
->addIf($this->value !== self::UNSET_VALUE, ' = '.$this->value)
->addLine(';');
}

Expand Down
4 changes: 2 additions & 2 deletions src/HackBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function addMultilineCall(
}

$this
->addWithSuggestedLineBreaks("$func_call_line(")
->addWithSuggestedLineBreaks($func_call_line."(")
->newLine()
->indent()
->addLinesWithSuggestedLineBreaks(Vec\map($params, $line ==> $line.','))
Expand Down Expand Up @@ -577,7 +577,7 @@ private function addSimpleMultilineCall(
Traversable<string> $params,
): this {
return $this
->addLine("$name(")
->addLine($name."(")
->indent()
->addLines(Vec\map($params, $line ==> $line.','))
->unindent()
Expand Down
3 changes: 1 addition & 2 deletions src/HackfmtFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

namespace Facebook\HackCodegen;

use namespace HH\Lib\Str;

final class HackfmtFormatter implements ICodegenFormatter {
public function format(
string $code,
string $file_name,
string $_file_name,
): string {
$output = array();
$exit_code = null;
Expand Down
6 changes: 3 additions & 3 deletions src/PartiallyGeneratedCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private function iterateCodeSections(
} else if (\preg_match($begin, $line) === 1) {
if ($current_id !== null) {
throw new PartiallyGeneratedCodeException(
"The manual section $current_id was open before ".
"The manual section ".$current_id." was open before ".
"the previous one was closed",
);
}
Expand All @@ -176,7 +176,7 @@ private function iterateCodeSections(

if (C\contains($seen_ids, $current_id)) {
throw new PartiallyGeneratedCodeException(
"Duplicate manual section id: $current_id",
"Duplicate manual section id: ".$current_id,
);
}
$seen_ids[] = $current_id;
Expand All @@ -186,7 +186,7 @@ private function iterateCodeSections(
}
if ($current_id !== null) {
throw new PartiallyGeneratedCodeException(
"The manual section $current_id was not closed at the end of code",
"The manual section ".$current_id." was not closed at the end of code",
);
}
if ($code) {
Expand Down
2 changes: 1 addition & 1 deletion src/SignedSourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function signFile(string $file_data): string {
$signature = \md5(static::preprocess($file_data));
$replaced_data =
\str_replace(static::TOKEN, 'SignedSource<<'.$signature.'>>', $file_data);
if ($replaced_data == $file_data) {
if ($replaced_data === $file_data) {
throw new \Exception(
'Before signing a file, you must embed a signing token within it.',
);
Expand Down
6 changes: 3 additions & 3 deletions src/_Private/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public static function remove(string $path): void {
return;
}
if (!\unlink($path)) {
throw new \Exception("Unable to remove `{$path}'.");
throw new \Exception("Unable to remove `".$path."'.");
}
}

public static function readFile(string $path): string {
$data = @\file_get_contents($path);
if ($data === false) {
throw new \Exception("Failed to read file `{$path}'.");
throw new \Exception("Failed to read file `".$path."'.");
}

return $data;
Expand All @@ -44,7 +44,7 @@ public static function writeFile(string $path, string $data): void {
$res = @\file_put_contents($path, $data);

if ($res === false) {
throw new \Exception("Failed to write file `{$path}'.");
throw new \Exception("Failed to write file `".$path."'.");
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/_Private/difference_render_fast.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ function difference_render_fast(string $old, string $new): string {
$t1 = explode("\n", $old);
$x = array_pop($t1);
if ($x > '') {
$t1[] = "$x\n\\ No newline at end of file";
$t1[] = $x."\n\\ No newline at end of file";
}

$t2 = explode("\n", $new);
$x = array_pop($t2);
if ($x > '') {
$t2[] = "$x\n\\ No newline at end of file";
$t2[] = $x."\n\\ No newline at end of file";
}

// build a reverse-index array using the line as key and line number as
Expand All @@ -48,7 +48,7 @@ function difference_render_fast(string $old, string $new): string {
// walk this loop until we reach the end of one of the lists
while ($a1 < count($t1) && $a2 < count($t2)) {
// if we have a common element, save it and go to the next
if ($t1[$a1] == $t2[$a2]) {
if ($t1[$a1] === $t2[$a2]) {
$actions[] = 4;
$a1++;
$a2++;
Expand Down Expand Up @@ -130,26 +130,26 @@ function difference_render_fast(string $old, string $new): string {
$out = array();

foreach ($actions as $act) {
if ($act == 1) {
if ($act === 1) {
$op |= $act;
$x1++;
continue;
}

if ($act == 2) {
if ($act === 2) {
$op |= $act;
$y1++;
continue;
}

if ($op > 0) {
$xstr = ($x1 == ($x0 + 1)) ? $x1 : ($x0 + 1).",$x1";
$ystr = ($y1 == ($y0 + 1)) ? $y1 : ($y0 + 1).",$y1";
$xstr = ($x1 === ($x0 + 1)) ? $x1 : ($x0 + 1).",".$x1;
$ystr = ($y1 === ($y0 + 1)) ? $y1 : ($y0 + 1).",".$y1;

if ($op == 1) {
$out[] = "{$xstr}d{$y1}";
} else if ($op == 3) {
$out[] = "{$xstr}c{$ystr}";
if ($op === 1) {
$out[] = $xstr."d".$y1;
} else if ($op === 3) {
$out[] = $xstr."c".$ystr;
}

// deleted elems
Expand All @@ -158,9 +158,9 @@ function difference_render_fast(string $old, string $new): string {
$x0++;
}

if ($op == 2) {
$out[] = "{$x1}a{$ystr}";
} else if ($op == 3) {
if ($op === 2) {
$out[] = $x1."a".$ystr;
} else if ($op === 3) {
$out[] = '---';
}

Expand Down
2 changes: 1 addition & 1 deletion test/CodegenFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private function createAndModifyPartiallyGeneratedFile(): string {
$new_content =
\str_replace('// manual_section_here', 'return $this->name;', $content);
$this->assertFalse(
$content == $new_content,
$content === $new_content,
"The manual content wasn't replaced. Please fix the test setup!",
);
Filesystem::writeFile($fname, $new_content);
Expand Down
14 changes: 7 additions & 7 deletions test/HackBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function testAddWithSuggestedLineBreaksNoBreakage(): void {
$body = $this
->getHackBuilder()
->addWithSuggestedLineBreaks(
"final class{$del}ClassNameJustLongEnoughToAvoidEightyColumns{$del}".
"final class".$del."ClassNameJustLongEnoughToAvoidEightyColumns".$del.
"extends SomeBaseClass",
);
$this->assertUnchanged($body->getCode());
Expand All @@ -192,8 +192,8 @@ public function testAddWithSuggestedLineBreaksWithBreakage(): void {
$body = $this
->getHackBuilder()
->addWithSuggestedLineBreaks(
"final abstract class{$del}ImpossibleClassLongEnoughToCrossEightyColumns".
"{$del}extends SomeBaseClass",
"final abstract class".$del."ImpossibleClassLongEnoughToCrossEightyColumns".
$del."extends SomeBaseClass",
);
$this->assertUnchanged($body->getCode());
}
Expand All @@ -211,11 +211,11 @@ public function testAddSmartMultilineCall(): void {
$body = $this
->getHackBuilder()
->addMultilineCall(
"\$foobarbaz_alphabetagama ={$del}\$this->callSomeThingReallyLongName".
"\$foobarbaz_alphabetagama =".$del."\$this->callSomeThingReallyLongName".
"ReallyReallyLongName",
Vector {
'$someSmallParameter',
"\$foobarbaz_alphabetagama +{$del}\$foobarbaz_alphabetagamaa +{$del}".
"\$foobarbaz_alphabetagama +".$del."\$foobarbaz_alphabetagamaa +".$del.
"\$foobarbaz_alphabetagamatheta_foobarbaz",
},
);
Expand Down Expand Up @@ -495,8 +495,8 @@ public function testLambdaMap(): void {
->addValue(
Map { 'foo' => 'bar' },
HackBuilderValues::map(
HackBuilderKeys::lambda(($_config, $v) ==> "'key:$v'"),
HackBuilderValues::lambda(($_config, $v) ==> "'value:$v'"),
HackBuilderKeys::lambda(($_config, $v) ==> "'key:".$v."'"),
HackBuilderValues::lambda(($_config, $v) ==> "'value:".$v."'"),
),
);
$this->assertUnchanged($body->getCode());
Expand Down

0 comments on commit f753113

Please sign in to comment.