Skip to content

Commit

Permalink
Clarify error message of linter about filename mismatch
Browse files Browse the repository at this point in the history
Summary: We have a linter checking that a file name is consistent with its class name if the file contains only one class. If the file also contains type definitions, these are ignored by the linter. However in that case the error message "file.php only contains MyClass, it should be named MyClass.php" is confusing, because the file does not "only contain MyClass". This diff adapts the error message to make it less confusing.

Reviewed By: madgen

Differential Revision: D64845159

fbshipit-source-id: b51a5828428210cee5f13600360558f4b3a7319e
  • Loading branch information
Catherine Gasnier authored and facebook-github-bot committed Oct 24, 2024
1 parent 01da9ba commit 653d1be
Show file tree
Hide file tree
Showing 35 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions hphp/hack/test/json/test_capitalised.php.exp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"errors":[
{
"descr":"test_capitalised.php only declares `f`, it should be named f.php instead.",
"descr":"f is the only function declared in test_capitalised.php, so that file should be named f.php instead.",
"severity":"warning",
"path":"test_capitalised.php",
"line":3,
Expand Down Expand Up @@ -30,4 +30,4 @@
}
],
"version":""
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "as_valid_type_with_opaque_alias.php--use_it.php", line 3, characters 10-12:
as_valid_type_with_opaque_alias.php--use_it.php only declares `foo`, it should be named foo.php instead. (Lint[5564])
foo is the only function declared in as_valid_type_with_opaque_alias.php--use_it.php, so that file should be named foo.php instead. (Lint[5564])
File "as_valid_type_with_opaque_alias.php--use_it.php", line 6, characters 3-11:
This expression has a type lie that makes Hack type checker think it is a different type than what it inferred. It is achieved using a type assertion through `as`. This can lead to fatals or subtle and latent behaviour changes. Even if the code is correct at the moment, the type checker won't produce any signal when the prerequisites for correctness change. (Lint[5808])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/call_user_func_array_sgrep.php.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "call_user_func_array_sgrep.php", line 3, characters 10-13:
call_user_func_array_sgrep.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in call_user_func_array_sgrep.php, so that file should be named test.php instead. (Lint[5564])
File "call_user_func_array_sgrep.php", line 4, characters 3-22:
Use argument unpacking instead. See https://www.facebook.com/groups/hackforhiphop/permalink/762166013832016/ (Lint[5542])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/classname_sgrep.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "classname_sgrep.php", line 3, characters 10-13:
classname_sgrep.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in classname_sgrep.php, so that file should be named test.php instead. (Lint[5564])
File "classname_sgrep.php", line 4, characters 3-14:
Write Foo::class instead of 'Foo' inside calls to Classes::get(), Classes::newMock(), etc. This improves the static analysis of your code. For example: Classes::newMock(ViewerContext::class) (Lint[5542])
File "classname_sgrep.php", line 5, characters 3-5:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/cleanup_sgrep.php.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File "cleanup_sgrep.php", line 3, characters 10-13:
cleanup_sgrep.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in cleanup_sgrep.php, so that file should be named test.php instead. (Lint[5564])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/clone_usage.php.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "clone_usage.php", line 3, characters 7-20:
clone_usage.php only declares `CloneUsageTest`, it should be named CloneUsageTest.php instead. (Lint[5564])
CloneUsageTest is the only class declared in clone_usage.php, so that file should be named CloneUsageTest.php instead. (Lint[5564])
File "clone_usage.php", line 7, characters 16-17:
Objects created with `clone` will have references to shared deep objects. Prefer to implement your own explicit copy method to ensure the semantics you want. See http://php.net/manual/en/language.oop5.cloning.php (Lint[5562])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/collection_literals_1.php.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "collection_literals_1.php", line 3, characters 10-10:
collection_literals_1.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in collection_literals_1.php, so that file should be named f.php instead. (Lint[5564])
File "collection_literals_1.php", line 4, characters 14-19:
Use `Vector {...}` instead of `new Vector(...)` (Lint[5002])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/collection_literals_2.php.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "collection_literals_2.php", line 3, characters 10-10:
collection_literals_2.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in collection_literals_2.php, so that file should be named f.php instead. (Lint[5564])
File "collection_literals_2.php", line 4, characters 14-19:
Use `Vector {...}` instead of `new Vector(...)` (Lint[5002])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/collection_literals_3.php.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File "collection_literals_3.php", line 3, characters 10-10:
collection_literals_3.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in collection_literals_3.php, so that file should be named f.php instead. (Lint[5564])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/collections_sgrep.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "collections_sgrep.php", line 3, characters 10-13:
collections_sgrep.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in collections_sgrep.php, so that file should be named test.php instead. (Lint[5564])
File "collections_sgrep.php", line 4, characters 7-12:
Use 'Vector {}' instead of 'new Vector(null)'. (Lint[5542])
File "collections_sgrep.php", line 5, characters 7-9:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/csprintf_argument_unpacking.php.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File "csprintf_argument_unpacking.php", line 3, characters 10-13:
csprintf_argument_unpacking.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in csprintf_argument_unpacking.php, so that file should be named test.php instead. (Lint[5564])
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: Lint[5564] only_declares_one_function.php only declares f, it should be named f.php instead. [1]
warning: Lint[5564] f is the only function declared in only_declares_one_function.php, so that file should be named f.php instead. [1]

only_declares_one_function.php:3:10
1 | <?hh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File "linter_classname_filename_mismatch.php", line 3, characters 7-10:
linter_classname_filename_mismatch.php only declares `Test`, it should be named Test.php instead. (Lint[5564])
Test is the only class declared in linter_classname_filename_mismatch.php, so that file should be named Test.php instead. (Lint[5564])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/lowercase_constants.php.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
File "lowercase_constants.php", line 3, characters 10-10:
lowercase_constants.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in lowercase_constants.php, so that file should be named f.php instead. (Lint[5564])
File "lowercase_constants.php", line 4, characters 10-13:
Please use `null` instead of `NULL` (Lint[5001])
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/null_check_strict.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "null_check_strict.php", line 12, characters 7-7:
null_check_strict.php only declares `X`, it should be named X.php instead. (Lint[5564])
X is the only class declared in null_check_strict.php, so that file should be named X.php instead. (Lint[5564])
File "null_check_strict.php", line 16, characters 9-16:
This is a sketchy null check on an expression of type ?int.
It detects nulls, but it will also detect many other falsy values, including `false`, `0`, `0.0`, `""`, `"0"`, empty Containers, and more.
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/null_check_strict2.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "null_check_strict2.php", line 12, characters 7-7:
null_check_strict2.php only declares `X`, it should be named X.php instead. (Lint[5564])
X is the only class declared in null_check_strict2.php, so that file should be named X.php instead. (Lint[5564])
File "null_check_strict2.php", line 17, characters 8-14:
This is a sketchy null check on an expression of type ?int.
It detects nulls, but it will also detect many other falsy values, including `false`, `0`, `0.0`, `""`, `"0"`, empty Containers, and more.
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/null_check_strict3.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "null_check_strict3.php", line 3, characters 10-10:
null_check_strict3.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in null_check_strict3.php, so that file should be named f.php instead. (Lint[5564])
File "null_check_strict3.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "null_check_strict3.php", line 6, characters 8-9:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/nullsafe3.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "nullsafe3.php", line 3, characters 10-10:
nullsafe3.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in nullsafe3.php, so that file should be named f.php instead. (Lint[5564])
File "nullsafe3.php", line 4, characters 8-9:
This expression has a type lie that makes Hack type checker think it is a different type than what it inferred. It is achieved using an `HH_FIXME` comment. This can lead to fatals or subtle and latent behaviour changes. Even if the code is correct at the moment, the type checker won't produce any signal when the prerequisites for correctness change. (Lint[5806])
File "nullsafe3.php", line 4, characters 8-15:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/perf_bad_smells_sgrep.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "perf_bad_smells_sgrep.php", line 3, characters 10-13:
perf_bad_smells_sgrep.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in perf_bad_smells_sgrep.php, so that file should be named test.php instead. (Lint[5564])
File "perf_bad_smells_sgrep.php", line 4, characters 3-12:
consider keys_with_truthy_values from core/utils. array_keys(array_filter(X)) === keys_with_truthy_values(X), but keys_with_truthy_values is faster. (Lint[5542])
File "perf_bad_smells_sgrep.php", line 5, characters 3-13:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/preparables_sgrep.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "preparables_sgrep.php", line 3, characters 10-13:
preparables_sgrep.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in preparables_sgrep.php, so that file should be named test.php instead. (Lint[5564])
File "preparables_sgrep.php", line 5, characters 3-7:
genak accepts Traversable, you could pass the 2nd parameter directly without ImmSet wrapper. (Lint[5542])
File "preparables_sgrep.php", line 6, characters 3-7:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/redundant_id.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "redundant_id.php", line 3, characters 10-10:
redundant_id.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in redundant_id.php, so that file should be named f.php instead. (Lint[5564])
File "redundant_id.php", line 4, characters 8-9:
`id()` is no longer necessary here. Just use parentheses! (Lint[5501])
File "redundant_id.php", line 4, characters 8-20:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/redundant_option_mixed.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "redundant_option_mixed.php", line 3, characters 7-7:
redundant_option_mixed.php only declares `C`, it should be named C.php instead. (Lint[5564])
C is the only class declared in redundant_option_mixed.php, so that file should be named C.php instead. (Lint[5564])
File "redundant_option_mixed.php", line 5, characters 12-12:
The generic parameter `T` is unused. (Lint[5624])
File "redundant_option_mixed.php", line 7, characters 12-12:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/self_ternary.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "self_ternary.php", line 3, characters 10-10:
self_ternary.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in self_ternary.php, so that file should be named f.php instead. (Lint[5564])
File "self_ternary.php", line 4, characters 8-9:
Prefer writing `X ?: Y` (with an empty left slot) which is more readable. (Lint[5553])
File "self_ternary.php", line 4, characters 8-9:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_array.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_array.php", line 3, characters 10-13:
sketchy_null_check_array.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_array.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_array.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_array.php", line 4, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_bool.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_bool.php", line 3, characters 10-13:
sketchy_null_check_bool.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_bool.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_bool.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_bool.php", line 4, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_dict.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_dict.php", line 3, characters 10-13:
sketchy_null_check_dict.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_dict.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_dict.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_dict.php", line 4, characters 7-8:
Expand Down
4 changes: 2 additions & 2 deletions hphp/hack/test/lint/sketchy_null_check_enum.php.exp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
File "sketchy_null_check_enum.php--file1.php", line 3, characters 6-8:
sketchy_null_check_enum.php--file1.php only declares `Foo`, it should be named Foo.php instead. (Lint[5564])
Foo is the only class declared in sketchy_null_check_enum.php--file1.php, so that file should be named Foo.php instead. (Lint[5564])
File "sketchy_null_check_enum.php--file2.php", line 3, characters 10-13:
sketchy_null_check_enum.php--file2.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_enum.php--file2.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_enum.php--file2.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_enum.php--file2.php", line 4, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_keyset.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_keyset.php", line 3, characters 10-13:
sketchy_null_check_keyset.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_keyset.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_keyset.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_keyset.php", line 4, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_newtype.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_newtype.php--file2.php", line 3, characters 10-13:
sketchy_null_check_newtype.php--file2.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_newtype.php--file2.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_newtype.php--file2.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_newtype.php--file2.php", line 4, characters 7-8:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_nullable_newtype.php--file2.php", line 3, characters 10-13:
sketchy_null_check_nullable_newtype.php--file2.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_nullable_newtype.php--file2.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_nullable_newtype.php--file2.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_nullable_newtype.php--file2.php", line 4, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_vec.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_vec.php", line 3, characters 10-13:
sketchy_null_check_vec.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_vec.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_vec.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_vec.php", line 4, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/sketchy_null_check_vector.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_check_vector.php", line 3, characters 10-13:
sketchy_null_check_vector.php only declares `test`, it should be named test.php instead. (Lint[5564])
test is the only function declared in sketchy_null_check_vector.php, so that file should be named test.php instead. (Lint[5564])
File "sketchy_null_check_vector.php", line 4, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_check_vector.php", line 4, characters 7-8:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_hiding_under_unresolved2.php", line 3, characters 10-10:
sketchy_null_hiding_under_unresolved2.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in sketchy_null_hiding_under_unresolved2.php, so that file should be named f.php instead. (Lint[5564])
File "sketchy_null_hiding_under_unresolved2.php", line 8, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_hiding_under_unresolved2.php", line 8, characters 7-8:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "sketchy_null_hiding_under_unresolved3.php", line 3, characters 10-10:
sketchy_null_hiding_under_unresolved3.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in sketchy_null_hiding_under_unresolved3.php, so that file should be named f.php instead. (Lint[5564])
File "sketchy_null_hiding_under_unresolved3.php", line 8, characters 7-8:
There are no statements in the body of this `if` branch. (Lint[5556])
File "sketchy_null_hiding_under_unresolved3.php", line 8, characters 7-8:
Expand Down
2 changes: 1 addition & 1 deletion hphp/hack/test/lint/stdlib_str_usage.php.exp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "stdlib_str_usage.php", line 3, characters 10-10:
stdlib_str_usage.php only declares `f`, it should be named f.php instead. (Lint[5564])
f is the only function declared in stdlib_str_usage.php, so that file should be named f.php instead. (Lint[5564])
File "stdlib_str_usage.php", line 4, characters 7-35:
There are no statements in the body of this `if` branch. (Lint[5556])
File "stdlib_str_usage.php", line 5, characters 7-31:
Expand Down

0 comments on commit 653d1be

Please sign in to comment.