Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/tools/qmllint/main.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | static bool lint_file(const QString &filename, bool silent) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | QFile file(filename); | - | ||||||||||||
8 | if (!file.open(QFile::ReadOnly)
| 0 | ||||||||||||
9 | QMessageLogger(__FILE__, 46, __PRETTY_FUNCTION__).warning() << "Failed to open file" << filename << file.error(); | - | ||||||||||||
10 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
11 | } | - | ||||||||||||
12 | - | |||||||||||||
13 | QString code = QString::fromUtf8(file.readAll()); | - | ||||||||||||
14 | file.close(); | - | ||||||||||||
15 | - | |||||||||||||
16 | QQmlJS::Engine engine; | - | ||||||||||||
17 | QQmlJS::Lexer lexer(&engine); | - | ||||||||||||
18 | - | |||||||||||||
19 | QFileInfo info(filename); | - | ||||||||||||
20 | bool isJavaScript = info.suffix().toLower() == QLatin1String("js"); | - | ||||||||||||
21 | lexer.setCode(code, 1, !isJavaScript); | - | ||||||||||||
22 | QQmlJS::Parser parser(&engine); | - | ||||||||||||
23 | - | |||||||||||||
24 | bool success = isJavaScript
| 0 | ||||||||||||
25 | - | |||||||||||||
26 | if (!success
| 0 | ||||||||||||
27 | const auto diagnosticMessages = parser.diagnosticMessages(); | - | ||||||||||||
28 | for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { | - | ||||||||||||
29 | QMessageLogger(__FILE__, 66, __PRETTY_FUNCTION__).warning("%s:%d : %s", QtPrivate::asString(filename).toLocal8Bit().constData(), m.loc.startLine, QtPrivate::asString(m.message).toLocal8Bit().constData()); | - | ||||||||||||
30 | } never executed: end of block | 0 | ||||||||||||
31 | } never executed: end of block | 0 | ||||||||||||
32 | - | |||||||||||||
33 | return never executed: success;return success; never executed: return success; | 0 | ||||||||||||
34 | } | - | ||||||||||||
35 | - | |||||||||||||
36 | int main(int argv, char *argc[]) | - | ||||||||||||
37 | { | - | ||||||||||||
38 | QCoreApplication app(argv, argc); | - | ||||||||||||
39 | QCoreApplication::setApplicationName("qmllint"); | - | ||||||||||||
40 | QCoreApplication::setApplicationVersion("1.0"); | - | ||||||||||||
41 | - | |||||||||||||
42 | QCommandLineParser parser; | - | ||||||||||||
43 | parser.setApplicationDescription(QLatin1String("QML syntax verifier")); | - | ||||||||||||
44 | parser.addHelpOption(); | - | ||||||||||||
45 | parser.addVersionOption(); | - | ||||||||||||
46 | QCommandLineOption silentOption(QStringList() << "s" << "silent", QLatin1String("Don't output syntax errors")); | - | ||||||||||||
47 | parser.addOption(silentOption); | - | ||||||||||||
48 | parser.addPositionalArgument(QLatin1String("files"), QLatin1String("list of qml or js files to verify")); | - | ||||||||||||
49 | - | |||||||||||||
50 | parser.process(app); | - | ||||||||||||
51 | - | |||||||||||||
52 | const auto positionalArguments = parser.positionalArguments(); | - | ||||||||||||
53 | if (positionalArguments.isEmpty()
| 0 | ||||||||||||
54 | parser.showHelp(-1); | - | ||||||||||||
55 | } never executed: end of block | 0 | ||||||||||||
56 | - | |||||||||||||
57 | bool silent = parser.isSet(silentOption); | - | ||||||||||||
58 | - | |||||||||||||
59 | - | |||||||||||||
60 | - | |||||||||||||
61 | bool success = true; | - | ||||||||||||
62 | - | |||||||||||||
63 | for (const QString &filename : positionalArguments) | - | ||||||||||||
64 | - | |||||||||||||
65 | - | |||||||||||||
66 | - | |||||||||||||
67 | - | |||||||||||||
68 | success &= lint_file(filename, silent); never executed: success &= lint_file(filename, silent); | 0 | ||||||||||||
69 | - | |||||||||||||
70 | return never executed: success ? 0 : -1;return success ? 0 : -1; never executed: return success ? 0 : -1; | 0 | ||||||||||||
71 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |