From fcd69822247d8a2b4960df8f4466026ff214b0c2 Mon Sep 17 00:00:00 2001 From: nicxvan Date: Sat, 28 Dec 2024 21:46:20 -0500 Subject: [PATCH 1/2] Add attributes check to ScopeIndentSniff --- .../Sniffs/WhiteSpace/ScopeIndentSniff.php | 1 + tests/Drupal/bad/bad.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php index 6da012eb..f2b04020 100644 --- a/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -962,6 +962,7 @@ public function process(File $phpcsFile, $stackPtr) T_OPEN_CURLY_BRACKET, T_COLON, T_OPEN_TAG, + T_ATTRIBUTE_END, ] ) === false ) { diff --git a/tests/Drupal/bad/bad.php b/tests/Drupal/bad/bad.php index cf249d9c..b32f11b0 100644 --- a/tests/Drupal/bad/bad.php +++ b/tests/Drupal/bad/bad.php @@ -838,6 +838,26 @@ function test28() { enum aBad_NameForAnEnum { } +/** + * Test PHP attributes. + */ +class TestPhpAttributes { + + /** + * Bar property. + */ + #[NotBlank] + private bool $bar; + + /** + * Tests method with PHP attribute and docblock. + */ + #[\ReturnTypeWillChange] + public function attributes(): void { + } + +} + /** * A test class. */ From 926bb739208afa4f9527b80346f45f4939676bd4 Mon Sep 17 00:00:00 2001 From: nicxvan Date: Sun, 29 Dec 2024 23:03:35 -0500 Subject: [PATCH 2/2] Move test cases --- .../Drupal/WhiteSpace/ScopeIndentUnitTest.inc | 19 ++++++++++++++++++ .../WhiteSpace/ScopeIndentUnitTest.inc.fixed | 19 ++++++++++++++++++ tests/Drupal/bad/bad.php | 20 ------------------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc b/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc index 582df387..7b753fd1 100644 --- a/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc +++ b/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc @@ -203,3 +203,22 @@ $has_index_value_scalar['foo']['value'] = array ( EXPECTED ], ]; + +/** + * Test PHP attributes. + */ +class TestPhpAttributes { + + /** + * Bar property. + */ + #[NotBlank] + private bool $bar; + + /** + * Tests method with PHP attribute and docblock. + */ + #[\ReturnTypeWillChange] + public function attributes(): void {} + +} diff --git a/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc.fixed b/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc.fixed index 4c74f205..a1b3fa4d 100644 --- a/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc.fixed +++ b/tests/Drupal/WhiteSpace/ScopeIndentUnitTest.inc.fixed @@ -215,3 +215,22 @@ $has_index_value_scalar['foo']['value'] = array ( EXPECTED ], ]; + +/** + * Test PHP attributes. + */ +class TestPhpAttributes { + + /** + * Bar property. + */ + #[NotBlank] + private bool $bar; + + /** + * Tests method with PHP attribute and docblock. + */ + #[\ReturnTypeWillChange] + public function attributes(): void {} + +} diff --git a/tests/Drupal/bad/bad.php b/tests/Drupal/bad/bad.php index b32f11b0..cf249d9c 100644 --- a/tests/Drupal/bad/bad.php +++ b/tests/Drupal/bad/bad.php @@ -838,26 +838,6 @@ function test28() { enum aBad_NameForAnEnum { } -/** - * Test PHP attributes. - */ -class TestPhpAttributes { - - /** - * Bar property. - */ - #[NotBlank] - private bool $bar; - - /** - * Tests method with PHP attribute and docblock. - */ - #[\ReturnTypeWillChange] - public function attributes(): void { - } - -} - /** * A test class. */