Skip to content

Commit

Permalink
fix lint (including example codegen)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjergus committed Mar 30, 2020
1 parent 67fb005 commit 7dd1a68
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 106 deletions.
4 changes: 2 additions & 2 deletions examples/dorm/CodegenDorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function getConstructor(): CodegenConstructor {
private function getLoad(): CodegenMethod {
$sql = 'select * from '.
$this->schema->getTableName().
' where '.$this->schema->getIdField().'=".$id."';
' where '.$this->schema->getIdField().'=\'.$id.\'';

// Here's how to build a block of code using hack_builder.
// Notice that some methods have a sprintf style of arguments
Expand All @@ -97,7 +97,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
18 changes: 9 additions & 9 deletions examples/dorm/CodegenMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,22 @@ private function getSaveMethod(): CodegenMethod {
)
->startIfBlock('$id === null')
->addLine('$this->checkRequiredFields();')
->addLine('$names = "(".implode(",", $quoted->keys()).")";')
->addLine('$values = "(".implode(",", $quoted->values()).")";')
->addLine('$names = \'(\'.implode(\',\', $quoted->keys()).\')\';')
->addLine('$values = \'(\'.implode(\',\', $quoted->values()).\')\';')
->addLinef(
'$st = "insert into %s ".$names." values ".$values;',
'$st = \'insert into %s \'.$names.\' values \'.$values;',
$this->schema->getTableName(),
)
->addLine('$conn->exec($st);')
->addReturnf('(int) $conn->lastInsertId()')
->addElseBlock()
->addAssignment(
'$pairs',
'$quoted->mapWithKey(($field, $value) ==> $field."=".$value)',
'$quoted->mapWithKey(($field, $value) ==> $field.\'=\'.$value)',
HackBuilderValues::literal(),
)
->addLinef(
'$st = "update %s set ".implode(",", $pairs)." where %s=".$this->id;',
'$st = \'update %s set \'.implode(\',\', $pairs).\' where %s=\'.$this->id;',
$this->schema->getTableName(),
$this->schema->getIdField(),
)
Expand Down Expand Up @@ -219,8 +219,8 @@ private function getCheckRequiredFieldsMethod(): CodegenMethod {
'invariant',
Vector {
'$missing->isEmpty()',
'"The following required fields are missing: %s"',
'implode(", ", $missing)',
'\'The following required fields are missing: %s\'',
'implode(\', \', $missing)',
}
);

Expand All @@ -234,7 +234,7 @@ private function getSetters(): Vector<CodegenMethod> {
$methods = Vector {};
foreach($this->schema->getFields() as $name => $field) {
if ($field->getType() === 'DateTime') {
$value = '$value->format("Y-m-d")';
$value = '$value->format(\'Y-m-d\')';
} else {
$value = '$value';
}
Expand All @@ -250,7 +250,7 @@ private function getSetters(): Vector<CodegenMethod> {
->addInlineComment('You may manually change this section of code');
}
$body
->addLinef('$this->data["%s"] = %s;', $field->getDbColumn(), $value);
->addLinef('$this->data[\'%s\'] = %s;', $field->getDbColumn(), $value);

if ($field->isManual()) {
// You always need to close a manual section
Expand Down
2 changes: 1 addition & 1 deletion examples/dorm/DormCodegenCLI.hack
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class DormCodegenCLI extends \Facebook\CLILib\CLIWithRequiredArguments {
$instance = $ref->newInstance() as DormSchema;
/* HHAST_IGNORE_ERROR[DontAwaitInALoop] */
await $this->getStdout()
->writeAsync("Generating code for ".$class_name."\n");
->writeAsync('Generating code for '.$class_name."\n");
(new CodegenDorm($instance))->generate();
(new CodegenMutator($instance))->generate();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/dorm/demo/DormUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* To re-generate this file run codegen.hack DormUserSchema
*
*
* @partially-generated SignedSource<<bb328713820ebe866a4e0292daa0a4de>>
* @partially-generated SignedSource<<38fb8f142407a1689b579ad904452961>>
*/
use namespace Facebook\TypeAssert;

Expand All @@ -25,7 +25,7 @@ private function __construct(private self::TData $data) {

public static function load(int $id): ?DormUser {
$conn = new PDO('sqlite:/path/to/database.db');
$cursor = $conn->query("select * from user where user_id=".$id."");
$cursor = $conn->query('select * from user where user_id='.$id.'');
$result = $cursor->fetch(PDO::FETCH_ASSOC);
if (!$result) {
return null;
Expand Down
26 changes: 13 additions & 13 deletions examples/dorm/demo/DormUserMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* To re-generate this file run codegen.php DormUserSchema
*
*
* @partially-generated SignedSource<<48c599867b0b679f5bb9cf27d8801e89>>
* @partially-generated SignedSource<<cdbb99cace41afb39438c6b6a0ed401f>>
*/

final class DormUserMutator {
Expand Down Expand Up @@ -40,14 +40,14 @@ public function save(): int {
$id = $this->id;
if ($id === null) {
$this->checkRequiredFields();
$names = "(".implode(",", $quoted->keys()).")";
$values = "(".implode(",", $quoted->values()).")";
$st = "insert into user ".$names." values ".$values;
$names = '('.implode(',', $quoted->keys()).')';
$values = '('.implode(',', $quoted->values()).')';
$st = 'insert into user '.$names.' values '.$values;
$conn->exec($st);
return (int) $conn->lastInsertId();
} else {
$pairs = $quoted->mapWithKey(($field, $value) ==> $field."=".$value);
$st = "update user set ".implode(",", $pairs)." where user_id=".$this->id;
$pairs = $quoted->mapWithKey(($field, $value) ==> $field.'='.$value);
$st = 'update user set '.implode(',', $pairs).' where user_id='.$this->id;
$conn->exec($st);
return $id;
}
Expand All @@ -62,36 +62,36 @@ public function checkRequiredFields(): void {
$missing = $required->removeAll($this->data->keys());;
invariant(
$missing->isEmpty(),
"The following required fields are missing: %s",
implode(", ", $missing),
'The following required fields are missing: %s',
implode(', ', $missing),
);
}

public function setFirstName(string $value): this {
$this->data["first_name"] = $value;
$this->data['first_name'] = $value;
return $this;
}

public function setLastName(string $value): this {
$this->data["last_name"] = $value;
$this->data['last_name'] = $value;
return $this;
}

public function setBirthday(DateTime $value): this {
$this->data["birthday"] = $value->format("Y-m-d");
$this->data['birthday'] = $value->format('Y-m-d');
return $this;
}

public function setCountryId(int $value): this {
/* BEGIN MANUAL SECTION CountryId */
// You may manually change this section of code
$this->data["country_id"] = $value;
$this->data['country_id'] = $value;
/* END MANUAL SECTION */
return $this;
}

public function setIsActive(bool $value): this {
$this->data["is_active"] = $value;
$this->data['is_active'] = $value;
return $this;
}
}
6 changes: 3 additions & 3 deletions examples/dorm/demo/demo_usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ function dorm_demo_main(): void {
->setIsActive(true)
->save();

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

$user = \DormUser::load($id);
invariant($user is nonnull, 'Failed to load user');
echo "Loaded: ".$user->getFirstName()." ".$user->getLastName()."\n";
echo 'Loaded: '.$user->getFirstName().' '.$user->getLastName()."\n";

\DormUserMutator::update($id)
->setFirstName('Peter')
Expand All @@ -56,5 +56,5 @@ function dorm_demo_main(): void {

$user = \DormUser::load($id);
invariant($user is nonnull, 'Failed to load user');
echo "Loaded: ".$user->getFirstName()." ".$user->getLastName()."\n";
echo 'Loaded: '.$user->getFirstName().' '.$user->getLastName()."\n";
}
2 changes: 1 addition & 1 deletion src/BaseCodeBuilder.hack
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ abstract class BaseCodeBuilder {
final public function getCode(): string {
invariant(
!$this->wasGetCodeCalled,
"You may only call getCode() once on a given HackBuilder object.",
'You may only call getCode() once on a given HackBuilder object.',
);
$this->wasGetCodeCalled = true;
return $this->code->detach();
Expand Down
4 changes: 2 additions & 2 deletions src/CodegenClass.hack
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ final class CodegenClass extends CodegenClassish {
$this->declComment,
$this->isAbstract ? 'abstract ' : '',
$this->isFinal ? 'final ' : '',
"class ".$this->name.$generics_dec,
'class '.$this->name.$generics_dec,
$this->extendsClass !== null
? HackBuilder::DELIMITER."extends ".$this->extendsClass
? HackBuilder::DELIMITER.'extends '.$this->extendsClass
: '',
);

Expand Down
6 changes: 3 additions & 3 deletions src/CodegenEnum.hack
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ final class CodegenEnum implements ICodeBuilderRenderer {
->ensureNewLine()
->addWithSuggestedLineBreaksf(
'%s%s%s {',
"enum ".$this->name,
HackBuilder::DELIMITER.": ".$this->enumType,
$this->isAs !== null ? HackBuilder::DELIMITER."as ".$this->isAs : '',
'enum '.$this->name,
HackBuilder::DELIMITER.': '.$this->enumType,
$this->isAs !== null ? HackBuilder::DELIMITER.'as '.$this->isAs : '',
);

if (!C\is_empty($this->members)) {
Expand Down
10 changes: 5 additions & 5 deletions src/CodegenFactoryTrait.hack
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ trait CodegenFactoryTrait implements ICodegenFactory {
string $class,
): CodegenGeneratedFrom {
return
new CodegenGeneratedFrom($this->getConfig(), "Generated from ".$class);
new CodegenGeneratedFrom($this->getConfig(), 'Generated from '.$class);
}

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

Expand All @@ -193,7 +193,7 @@ trait CodegenFactoryTrait implements ICodegenFactory {
): CodegenGeneratedFrom {
return new CodegenGeneratedFrom(
$this->getConfig(),
"Generated from ".$class."::".$method."()['".$key."']",
'Generated from '.$class.'::'.$method."()['".$key."']",
);
}

Expand All @@ -207,13 +207,13 @@ trait CodegenFactoryTrait implements ICodegenFactory {
invariant(
$last !== null,
"Couldn't get the strack trace. Please pass the script name to ".
"codegenGeneratedFromScript",
'codegenGeneratedFromScript',
);
$script = $this->codegenFile($last['file'])->getRelativeFileName();
}
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/CodegenFile.hack
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ final class CodegenFile {
* setShebangLine('#!/usr/bin/env hhvm')
*/
public function setShebangLine(string $shebang): this {
invariant(!\strpbrk($shebang, "\n"), "Expected single line");
invariant(!\strpbrk($shebang, "\n"), 'Expected single line');
invariant(Str\starts_with($shebang, '#!'), 'Shebang lines start with #!');
$this->shebang = $shebang;
return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/CodegenFunctionish.hack
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ abstract class CodegenFunctionish implements ICodeBuilderRenderer {

$multi_line_builder = (new HackBuilder($this->config))
->add($keywords)
->addLine($this->name."(")
->addLine($this->name.'(')
->indent()
->addLines($parameter_lines)
->unindent()
Expand Down Expand Up @@ -224,7 +224,7 @@ abstract class CodegenFunctionish implements ICodeBuilderRenderer {
if ($this->docBlock !== null && $this->docBlock !== '') {
if ($this->generatedFrom) {
$builder->addDocBlock(
$this->docBlock."\n(".$this->generatedFrom->render().")",
$this->docBlock."\n(".$this->generatedFrom->render().')',
);
} else {
$builder->addDocBlock($this->docBlock);
Expand Down
2 changes: 1 addition & 1 deletion src/CodegenShapeMember.hack
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
) {
invariant(
$type is string || $type is CodegenShape,
"You must provide either a string or shape",
'You must provide either a string or shape',
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/CodegenType.hack
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ final class CodegenType implements ICodeBuilderRenderer {
public function appendToBuilder(HackBuilder $builder): HackBuilder {
invariant(
$this->type !== null || $this->codegenShape !== null,
"You need to set either the type or the shape",
'You need to set either the type or the shape',
);
$builder->addf('%s %s = ', $this->keyword, $this->name);
if ($this->type !== null) {
return $builder->add($this->type)->closeStatement();
}
invariant(
$this->codegenShape !== null,
"Somehow the type and the shape were null!",
'Somehow the type and the shape were null!',
);
return $builder->addRenderer($this->codegenShape)->closeStatement();
}
Expand Down
2 changes: 1 addition & 1 deletion src/CodegenUsesTrait.hack
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class CodegenUsesTrait {
public function render(): string {
return (new HackBuilder($this->config))
->addInlineComment($this->comment)
->addLinef("use %s;", $this->name)
->addLinef('use %s;', $this->name)
->getCode();
}
}
16 changes: 8 additions & 8 deletions src/HackBuilder.hack
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final class HackBuilder extends BaseCodeBuilder {
}

$this
->addWithSuggestedLineBreaks($func_call_line."(")
->addWithSuggestedLineBreaks($func_call_line.'(')
->newLine()
->indent()
->addLinesWithSuggestedLineBreaks(Vec\map($params, $line ==> $line.','))
Expand Down Expand Up @@ -204,19 +204,19 @@ final class HackBuilder extends BaseCodeBuilder {
case ContainerType::DICT:
case ContainerType::KEYSET:
case ContainerType::VEC:
$container_sign = "[";
$container_sign = '[';
break;
case ContainerType::IMM_MAP:
case ContainerType::IMM_SET:
case ContainerType::IMM_VECTOR:
case ContainerType::MAP:
case ContainerType::SET:
case ContainerType::VECTOR:
$container_sign = " {";
$container_sign = ' {';
break;
case ContainerType::SHAPE_TYPE:
case ContainerType::PHP_ARRAY:
$container_sign = "(";
$container_sign = '(';
break;
}
return $this->addLine(((string)$type).$container_sign)->indent();
Expand All @@ -234,19 +234,19 @@ final class HackBuilder extends BaseCodeBuilder {
case ContainerType::DICT:
case ContainerType::KEYSET:
case ContainerType::VEC:
$container_sign = "]";
$container_sign = ']';
break;
case ContainerType::IMM_MAP:
case ContainerType::IMM_SET:
case ContainerType::IMM_VECTOR:
case ContainerType::MAP:
case ContainerType::SET:
case ContainerType::VECTOR:
$container_sign = "}";
$container_sign = '}';
break;
case ContainerType::SHAPE_TYPE:
case ContainerType::PHP_ARRAY:
$container_sign = ")";
$container_sign = ')';
break;
}
return $this->unindent()->add($container_sign);
Expand Down Expand Up @@ -581,7 +581,7 @@ final class HackBuilder extends BaseCodeBuilder {
Traversable<string> $params,
): this {
return $this
->addLine($name."(")
->addLine($name.'(')
->indent()
->addLines(Vec\map($params, $line ==> $line.','))
->unindent()
Expand Down
Loading

0 comments on commit 7dd1a68

Please sign in to comment.