The warnings should be part of the linting visitor.
Introduce a new warning category for the exising warning about
duplicate enum entries.
Amends bbce9ea73f
This also (re)moves the test for warnings about enums in inline
components from qmltc. These warnings should be generated by qmllint.
Some files that had enum inside of inline components may no longer fail
to compile because of the warning. This is fine as the enum is not
accessible anyways.
Amends f368be4320
Task-number: QTBUG-119890
Change-Id: I90f280e2e443504ab336b4c2ad85bf7e53e4544f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Implement the confusing pluses and minuses warnings. Those are triggered
for weird combinations of unary pluses and pre increments inside of
additions. (same for unary minuses and pre decrements).
Task-number: QTBUG-129307
Change-Id: I45c202efa58a588090d872f0bf8f43523c24a957
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Warn about usages of the void keyword. This warning is off by default,
mirroring the behavior of eslint.
Task-number: QTBUG-129307
Change-Id: Iba1cc09e028d5053ef1aa28f01f1694efa5c250f
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Implement the WarnXConstructor and complain about a specific set of
constructors.
Task-number: QTBUG-129307
Change-Id: I27e0cfcb1f061bb2efff1721da4a2bbdb01fcf2f
Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
Warn when comma expressions are used outside of for-loops.
Task-number: QTBUG-129307
Change-Id: Ic86bf3af7f122f73b70e18c728c72f64c355f982
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Merge conflicts are slowing us down quite a bit when working on
qmllint. Sorting the logging categories will reduce their number.
As a drive-by: fix macro
Change-Id: Ibee997c79b29128c209018a2aa010a35e7d13991
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
The binding might not update if their value changes.
Fixes: QTBUG-112508
Change-Id: I27801d662117a89c0fdddc2aaa2f1dde21b238df
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
The compiler is very polite and does not tell the user about its useless
code. Codegen::statementList(StatementList *ast) silently discards
unreachable statements during byte code generation.
Warn the user that their code is unreachable. Don't warn about
function definitions because these ones are "hoisted" up,
which means that their definition is supposed to be pushed up, so that
they can be used even if they are behind a "return" or "throw"
statement.
Don't use the qqmljsbasicblock analysis for that, it reports too many
"false positives" where the compiler generates dead code that can't be
fixed by the user.
Task-number: QTBUG-129307
Change-Id: Ia26e8af1adf4e63b26dcaa7fb10be73b7eb084d7
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Warn about functions used before their declaration. Its not technically
an error like the "var used before declaration" because functions are
"hoisted up" and therefore available even before their declaration, so
create a new warning category for it instead of reusing the "var used
before declaration" category. Disable the warning by default: Qt Creator
used to have it as default, while other tools like eslint don't.
For the same reason, don't warn about functions used before declaration
during codegen, and add a method to warn about it in
CodeGenWarningInterface. The code for "var used before declaration"
can be reused by function declarations by adding a sourcelocation for
function declarations in the "addLocalVar"-call, so make sure to
differentiate between functions and vars by adding an extra member to
Context::ResolvedName.
Task-number: QTBUG-129307
Change-Id: I83a4f8cd00c120db23a0cec3365a00ed44de2836
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Allow warnings to be emitted in multiple parts, as a preparation step to
have two warnings for "var-used-before-declaration": one of the usage
and one for the declaration.
Added an extra parameter to log that overrides the line number used to
determine whether the current warning is ignored or not. This assumes
that both main and secondary messages both use the same warning
category.
Task-number: QTBUG-129307
Change-Id: I82ed01d417070b13e3c91ea82218e0d858e10d24
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Using an optional lookup '?.' on a base type that cannot be null or
undefined or when looking up an enum value is pointless. We generate a
normal lookup for this in the compiler, but the bytecode keeps these
redundant instructions in.
Task-number: QTBUG-135649
Change-Id: I95d8b4ed22afa1bdc46a3f8b3d60a499d43931ac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Complain about usages of Eval in qmllint, and make the
qqmljstypepropagator analyze eval calls.
Task-number: QTBUG-129307
Change-Id: I577612220383c624e960db60ed755e0f2dbc59aa
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Added some macros to static_assert that the logging categories are
unique in name, settings name and description. This excludes empty
strings.
A duplicate description was already found and fixed thanks to this.
Change-Id: I9fd689065f5bb3a567143ed78211800f88543408
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Warn for assignments inside of if-statement conditions.
Task-number: QTBUG-129307
Change-Id: If1e4d85b6cdbf4f076d91dcf8d7600988f51d6a1
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Fix a typo in the top-level-component description.
Pick-to: 6.8 6.9
Task-number: QTBUG-135020
Change-Id: I22b0e83567fa71346486d206e21e182fabde2718
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
The category is default, it has no setting name and also no commandline
parameter. Remove the bogus ones and use empty strings instead.
Task-number: QTBUG-135020
Change-Id: Ie8847a379c86f705cb7883615bb71b76e08ec4ce
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Make sure both have their own setting key, but still support the
previous "buggy" setting key. Print a deprecated warning when finding
the buggy setting key in a setting file.
Task-number: QTBUG-135020
Change-Id: I364e7e41380de43a0883bcf4d3f6cefcf11b6c90
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Amends d876ce343d and add a description
and a settingname to the missing-enum-entry category, so that it can get
registered into qmllint.
Also fix the test to expect a warning instead of an info message. Info
messages are selected by default for unregistered categories.
Task-number: QTBUG-135020
Change-Id: I1fe3684bb12c198633bb86e1cb96a390f352739b
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Before this commit, adding one warning category required changing three
different code locations. This makes adding new categories complicated
and error-prone. We will need to potentially add a lot of new categories
for QTBUG-129307, and d876ce343d is an
example where a warning category was introduced but not registered into
qmllint (it can't be controlled with commandline parameters, nor
settings, nor is it listed by qmllints --help method...).
With this commit, new warning categories only need to be added in two places:
the QMLLINT_DEFAULT_CATEGORIES macro and the public header
qqmljsloggingcategories.h.
Task-number: QTBUG-135020
Task-number: QTBUG-129307
Change-Id: I915ae8da7fe0a01b7518ed8c113be5bb640de75b
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Add a new disabled mode to qqmljslogger that is used when warnings
emitted by qqmljsimportvisitor are actually not shown to the user. Add a
comment explaining the difference to a silenced logger (that still
processes warnings and can be used to generate a JSON representation of
the warnings) and a disabled logger (that does not contain any warning).
Disable the logger in QQmlJSTypeReader that is only used for the (lazy
file creation.
This avoids expensive didYouMean() calls that slow down the linter and
only create warnings that are ignored by the linter.
Also add some ifs to qqmljslogger to avoid any useless computations when
the logger is disabled anyway.
This commit makes the runtime of tst_qmllint_benchmark:onlyQdsLintPlugin
on qtdesign-studio/examples/DesignEffectsDemo/content/Gallery.ui.qml go
from 500ms to 135ms (mean over 3 iterations) when the QtDesign studio
modules import paths are unavailable.
Task-number: QTBUG-133349
Change-Id: I5abaa5e6776e39f2dee7f1a92577a240dd5c61c1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We should only have one way to handle diagnostic messages: The
QQmlJSLogger. In addition each compile pass may result in an error that
prevents the running of further passes. But that error should not rely
on the selection of messages posted earlier.
For this to work we need to introduce a further state transition into
the logger. The logger now "archives" messages after compiling each
function, so that only the current function's compile errors are taken
into account as result of the current function's compilation.
Task-number: QTBUG-124913
Change-Id: I4b6d9910b80527cefb1aba02598114d1fe5ba172
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Certain compile passes may be run multiple times and only the last run
counts. We need to be able to roll back the logger to the state before
the pass in that case.
Amends commit d70abd83dc
Pick-to: 6.9
Task-number: QTBUG-124913
Change-Id: Ie6174fc3d6ce60ca3f0a3fa27484a58e6febcc17
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
It seems that mixing different translation functions (id-based with
non-id based translations) is not supported in the same qml file.
Therefore, emit a warning when mixing up id and non-id translation
methods.
Currently, it is not possible to have warnings for mixing usages of
QT_TRANSLATE_NOOP(), QT_QSTR_NOOP(), QT_QSTRID_NOOP() but that
should not be too important for the actual feature, as calls to
QT_QSTR_NOOP and QT_TRANSLATE_NOOP only make sense when there is
a qsTr or qsTranslate around.
Add a QEXPECT_FAIL test for that.
Task-number: QTBUG-129308
Change-Id: I8b19ca997cd6b4b8619c53c079dd72b9510fb904
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
In qmllint, the import warnings are printed right after the "warnings
occurred while importing" warning despite them having no sourcelocation.
This warning gets a default sourcelocation when used in qmlls which
points to the first line of the file, so the "Failed to import" warning
ends up an the first line of a file, and not on the same line as the
"warnings occurred while importing" warning. This is confusing for users.
Modify a test to expect that the "Failed to import" warning has a valid
sourcelocation, so that it is shown on the correct line in qmlls.
Fixes: QTBUG-131958
Pick-to: 6.8 6.9
Change-Id: Ia0c327b82e89cd0a003d05b4c3efe693fb3b3ed7
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>