Commit Graph

99 Commits

Author SHA1 Message Date
Maximilian Goldstein 171219a5cc qmllint: Fix some settings not being checked properly
Previously some settings were only checked before any settings file
could be loaded, thus resulting in misapplied settings.
Now every settings option will be applied on a per-file basis as it
should be.

Pick-to: 6.2
Change-Id: Ib7c8a8d7dbec2d4379f634488e3899e1746c0c51
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-29 17:49:13 +02:00
Maximilian Goldstein 363c233575 qmllint: Fix crash when builtins are not found
Previously builtins not being found would lead to an endless loop that
crashes qmllint. Now missing builtins are handled gracefully,
aborting linting without crashing as this an unrecoverable error.

Change-Id: Ia585b1e0e5c972dad0eeabf8df06edf71eaea0c7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-10-29 17:49:13 +02:00
Ulf Hermann 6b33e7cff3 qmllint: Don't leak the QQmlJSTypeInfo object
We want it to be mutable even where Codegen itself is const. Therefore,
it needs to live outside Codegen.

Change-Id: Ie4997118a1fdf8d60bd5670baa506ed0bfb98bad
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2021-09-30 12:48:57 +02:00
Fabian Kosmale 466edbf12c Remove obsolete bootstrap code
Change-Id: Ifcbf81b5ee04753af916dc1ef1177617785c961d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-09-30 12:48:57 +02:00
Maximilian Goldstein 655c8ec05f qmllint: Put warning options at the top
This puts them right below the description of warning levels and hopefully makes the whole help easier to read.

Task-number: QTBUG-95971
Change-Id: Iff6062e700c2c277fc4c69a8130ba6b2dd5e35c0
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-08-26 15:43:32 +02:00
Andrei Golubev 07f9525f3e Decouple QQmlJSLogger from QQmlImportVisitor
QQmlImportVisitor was accepting ctor paratemeters for the QQmlJSLogger,
creating own logger internally. This seems wrong since in that case we
kind of have separate logger for visitor and type resolver (among other
entities)

On top of this, the import visitor had a silent logging by default
(and the QQmlJSLogger is not silent on the contrary) which in fact hid
some issues that should've been reported by qmllint (but they weren't)
For consistency, the silent logger is still used. And the ultimate fix
would be to use FindWarningsVisitor instead of QQmlJSImportVisitor
as currently we do 2 AST traversals in qmllint

Change-Id: I4c54b76d130e7e8f31c90a148edc1c02f7e86ab8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-08-19 08:33:33 +02:00
Maximilian Goldstein ef07501652 qmllint: Move use-before-declaration warning out of checkidentifiers
Another step to making checkidentifiers obsolete.

Change-Id: I14be7491387200101b66e0930faf16e9b61d4159
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-08-04 17:15:22 +02:00
Maximilian Goldstein 2eb6d20246 qmllint: Use type propagator to provide unqualfied access warnings
Do not rely on checkidentifiers to provide unqualified access warnings anymore. Using the type propagator ought to be more accurate and will help remove the relatively hacky checkidentifiers code completely later on.

Change-Id: I40cc040b9455962abbd2ec84cdb494fcec1ab79d
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-07-27 09:43:23 +02:00
Maximilian Goldstein 44c46c15c0 qqmljstypepropagator: Use logger system
In order to properly integrate the type propagator into qmllint we need to use the logging system instead of qWarning().

Change-Id: Ie9840066f8afa3d7f8a63a69444b6dc20c41a706
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-07-07 14:03:24 +02:00
Maximilian Goldstein 67894892da qmllint: Integrate type inference warnings
This change helps bring in type inference and compiler warnings previously only generated by qmlcachegen+.
These warnings are disabled by default and have to be enabled manually via the --compiler option.

Also makes the logger handle zero length SourceLocations properly by just highlighting the entire line instead of hitting an assert.

Change-Id: Iebad6e9236214d9367f97487e7b5787592edab7d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-07-07 14:03:21 +02:00
Craig Scott 7365b0d1c6 CMake: Run qmllint on the qml files in the source tree
In order to use the source tree files, qmllint needs to know where they
will end up in the resource system. The source files could be at any
arbitrary location and have their resource path set by a
QT_RESOURCE_ALIAS source file property. Therefore, we have to give the
generated .qrc files to qmllint so it can work out where each source
file will end up.

The qmllint command previously only supported a single --resource
option, but now we need to potentially pass more than one .qrc file.
Extend qmllint to allow multiple --resource options to be given, in
the same way that multiple -I options can be given.

Task-number: QTBUG-94761
Pick-to: 6.2
Change-Id: Ibeb6541e1f54bea6eeeccd07426dd238b0459ff2
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2021-07-07 12:07:48 +10:00
Maximilian Goldstein 3b3d0c6f3c qmllint: Implement severity levels
qmllint now supports logging levels of different severities. Still lacking a good way to toggle the verbosity more granularly though (i.e. disabling only info messages while still receiving the rest).

Change-Id: I71abddcdf1adf60315a87d776af8085acf7aeffe
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-07-02 17:25:21 +02:00
Maximilian Goldstein b4cc56e6bf qmllint: Remove deprecated options
We kept these around for compatibility in Qt 6.2 but now it's time to get rid off them

[ChangeLog][QtQuick][qmllint] The deprecated --no-[category] options from Qt 6.1 are now fully removed, use the new style of options as outlined in --help.

Change-Id: Ie564a8262fdefa2685fe86b59b46dc3aa25d4958
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-07-02 13:38:41 +02:00
Maximilian Goldstein b4d9bf79e1 qmllint: Hide deprecated options
We shouldn't keep advertising options we're deprecating anyway, just warn when they are still passed to qmllint.

Change-Id: Ibe53c51fc473719d021f912243921b6511ebd2f4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-06-24 09:02:08 +02:00
Maximilian Goldstein 7c3e059a8d qmllint: Make the tool version equal the Qt version
Use the Qt version instead of 1.0. Especially important since qmllint allows for mixing and matching the tool with other Qt versions.

Change-Id: Ib485578f93d8e61f2aa76bb610c3fd87ed71cd60
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-06-03 14:58:12 +02:00
Maximilian Goldstein 9f389ee75d qmllint: Add ability to ignore individual warnings
Allows users to ignore individual warnings by adding a "// qmllint disable" comment in the line that triggers the warning.
This feature is especially useful for use in pre-commit / CI tests as it allows to add exceptions for individual warnings that cannot be fixed immediately.

[ChangeLog][qmllint][New Feature] You can now ignore individual warnings by adding "// qmllint disable"
in the line causing it. You may also specify one or more warning type to ignore ("// qmllint disable warningtype1 warningtype2...") which is preferable. This can also be done for entire blocks of code by using "// qmllint disable" in an empty line and ending it with "// qmllint enable"

Change-Id: Iea6c29132d6b51ecfb5e5d8a19a43446a7286c24
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-03 08:54:57 +02:00
Maximilian Goldstein d2bb3513b4 qmllint: Add support for outputting warnings as JSON
Adds the ability to output warnings as JSON, one line per file.
This makes it way easier to process qmllint warnings for use in CI tooling or IDEs.

[ChangeLog][QtQml][qmllint] Add the ability to output warnings as JSON for use in tooling.

Change-Id: Iecd48e123859aa939bd9753cb8f6e44d4d7e3667
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-01 17:41:45 +02:00
Maximilian Goldstein 73d51eed2f qmllint: Add support for loading options from settings
This change adds support for a reading a simple settings file (.qmllint.ini) to set log levels and various other options.
The settings file applies on a per-directory basis so linting files in two subdirectories with different settings will use their respective settings files.
If the directory of the linted file does not contain any settings we search through all parent directories.

This is implemented in a way that qmlformat can also utilize the settings file code.

This makes qmllint more useful for larger projects that might want different settings for different parts of their QML code.
It also allows for better integration in CI checks and pre-commit hooks.

[ChangeLog][General][qmllint] 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

Change-Id: I94e4a47916b5dfd16c3a69efdba3858235cab738
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-05-27 11:30:12 +02:00
Maximilian Goldstein 26290c8bca qmllint: Introduce import caching
Previously we only cached processed qmldirs, now we cache full modules and dependencies.
This leads to manyfold speed increase (10 times in my tests) when lots of files are linted in one invocation of qmllint and those files have a lot of imports with shared dependencies.

Change-Id: Ifcd1eb9d620ca7a18c0a3d6395fbb6d003472dab
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-05-26 13:15:10 +02:00
Maximilian Goldstein 7a9b84ca6d qmllint: add options for setting logging levels
Add the ability to individually disable and set the severity of all warnings produced by qmllint.

Change-Id: I46081f8b37fb90f8d0f4a5f2f08223d7b7285041
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-09 15:26:52 +02:00
Maximilian Goldstein 954071f372 qmlcompiler/qmllint: Use unified logger
Improves the logging situation greatly by allowing all logging messages to be assigned different severities,
highlighting the code that caused them and by now ensuring a qmllint warning will always result in a non-zero exit code.

A later patch will expose more of these options to the user.

Change-Id: Id9b036fe3ba80dd18e9f8cb1b05efa891713d5a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-29 12:31:01 +01:00
Maximilian Goldstein 93984dfc86 qmllint: Only exclude default QML import dirs when explicitly requested
Previously specifying any additional QML import directories would lead to the default directories to be excluded.
This can be useful if you want to run qmllint on a project using a different Qt version but
this is not behavior you want in most cases.

[ChangeLog][qmllint][Important Behavior Change] Using -I no longer excludes default QML import directories.
Use --bare to get the old behavior.

Change-Id: I2ca5789cd44306bcad54f7b1b82049c21f721d3d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-25 15:33:27 +01:00
Ulf Hermann 7ecd4b6d1f qmllint: Resolve imported files by qrc path if available
If a file is part of the resource file system, the implicit directory is
also in the resource file system. We can use QQmlJSResourceFileMapper to
figure this out.

Change-Id: I48d86c308c7ec38d9971b84e7f059daa3baf63ee
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-24 13:01:48 +01:00
Ulf Hermann b17ccb8af9 Use QLibraryInfo::QmlImportsPath rather than Qml2ImportsPath
The "2" is meaningless and there is a better name available now.

Task-number: QTBUG-85064
Change-Id: I65d26b06712ed7dcf2825f16dffaa6060dd86985
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-02-09 21:46:43 +01:00
Ulf Hermann 9b407b68d1 qmllint: Fix auto-importing of qmltypes from same directory
Fixes: QTBUG-90513
Pick-to: 6.0
Change-Id: Ic39e72d6df20be30c61123a7f8091d70dbc2d924
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-21 14:17:59 +01:00
Ulf Hermann 678d4ec4b6 Unify QQmlJSImportVisitor and FindWarningsVisitor
They are both pretty much doing the same thing, except that the import
visitor is not as thorough. We need the full analysis in QtQmlCompiler,
so we successively move the code over.

Change-Id: If7fb47f88165fd8b61f4ccc408ccfbb7dad533e6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-15 10:44:25 +02:00
Ulf Hermann ccd348d4b7 qmllint: Uncruftify the importing of base qmltypes
builtins.qmltypes are imported separately now. Any other bare qmltypes
files without qmldir should be specified explicitly. If none are
specified, qmllint looks in the current directory for qmltypes files,
not in all possible import paths. This is still somewhat weird, but
admittedly it's handy for qmltypes files generated for application
binaries. For the same reason, we unconditionally include the current
directory in the list of default import paths. Previously this was done
if no explicit qmltypes files were specified, which makes little sense.

Change-Id: Iaa56f8b40b3ec3045f55928251d7efea5616d23b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:32:29 +02:00
Volker Hilsheimer a15840a8df Fix additional warnings from usage of deprecated APIs
Replace QLibaryInfo::location with QLibraryInfo::path, and remove usage of
Qt::AA_EnableHighDpiScaling, which doesn't have any effect anymore.

Change-Id: I347e8a83e0f4c2b4405f2512e569ad3234f05a98
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2020-09-16 12:44:59 +02:00
Maximilian Goldstein f88cc9aadb qmllint: Fix typo
Change-Id: Iec3632bdf2446d9a54397c113b648db1c4f7db6e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-05-14 11:32:43 +02:00
Maximilian Goldstein ac5c765f29 qmllint: Add flags for toggling warnings
Enables all warnings by default and makes it possible to toggle
individual ones using command line flags.

Change-Id: Ie55f32f646fd9422313977969f9f00b59ee9ad99
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-04-30 18:56:19 +02:00
Maximilian Goldstein a5b4d3dbab qmltyperegistrar: Use target instead of template name
Due to the fact that multiple targets may be present in the same
directory we have to ensure they all get a unique qmltypes.

Fixes: QTBUG-82710
Change-Id: I4d7966035644b68f7d3330a4c974369503c48bf2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2020-03-26 13:41:46 +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
Ulf Hermann 6fb335ebce qmllint: Cleanup
qmllint needed to be refactored before we can add any new functionality:
* Fix all the (C++) linter warnings
* Remove pointless namespaces
* Merge ScopeTree and FakeMetaObject into one class
* Remove the "Fake" from class and variable names
* Remove dead code
* Add "We mean it" warnings everywhere
* Unify #include style

This also "accidentally" fixes the automatic matching of signal handlers
in Connections elements to signals in their parent scopes.

Change-Id: Idf8daae34dfd6c0ee00da28b017f921da3eba25c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-11-18 10:39:23 +01:00
Ulf Hermann 3d0bec491e qmllint: Parse .mjs files as JavaScript rather than QML
Change-Id: I80783289452300d4609a27f5b470ecdeeeca5e71
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-10-15 13:49:14 +02:00
Ulf Hermann 531cf90305 Make qmllint read qmldir files and qmltypes files in app directory
This makes it possible to resolve components which were either directly
registered in the application or specified as composite types in qmldir
files.

Change-Id: I42482563f31ac780d6b37e62375d09d122c4a308
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-09-25 10:03:07 +02:00
Ulf Hermann 33635f60a7 qmllint: Honor --silent argument
Change-Id: Ie63654139aeb7bfd241be865f33c399c23e08cc3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-09-19 11:28:10 +02:00
Fabian Kosmale 392521048c Extend linter to check for unqualified ids
The linter has gained a new option (-U/--check-unqualified).
If run with this option, it warns about occurrences of unqualified identifiers.
Furthermore, it attempts to detect the reason for why the identifier can be
used unqalified:

- If the id originates from the root element, it suggests to qualify the
  access either with the root element's id, or with "parent" if applicable.

- If the id is the parameter of a signal, it suggests to use functions in the
  handler, instead of relying on the signal parameters to be "magically"
  injected into scope.

The linter does not attempt to handle with statements, but warns the
user instead that they are a bad idea.

Change-Id: I9aaf28c37595d84886a1071d49b86799b222a617
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-12 15:31:16 +02:00
Ulf Hermann d4d197d062 Simplify errors and diagnostics
We only need two classes to describe all possible diagnostics:

* A low-level private POD DiagnosticMessage. This is easily copied and
  passed around internally. It doesn't need to adhere to a stable API
  and it doesn't carry any extra baggage.

* The high-level public QQmlError with its stable interface. This can
  internally also use a DiagnosticMessage as storage.

Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-06-14 19:08:51 +02:00
Ulf Hermann c8c2db3f5b Split QV4::Value into a static and a dynamic part
The static part can be used for compilation and won't resolve managed
objects. This allows us to remove all the remaining V4_BOOTSTRAP.

Change-Id: Id2f6feb64c48beb2a407697881aea8c0d791a532
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-31 15:03:33 +02:00
Liang Qi 0076c44d39 Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
	src/quick/util/qquickutilmodule.cpp
	tools/qmllint/main.cpp

Change-Id: Ic2283f88c293ca7fc776de3e83eb4c7812309d8a
2017-01-26 00:34:21 +01:00
Tasuku Suzuki 9aed949bb9 Fix build without features.commandlineparser
Change-Id: I3a23e53fc647f5257593e0aece7198eea430cf14
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-25 04:52:58 +00:00
Anton Kudryavtsev 909d6498ed tools: replace 'foreach' with 'range for'
Catch rvalues to prevent detach()'ing.

Change-Id: I7be159a405c994429c0eee10805bfe96fcf4c806
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2016-08-22 08:32:23 +00:00
Jani Heikkinen 38ec3bd755 Updated license headers
From Qt 5.7 -> tools & applications are lisenced under GPL v3 with some
exceptions, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new GPL-EXCEPT header instead of LGPL21 one
(in those files which will be under GPL 3 with exceptions)

Change-Id: I04760a0801837cfc516d1c7c02d4f503f6bb70b6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-20 11:46:25 +00:00
Simon Hausmann 9556f6d075 Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
	src/qml/jsruntime/qv4engine_p.h
	src/quick/items/qquickitemsmodule.cpp
	src/quick/items/qquicktext.cpp
	src/quick/util/qquickpixmapcache.cpp
	tests/auto/quick/qquickwindow/tst_qquickwindow.cpp

Change-Id: I90ecaad6a4bfaa4f36149a7463f4d7141f4a516a
2015-06-04 10:28:48 +02:00
Sérgio Martins 35bb082b25 qmllint: Fix parsing js files with .import directives
For .pragmas we removed them explicitly but the correct fix is to
not use "qmlMode" when setting code in the lexer.

Change-Id: I6ffc0ca9e7ebab09fbf91e647d292ff0a3a1fd7d
Task-number: QTBUG-45916
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-05-09 08:41:54 +00:00
Lars Knoll 0a499043fb Get rid of qv4value_inl_p.h and replace it by qv4typedvalue_p.h
This is a cleaner separation and further reduces include dependencies
in the definitions of our basic data structured.

Change-Id: I18aa86cdea0c0dfbc16075d4d617af97e638811e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:20:43 +00:00
Jani Heikkinen c5796292ad Update copyright headers
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.

Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
2015-02-12 10:28:11 +00:00
Jani Heikkinen e7ceacda70 Update license headers and add new licenses
- Renamed LICENSE.LGPL to LICENSE.LGPLv21
- Added LICENSE.LGPLv3 & LICENSE.GPLv2
- Removed LICENSE.GPL

Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0
Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
2014-08-25 11:28:46 +02:00
Sérgio Martins 4e65caefe6 Introducing qmllint tool.
A command line program that returns 0 if a .qml file is syntactically
correct.

Ideal to integrate into continuous integration systems.

[ChangeLog][QtQml] Added QML linter tool.

Change-Id: Id420159298e9d2390acd870fee9cf1c3d08e2dec
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-08-05 18:49:30 +02:00