| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | #include <QDebug> | - |
| 30 | #include <QFile> | - |
| 31 | #include <QFileInfo> | - |
| 32 | #if QT_CONFIG(commandlineparser) | - |
| 33 | #include <QCommandLineParser> | - |
| 34 | #endif | - |
| 35 | #include <QCoreApplication> | - |
| 36 | | - |
| 37 | #include <private/qv4value_p.h> | - |
| 38 | #include <private/qqmljslexer_p.h> | - |
| 39 | #include <private/qqmljsparser_p.h> | - |
| 40 | #include <private/qqmljsengine_p.h> | - |
| 41 | | - |
| 42 | static bool lint_file(const QString &filename, bool silent) | - |
| 43 | { | - |
| 44 | QFile file(filename); | - |
| 45 | if (!file.open(QFile::ReadOnly)) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 46 | qWarning() << "Failed to open file" << filename << file.error(); | - |
| 47 | return false; never executed: return false; | 0 |
| 48 | } | - |
| 49 | | - |
| 50 | QString code = QString::fromUtf8(file.readAll()); | - |
| 51 | file.close(); | - |
| 52 | | - |
| 53 | QQmlJS::Engine engine; | - |
| 54 | QQmlJS::Lexer lexer(&engine); | - |
| 55 | | - |
| 56 | QFileInfo info(filename); | - |
| 57 | bool isJavaScript = info.suffix().toLower() == QLatin1String("js"); | - |
| 58 | lexer.setCode(code, 1, !isJavaScript); | - |
| 59 | QQmlJS::Parser parser(&engine); | - |
| 60 | | - |
| 61 | bool success = isJavaScript ? parser.parseProgram() : parser.parse();| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 62 | | - |
| 63 | if (!success && !silent) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 64 | const auto diagnosticMessages = parser.diagnosticMessages(); | - |
| 65 | for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { | - |
| 66 | qWarning("%s:%d : %s", qPrintable(filename), m.loc.startLine, qPrintable(m.message)); | - |
| 67 | } never executed: end of block | 0 |
| 68 | } never executed: end of block | 0 |
| 69 | | - |
| 70 | return success; never executed: return success; | 0 |
| 71 | } | - |
| 72 | | - |
| 73 | int main(int argv, char *argc[]) | - |
| 74 | { | - |
| 75 | QCoreApplication app(argv, argc); | - |
| 76 | QCoreApplication::setApplicationName("qmllint"); | - |
| 77 | QCoreApplication::setApplicationVersion("1.0"); | - |
| 78 | #if QT_CONFIG(commandlineparser) | - |
| 79 | QCommandLineParser parser; | - |
| 80 | parser.setApplicationDescription(QLatin1String("QML syntax verifier")); | - |
| 81 | parser.addHelpOption(); | - |
| 82 | parser.addVersionOption(); | - |
| 83 | QCommandLineOption silentOption(QStringList() << "s" << "silent", QLatin1String("Don't output syntax errors")); | - |
| 84 | parser.addOption(silentOption); | - |
| 85 | parser.addPositionalArgument(QLatin1String("files"), QLatin1String("list of qml or js files to verify")); | - |
| 86 | | - |
| 87 | parser.process(app); | - |
| 88 | | - |
| 89 | const auto positionalArguments = parser.positionalArguments(); | - |
| 90 | if (positionalArguments.isEmpty()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 91 | parser.showHelp(-1); | - |
| 92 | } never executed: end of block | 0 |
| 93 | | - |
| 94 | bool silent = parser.isSet(silentOption); | - |
| 95 | #else | - |
| 96 | bool silent = false; | - |
| 97 | #endif | - |
| 98 | bool success = true; | - |
| 99 | #if QT_CONFIG(commandlineparser) | - |
| 100 | for (const QString &filename : positionalArguments) | - |
| 101 | #else | - |
| 102 | const auto arguments = app.arguments(); | - |
| 103 | for (const QString &filename : arguments) | - |
| 104 | #endif | - |
| 105 | success &= lint_file(filename, silent); never executed: success &= lint_file(filename, silent); | 0 |
| 106 | | - |
| 107 | return success ? 0 : -1; never executed: return success ? 0 : -1; | 0 |
| 108 | } | - |
| | |