From 452a636fe83468eb6553c8e69df3b09ed90bfcf8 Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Sun, 21 Jan 2024 14:10:22 +0900 Subject: [PATCH] Fix incorrect formatting after use statements #6980 - https://github.com/apache/netbeans/issues/6980 - Fix the below case - Add unit tests Example: ```php 0) { countSpaces = ws.spaces; break; case WHITESPACE_INDENT: + if (formatTokens.get(index - 1).getId() == FormatToken.Kind.WHITESPACE_AFTER_USE) { + // GH-6980 + // namespace { + // use Vendor\Package\ExampleClass; + // $variable = 1; // add indent spaces here + // } + countSpaces = indent; + } indentLine = true; break; case INDENT: diff --git a/php/php.editor/test/unit/data/testfiles/formatting/blankLines/issueGH6980_01.php b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/issueGH6980_01.php new file mode 100644 index 000000000000..a79bc5dd6a9b --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/formatting/blankLines/issueGH6980_01.php @@ -0,0 +1,22 @@ + options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 1); + reformatFileContents("testfiles/formatting/blankLines/issueGH6980_NSWithBlock01.php", options, false, true); + } + + public void testGH6980_NSWithBlock02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 1); + reformatFileContents("testfiles/formatting/blankLines/issueGH6980_NSWithBlock02.php", options, false, true); + } + + public void testGH6980_NSWithBlock03() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 1); + reformatFileContents("testfiles/formatting/blankLines/issueGH6980_NSWithBlock03.php", options, false, true); + } + + public void testGH6980_01() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 1); + reformatFileContents("testfiles/formatting/blankLines/issueGH6980_01.php", options, false, true); + } + + public void testGH6980_02() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 1); + reformatFileContents("testfiles/formatting/blankLines/issueGH6980_02.php", options, false, true); + } + + public void testGH6980_03() throws Exception { + HashMap options = new HashMap<>(FmtOptions.getDefaults()); + options.put(FmtOptions.BLANK_LINES_AFTER_USE, 1); + reformatFileContents("testfiles/formatting/blankLines/issueGH6980_03.php", options, false, true); + } + }