Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 7dd1a68

Browse files
committed
fix lint (including example codegen)
1 parent 67fb005 commit 7dd1a68

30 files changed

+106
-106
lines changed

examples/dorm/CodegenDorm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function getConstructor(): CodegenConstructor {
8787
private function getLoad(): CodegenMethod {
8888
$sql = 'select * from '.
8989
$this->schema->getTableName().
90-
' where '.$this->schema->getIdField().'=".$id."';
90+
' where '.$this->schema->getIdField().'=\'.$id.\'';
9191

9292
// Here's how to build a block of code using hack_builder.
9393
// Notice that some methods have a sprintf style of arguments
@@ -97,7 +97,7 @@ private function getLoad(): CodegenMethod {
9797
$body = $this->codegen->codegenHackBuilder()
9898
->addLinef('$conn = new PDO(\'%s\');', $this->schema->getDsn())
9999
->add('$cursor = ')
100-
->addMultilineCall('$conn->query', Vector {"\"".$sql."\""}, true)
100+
->addMultilineCall('$conn->query', Vector {"'".$sql."'"}, true)
101101
->addLine('$result = $cursor->fetch(PDO::FETCH_ASSOC);')
102102
->startIfBlock('!$result')
103103
->addReturnf('null')

examples/dorm/CodegenMutator.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,22 @@ private function getSaveMethod(): CodegenMethod {
165165
)
166166
->startIfBlock('$id === null')
167167
->addLine('$this->checkRequiredFields();')
168-
->addLine('$names = "(".implode(",", $quoted->keys()).")";')
169-
->addLine('$values = "(".implode(",", $quoted->values()).")";')
168+
->addLine('$names = \'(\'.implode(\',\', $quoted->keys()).\')\';')
169+
->addLine('$values = \'(\'.implode(\',\', $quoted->values()).\')\';')
170170
->addLinef(
171-
'$st = "insert into %s ".$names." values ".$values;',
171+
'$st = \'insert into %s \'.$names.\' values \'.$values;',
172172
$this->schema->getTableName(),
173173
)
174174
->addLine('$conn->exec($st);')
175175
->addReturnf('(int) $conn->lastInsertId()')
176176
->addElseBlock()
177177
->addAssignment(
178178
'$pairs',
179-
'$quoted->mapWithKey(($field, $value) ==> $field."=".$value)',
179+
'$quoted->mapWithKey(($field, $value) ==> $field.\'=\'.$value)',
180180
HackBuilderValues::literal(),
181181
)
182182
->addLinef(
183-
'$st = "update %s set ".implode(",", $pairs)." where %s=".$this->id;',
183+
'$st = \'update %s set \'.implode(\',\', $pairs).\' where %s=\'.$this->id;',
184184
$this->schema->getTableName(),
185185
$this->schema->getIdField(),
186186
)
@@ -219,8 +219,8 @@ private function getCheckRequiredFieldsMethod(): CodegenMethod {
219219
'invariant',
220220
Vector {
221221
'$missing->isEmpty()',
222-
'"The following required fields are missing: %s"',
223-
'implode(", ", $missing)',
222+
'\'The following required fields are missing: %s\'',
223+
'implode(\', \', $missing)',
224224
}
225225
);
226226

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

255255
if ($field->isManual()) {
256256
// You always need to close a manual section

examples/dorm/DormCodegenCLI.hack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class DormCodegenCLI extends \Facebook\CLILib\CLIWithRequiredArguments {
4444
$instance = $ref->newInstance() as DormSchema;
4545
/* HHAST_IGNORE_ERROR[DontAwaitInALoop] */
4646
await $this->getStdout()
47-
->writeAsync("Generating code for ".$class_name."\n");
47+
->writeAsync('Generating code for '.$class_name."\n");
4848
(new CodegenDorm($instance))->generate();
4949
(new CodegenMutator($instance))->generate();
5050
}

examples/dorm/demo/DormUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* To re-generate this file run codegen.hack DormUserSchema
77
*
88
*
9-
* @partially-generated SignedSource<<bb328713820ebe866a4e0292daa0a4de>>
9+
* @partially-generated SignedSource<<38fb8f142407a1689b579ad904452961>>
1010
*/
1111
use namespace Facebook\TypeAssert;
1212

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

2626
public static function load(int $id): ?DormUser {
2727
$conn = new PDO('sqlite:/path/to/database.db');
28-
$cursor = $conn->query("select * from user where user_id=".$id."");
28+
$cursor = $conn->query('select * from user where user_id='.$id.'');
2929
$result = $cursor->fetch(PDO::FETCH_ASSOC);
3030
if (!$result) {
3131
return null;

examples/dorm/demo/DormUserMutator.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* To re-generate this file run codegen.php DormUserSchema
77
*
88
*
9-
* @partially-generated SignedSource<<48c599867b0b679f5bb9cf27d8801e89>>
9+
* @partially-generated SignedSource<<cdbb99cace41afb39438c6b6a0ed401f>>
1010
*/
1111

1212
final class DormUserMutator {
@@ -40,14 +40,14 @@ public function save(): int {
4040
$id = $this->id;
4141
if ($id === null) {
4242
$this->checkRequiredFields();
43-
$names = "(".implode(",", $quoted->keys()).")";
44-
$values = "(".implode(",", $quoted->values()).")";
45-
$st = "insert into user ".$names." values ".$values;
43+
$names = '('.implode(',', $quoted->keys()).')';
44+
$values = '('.implode(',', $quoted->values()).')';
45+
$st = 'insert into user '.$names.' values '.$values;
4646
$conn->exec($st);
4747
return (int) $conn->lastInsertId();
4848
} else {
49-
$pairs = $quoted->mapWithKey(($field, $value) ==> $field."=".$value);
50-
$st = "update user set ".implode(",", $pairs)." where user_id=".$this->id;
49+
$pairs = $quoted->mapWithKey(($field, $value) ==> $field.'='.$value);
50+
$st = 'update user set '.implode(',', $pairs).' where user_id='.$this->id;
5151
$conn->exec($st);
5252
return $id;
5353
}
@@ -62,36 +62,36 @@ public function checkRequiredFields(): void {
6262
$missing = $required->removeAll($this->data->keys());;
6363
invariant(
6464
$missing->isEmpty(),
65-
"The following required fields are missing: %s",
66-
implode(", ", $missing),
65+
'The following required fields are missing: %s',
66+
implode(', ', $missing),
6767
);
6868
}
6969

7070
public function setFirstName(string $value): this {
71-
$this->data["first_name"] = $value;
71+
$this->data['first_name'] = $value;
7272
return $this;
7373
}
7474

7575
public function setLastName(string $value): this {
76-
$this->data["last_name"] = $value;
76+
$this->data['last_name'] = $value;
7777
return $this;
7878
}
7979

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

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

9393
public function setIsActive(bool $value): this {
94-
$this->data["is_active"] = $value;
94+
$this->data['is_active'] = $value;
9595
return $this;
9696
}
9797
}

examples/dorm/demo/demo_usage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ function dorm_demo_main(): void {
4242
->setIsActive(true)
4343
->save();
4444

45-
echo "Created user with id ".$id."\n";
45+
echo 'Created user with id '.$id."\n";
4646

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

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

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

src/BaseCodeBuilder.hack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ abstract class BaseCodeBuilder {
410410
final public function getCode(): string {
411411
invariant(
412412
!$this->wasGetCodeCalled,
413-
"You may only call getCode() once on a given HackBuilder object.",
413+
'You may only call getCode() once on a given HackBuilder object.',
414414
);
415415
$this->wasGetCodeCalled = true;
416416
return $this->code->detach();

src/CodegenClass.hack

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ final class CodegenClass extends CodegenClassish {
153153
$this->declComment,
154154
$this->isAbstract ? 'abstract ' : '',
155155
$this->isFinal ? 'final ' : '',
156-
"class ".$this->name.$generics_dec,
156+
'class '.$this->name.$generics_dec,
157157
$this->extendsClass !== null
158-
? HackBuilder::DELIMITER."extends ".$this->extendsClass
158+
? HackBuilder::DELIMITER.'extends '.$this->extendsClass
159159
: '',
160160
);
161161

src/CodegenEnum.hack

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ final class CodegenEnum implements ICodeBuilderRenderer {
8383
->ensureNewLine()
8484
->addWithSuggestedLineBreaksf(
8585
'%s%s%s {',
86-
"enum ".$this->name,
87-
HackBuilder::DELIMITER.": ".$this->enumType,
88-
$this->isAs !== null ? HackBuilder::DELIMITER."as ".$this->isAs : '',
86+
'enum '.$this->name,
87+
HackBuilder::DELIMITER.': '.$this->enumType,
88+
$this->isAs !== null ? HackBuilder::DELIMITER.'as '.$this->isAs : '',
8989
);
9090

9191
if (!C\is_empty($this->members)) {

src/CodegenFactoryTrait.hack

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ trait CodegenFactoryTrait implements ICodegenFactory {
173173
string $class,
174174
): CodegenGeneratedFrom {
175175
return
176-
new CodegenGeneratedFrom($this->getConfig(), "Generated from ".$class);
176+
new CodegenGeneratedFrom($this->getConfig(), 'Generated from '.$class);
177177
}
178178

179179
final public function codegenGeneratedFromMethod(
@@ -182,7 +182,7 @@ trait CodegenFactoryTrait implements ICodegenFactory {
182182
): CodegenGeneratedFrom {
183183
return new CodegenGeneratedFrom(
184184
$this->getConfig(),
185-
"Generated from ".$class."::".$method."()",
185+
'Generated from '.$class.'::'.$method.'()',
186186
);
187187
}
188188

@@ -193,7 +193,7 @@ trait CodegenFactoryTrait implements ICodegenFactory {
193193
): CodegenGeneratedFrom {
194194
return new CodegenGeneratedFrom(
195195
$this->getConfig(),
196-
"Generated from ".$class."::".$method."()['".$key."']",
196+
'Generated from '.$class.'::'.$method."()['".$key."']",
197197
);
198198
}
199199

@@ -207,13 +207,13 @@ trait CodegenFactoryTrait implements ICodegenFactory {
207207
invariant(
208208
$last !== null,
209209
"Couldn't get the strack trace. Please pass the script name to ".
210-
"codegenGeneratedFromScript",
210+
'codegenGeneratedFromScript',
211211
);
212212
$script = $this->codegenFile($last['file'])->getRelativeFileName();
213213
}
214214
return new CodegenGeneratedFrom(
215215
$this->getConfig(),
216-
"To re-generate this file run ".$script,
216+
'To re-generate this file run '.$script,
217217
);
218218
}
219219

0 commit comments

Comments
 (0)