Commit Graph

48 Commits

Author SHA1 Message Date
Sami Shalayel 282add1abf qmllint: allow plugins to set default category level
Add a defaultLevel value to the .json file shipped with the plugins that
allow plugins to set the default level of their categories.

Change-Id: I4a13366ce705ba104414b41e729d12769ab83821
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2024-10-29 13:00:19 +01:00
Sami Shalayel 42856ea39a qqmljslinter: only search files for plugins
Add a flag to the QDirIterator as only files can be loaded as plugins.
Discovered while debugging as this iterates also over "." and ".."
without the flag.

Change-Id: Ia1070b40541b8c769a457143978576b05c84e2bf
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2024-10-28 21:33:42 +02:00
Ulf Hermann bc125ff647 QmlCompiler: Refactor handling of warnings in import visitor
We want to replay the warnings when we import the same module again.
This happens if we lint multiple files with different imports, some
direct and some indirect.

Pick-to: 6.8
Fixes: QTBUG-118588
Change-Id: I75da4e62acea675342ce8f86f9609f1786ffbdd0
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2024-09-19 21:25:25 +02:00
Sami Shalayel 2b2deb0a11 qmlls: use .qml from source folders
Previously, qmlls (like all the other tooling) was only working on the
build folder for imports. This leads to bugs like QTBUG-127661 where
go-to-definition jumps to the build folder qml file.

This commit changes the Dom to use a "best of both worlds" approach:
import .qml files from the source folder but load the rest (qmldir,
qmltypes, ...) from the build folder.

Add a flag to QQmlJSImporter that enables the build-folder-path-to-
source mapping, and use it in the DomEnvironment::SemanticAnalysis's
importer.

In the qqmldomastcreator, load the implicit import directory from the
build folder instead of the source folder, and explicitly load qmldirs
of that implicitly imported directory to make the implicit directory
import actually do something.

In DomEnvironment, map files from the build folders (for example loaded
via a qmldir from a build folder) to their source folders before loading
them..

Finally add a test to make sure that go-to-definition jumps to the
source folder instead of the build folder qml file.

Pick-to: 6.8 6.7
Fixes: QTBUG-127661
Change-Id: I764826a7d3c98d2e34e5af8e3ba6dea1526c593c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2024-09-10 12:01:36 +02:00
Olivier De Cannière cc87c4ade4 Compiler: Don't pass a moved-from type resolver to PassManager
This can lead to crashes in static analysis passes when they try to use
the resolver.

Pick-to: 6.8 6.7 6.5
Change-Id: I2f7951374a3aa6bd38ef93333b97b08d9a46dd13
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2024-08-12 17:31:55 +00:00
Fabian Kosmale e14c148261 qmllint: avoid stale typeresolver pointer
It's not accessible via public API, but it risks wrecking havoc on
internal plugins, and would also likely cause issues if we were to
expose the global JS object to QQmlSA plugins.

The current fix is rather a minimal workaround, we should revisit
whether codegen should really take ownership of the typeResolver.

Pick-to: 6.8
Change-Id: I6ca6e78527ce886155cfc0a21038348da2982c03
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2024-07-02 13:51:34 +02:00
Jari Helaakoski 4949768067 Fix test compilation issues with QtLite configuration
Now developer build tests compile, but some are not working.
Functional fix will come later via separate tasks.

Task-number: QTBUG-122999
Change-Id: I0a0dfcf7affb73f928b8be62b3576a6a51658488
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2024-04-30 09:00:03 +00:00
Sami Shalayel d94ec776a7 Make qmljsliteralbindingcheck a QQmlSA::PropertyPass
Use the private API to convert QQmlSA objects into QQmlJS elements
wherever it was not possible to use the QQmlSA objects:

The static method canConvertForLiteralBinding has a comment that seems
to say 'we need this so dont touch this' so do not change its code.
Furthermore, it requires a QQmlJSTypeResolver, so obtain it from the
PassManager's private struct.

It seems that QQmlJSLiteralBindingCheck was the only user of
QQmlJSMetaPropertyBinding::literalTypeName, so move it to
QQmlJSLiteralBindingCheck instead of adding literalTypeName to the
QQmlSA interface.

Make QQmlJSLinter always create the passManager, even when there are no
plugins available, such that the QQmlJSLiteralBindingCheck can be run
using the QQmlSA interface. Also fix Qmltc to use the new
QQmlJSLiteralBindingCheck api.

Change-Id: I27dfc63d411e38740e2993ccf9af352271ae6d47
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2024-04-05 17:45:42 +02:00
Ulf Hermann 8fce21105d qmllint: Remove duplicates from fixes before applying them
There can be multiple places that suggest the same fix in a file. We
only want to apply it once.

Pick-to: 6.7 6.6 6.5
Fixes: QTBUG-118982
Change-Id: Ie14bf5904c7480074c44f80bb855d28e9b132588
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2024-02-20 10:07:23 +01:00
Ulf Hermann b7aba647b0 QQmlSA: Remove cruft from public API
Methods you can't use should not be visible, and PassManager needs to be
Q_DISABLE_COPY_MOVE.

Task-number: QTBUG-116682
Change-Id: Ib308bf3a5bac3dd78b52b82b01bc8f2bc13835b3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-10-23 14:27:26 +02:00
Fabian Kosmale bc709184af qmllint: Use settings name as settings name
We weren't actually considering the sections name from the json config
file. Fix this, and only use the CLI option name as a fallback.

Pick-to: 6.6 6.6.0
Change-Id: Ieb88d4840164d903c228ec39ce9943715221ca92
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-09-21 00:07:22 +02:00
Olivier De Cannière cdd7fe05f6 QQmlSA: Create an abstraction layer for static analysis
This patch adds abstractions for QML Elements, Bindings, Methods and
Properties. This abstraction layer avoids exposing internal details and
should be more suited for static analysis tasks. It is now possible to
write qmllint plugins without including private headers.

As a drive-by, change tst_qmllint:verifyJsRoot to open files in text
mode instead of binary. This fixes an issue where line endings cause
issues on Windows.

Fixes: QTBUG-102276
Change-Id: I6b6e53f1e0078734a18f3aa51807fbe875b375f0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-30 13:42:35 +02:00
Ulf Hermann aa49d0f2d9 qmllint: Fix attached property re-use detection
Move the detection into the QtQuick lint plugin. It's mostly meant for
QQC, so let's auto-enable it for attached types derived from
QQuickAttachedPropertyPropagator.

To this end, two new categories are introduced: The Quick lint plugin
gets its own attached-property-reuse category which is synonymous to the
default category of the same name. Furthermore, we add a
controls-attached-property-reuse category for only checking controls.
That one is implied by either of the others.

Finally, fix the id vs. scope resolution to actually do something.
This way we can give appropriate hints when the outer type has an ID
already.

Pick-to: 6.5
Fixes: QTBUG-110834
Change-Id: Ib71a9e3bbc10bac77f36db6cc441af88df20fd33
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-14 13:32:13 +01:00
Ulf Hermann 403f4117e2 qmllint: Uncruftify FixSuggestion
In this form we can expose it in QQmlSA.

Pick-to: 6.5
Task-number: QTBUG-110834
Change-Id: Ieb0cf31b6e86379c0d80f89bc6c63b129f269798
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-08 21:14:39 +01:00
Ulf Hermann 5c594515f6 qmllint: Provide import paths and resource files when linting modules
Those are just as important for modules as for single files.

Pick-to: 6.5
Change-Id: I201d62c61988abc2dfba6300a1cfc355203fec75
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-02-07 19:23:12 +01:00
Ulf Hermann 7b0b09d87c qmlls, qmllint: Avoid memory leaks
Pick-to: 6.5
Fixes: QTBUG-104643
Change-Id: I5ca0fea2ef6f822b70c08bc6e49f0d07a732b299
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-01-16 09:49:17 +01:00
Sami Shalayel 784367ad17 QQmlJSMetaParameter: Encapsulate parameter information
Previously, there were four lists that contained each one entry
for each parameter. There was one list responsible for the names, types,
type names and const-qualifiers but this was quite bothersome to use
(e.g. they not always had the same length).

This commit introduces QQmlJSMetaParameter to
encapsulate all the information required when manipulating parameters.
This reduce the 4 lists to one, making parameters easier to handle
and QQmlJSMetaMethod easier to read.

This is a purely refactoring change, no new functionality was added.

Task-number: QTBUG-107625
Change-Id: Ia41b823c9e6294ee26e828071b802cac6b4058ce
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-12-02 10:39:48 +01:00
Ulf Hermann b7fd5774f6 QmlCompiler: Enforce consistency of ContextualTypes
An instance of ContextualTypes can only either hold QML types or
internal types. We always need an integer and an array type, though.

Previously, "int" was always added to the used types when it was looked
up for potentially resolving enums. This prevented the builtins from
being reported as unused import. Since we pass "int" as a separate
member now, prevent the builtins from being recorded as import location
in the first place.

Task-number: QTBUG-107171
Change-Id: I288b6e070c2039d4ac85073886c9929a2eed3998
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-11-02 09:51:14 +01:00
Sami Shalayel c52b7fdca8 qmlcompiler: refactor ContextualTypes to know its context
The code in qmlcompiler working on ContextualTypes is very confusing
as it handles internal types (c++ and synthetic jsrootgen type names)
and qml types at the same places.
Furthermore, some methods like qqmljsscope::findType() have different
behaviors when running in different contexts, e.g. in the internal
type context it needs to lookup namespaced c++ enums (e.g.
QQmlComponent::Status) while in the qml type context it needs to
lookup inline components (qmlFileName.MyInlineComponent).

Changed ContextualTypes to be a struct with the types QHash and
an enum with the context (QML or INTERNAL),

Drive-by change: amend the iterations over types.keys() to use an iterator
instead of allocating a temporary QList as types is not that small
(may contain around 400 items just for the builtins).

Fixes: QTBUG-107191
Change-Id: Ib463ec873019ea1e6844c522a090030e9a44d53f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-14 09:36:56 +02:00
Marc Mutz 958cd3ee10 Port from container::count() and length() to size()
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:

  auto QtContainerClass = anyOf(
      expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
      expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.

Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-07 23:38:48 +02:00
Semih Yavuz 9806849b05 qmllint: Fix crash due to index out of range
Opening input files in binary mode may cause file to be parsed
incorrectly. To prevent the crash, Check if element in container is within the range
of valid elements before accessing it. Note that qmllint will ignore the comment
directives and may not function correct in that case.
QTBUG-106813 should solve this.

Pick-to: 6.4
Fixes: QTBUG-106613
Change-Id: I1a5705474905a747fbcc4874c3ff2038f539f42f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-09-22 23:45:53 +02:00
Volker Hilsheimer 761beaa354 Fix build-breaking warnings
Qt's asKeyValueRange of associative containers cannot return references
to key/value pairs, so Apple's clang warns when using ranged-for with
references to elements.

Use a structured binding instead as the loop variable, and delay some
conversions of QSet<QString> to QStringList until the list is needed.

Change-Id: I37aa101e6d9cd008cde0c2db790132dc051a249b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-09-01 22:12:33 +02:00
Ulf Hermann 11da5cdcb0 QmlCompiler: Avoid unnecessary copies in loops
Coverity-Id: 397268
Coverity-Id: 397269
Change-Id: Iacbf6c8a57dbdee02e75f4faeed0a0f31d37500f
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-08-29 13:21:13 +02:00
Maximilian Goldstein b12343d59c qmllint: Also check methods when linting modules
Also lint methods in addition to properties when verifying whether any
types are missing or not fully resolved.

Change-Id: Ia7629d2b2427053c497bffca2b5d5b3a3f0bb027
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-08-01 09:53:27 +02:00
Volker Hilsheimer aa9412615b Fix warning from iterating over references
Apple clang says:

error: loop variable 'kv' is always a copy because the range of type
'QtPrivate::QKeyValueRange<const QHash...> &>'
does not return a reference [-Werror,-Wrange-loop-analysis]

Change-Id: I4dc43805d3d3f723e5ec8cc504969cda3d99fb43
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-26 15:32:35 +02:00
Maximilian Goldstein 34d52f8b2c qmllint: Implement module linting
This change allows for modules to be linted via the -M flag.
This will check whether an individual module has a sound qmldir and
qmltypes. It will also verify whether all its types and the types of
properties can be resolved.

It does not lint individual QML files.

[ChangeLog][qmllint][New Feature] Individual modules can now be linted
via the -M option

Fixes: QTBUG-103264
Change-Id: I3ced4b0bc05358e9216c9819f1dca67af909405e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-07-25 12:26:06 +02:00
Maximilian Goldstein 4e3e0b6b7c qqmljslogger: Print ids of warnings
Also exposes the id information in the Message object and adds it to the
JSON output.

Change-Id: I6b27e644583408cca3e39b75210610db09fefa8b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-07-13 16:30:39 +02:00
Maximilian Goldstein bd38bd435a qmljscompiler: Replace categories with more specific warning ids
This change replaces a lot of generic category names with several warning
ids to replace them.

Change-Id: I9b13b931e7ed3d56b71d6292a6a77bec69647ffd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-07-08 10:28:50 +02:00
Timur Pocheptsov a957382cf1 Fix the compilation error
Clang does not like the ref. and says: "note, use non-reference type ..."

Change-Id: I838f81e2b02ebaac57295ca7d662a0a6db4ac056
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
2022-07-06 16:50:35 +02:00
Maximilian Goldstein a9038a6cc6 QQmlJSLogger: Switch to an ID based system
This change makes qmljslogger use an ID based system for categorizing
logging entries instead of using an enum. This allows plugins to
register their own logging categories after the fact.

It's also necessary for us to later show the warning ID when
printing warnings and for creating documentation for each ID entry.

Currently not every ID maps cleanly to only one type of warning,
this has to be cleaned up in a follow-up change.

Task-number: QTBUG-103453
Change-Id: I4cac6be7ca165b938e0ea032d077823bf17baf75
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-30 11:23:36 +02:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00
Maximilian Goldstein 2ebee301fd Reimplement PropertyPass to evaluate bindings
This change reimplements the PropertyPass to be based on bindings
rather than on just iterating over elements. This is a lot less
cost intensive than iterating over all properties regardless of
whether they are actually used. You may still achieve the same
thing with the more flexible element pass, just with the benefit
that you can choose what properties you want to iterate over
instead of iterating over all of them.

To demonstrate the passes usefulness the existing attached property
warnings are ported to use the binding pass and can now also warn
when an attached property is read or written in a context where
it's not supposed to be used.

Fixes: QTBUG-102860
Fixes: QTBUG-102418
Task-number: QTBUG-102859
Change-Id: Iea87a1b05b954429b8bf00fd27b60487940af679
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-05-16 18:22:45 +02:00
Maximilian Goldstein 938bd97077 qqmljstyperesolver: Allow for disabling cloning
Previously it was not possible to disable cloning of types but we need
to do this in order for linting to not be disturbed. This patch adds
a flag that can be toggled to disable it, although it is still enabled
by default.

Change-Id: I5b19a48395e27975343fb1999d8106e0bb07d53a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-05-09 16:50:07 +02:00
Sona Kurazyan 2c9c1590e6 Replace uses of deprecated _qs with _s/QStringLiteral
Task-number: QTBUG-101408
Change-Id: Ic925751b73f52d8fa5add5cacc52d6dd6ea2dc27
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-29 09:47:43 +02:00
Ulf Hermann dc815b797c Move literal types check out of QQmlJSTypeResolver
The type resolver should not do any semantic analysis on its own. This
fixes a bug triggered by invoking the literal type analysis from
qmlcachegen (which is not interested in literal bindings at all).

While this doesn't fix the root cause, qmlcachegen will definitely not
crash in this place anymore. There will be a follow-up bug to figure out
what is actually happening.

Pick-to: 6.3
Fixes: QTBUG-102598
Change-Id: Ic5b1f1cdebc960e0ec56f54d8bdd11bac08f0521
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
2022-04-27 15:29:24 +02:00
Maximilian Goldstein 1552b00d1e qmllint: Add option to disable individual plugins
Adds a command line option and settings entry in order to
disable individual plugins. Previously you could only
disable all of them.

Fixes: QTBUG-102420
Change-Id: I5a35093c32f5f86eef1e31dd42b77c95e38bb01f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-21 21:04:01 +02:00
Maximilian Goldstein 28fd6bd25c qqmljslinter: Warn about duplicate plugin names
If two plugins have the same name, warn about it and don't load the
second one.

Fixes: QTBUG-102421
Change-Id: If386acf9fbbfc12cec8ce708516c11940ef2856e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-21 21:04:01 +02:00
Maximilian Goldstein 78562b7dc1 qqmljslinter: Run plugin passes earlier
Turns out just cloning the root scope is not enough to avoid the
duplicated scopes after all. We'll just have to have the plugins run
before the compiler logic for now.

Change-Id: I5f44c7d14b5c3ade8e7fff0fbc98d14e34b875ec
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-12 14:03:18 +02:00
Maximilian Goldstein d8a4175a3a qqmljslinter: Fix codechecker warnings
Change-Id: Ifbc2858093ad2374fc9a2e3d6904cfaef6aad6d3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-11 14:12:09 +02:00
Maximilian Goldstein 324b625f9f Turn the QtQuick qmllint plugin into a proper shared library
Previously it was just a static library that we linked qmllint against
now it's properly installed in the qmllint plugins folder and can be
utilized in the language server as well.

Fixes: QTBUG-102278
Change-Id: I4aec42d1e2ba113237ee5ba148085e69b7251506
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-11 14:12:09 +02:00
Maximilian Goldstein 7c9276d38b qmllint: Integrate plugin infrastructure
Integrates the plugin and pass infrastructure into qmlcompiler and qmllint proper.
Plugins are searched for in the "qmllint" subfolder of the Qt installation's plugin
directory. In addition we also support loading statically linked plugins.

[ChangeLog][qmllint][New Feature] qmllint can now be extended via plugins. Use --plugins
to get a list of available plugins.

Original-patch-by: Fabian Kosmale <fabian.kosmale@qt.io>
Change-Id: I75a09dd978fc7724aca4931f055cc71c7ced971b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-05 14:06:56 +02:00
Ulf Hermann aea732d607 Avoid copying QQmlJSScope
The factory should populate the pre-existing scope rather than copy it
into place. This way we can detect inheritance cycles involving the
pre-existing scope.

However, now we may detect the inheritance cycles earlier, when
resolving the types inside the lazy loading. We have the right pointers
available there now, after all. Therefore, add a way to propagate base
type errors out of the factory. When clearing the base type, we can now
give a reason for that. When checking the inheritance cycles we
retrieve that reason and log it.

We also remove the special casing of the ScopeType property of
QQmlJSScope. There is no real reason to set it in the ctor. As we
delay the population of QQmlJSScope now, we have to set it later.

Pick-to: 6.2 6.3
Task-number: QTBUG-102153
Change-Id: I49cf6e20f59fbdb6ed98a82040b3b159676f5975
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-04-04 09:09:49 +02:00
Maximilian Goldstein 0092c27580 qmllint: Represent fix suggestion filename in JSON
Previously this information didn't get exposed in the JSON interface.
Now if a file other than the one the message belongs to has a fix
suggestion it will be properly represented in JSON.

Change-Id: I48f0f555dadd471ccfc58a5c9627c52f28b5e112
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-03-24 19:38:12 +01:00
Maximilian Goldstein a398e06c61 qmllint: Support automatically applying suggestions
We now support automatically applying fix suggestions that don't
need any additional user input. This allows us to automatically
solve issues such as unqualified access and multiline strings.

[ChangeLog][qmllint][New Feature] Added the ability to automatically
fix some warnings, use -f to automatically fix your files or add
--dry-run to see what changes would be made first.

Change-Id: I2dc7587137d74267f60c08bb94a035f1a85a62b1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-14 09:43:15 +01:00
Maximilian Goldstein 195af3ce69 qmlcompiler: Allow for logging other files and add auto-fix infrastructure
This change makes sure the logger can write messages and show excerpts
from files other than the current one. This is necessary in order to
give users hints about problems that arise due to other components.

It also adds a field to FixSuggestion::Fix which specifies whether a
suggested fix can be applied automatically or is only a hint.

Change-Id: I94a929d3fc3fc966591cffb99e67309d264c38e7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-03-03 11:19:51 +01:00
Maximilian Goldstein 2ea887cca0 qmldir: Allow for specifying default imports
Adds the option to specify default optional imports in qmldir for
tooling to load. Previously we would just load all entries.

This allows code that that relies on modules utilizing optional imports
(i.e. everything utilizing QtQuick.Controls) to still be supported in a
limited capacity.

This change also adds the necessary CMake API to add these entries to
qmldir files. It also disables loading optional imports by default
and only leaves them enabled for qmllint.

Change-Id: Iff6aaac9cb0ec72b7a2853b60840a4d28c84aa25
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-14 12:38:10 +01:00
Andrei Golubev 690b7cb6a2 Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)

To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)

One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point

Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
  and is actually questionable). Instead, we can ignore a
  particular category explicitly
* Category levels are repurposed as category severities
  (at least from the high-level picture that always should've
  been this way)
* log{Warning,Info,Critical} removed. We use category severity
  instead
* "category error" makes zero sense so removed: if our severity
  is:
  - QtWarningMsg (qmllint), it is already an "error"
  - QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
  category would be both an error and not an error

Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-12 23:21:29 +01:00
Maximilian Goldstein 07917626f5 qmlcompiler: Remove qmllint library
Since all of the superfluous components of qmllint have been
removed now, we can just move what little custom linter logic
remains to qmlcompiler.

Change-Id: I91c752cb895e7d6c6f2dd4e2ccafb6cd05afa225
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-02-03 22:55:53 +01:00