Commit Graph

54 Commits

Author SHA1 Message Date
Maximilian Goldstein e14d13bea6 qmlformat: Implement settings file
Implements controlling qmlformat via a settings file as can be done for qmllint.

[ChangeLog][General][qmlformat] Adds the ability to set linting options
via a settings file rather than using command line parameters. Use
--write-defaults to generate a template with default values for editing.
Use --ignore-settings to disable this feature.

Fixes: QTBUG-86415
Change-Id: I282c3b994ca6cc491a27b45f531f1ba1c2652ef7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-26 12:03:40 +02:00
Joerg Bornemann 0d6d3c7bc5 Skip unnecessary commands when cross-building tools
Call qt_internal_return_unless_building_tools() directly after
qt_internal_add_tool() to avoid having to special-case code for when
this function only creates imported targets in cross-builds.

Task-number: QTBUG-85084
Change-Id: I5c8f2ecdf4936cfd15cb530e896bc4e5b5531620
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-10-08 10:37:35 +02:00
Fawzi Mohamed 70dac58bd9 replace devtools library with QtQml
qmldevtools was needed when building with qmake, and to avoid circular
dependencies in the tools (before making QtQml minimal).
Now it can be avoided.
This change will make qmldom, qmlformat, qmlimportscanner and qmllint
depend on QtQml (just like the other Qml tools) and not be always
completely static (qmldevtools was always a static library, QtQml
normally isn't).

Change-Id: Idfa0a70e51f0d4999fb9753121c6c228ae69c9bb
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-07-02 12:06:21 +02:00
Maximilian Goldstein 81ad9f39af qmlformat: Use the Qt version instead of 1.0
This makes way more sense than just sticking to 1.0 forever or introducing our own tooling versioning and is consistent with qmllint.

Pick-to: 6.2
Change-Id: Id797191e6b343b97831409e8d5f888761f91b1d5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-06-22 11:06:36 +02:00
Fawzi Mohamed dc5d14c396 qmlformat: use QmlDom
Replace qmlformat with the formatter using qml dom

Change-Id: Ie90814260f2d3b9e589ce04381d5ad1880c5b519
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-05 00:08:00 +02:00
Craig Scott 63a601dc29 CMake: Remove unneeded *.pro and .prev_CMakeLists.txt files
The .pro files corresponding to the .prev_CMakeLists.txt files
have already been removed.

Change-Id: I254eafe4c7de1a516e33bd9cb3d9879e73fa83b4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2021-05-19 10:46:06 +10:00
Evgeniy A. Dushistov 45aa0853da qmlformat: fix QFSFileEngine::open: No file name specified
Since commit d48b874503 qmlformat
prints the message:
QFSFileEngine::open: No file name specified
on normal usage like:
qmlformat path/to/qml
qmlformat -i path/to/qml

This is because it tries to open the file specific by the
"files" option event if no such option was passed.

Pick-to: 6.0 6.1
Change-Id: Id14247210fc77a3f10dc25866607a9952fe81dfa
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-14 12:10:07 +00:00
Maximilian Goldstein 5f7ecce233 Implement optional chaining
This change implements optional chaining (https://github.com/tc39/proposal-optional-chaining) by adding a new type of optional lookup with an offset to the end of a chain.
If `undefined` or `null` is encountered during an access marked as optional, we jump to that end offset.

Features:
- Full support for all kinds of optional chain
- With some codegen overhead but zero overhead during normal non-optional FieldMemberExpression resolution
- Properly retains this contexts and does not need to resolve anything twice (this has been an issue previously)
- No extra AST structures, just flags for existing ones

[ChangeLog][QtQml] Added support for optional chaining (https://github.com/tc39/proposal-optional-chaining)

Fixes: QTBUG-77926
Change-Id: I9a41cdc4ca272066c79c72b9b22206498a546843
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-13 19:19:56 +02:00
Fabian Kosmale bcbd57d2a1 Remove using directive in headers
Having those in tooling headers is not really critical, but avoids some
CodeChecker warnings.

Change-Id: I33e54ca3519b79a00d582970770e8ab0b06ca742
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-19 23:43:55 +01:00
Fawzi Mohamed 6d51f997df Uniformly support shebang
The "qml" tool was the only way of loading QML files that would respect
a shebang line. This is problematic as this way you cannot load such
files programatically using QQmlComponent, limiting their re-use. Common
tools like Qt Creator, but also qmllint, qmlformat, qmlcachegen, etc
would not recognize files with shebangs.

By moving she-bang support directly in the lexer all tools implicitly
support it.
Note that we could just as easily support '#' as extra comment
character along with //, but here we narrowly add support for in
the first line only, as node does (this means that javascript files
using she-bang accepted by node, are now accepted also by qml).

The only tool needing some adjustments is qmlformat, that has to emit
the she-bang again as she-bang and as first line.
Add tests for qmlformat, and sprinkle some she-bangs in the other
tests just to be sure it doesn't affect anything.

Change-Id: I1f6d881c7438bdb23163b5dbe829d59a35d11132
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2021-02-15 18:22:27 +01:00
Furkan Uzumcu 1c35c8f71e qmlformat: Use a struct to hold the command line options
Keeping the parser and the code that uses the command line options in
the same function increases the number of lines for the same function,
making it harder to read, and the number of arguments for parseFile
function, makes it harder to understand and maintain.

This commit adds an `Options` struct to hold on to the command line
options and a build function to create the `Options` object.

Pick-to: 6.1
Change-Id: I5dec0a5a5e990f413ee65bf2eba2ea1087e0ea28
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-02-10 08:29:29 -05:00
Fabian Kosmale 78ab4b8d8b Remove the qmake project files
Remove all qmake project files, except for examples which are used to
test that qmake continues to work.

Change-Id: Ic4abb72dc2dcd75df7a797c56056b6b3c5fe62ac
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-01-15 15:34:22 +01:00
Maximilian Goldstein cf3e0559b0 qmlformat: Remove import sorting
Remove import sorting due to the fact that sorting imports can break code.

[ChangeLog][QML Tooling][qmlformat] Remove import sorting and the (now obsolete) -n parameter to disable it

Fixes: QTBUG-89295
Pick-to: 6.0
Change-Id: I5ff13d0ae3c715db7645b412152aadb31811ce5a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-12-11 11:40:12 +01:00
Maximilian Goldstein db0b7cfcb2 qmlformat: Add indent options
Adds the ability to use tabs or any amount of spaces for indentation
instead of the default of 4 spaces.

[ChangeLog][QML][qmlformat] Added option to customize
indentation.

Fixes: QTBUG-86413
Change-Id: I3c370dda2d0069ef61202a2d862ce15bc513e55e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-24 15:05:13 +01:00
Maximilian Goldstein 61417ad352 qmlformat: Make arrow functions one liners
Fixes: QTBUG-87179
Change-Id: Ieb7dffab59923bcb2ce8745c499eff7de44134b1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-10-08 09:57:47 +02:00
Maximilian Goldstein 26fa3d2cef qmlformat: Make empty objects one liners
Fixes: QTBUG-87181
Change-Id: Ic8b7f69b4f9faf907ec75f27b689ba3686eb013f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-07 13:08:19 +02:00
Maximilian Goldstein 49391fcc41 qmlformat: Fix computed property names
Fixes: QTBUG-87222
Pick-to: 5.15
Change-Id: If1da02d503041009b82651e1087fb4a1bdd79d59
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-10-07 10:43:17 +02:00
Alexandru Croitor 08adbefa13 CMake: Regenerate projects to use new qt_internal_ API
Modify special case locations to use the new API as well.

Task-number: QTBUG-86815
Change-Id: I3b964e3baf0cc7040830156dac30358ea1152801
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-10-06 13:19:37 +02:00
Maximilian Goldstein 9cfda79202 qmlformat: Fix formatting of for...of loops using array variables
Fixes: QTBUG-86980
Pick-to: 5.15
Change-Id: Id27350821051709894c7645a362cfdf7ce0d279c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-10-06 09:02:50 +02:00
Maximilian Goldstein ecd018b483 qmlformat: Fix inline components
Fixes: QTBUG-86979
Pick-to: 5.15
Change-Id: Ie8863bc2ecf75a9dd8e4af5e96e48c30e7acbacd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-05 15:14:53 +02:00
Maximilian Goldstein 5d9b0d30df qmlformat: Fix multiline comment attachment
Pick-to: 5.15
Change-Id: I3ba8a4cd683df3309dd6df31b1fd426a0875f8fa
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-04 12:33:24 +02:00
Karsten Heimrich 8b8cfb6a8e Remove last remaining use of QStringRef
Change-Id: I91685ac4cf1f5186d58252587fb8c7d7375372b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-08-23 16:45:25 +02:00
Evgeniy A. Dushistov ac68310b78 qmlformat: fix handling of "if else" inside "if" in "if else"
Fixes: QTBUG-86060
Change-Id: I7a191c451793bf4e1f6a2bd02ceb36b5957136c2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-08-20 17:23:40 +03:00
Alexandru Croitor 0f19f571ee CMake: Regenerate projects
We need the qt_add_tool changes to successfully configure qemu builds.
The rest of the changes are just to be in sync with the .pro files.

Change-Id: I7bcc08ac58f57a5761aedef09761428c55235289
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-07-09 15:51:40 +02:00
Maximilian Goldstein 48ae309fcf qmlformat: Allow for minor and major versions to be omitted
Change-Id: I85897930980bb98ba9f968cdf70696547493b1d5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-07-08 12:23:34 +02:00
Maximilian Goldstein a2969b1720 qmlformat: Fix handling of empty blocks
Empty blocks were often not handled properly.
(i.e. in if, for and while blocks)

Fixes: QTBUG-85321
Pick-to: 5.15
Change-Id: I4035dd239a095814362e0aec142b387dc113f282
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-07-02 13:47:15 +02:00
Maximilian Goldstein 9df9059a4b qmlformat: Fix template literals
Fixes: QTBUG-85317
Pick-to: 5.15
Change-Id: I52589b681690a55f7bba7d7d9c675dc22ffa1587
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-07-02 09:58:58 +02:00
Maximilian Goldstein 38e0b279d9 qmlformat: Fix multiline bindings
Some bindings may turn multiline while formatting.
This change makes sure this is handled properly.

Fixes: QTBUG-85289
Pick-to: 5.15
Change-Id: I6df98b926d69a23480003c3d9705bc34c3dd0d5d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-07-01 12:34:53 +02:00
Maximilian Goldstein d48b874503 qmlformat: Add files option
Adds a flag for formatting files listed in a file

Fixes: QTBUG-85078
Change-Id: I235db3ad52291d2c211b092b8505340728be3949
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-06-25 09:02:11 +02:00
Maximilian Goldstein eb90e8ee33 qmlformat: Fix nested functions
Fixes: QTBUG-85035
Change-Id: I5e1cb003b7b84547e3408a086eebf3be740e6860
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-06-25 09:02:10 +02:00
Maximilian Goldstein 88b3d1fd26 qmlformat: Fix inline components
Fixes: QTBUG-85189
Change-Id: I2b30595b44d14b89406b126d3d148f51f8bfbca4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-06-25 09:02:08 +02:00
Maximilian Goldstein df1f4c9a9f qmlformat: Fix nested ifs
Fixes: QTBUG-85077
Change-Id: Ia2fec64a389fd7355f3fcf9438408b021c5abef4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-06-18 12:46:17 +02:00
Maximilian Goldstein 15777b94ee qmlformat: Fix trailing newline in if blocks
Fixes: QTBUG-85003
Change-Id: Ie68c838c9bc1d52181a741871279bee5a8020855
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-06-17 13:04:42 +02:00
Maximilian Goldstein 237a0e86c7 qmlformat: Copy string literals verbatim
Copy string literals verbatim instead of reformatting them.

Fixes: QTBUG-84599
Change-Id: I36307eb30faa586f50cf0ce2660fb4e2686a3e4a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-06-17 13:04:42 +02:00
Alexandru Croitor 476d1f5760 CMake: Regenerate qtdeclarative/tools
Includes
 - A bunch of TARGET_DESCRIPTION

Change-Id: I6acfe05187afbdd45cf7e1bf8634f1554a51c791
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-05-29 10:01:19 +02:00
Maximilian Goldstein 1c0c8509da Fix 'as' binary operation using invalid types
Fixes: QTBUG-81392
Change-Id: Ic83091c547a7854b7fa86b44d93c575bd7426bae
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-05-20 13:46:36 +02:00
Qt Forward Merge Bot 2812184e1b Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/qml/jsruntime/qv4executablecompilationunit.cpp
	src/qml/jsruntime/qv4executablecompilationunit_p.h
	src/qml/qml/qqmlobjectcreator.cpp
	src/qml/qml/qqmlpropertycachecreator_p.h
	src/qml/qml/qqmltypecompiler.cpp
	src/qml/qml/qqmltypedata.cpp
	tests/auto/qml/qmlformat/tst_qmlformat.cpp
	tools/qmllint/scopetree.cpp
	src/qml/qml/qqmlapplicationengine_p.h

Adjusted tools/qmllint/findunqualified.cpp to use newer API

Change-Id: Ibfb4678ca39d626d47527265e3c96e43313873d4
2020-04-09 10:08:41 +02:00
Maximilian Goldstein 8ab467835c qmlformat: Fix inconsistent if statements
Should now produce more consistent output for if statements.

Fixes: QTBUG-82261
Change-Id: I39da0c80c4aadc2c5bdef32953c34ed9f0708a9e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-03-25 11:24:32 +01:00
Maximilian Goldstein 20370505b3 qmlformat: Improve comment attachment
- Fixes UiPublicMember nodes having a newline between comment and first node
- Implements a Front_Inline type so comments at the beginning of object
  definitions are handled properly

Fixes: QTBUG-82259
Change-Id: I0b40290037ce88a9ffe16390d72cbf3d704db41a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-25 09:01:14 +01:00
Maximilian Goldstein 4faf242d1a qmlformat: Add option for alternative line endings
Allows user to decide between native (default), macos (\r), unix (\n) or windows (\r\n)
line endings.

Fixes: QTBUG-82258
Change-Id: Ie1eb365085815cbbebbf0d026c6f72f0ef2acb9d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-25 06:15:13 +01:00
Alexandru Croitor 14492ecee2 CMake: Regenerate and adapt to merge from dev
Change-Id: If8daa6152a563d4309d7342414780ef75b9f5589
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
2020-03-12 14:05:23 +00:00
Qt Forward Merge Bot d51d5ff3c1 Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/qml/compiler/qqmlirbuilder_p.h
	src/qml/qml/qqmlpropertycachecreator_p.h
	src/qmltyperegistrar/qmltypesclassdescription.cpp
	src/qmltyperegistrar/qmltypesclassdescription.h
	src/qmltyperegistrar/qmltypescreator.cpp
	src/quick/items/qquicktext_p.h
	src/quick/util/qquickvaluetypes_p.h

Change-Id: Ic209741592e7b85820bf3845722023a190ebc1c5
2020-03-09 09:58:49 +01:00
Simon Hausmann 8ab237edf1 Restore offset/length in QQmlJS::DiagnosticMessage
This is needed in a few places outside of declarative, so this change
restores the loc member in DiagnosticMessage and moves
QQmlJS::AST::SourceLocation into common's QQmlJS namespace/directory.
QQmlError is unaffected and retains only line/column.

Amends d4d197d062

Change-Id: Ifb9d344228e3c6e9e26fc4fe112686f9336ea2b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-03-02 10:35:50 +01:00
Qt Forward Merge Bot 3e758800b4 Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
	src/imports/qtqml/plugin.cpp
	src/qml/qml/qqml.h
	src/qml/qml/qqmlmetatype.cpp
	src/qml/qml/qqmlmetatype_p.h
	src/qml/qml/qqmltypeloader.cpp
	src/qml/types/qqmlbind.cpp
	src/quick/items/qquickitemsmodule.cpp
	tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

Change-Id: I52548938a582cb6510271ed4bc3a9aa0c3c11df6
2020-02-17 10:21:59 +01:00
Fawzi Mohamed 229e3220ef qmlformat: preserve annotations
Change-Id: I22e72d91f6d422e93a7ebc642a8449cb490aec20
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2020-02-12 18:29:06 +01:00
Maximilian Goldstein 4df2438531 qmlformat: Enforce more of the coding conventions
Now also enforces:
- states and transitions being the last elements in an object
- large bindings being the last bindings

Change-Id: I8be1db4eb2bc9dd429dd5b9abab70a1362f47dfb
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-02-12 12:48:58 +01:00
Ulf Hermann 789929f939 Use QTypeRevision for all versions and revisions
In many places we carry major and minor versions or revisions that are
loosely coupled to minor versions. As the Qt minor version resets now,
we need to handle these things more systematically. In particular, we
need to add a "major" part to revisions.

QTypeRevision can express the current major/minor pairs more efficiently
and can also be used to add a major version to revisions. This change
does not change the semantics, yet, but only replaces the types.

Change-Id: Ie58ba8114d7e4c6427f0f28716deee71995c0d24
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-02-03 15:22:12 +01:00
Maximilian Goldstein e080f48f90 qmlformat: Support even more language features
Adds support (among other things) for:
- Pragmas
- Type annotations
- get / set properties
- Some previously unsupported escape sequences (\b,\v...)
- Calling methods on numeric literals

Also now checks whether the dumped code is still parsable.

Change-Id: Ia142a7c0b3e608115e79c1d98a62b682dce4eec9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-01-30 08:24:40 +01:00
Maximilian Goldstein 9e674be4fb qmlformat: Fix some language features being unsupported
qmlformat now supports:
- arrow functions
- generator functions
- this expressions
- object patterns
- regex literals
- type expressions
- plain expressions

Aborts if an error occurs during dumping now.

Also now automatically tests qmlformat against all example / test qml
files.

Change-Id: Idc24004c6f2c1cd65289bcad75985a1ef047c8d2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-01-17 10:02:29 +01:00
Ulf Hermann 728abd1dbc qmlformat: Fix default construction of Comment
m_location would be uninitialized.

Change-Id: Ieeeb0c0783a0b8e6f919019bd2ddcc1752993eaf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-01-10 21:20:13 +01:00