From 653d1be16238a2ab907c2762dbaeca23f067f160 Mon Sep 17 00:00:00 2001 From: Catherine Gasnier Date: Thu, 24 Oct 2024 07:08:31 -0700 Subject: [PATCH] Clarify error message of linter about filename mismatch 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 --- hphp/hack/test/json/test_capitalised.php.exp | 4 ++-- hphp/hack/test/lint/as_valid_type_with_opaque_alias.php.exp | 2 +- hphp/hack/test/lint/call_user_func_array_sgrep.php.exp | 2 +- hphp/hack/test/lint/classname_sgrep.php.exp | 2 +- hphp/hack/test/lint/cleanup_sgrep.php.exp | 2 +- hphp/hack/test/lint/clone_usage.php.exp | 2 +- hphp/hack/test/lint/collection_literals_1.php.exp | 2 +- hphp/hack/test/lint/collection_literals_2.php.exp | 2 +- hphp/hack/test/lint/collection_literals_3.php.exp | 2 +- hphp/hack/test/lint/collections_sgrep.php.exp | 2 +- hphp/hack/test/lint/csprintf_argument_unpacking.php.exp | 2 +- .../only_declares_one_function.php.exp | 2 +- .../hack/test/lint/linter_classname_filename_mismatch.php.exp | 2 +- hphp/hack/test/lint/lowercase_constants.php.exp | 2 +- hphp/hack/test/lint/null_check_strict.php.exp | 2 +- hphp/hack/test/lint/null_check_strict2.php.exp | 2 +- hphp/hack/test/lint/null_check_strict3.php.exp | 2 +- hphp/hack/test/lint/nullsafe3.php.exp | 2 +- hphp/hack/test/lint/perf_bad_smells_sgrep.php.exp | 2 +- hphp/hack/test/lint/preparables_sgrep.php.exp | 2 +- hphp/hack/test/lint/redundant_id.php.exp | 2 +- hphp/hack/test/lint/redundant_option_mixed.php.exp | 2 +- hphp/hack/test/lint/self_ternary.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_array.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_bool.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_dict.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_enum.php.exp | 4 ++-- hphp/hack/test/lint/sketchy_null_check_keyset.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_newtype.php.exp | 2 +- .../test/lint/sketchy_null_check_nullable_newtype.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_vec.php.exp | 2 +- hphp/hack/test/lint/sketchy_null_check_vector.php.exp | 2 +- .../test/lint/sketchy_null_hiding_under_unresolved2.php.exp | 2 +- .../test/lint/sketchy_null_hiding_under_unresolved3.php.exp | 2 +- hphp/hack/test/lint/stdlib_str_usage.php.exp | 2 +- 35 files changed, 37 insertions(+), 37 deletions(-) diff --git a/hphp/hack/test/json/test_capitalised.php.exp b/hphp/hack/test/json/test_capitalised.php.exp index 8f9dfa10acf27f..319f43c4b02f2e 100644 --- a/hphp/hack/test/json/test_capitalised.php.exp +++ b/hphp/hack/test/json/test_capitalised.php.exp @@ -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, @@ -30,4 +30,4 @@ } ], "version":"" -} +} \ No newline at end of file diff --git a/hphp/hack/test/lint/as_valid_type_with_opaque_alias.php.exp b/hphp/hack/test/lint/as_valid_type_with_opaque_alias.php.exp index 0ecf9ec839d264..48aa46fede4a00 100644 --- a/hphp/hack/test/lint/as_valid_type_with_opaque_alias.php.exp +++ b/hphp/hack/test/lint/as_valid_type_with_opaque_alias.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/call_user_func_array_sgrep.php.exp b/hphp/hack/test/lint/call_user_func_array_sgrep.php.exp index 93e569f7b5d58b..9e05e2a8b0fc9c 100644 --- a/hphp/hack/test/lint/call_user_func_array_sgrep.php.exp +++ b/hphp/hack/test/lint/call_user_func_array_sgrep.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/classname_sgrep.php.exp b/hphp/hack/test/lint/classname_sgrep.php.exp index 9c06ec85353d51..e0c241cb0c43d3 100644 --- a/hphp/hack/test/lint/classname_sgrep.php.exp +++ b/hphp/hack/test/lint/classname_sgrep.php.exp @@ -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: diff --git a/hphp/hack/test/lint/cleanup_sgrep.php.exp b/hphp/hack/test/lint/cleanup_sgrep.php.exp index 7bdfd21c6a1e3a..384348a98bcfc6 100644 --- a/hphp/hack/test/lint/cleanup_sgrep.php.exp +++ b/hphp/hack/test/lint/cleanup_sgrep.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/clone_usage.php.exp b/hphp/hack/test/lint/clone_usage.php.exp index ac085579c52d0d..ecba68eba30165 100644 --- a/hphp/hack/test/lint/clone_usage.php.exp +++ b/hphp/hack/test/lint/clone_usage.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/collection_literals_1.php.exp b/hphp/hack/test/lint/collection_literals_1.php.exp index a1ef10fb6009b3..7d555bd117e36e 100644 --- a/hphp/hack/test/lint/collection_literals_1.php.exp +++ b/hphp/hack/test/lint/collection_literals_1.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/collection_literals_2.php.exp b/hphp/hack/test/lint/collection_literals_2.php.exp index 5b58235d1feb97..3e144baa94a4bc 100644 --- a/hphp/hack/test/lint/collection_literals_2.php.exp +++ b/hphp/hack/test/lint/collection_literals_2.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/collection_literals_3.php.exp b/hphp/hack/test/lint/collection_literals_3.php.exp index e4d16cad4f214a..244dccde612180 100644 --- a/hphp/hack/test/lint/collection_literals_3.php.exp +++ b/hphp/hack/test/lint/collection_literals_3.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/collections_sgrep.php.exp b/hphp/hack/test/lint/collections_sgrep.php.exp index e7e6b62889497e..2a8eca24db59b6 100644 --- a/hphp/hack/test/lint/collections_sgrep.php.exp +++ b/hphp/hack/test/lint/collections_sgrep.php.exp @@ -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: diff --git a/hphp/hack/test/lint/csprintf_argument_unpacking.php.exp b/hphp/hack/test/lint/csprintf_argument_unpacking.php.exp index d3b368e300ea33..c7df5ab58ee75c 100644 --- a/hphp/hack/test/lint/csprintf_argument_unpacking.php.exp +++ b/hphp/hack/test/lint/csprintf_argument_unpacking.php.exp @@ -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]) diff --git a/hphp/hack/test/lint/error_formatting_highlighted/only_declares_one_function.php.exp b/hphp/hack/test/lint/error_formatting_highlighted/only_declares_one_function.php.exp index 7a991350f47baa..d953956a42fdf4 100644 --- a/hphp/hack/test/lint/error_formatting_highlighted/only_declares_one_function.php.exp +++ b/hphp/hack/test/lint/error_formatting_highlighted/only_declares_one_function.php.exp @@ -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 |