aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlformat/data
Commit message (Collapse)AuthorAgeFilesLines
* qmlformat: Add GroupAttributesTogether optionXavier BESSON2025-11-252-0/+113
| | | | | | | | | | | | Equivalent to NormalizeOrder but reorder QML categories without sorting attributes (property definitions, property bindings, methods, signals, enums) Fixes: QTBUG-132060 Change-Id: Ib46ce4bb58ce46e3293d14954b0e363837b64b76 Original-patch-by: Oliver Kuss <oliver.kuss@okapp.de> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Fix SemicolonRule option ignored in config fileSemih Yavuz2025-11-031-0/+2
| | | | | | | | | | | | The SemicolonRule setting from .qmlformat.ini was not being applied, only the command line option took effect. Pick-to: 6.10 Fixes: QTBUG-141638 Change-Id: I471fde37c3650e872a893ce46bb5f55e9cc3158e Initial-Patch-By: Dmitry Makarenko <kryksyh@gmail.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: Support disabling formatting for script expressions via commentsSemih Yavuz2025-10-015-0/+338
| | | | | | | | | | | Extend qmlformat to allow disabling formatting for script expressions using // qmlformat off/on comments. Update ScriptFormatter and tests to verify correct behavior for various scenarios, including fuzzy and normalized modes. Task-number: QTBUG-97796 Change-Id: I56d54cca1751d41f4ea5c1d6c562e9e03e760f33 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: disable formatting of non-script expressions via commentsSemih Yavuz2025-10-013-0/+109
| | | | | | | | | | | Implement handling of // qmlformat off and // qmlformat on comments to allow selective disabling and enabling of formatting in QML files. Extend OutWriter to track disabled regions and skip formatting output accordingly. Task-number: QTBUG-97796 Change-Id: I5a0817f3229bb9916ee077d2d946c54f5dfc0c4f Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: stop moving comments around QmlObjectsSami Shalayel2025-09-303-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | Remove the workaround for QmlObject's formatting, and always create the filelocations for its `{}` tokens in qqmldomastcreator. Now that our comments are printed at the correct places, fix the wrong indentation they get by following ScriptFormatter::outWithComments()'s indentation helper: introduce a new enum IndentedCommentOption, and automatically set it for `{}[]` regions. This allows to increase/decrease the indent after/before writing comments, so that the comments get a correct indent. Adapt the existing tests to not expect comments to move around qml objects anymore, and that comments can now attach to QmlObject `{}` tokens in tst_qmldomitem.h. Task-number: QTBUG-137944 Task-number: QTBUG-97796 Task-number: QTBUG-123386 Task-number: QTCREATORBUG-33333 Change-Id: Ice3cff8a24f4b55e0b642da00b3081892abdf2a1 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io>
* qmlformat: add 'single line empty objects' optionXavier BESSON2025-08-262-0/+38
| | | | | | | Fixes: QTCREATORBUG-33333 Change-Id: Ia7eca0392418ec9b5cd13de8f6b5e263f4f09e72 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* tst_qmlformat: Rename QEXPECT_FAIL test files to show that they now passOlivier De Cannière2025-07-022-0/+0
| | | | | | | | Amends a3863b2d8bfdd2a0c138e857d3f119a5f6dfc11e Pick-to: 6.10 6.9 6.8 Change-Id: I756621e2ac6d57a555395cb69914e2d0b4431d0e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: Fix comment handling around enumsOlivier De Cannière2025-06-302-0/+22
| | | | | | | | | | | | | | | | | | Add more regions for comments to attach to. Remove special casing preventing comments to attach to the braces of an enum. It is no longer needed. The comma token belong to the enum entry after it. The opposite was assumpted to be true before which led to comments being attached to the wrong item and moving around. Task-number: QTBUG-133315 Task-number: QTBUG-123386 Pick-to: 6.10 6.9 6.8 Change-Id: I32f8c49aff6a4c88c323450beec9aa0f5bc5bbe5 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Dom: Create region for the colon token in signal param type annotationsOlivier De Cannière2025-06-302-0/+0
| | | | | | | | Task-number: QTBUG-133315 Task-number: QTBUG-123386 Pick-to: 6.10 6.9 6.8 Change-Id: I65dc2056b46b1b7a2b381805b53a6ef32c457aa3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Prevent superfluous space after Object name with commentOlivier De Cannière2025-06-302-0/+0
| | | | | | | Task-number: QTBUG-133315 Pick-to: 6.10 6.9 6.8 Change-Id: I2c3752fe900c65133a12470c567196640e142b31 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: fix crash on StatementListsSami Shalayel2025-06-062-0/+79
| | | | | | | | | | | | | | | | | | The pointer returned by ensureCommentForNode() is invalidated when the m_commentedElements map is modified, for example when inserting a new comment via another ensureCommentForNode(). In the StatementList, we actually don't need to create a comment, we just need to lookup one comment, so partially revert the apparently drive-by change from b91ca3e0bc0b7e0b1ec53b41698d2325337dae59. A separate commit will make ensureCommentForNode() private to avoid similar crashes in the future. Fixes: QTBUG-137413 Pick-to: 6.8 6.9 6.10 Change-Id: I6e281cc155e2179a880fa4a876133d90c4afae75 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* qmlformat: customizable semicolonSemih Yavuz2025-05-139-0/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add semicolon option to qmlformat. While --Always always appends semicolons to the JS statements, --essential removes the semicolons unless it is not safe to rely on ASI once semicolons are removed. Change the way EmptyStatements are handled. Prior to this commit, semicolons following if, for, foreach, while statements without bodies were added to the new line with some indentation. Make the semicolon following no-body items stick to the right paranthesis. If there is a chain of empty statements, write out a single one. [ChangeLog][qmlformat] New option semicolon-rule is added and EmptyStatement formatting behavior has changed. * Added --semicolon-rule option with modes: - --semicolon-rule=always: Always appends semicolons to JS statements. - --semicolon-rule=essential: Removes semicolons unless ASI makes it unsafe. * Changed handling of EmptyStatements: - Semicolons after control structures without a body (e.g., if, for, while) now appear directly after the closing parenthesis, instead of on a new line. - Consecutive empty statements are collapsed into a single semicolon. Fixes: QTBUG-107152 Change-Id: Ic95047a1f0077937d4c1f01328d77a3e6a4f22d6 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* test for tooling: don't pick up global settingsSami Shalayel2025-03-311-0/+2
| | | | | | | | | | | | Add dummy .ini files in the tests to stop tooling (qmllint, qmlls and qmlformat) from loading global settings. This avoids false positives where tests fail because the global configuration of these tools differ from the default one. Also copy the settings files in tests that copies the qml files into temporary folders. Change-Id: Ia904c6d4eda265e2080c1080c6b51849ab568d25 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: fix comments around class name and {}Sami Shalayel2025-03-182-0/+2
| | | | | | | | | | | | | | | | Add a comment anchor to class declarations to preserve comments around the class identifier and the `{}` braces. Make sure that invalid sourcelocations are not used as comment anchors. Also remove extra preVisit()/postVisit() calls that did print comments twice! Pick-to: 6.9 6.8 Fixes: QTBUG-133316 Task-number: QTBUG-123386 Change-Id: I04f06fdb4c8f7b69d7483238116f0d0358bf13ed Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Add missing space in JS class methodsSami Shalayel2025-03-183-8/+8
| | | | | | | | Add missing space in JS class methods. Fixes: QTBUG-119404 Change-Id: Ife43bc86ff51183f9aab79254d3492fba1d8b401 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: add custom comment anchoring for caseSami Shalayel2025-03-182-0/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a way to customize where comments are anchored. Prior to this commit, comments could only be anchored to an AST::Node firstSourceLocation() or lastSourceLocation(). This commit extends the current functionality to be able to anchor comments somewhere between firstSourceLocation() and lastSourceLocation(). This allows to fix the bug where comments would be printed before the ":" in case statements, because they would get attached to the expression inside the case-statement, instead of getting attached to the colon of the case-statement. Extend AstRangesVisitor to add the sourcelocation of the ":" in case- statements to the list of sourcelocations where comments can be attached to. The anchors enum is not meant to be extended: instead, an anchor is either DefaultAnchor for comments attached to AST::Node*, or token.begin() for some QQmlJS::SourceLocation token inside an AST::Node*. Pick-to: 6.9 6.8 6.5 Fixes: QTBUG-132886 Change-Id: I0a18f09b3631b8798b6697298e532b47ddc7cb20 Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Support the final property attributeOlivier De Cannière2025-03-062-0/+32
| | | | | | | | | Note that any actual language support for final will be added in later commits. Task-number: QTBUG-98320 Change-Id: I8b8f9fbc998219ed4cd504c10f54bc3483e65f06 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Error out when no input files are providedOlivier De Cannière2025-02-193-0/+6
| | | | | | | | | | | | | | | | | | | | | | qmlformat now errors out if -No input is provided as a positional argument and -F is not set -A positional argument does not exist -Option -F is set but the file does not exist -Option -F is set but the file is empty -Option -F is set but the file points to a file that doesn't exist TestQmlformat::testFilesOption was modified to no longer try to format a nonexistent file. That should now get rejected early. TestQmlformat::settingsFromFileOrCommandLine was modified to pass at least one file to prevent an error. [ChangeLog][Qml][qmlformat] qmlformat will now error out if no files are provided as positional arguments or via the -F option. Pick-to: 6.9 6.8 Change-Id: I7f900242c3e9e9041c9a08057a7e898e26c17493 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Accept `from` as an identifierOlivier De Cannière2025-02-034-0/+24
| | | | | | | | | | | | | From is defined as an identifier with a special meaning in the context of imports. This means it should generally be accepted as an identifier in other contexts. This fixes weird line indentation issues with the IndentingLineWriter. Fixes: QTBUG-132065 Pick-to: 6.9 6.8 Change-Id: Iea5bf3af5d43af9a97f0f8e7867d12337e4041ca Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* line-by-line format: Fix state transitions for property definitionsOlivier De Cannière2025-02-032-0/+16
| | | | | | | | | | | | | | | The line-by-line formatter would in certain cases considier that a property definition was completed after having seen only the `property` token. Fix the state transition to also handle T_RESERVED_WORD tokens. Picking this back to previous versions is not trivial as this particular situation seems to break in different ways first. Fixes: QTBUG-133398 Pick-to: 6.9 Change-Id: I1123fe41e55d2d31c5d245dafe6c8684bca93e39 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Have the outWriter ensure spaces instead of adding themOlivier De Cannière2025-01-3114-0/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When formatting comments we try to preserve the spacing that the user used around them. We keep track of how many spaces come before and after a comment and insert them back accordingly. However, when we continue to write out the following tokens we add spaces to separate them. This space was being inserted unconditionally. This could lead to a space being accounted for twice for certain comment configurations. Once by the recorded amount of spaces after the comment and once by the standard space to separate tokens. This would lead to spaces being inserted in the formatted code that weren't there originally in the user's code. One space would be inserted like this for every format call. To solve this, don't unconditionally insert a space to separate the tokens but only make sure there is a space. This issue can be reproduced in many "places" of the grammar. This patch eliminates a good amount of them but not all. Created QTBUG-133315 and QTBUG-133316. Fixes: QTBUG-131386 Pick-to: 6.9 6.8 Change-Id: I25ac67f49a0198047912ef3f04dda3afc5cb9f66 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: fix precedence of settingsSemih Yavuz2025-01-291-0/+8
| | | | | | | | | | | Options set through commandline should have the precedence over the settings read from .ini file. Introduce a mapper in the setting, that marks the option if set by command line input. Add more tests. Pick-to: 6.8 6.9 Fixes: QTBUG-133225 Change-Id: Id0b18655f7bf64670dab4e38f5aff2fdaa889f1b Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: move configuration functions into librarySemih Yavuz2025-01-291-0/+8
| | | | | | | | | | ...Then we can add tests for them. More tests to be added in the next commit. Pick-to: 6.8 6.9 Task-number: QTBUG-133225 Change-Id: I3f40ddc3d0895a785d6bce359c63ad6ad4d70606 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Preserve "?." tokens for various member access expressionsOlivier De Cannière2025-01-292-0/+12
| | | | | | | Fixes: QTBUG-132280 Pick-to: 6.9 6.8 Change-Id: I9307a70eea4640da19124f65e49cb3c661d443a1 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Reorder imports alphabeticallyOvidiu Tepescu2025-01-132-0/+49
| | | | | | | | | | | Reorder imports alphabetically. [ChangeLog][qmlformat] qmlformat now supports sorting of imports, there is a new commandline option -S that is used to sort imports. Fixes: QTBUG-132061 Change-Id: Ic163456d2beed84833f7aadef0688d37292ef0f2 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmlformat: respect the type annotated signal formSemih Yavuz2024-09-032-0/+10
| | | | | | | | | | | A qml signal can have both a(int x) and a(x: int) form. qmlformat currently converts the type annotated signal form into type prefixed form. It should respect the order. Pick-to: 6.7 6.8 Task-number: QTBUG-128423 Change-Id: I746ea66949abc72e8012974b3fb0a06878950b77 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Do not remove the enum items' default valueSemih Yavuz2024-06-052-0/+24
| | | | | | | | | | | | | | | | Figuring out if the enum item has an explicit value is quite error-prone in dom. Instead, retrieve this information from the parser by checking if the value token exist. Introduce an enum that tracks if enumitem's value is explicitly set or not. Also, fix incorrect region mapping while writing out the enum item dom element. Fixes: QTBUG-125914 Pick-to: 6.8 6.7 6.5 Change-Id: I911621b215de09ff3f18279d83881bc9421080c2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Preserve up to 1 empty line between statementsLuca Di Sera2024-04-117-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `qmlformat` processes a `ScriptExpression` such as the `onClicked` body in the following snippet: ``` import QtQuick MouseArea { onClicked: { console.log("start"); console.log("end"); } } ``` It will remove every empty lines between statements. For example, in the above snippet, the two log statements will be on successive lines in the formatted output, removing the empty line in-between them in the original version. `qmlformat` will now, instead, allow up to 1 empty line to be preserved between statements, if at least one empty line is present in the original version. The formatting for `StatementList`s in `ScriptExpression`s is handled by the relevant overload of `ScriptFormatter::visit`. The code relative to inserting newlines in-between statements in the list was modified to take into account the possible presence of additional empty lines in between the statements, outputting an adequate amount of newlines to preserve up to 1 empty line. The utility method `ScriptFormatter::newLine`, which is used to output a single newline character, was modified to take a parameter representing the amount of newlines that should be added, allowing multiple newline characters to be written by a single call. A non-exhaustive test-case for the new behavior was added to track it. Certain pre-existing snapshot test-cases were modified to be in line with the new output of `qmlformat`. Fixes: QTBUG-123864 Change-Id: I552d1f7ce2c035b9087cb60a3b6e3480c5ae969a Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QMLFormat | Support ESM formattingDmitrii Akshintsev2024-03-204-0/+100
| | | | | | | | | | Adding tests for Ecmascript Module formatting Change-Id: Iaac7be13d9c1ed1119afc5ebdd9b09a990ed944a Task-number: QTBUG-123386 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Correct license for test filesLucie Gérard2024-02-274-4/+4
| | | | | | | | | | | | | | According to QUIP-18 [1], all test files should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I26d72e8de04d4c7c57b3b7838af5d033265de5ba Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Kai Köhne <kai.koehne@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QmlFormat: Support .js files (CLI tool)Dmitrii Akshintsev2024-01-254-0/+30
| | | | | | | | | | | | This commit contains last pieces of changes necessary for the formatting of .js files using qmlformat CLI. What's not included: normalize && function spacing for .js files Task-number: QTBUG-117849 Pick-to: 6.7 Change-Id: I6a4260f074ce05ce07cdcff185a1cf7737d3a44c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: Don't add unnecessary newlines in empty JavaScript blocksJoshua Goins2024-01-212-0/+11
| | | | | | | | | | | When an empty JavaScript block is formatted then don't put in a newline and keep the braces on the same line. An additional test is added as an example. Pick-to: 6.5 6.6 6.7 Change-Id: I01c8f09d43a91b91312bc1c94b153eaff1f55818 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* qmlformat: Don't add unnecessary newlines in empty objectsJoshua Goins2024-01-2015-48/+31
| | | | | | | | | | | | | Empty component and object declarations are now collapsed, instead of putting the ending right brace on a new line. This makes code that uses these more readable and reduces the amount of lines used. The test data is updated to reflect this new behavior. Fixes: QTBUG-108660 Pick-to: 6.5 6.6 6.7 Change-Id: Ifecfa2a37d5f787a89718ddcdefba17f305b181c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmlls: fix formatting of commentsSami Shalayel2024-01-164-0/+33
| | | | | | | | | | | | | | | | Fix formatting of comments in qmlls by not formatting a DomItem that was constructed with the "WithScriptExpression" option. Instead, create a new Dom representation without the problematic option. This is required to fix the CI failure of the 'qmlls: fix QmlObject and type annotation completion' commit in the relation chain. Fixes: QTBUG-120484 Pick-to: 6.7 Change-Id: Ic474728455a4938b0e28f4bd4f759d9fc7efef24 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Fix property names with escape charsSemih Yavuz2024-01-102-0/+31
| | | | | | | | | | | | Formatter was breaking the string literal property names if they consisted some escape sequences. Remove the complicated logic for rewriting, instead use the same literal that was scanned and assigned to propertyName. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-113776 Change-Id: I87d8c31d4893001e784536302e33f1f517f21acd Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Don't indent call expression twiceJoshua Goins2023-12-132-22/+22
| | | | | | | | | | | This is common when passing properties to functions, which are inside of a new block. The test data is changed to accommodate this new expected behavior. Pick-to: 6.5 6.6 6.7 Change-Id: I27e19468ff3af11ffcacf38cafec4754fb9ec5d7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Fix object declaration indentation in arraysJoshua Goins2023-12-124-5/+21
| | | | | | | | | | | | | Object declarations inside of array patterns did not insert newlines correctly. This fixes those while not touching other types of array initializations (such as numeric literals) and the one of test data. When extra commas are added to the end of arrays, they are now kept on the correct line as well. Pick-to: 6.5 6.6 6.7 Change-Id: I8fe67ef066b84f56237449c7695990daa915b4b6 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Don't remove newlines between import statementsJoshua Goins2023-12-083-0/+22
| | | | | | | | | | | | When writing QML files, it's common to use newlines to separate groups of import statements (e.g. separating imports from Qt and your own.) Now qmlformat will preserve the newline grouping, but ensure that it's only one newline and will strip out extra ones. A test is added to ensure this does not regress. Pick-to: 6.5 6.6 Change-Id: I8f158c46886bc0be2313a0e57d6b7c52a1df28fa Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlFormat: Support .js files (in memory formatting)Dmitrii Akshintsev2023-12-0724-0/+99
| | | | | | | | | | | | | | | | | Previous commits in the stack introduced the possibility of loading .js files to the DOM environments and keeping the content inside the corresponding JSFile abstraction. This commit introduces 1. writeOut method for the JSFile required by the qmlformat 2. formatting of .import .pragma library directives & helper objects 3. Adding support of JSFile in OutWriter::updatedFile 4. Tests covering in Memory formatting Task-number: QTBUG-117849 Change-Id: I741f06058aec8a280f64b05a755d25fc8fe1d1f7 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: fix formatting with -F optionSemih Yavuz2023-10-164-0/+38
| | | | | | | | | | qmlformat accepts -F option to format a list of files given in another file. That should supposed to be inplace, but qmlformat would send output to stdout. To fix this, force inplace formatting if the options.files are not empty. Change-Id: If62dd3edde91460eba5812b1d7aea1b7422f46bf Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: fix object destructuring, take 2Semih Yavuz2023-09-122-9/+100
| | | | | | | | | | | The previous commit was omitting writing the binding targets. Fix it and add more complicated object destructuring tests. Amends 115916f217b0dc299b8df298f5c9c30369f561f8 Pick-to: 6.6 6.5 Change-Id: Iec994dace3b2c15e2c8826086466e66b70304e1a Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: correctly handle rest operator in method parametersSemih Yavuz2023-09-122-0/+24
| | | | | | | | | | | | Method parameter can have the rest operator leading to an identifier or a binding element. So far this is not represented in MethodParamter dom item. Initialize a new field "isRestOperator" and populate that information when creating method parameter dom item. Task-number: QTBUG-116392 Pick-to: 6.6 6.5 Change-Id: I701390b8ec1e323628072d43796c40499c4d56e1 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: fix incorrect destructuring of objectsSemih Yavuz2023-09-122-0/+33
| | | | | | | | | When creating dom objects, we populate MethodParameter::value for object or array deconstruction in function arguments but we don't write them out. Pick-to: 6.6 6.5 Change-Id: Id02ac6ac28ec8ae3d25a2f37de3361ecff3a3bf6 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Don't add unnecessary space in target bindingsJoshua Goins2023-08-116-6/+6
| | | | | | | | | | | | qmlformat was erroneously adding an extra space in target bindings like "Behavior on opacity {". The extra space is removed, and the tests are updated to prevent regression for this behavior. Fixes: QTBUG-114801 Pick-to: 6.5 6.6 Change-Id: I79f563e40c75a325ab13f1fbffd73daa71fe1ec9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* qmlformat: fix formatting of object destructuringSemih Yavuz2023-08-013-3/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following issues are fixed: - [1]Incorrect detection of the property name as a string literal and thus writing out them with quotation marks - [2] Duplication of property name when a scoped variable is used as property key - [3] Writing out additional brackets during deconstruction - [4] Incorrect formatting when a default is assigned to a lhs variable like [a = 24, b] = array - [5] Automatic addition of "" characters into the object keys - [6] Automatic addition of assignment operator, instead only add it when there is a pending initializer Also, add the colon token location which was missing in the pattern property rules. Remove it from a couple of rules that was giving incorrect result. We require the location information of the colon token to be correct when formatting. A few of tst_qmlformat and tst_reformatter tests are adapted to the above mentioned changes [1], [2], [5]. [ChangeLog][qmlformat][Important Behavior Changes] qmlformat will no longer add "" characters automatically in the object keys unless the object key is actually a string literal. Also, using a scoped variable as the property key will no longer result in the duplication of the property name. Pick-to: 6.6 Fixes: QTBUG-108275 Fixes: QTBUG-114839 Change-Id: I272d41d13df34ff5877f3efebe43c80255dd7c2b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: Handle pragma directive correctlySemih Yavuz2023-06-092-0/+16
| | | | | | | | | | | | | Dom representation for pragma used to be created by leaving out pragma directive value list. That caused qmlformat to remove the corresponding list. Fix it by including value list while creating dom for pragma. Fixes: QTBUG-114364 Pick-to: 6.5 6.6 Change-Id: I87f6e324452f196c147f5606f15c01e22caa39a5 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: change comment handling behaviorSemih Yavuz2023-04-127-1/+37
| | | | | | | | | | | | | | | | | | | | | | Cumulative commit for adding zero-length comments in qmljsengine and also handling of empty lines after comments. qmljsengine only adds comments if the relavant comment length is larger than 0. Allow adding zero length comments since empty comments might be useful and required in some situations. Unlike the other formatting tools (clang-format, rustfmt) qmlformat didnt respect the emptylines after comments and stick the comments to the associated element. Change this behavior such that a newline/ blankline is added(but no more than one). A few tests in qmldom/reformatter needed to be edited due to this new behavior. Pick-to: 6.5 Fixes: QTBUG-111231 Change-Id: I2fcdda0bfe569b7a1d19c4058e1604cb0d73291d Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Fix handling of object destructuring in functionsFabian Kosmale2023-03-022-0/+18
| | | | | | | | | | We weren't considering the bindingTarget of PatternElements, which broke functions using object destructuring in the parameter list. Fixes: QTBUG-111511 Pick-to: 6.5 6.5.0 6.2 Change-Id: Ie22fed2160538bf0c5733b5aced0fdac64621346 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Add ECMAScript class reformatterSemih Yavuz2023-01-262-0/+82
| | | | | | | | | | | qmlformat currently discards ES classes, and only reformats the element list inside that class. Implement a class declaration visitor which reformats ES classes in qml file. Pick-to: 6.5 6.2 Fixes: QTBUG-110321 Change-Id: I9fa2561902dbcfde5e8fb041bc5dedcc56bb66cc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: fix omitting some comments while reformattingSemih Yavuz2023-01-232-0/+26
| | | | | | | | | | | | | | | We rewrite comments associated to a node on the preVisit call (if they were marked as preComment), or postVisit( if comments were marked as postComments) of the reformatter. If the comment associated with a patternProperty kind of node, neither of these functions are called. Add missing call to previsit/postVist in the pattern property node visit. Pick-to: 6.4 6.5 Fixes: QTBUG-109074 Change-Id: If57968b3f5dbd83aa23dc2cd2bca3608ee841d49 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>