aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlformat
Commit message (Collapse)AuthorAgeFilesLines
* qmlformat: Add GroupAttributesTogether optionXavier BESSON6 days3-0/+129
| | | | | | | | | | | | 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-032-0/+13
| | | | | | | | | | | | 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: Add argument to output available optionsXavier BESSON2025-10-301-0/+101
| | | | | | Task-number: QTCREATORBUG-33305 Change-Id: I9e23a755da0354ab1d64b7f50ff6f9cc7acbe85a Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Support disabling formatting for script expressions via commentsSemih Yavuz2025-10-016-0/+352
| | | | | | | | | | | 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: expand OutWriter's constructorSemih Yavuz2025-10-011-2/+2
| | | | | | | | | | | | | | | | code and comment location information is needed by OutWriter to scan format directives. Allow these to be created at OutWriters' construction. Get this informations through ExternalOwningItem interface. Unfortunately, ExternalOwningItem interface won't provide comment() or engine(). Use derived types to get that information for JSFile and QmlFile. Task-number: QTBUG-97796 Change-Id: I57ef2a3a52579dd5698219a6e6ac9449c113d080 Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: disable formatting of non-script expressions via commentsSemih Yavuz2025-10-014-0/+153
| | | | | | | | | | | 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-304-7/+67
| | | | | | | | | | | | | | | | | | | | | | | | 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-263-0/+46
| | | | | | | Fixes: QTCREATORBUG-33333 Change-Id: Ia7eca0392418ec9b5cd13de8f6b5e263f4f09e72 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* tst_qmlformat_cli: make sure qmlformat settings stay stableSami Shalayel2025-08-181-0/+15
| | | | | | | | Add a test to make sure that the keys stay stable, and don't get changed in the future. Change-Id: If5a4c06d4f821fd4f6269e61bbb89bd120e79243 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* tst_qmlformat_cli: also test default values for semicolonruleSami Shalayel2025-08-181-0/+3
| | | | | | | Add a test for the default value of the semicolon rule. Change-Id: Id2e52bbc277707ef042675a4f91254a072a98c37 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* tst_qmlformat_cli: remove hand-written keysSami Shalayel2025-08-141-21/+32
| | | | | | | | | | Remove the hand-written keys from the test and use the static strings instead. One of the previous hand-written key had a typo. Also make sure that the settings are really set, as QVariant::toBool() returns false for a unset settings, for example in the case of the key with the typo. Change-Id: I15da10409fbf374a475dc3930844fd56120f370a Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* tst_qmlformat: run on commentInEnum and commentInQmlObject.qml filesSami Shalayel2025-08-071-0/+5
| | | | | | | | | | Amends ff6d16d58bef108b7bbe35aa8e9d79dd3a2ea872 that added the files but didn't use them. Task-number: QTBUG-138896 Pick-to: 6.10 6.9 6.8 Change-Id: I1835e2a8db9e374628da7bb8e16c39d876dc9d91 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* qqmltoolingsettings: refactor search()Semih Yavuz2025-07-181-1/+1
| | | | | | | | | | | Return structured result instead of bool from search(). Update search() and read() to adapt the return. Add an isValid() convenience method to return type. Refactor search implementation into separate helper methods. Task-number: QTBUG-107212 Change-Id: I858951f0d4a7714eff01a3e6fcf96f92e2684ae1 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* tst_qmlformat: Rename QEXPECT_FAIL test files to show that they now passOlivier De Cannière2025-07-023-3/+3
| | | | | | | | 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-303-2/+24
| | | | | | | | | | | | | | | | | | 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-303-5/+3
| | | | | | | | 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-303-4/+2
| | | | | | | 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-063-0/+81
| | | | | | | | | | | | | | | | | | 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-1310-0/+198
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Tests: include QTest, not QtTestGiuseppe D'Angelo2025-04-152-2/+3
| | | | | | | | | | | | | Never use module-wide inclusions. They blow up build times. For QtTest this is usually just a typo (QTest was meant instead). Add missing includes as needed. In the diffs I've spotted other huge inclusions (QtQuick, QtQml), but those need more attention. Task-number: QTQAINFRA-7110 Pick-to: 6.9 6.8 Change-Id: I74bf3fe212f50a7a3a6af2b1c80bbcaabc2516d7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_qmlformat: fix an uninitialized variable usageGiuseppe D'Angelo2025-04-101-1/+1
| | | | | | | | | | | | | | | GCC rightfully complains that /home/qt/work/qt/qtdeclarative/tests/auto/qml/qmlformat/tst_qmlformat.cpp:263:21: warning: ‘writtenOut’ may be used uninitialized in this function [-Wmaybe-uninitialized] 263 | *didSucceed = writtenOut; | ~~~~~~~~~~~~^~~~~~~~~~~~ because if we don't enter the if, we never initialize writtenOut. Initialize it. Pick-to: 6.9 6.8 Change-Id: I6d3bb8038e524773a11b3333bf65654593f01da9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* test for tooling: don't pick up global settingsSami Shalayel2025-03-312-0/+5
| | | | | | | | | | | | 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>
* tst_qmlformat: move cli stuff to tst_qmlformat_cliSami Shalayel2025-03-313-487/+550
| | | | | | | | | Move the tests that require spawning a qmlformat process into tst_qmlformat_cli. Fixes: QTBUG-134669 Change-Id: I38f2e624bcd6152074604663bc4a626783097bda Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* tst_qmlformat: move common functionality into headerSami Shalayel2025-03-313-156/+174
| | | | | | | | | Prepare for the splitting of tst_qmlformat into tst_qmlformat_cli by moving the base into a header. Task-number: QTBUG-134669 Change-Id: I76fbdf2f9d31a2e160d6ae0389a409c2214d36da Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* tst_qmlformat: extract common code into base classSami Shalayel2025-03-311-153/+158
| | | | | | | | | Prepare for the splitting of tst_qmlformat into tst_qmlformat_cli by extracting common functionality into a base class. Task-number: QTBUG-134669 Change-Id: I66a72b128802a51b0289320e6022bd69c6cfe4ff Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* tst_qmlformat: clean up in-process formatting methodSami Shalayel2025-03-311-116/+70
| | | | | | | | Remove the unused arguments and run clang-format on it. Task-number: QTBUG-134669 Change-Id: I1aff620feb26a160f4330807a56a5985c7c5fc12 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* tst_qmlformat: prefer in-process formatting instead of out-of-processSami Shalayel2025-03-311-143/+174
| | | | | | | | | | | | Move all the tests from testFormat() to a newly added qml() function that do not seem to test any command line parameters. The qml() function runs the tests in-process instead of spawning extra qmlformat processes. Task-number: QTBUG-134669 Change-Id: I99bfd8a840c31cd2b0a4c889c0f0ca39b8c73eb2 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-184-10/+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-183-0/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-063-0/+36
| | | | | | | | | 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>
* tst_qmlformat: Clean up testFilesOptionOlivier De Cannière2025-02-191-16/+12
| | | | | | | | | The test would leave behind the temporary directory it created and would fail to detect when qmlformat returns with a non-zero value. Change-Id: Ib6c5a43599aea5d8f7bfec9d6a13059a7386e133 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Error out when no input files are providedOlivier De Cannière2025-02-194-9/+34
| | | | | | | | | | | | | | | | | | | | | | 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>
* tst_qmlformat: Rework commandLinesOptions testOlivier De Cannière2025-02-191-7/+4
| | | | | | | | | | | | The `file` argument of the test is copied to a temporary file which is then immediately overwritten by the output of the qmlformat process. Remove the `file` argument and don't copy it. Pick-to: 6.9 6.8 Change-Id: Ic9ec826cdf521559facf63172f9dc7f08215c199 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmlformat: Accept `from` as an identifierOlivier De Cannière2025-02-035-0/+30
| | | | | | | | | | | | | 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-033-0/+20
| | | | | | | | | | | | | | | 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-3115-0/+148
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: add test for applying settings for files optionSemih Yavuz2025-01-291-0/+10
| | | | | | Pick-to: 6.8 6.9 Change-Id: I65b430362895259d8b91f064426e34d71eaf2c72 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: fix precedence of settingsSemih Yavuz2025-01-292-0/+73
| | | | | | | | | | | 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-293-0/+60
| | | | | | | | | | ...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: fix --write-defaultsSemih Yavuz2025-01-291-0/+31
| | | | | | | | | | Prior to this commit, --write-defaults was only writing the subset of the existing settings. In fact, each setting has a default value and those should be seen in the .qmlformat.ini file to be written. Pick-to: 6.8 6.9 Change-Id: Ie7f8fac653d0bc7099821136f5ad8ce8ee14c714 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: Preserve "?." tokens for various member access expressionsOlivier De Cannière2025-01-293-0/+14
| | | | | | | 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-133-0/+53
| | | | | | | | | | | 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: fix error message outputSemih Yavuz2025-01-091-0/+50
| | | | | | | | | | | | | | We don't need m_valid to check if there is an error. Do validity check by m_error.isEmpty(). Prior to this commit, an invalid command line option given to qmlformat wouldn't spit out the error message and qmlformat would silently ignore the error and run with default settings. For example, the command qmlformat -W -342523 <filepath> should error out with this commit since a negative line length is given. Change-Id: Ie7d07e3b2b3714793f9abed4558003cc5ad77b34 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlformat: respect the type annotated signal formSemih Yavuz2024-09-033-0/+13
| | | | | | | | | | | 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-053-1/+27
| | | | | | | | | | | | | | | | 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: "Move" testExample e2e tests to /manualDmitrii Akshintsev2024-04-231-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | testExample, normalizeExample and actually most of the tests in tst_qmlformat are e2e tests and in general QmlFormat lacks unit test coverage, compensating it with e2e. The biggest problem atm that some of those tests (namely testExample) take too much time to execute because it runs QmlFormat over almost all files in examples and tests directories. Unfortunately atm our QA&QE infra can't provide tools for an easy automated setup of potentially time-consuming tests. As a workaround this commit: 1. "Moves" testExample and normalizeExample to the /manual tests 2. Preserves a very small fraction of testData for automated testing "just in case" Steps to repro: 1. configure with the flag `-make manual-tests` 2. `ninja e2e_qmlformat` 3. run ;) Fixes: QTBUG-122990 Change-Id: Id41baee15e8826f4def5787f62790ed46f00e5dc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: Preserve up to 1 empty line between statementsLuca Di Sera2024-04-118-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Tests: check that QFile::open succeedsGiuseppe D'Angelo2024-04-041-1/+2
| | | | | | | | | | Wrap it in QVERIFY if possible. If not possible (e.g. a function that returns non-void, or not an autotest function) use qFatal to abort the test. Change-Id: Ie255024d29507e928a94e67d9af1cd436df4f1df Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QMLFormat | Support ESM formattingDmitrii Akshintsev2024-03-205-8/+151
| | | | | | | | | | 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>