Commit Graph

47 Commits

Author SHA1 Message Date
Olivier De Cannière ee5c015b3a Compiler: Make qqmljsscope::filePath hold the source location more often
Previously, it would hold the location of the copy in the build
directory or in the resource file system.

This should improve the accuracy of the information that we can report
back. For example, the file location of files reported in aotstats will
now be those in the source folder.

The changes necessary for this patch were found through trial and error
by asserting that the filePath respect a certain form and fixing what I
could. There remain cases where the filePath still contains a location
in the build directory. We would need some other change to report those
accurately as well.

Finally, sometimes the filePath is empty or does not contain a valid
path at all but instead what seems to be the location of an included
file. It can have the form "private/..._p.h" for example.

Pick-to: 6.8
Change-Id: I77a2596f6c4a179580d924a6e9324e43dbb86c0c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-10-31 11:49:54 +01:00
Olivier De Cannière 660fc8fb7d QmlCompiler: Rename QQmlJSLogger's fileName to filePath
This is done in prepartion for the following patch in the chain.

Pick-to: 6.8
Change-Id: If8ce75be8ba00e7e4cdd5a0f5e66319ab0d36755
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-10-31 11:49:54 +01:00
Ulf Hermann ae7419479a QmlCompiler: Log double colon if source location missing
This causes the lines logged to be shown in Qt Creator's issues pane.

Fixes: QTCREATORBUG-31526
Change-Id: I2c55d09a779cd4a51df5dda0e4ef894de235f974
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2024-09-04 23:29:40 +02:00
Fabian Kosmale d77693a028 QQmlSA: Don't expose QQmlJS namespace
QQmlSA is meant as the public namespace, QQmlJS is (at least currently)
completely internal. However, LoggerWarningID currently only existed in
QQmlJS.
Move it into QQmlSA, add some minimal class documentation and add a
typedef in QQmlJS (inside a private header) to avoid the need to modify
all users.

Pick-to: 6.6.0 6.6
Change-Id: Icff860c92054ac810c6e15eb26090d38fbc2c965
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-09-21 00:07:22 +02:00
Thiago Macieira b881ca8f4e Re-workaround the maybe-uninitialized warning from GCC 11+
It's still happening with GCC 13.

My guess is that the includes changed so the disabling wasn't applying.

Amends 067d5a3334.

Pick-to: 6.5 6.6
Change-Id: I80612a7d275c41f1baf0fffd177a234b8fd398e1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-11 10:00:01 -07:00
Ulf Hermann c000ea178b QmlCompiler: Clean up some includes
Change-Id: Ib9ffe5e604ccbdb7e841b28111954e38b862b15a
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-06-06 12:56:37 +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
Olivier De Cannière d876ce343d QmlCompiler: Simplify isRescricted checks down to only enums
Most checks in isRestricted were redundant. Only those related to enums
seem to be useful. These are kept in the new checkForEnumProblems while
isRestricted is removed.

The error checking in checkForEnumProblems should also provide better
error messages for enum problems.

Pick-to: 6.5
Change-Id: Ic3f3589464ebe519bee8b4c580b2e80d310c937f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-22 13:57:24 +01: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
Semih Yavuz 33dbd8eb13 qmllint: Move qmlControlSanity loggers into a plugin
QmlImportVisitor has some log messages that is only used for controls
sanity tests. Move these loggers into a QuickControlsSanity plugin.

Move the relevant tests from tst_qmllint to tst_sanity as we link the
plugin to tst_sanity. Also remove qmlControlsSanity category from the
default categories of QQmlJsLogger as it should be only utilised by this
plugin.

Task-number: QTBUG-103276
Change-Id: Iacc624711a2cd00aeb9d89fbde7c0131896d30ce
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-01-23 10:45:30 +01:00
Ulf Hermann c7c4ac6e32 QmlCompiler: Do not print context for source locations of length 0
We generally print a second message to clarify the context anyway.

Fixes: QTBUG-108851
Change-Id: Iba392f2983498ecb1d780034523feab8d9057b84
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-11-30 14:29:41 +01:00
Sami Shalayel 3103bf5a42 QQmlJSImportVisitor: warn when uncreatables are created
isCreatable in qqmljsscope just returns the value of the flag as it was
read from the qmltypes, which is slightly confusing as isCreatable is an
opt-out option.
Instead, isCreatable should reflect whether the type is creatable or not.
A type is uncreatable if and only if it is a singleton, an attached
type, a c++ type with QML_UNCREATABLE and types without default constructor.
This uncreatibility can also be inherited to composite types.
Types without default constructor require QML_UNCREATABLE or
QML_ANONYMOUS, and will be handled in another commit.

Now that uncreatable types can be detected, emit a warning when a singleton
or an uncreatable type is created: up to now no such warning was emitted.
This warning can be seen when using qmllint or qmltc.

By the way, also fix qmltc to not assert when something goes wrong (e.g.
because an uncreatable or singleton type was created).

Change-Id: I9a82106a801d14063407eb4e54858b1ca9fd578b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-11-23 10:29:25 +01:00
Semih Yavuz 162654925e qmllint: Warn about duplicated signal/property names
Qmllint does not warn about duplicated property and
signal names while qmlengine complains about them. Introduce a new logging
category for the duplicated names and log duplicated property/signals.
This change breaks one of tst_qmljsscope testcase as it expects no
logging within that case, edit it.

Fixes: QTBUG-106579
Change-Id: I7732e08778a25e1eb2ba980ae395564b98c665a5
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-10-22 13:54:48 +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
Sami Shalayel 169f0f7166 qmltc: reject top level components
In qqmljsimportvisitor, print an error message and return false when a
top level component is visited.
Also, remove all the tests expecting qmltc to accept top level
components and add a test to see that the error is correctly emitted for
top level components.
Fix qmllint tests using top level components.

Fixes: QTBUG-106558
Task-number: QTBUG-106547
Change-Id: I101b42fc7499049fcebca18e7aeab57fa6705f81
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-09-19 17:19:03 +02:00
Fabian Kosmale 58e751de88 Disable qmllint's deferred property check
This mirrors 9d22088d93, which removed the
warning from the engine.

Pick-to: 6.4
Task-number: QTBUG-106069
Change-Id: Ib714bfbd251dcf30becd920c85ac65aceab43707
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-08-31 13:09:32 +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
Maximilian Goldstein ffecd90afa qmllint: Hide plugin category
The plugin category is only used for our debugging passes anymore, just
hide it from the user from now. Maybe it could be removed later on.

Change-Id: Ifa7e55ee950277d0b9e75cfe590b9052767a256a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-07-01 10:40:18 +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
Thiago Macieira 067d5a3334 QQmlJSLogger: disable warning from GCC 11 & 12
I think it's coming from the push_back in QQmlJSLogger::log(), but GCC
appears to require the warning be suppressed at the template, not the
instantiation point.

GCC 11:
qarraydataops.h:581:11: error: ‘*(QArrayDataPointer<FixSuggestion::Fix>*)((char*)&tmp + offsetof(Message, Message::fixSuggestion.std::optional<FixSuggestion>::<unnamed>.std::_Optional_base<FixSuggestion, false, false>::<unnamed>)).QArrayDataPointer<FixSuggestion::Fix>::ptr’ is used uninitialized [-Werror=uninitialized]

GCC 12:
qarraydataops.h:581:11: error: ?*(QArrayDataPointer<FixSuggestion::Fix>*)((char*)&tmp + offsetof(Message, Message::fixSuggestion.std::optional<FixSuggestion>::<unnamed>.std::_Optional_base<FixSuggestion, false, false>::<unnamed>)).QArrayDataPointer<FixSuggestion::Fix>::d? may be used uninitialized [-Werror=maybe-uninitialized]

Pick-to: 6.2 6.3 6.4
Change-Id: I0e5f6bec596a4a78bd3bfffd16c995116afc2718
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-06-15 18:09:55 +00: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
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
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
Maximilian Goldstein 651bf47ab3 qmlcompiler: Implement structured QML static analysis
This patch adds the qqmlsa "framework", which is meant as a starting
point for a more structured, extendible static analysis for QML.
While qmllint (or rather, the QQmlJSImportVisitor used by it) can
already do quite a few checks internally, it is hard to extend.
Moreover, the checks there are interspersed with parsing code, and might
run before all types are resolved. We also do not want to add check that
are specific to QtQuick, Controls, Quick3D... into the core QtQml
module. This poses quite a few challenges: For instance, the color in
QML resolver depends on QtQuick/QtGui to check whether a string is
actually a color.

To overcome the issues mentioned above, we introduce the concept of
analysis passes, and a PassManger class. Passes can come in two shapes
currently:
- PropertyPasses run on each property that has a binding assigned to it
- ElementPasses run on each (sub-)object instantiated in the file
  A property can have multiple bindings assigned to it (due to e.g.
  Interceptors, but also for list properties). Therefore we pass a list of
  them to the ElementPass.
  Passes which only want to handle the "normal" case of one binding per
  property can use SimpleElementPass, which for now just takes the first
  property in the list.
Passes have a pure virtual run function, in which the actual work is
done. They also have a filter function, which in the default
implementation simply returns true, which means that the pass will run.
The filter function is there to make writing passes a bit more
structured, by separating the "do I need to analyze this" question from
the actual analysis part.

To solve the issue of library dependencies, we expose a plugin interface
that then returns passes to be run based on the root component.
Then, user can create a plugin implementing the interface,
which we will load the plugins from a known location, and register all
of them. This will be implemented in the next patch in this set.

Limitations:
- The current passes cannot touch the IR, and thus cannot
  really analyze what happens in script binding.
- (inline) components are currently badly handled
- QQmlJSScope has various issuse with grouped properties

Fixes: QTBUG-101604
Original-patch-by: Fabian Kosmale <fabian.kosmale@qt.io>
Change-Id: Ic96259a947fbb17f79aa58ca613c8d0905a9a74c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-03-29 13:28:04 +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 31abba8cdc qmlcompiler: Suggest fix for multiline strings
We can now suggest a template string to use instead that is properly
escaped. Once auto-fixing becomes available we can automatically replace
deprecated multiline strings with the new suggestion.

Task-number: QTBUG-92448
Change-Id: I4e77820b66ae960cde558a62689c5da328b8df5b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-03-02 14:21:08 +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 52c09a27ef qmllint: Use fix suggestions in a more structured way
Fix suggestions are now attached to the warnings they are caused by
and are also accessible via JSON.

This allows us to use the qmllint library for more of tst_qmllint,
greatly improving performance.

Change-Id: Idd0398028bff1272a75dc1193d2c15a25d335dbf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-10 17:11:05 +01:00
Maximilian Goldstein 46f397775e tst_sanity: Also handle ids via qmllint
Utilize our warning against using ids on deferred properties instead
of the id visitor.

To accomplish this cleanly we have to move our deferred property
warnings into a different category.

Also remove the BLACKLIST since the corresponding tests no longer exist
and the qmllint version of them does not require any blacklisting.

Fixes: QTBUG-96021
Change-Id: I35f88157c9c4aa20e006f09a1402e3100fe09fb9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-11-30 19:42:54 +01:00
Ulf Hermann e551331f38 Add a default implementation for QQmlJSAotCompiler
The default AOT compiler compiles QML code in indirect, dynamic mode. It
uses the logger's Log_Compiler category to determine the verbosity of
its output. In addition you can use the qt.qml.compiler.aot category for
even more verbosity. In preparation for using QQmlJSAotCompiler with
qmlcachegen, the default level of that category is increased to
QtFatalMsg. The highest level we actually output is QtDebugMsg, so it
doesn't make a difference yet.

If the logger's Log_Compiler category is set to produce errors, it will
qFatal() on "pragma Strict" violations.

Change-Id: Ieb74bfa7cd51cfa8616792ab467c32f6ba0e0702
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-11-29 23:12:45 +01:00
Maximilian Goldstein 608e1a8053 qmlcompiler: Use QT_BEGIN_NAMESPACE / QT_END_NAMESPACE everywhere
Some code was not properly wrapped in a namespace.

Change-Id: If70fd9782391309c511b66ae01eae43cb36292ac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-11-23 18:45:02 +01:00
Ulf Hermann c8f967f547 qmllint: Force fix suggestions to use QtInfoMsg
It makes no sense to use a higher message level for a fix suggestion. A
fix suggestion should be prefixed by the warning or error that triggers
it. That warning or error should have the actual level.

Change-Id: I4b5a2ec150afd469ea53697546541a7890c525ec
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-11-23 18:06:59 +01:00
Maximilian Goldstein e01ede4378 qmllint: Add ability to warn about not reusing attached types
This is mostly useful as an replacement for Quick Controls' tst_sanity but might also be useful in some other instances.

Fixes: QTBUG-96572
Change-Id: I5cf414bfeb369cbc394563c5c5ed807599b09a2f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-09-29 19:48:51 +02:00
Maximilian Goldstein 83f918b005 qmllint: Add ability to warn about function declarations
Another warning ability we need in order to replace controls' tst_sanity with something more sensible.
Probably not useful outside of that, so it is disabled by default.

Fixes: QTBUG-96573
Change-Id: I6241899f167f7ea5463ff5b3f157c616c1936cd2
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2021-09-24 14:23:42 +02:00
Fawzi Mohamed b69267d429 qmlcompiler: enable standalone building:
- convert to string to in a couple of places to work without
QStringView + operator
- import local files with "*" (not via <private/*>)

Change-Id: I1d7cdcbd39e609f36693733e98d4f74a7260ce88
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-08-31 13:51:06 +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
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 3b28a298b0 qmllint: Formalize fix suggestions
They are now handled by the logger instead of being done by external classes using the ColorOutput directly.
This will allow for modernizing the logger and for automatically applying those suggested fixes.

Fixes: QTBUG-94170
Change-Id: I90b960d22cb91203b8e8a5c69b0fdaf6fca2fc0c
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-07-01 18:08:00 +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 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 04c2546b82 qmllint: Add inline component support
Adds support for inline components for qmllint with a few things not working yet:
- Two inline components referencing each other
- Using inline components before they are declared

These two issues require a larger overhaul of qmllint as a whole and will be addressed in a different change.

Change-Id: I2834702c21a8eb728db4709d6f475c33796b3e4d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-14 16:39:40 +02:00
Maximilian Goldstein c44b350bf6 qmllint: Warn about multiline strings
Task-number: QTBUG-92448
Change-Id: Ic6305f05cb8a0af5c36ac03d8b541ac78cea0612
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-20 14:36:07 +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 3fde335a52 qmllint: Improve import warnings
Import warnings will now always be clearly associated with the line and import that
caused them. They're also visually separated now and don't redundantly show the importing files name in every warning.
Some type of imports such as file or URI based imports never had their warnings processed which is also fixed by this change.

Change-Id: I63d720fcf198ff5302c2566a91cde4c716697f7e
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-03-30 17:42:06 +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