33class LinterVisitor
final :
public QQmlJSImportVisitor
37 const QString &implicitImportDirectory,
38 const QStringList &qmldirFiles = QStringList(), QQmlJS::Engine *engine =
nullptr);
43 using QQmlJSImportVisitor::endVisit;
44 using QQmlJSImportVisitor::visit;
46 bool preVisit(QQmlJS::AST::Node *)
override;
47 void postVisit(QQmlJS::AST::Node *)
override;
52 bool visit(QQmlJS::AST::StringLiteral *)
override;
53 bool visit(AST::CommaExpression *)
override;
54 bool visit(QQmlJS::AST::NewMemberExpression *)
override;
55 bool visit(QQmlJS::AST::VoidExpression *ast)
override;
56 bool visit(QQmlJS::AST::BinaryExpression *)
override;
57 bool visit(QQmlJS::AST::UiImport *import)
override;
58 bool visit(QQmlJS::AST::UiEnumDeclaration *uied)
override;
59 bool visit(QQmlJS::AST::CaseBlock *)
override;
60 bool visit(QQmlJS::AST::ExpressionStatement *ast)
override;
61 bool visit(QQmlJS::AST::FunctionDeclaration *fdecl)
override;
62 bool visit(QQmlJS::AST::FunctionExpression *fexpr)
override;
63 bool visit(QQmlJS::AST::UiPublicMember *publicMember)
override;
64 bool visit(QQmlJS::AST::UiObjectDefinition *objectDefinition)
override;
65 bool visit(QQmlJS::AST::Type *typeAnnotation)
override;
67 bool visit(QQmlJS::AST::UiProgram *ast)
override;
70 const QQmlJSScope::JavaScriptIdentifier &identifier)
override;
77 QTypeRevision version;
79 QQmlJS::AST::UiImport *uiImport;
81 SeenImport(QQmlJS::AST::UiImport *i) : filename(i->fileName), id(i->importId), uiImport(i)
84 uri = i->importUri->toString();
86 version = i->version->version;
88 friend bool comparesEqual(
const SeenImport &lhs,
const SeenImport &rhs)
noexcept
90 return lhs.filename == rhs.filename && lhs.uri == rhs.uri
91 && lhs.version == rhs.version && lhs.id == rhs.id;
93 Q_DECLARE_EQUALITY_COMPARABLE(SeenImport)
95 friend size_t qHash(
const SeenImport &i, size_t seed = 0)
97 return qHashMulti(seed, i.filename, i.uri, i.version, i.id);
100 QQmlJS::Engine *m_engine =
nullptr;
101 QSet<SeenImport> m_seenImports;
102 QSet<std::pair<
const QQmlJSScope *, QString>> misplacedJSIdentifiers;
103 std::vector<QQmlJS::AST::Node *> m_ancestryIncludingCurrentNode;
104 QQmlJS::LinterRenamedComponents m_renamedComponents;
106 void handleDuplicateEnums(QQmlJS::AST::UiEnumMemberList *members, QStringView key,
107 const QQmlJS::SourceLocation &location);
108 void warnCaseNoFlowControl(QQmlJS::SourceLocation caseToken)
const;
109 void checkCaseFallthrough(QQmlJS::AST::StatementList *statements, SourceLocation errorLoc,
110 SourceLocation nextLoc);
112 const QString &name,
const QQmlJS::AST::Statement *statement,
113 const QQmlJS::AST::UiPublicMember *associatedPropertyDefinition =
nullptr)
override;
115 const AST::UiPublicMember *associatedPropertyDefinition)
override;
116 void handleUselessExpressionStatement(
const AST::ExpressionStatement *ast);
117 void handleRecursivelyInstantiatedType(AST::UiQualifiedId *qualifiedId);
118 void handleRenamedType(QQmlJS::AST::UiQualifiedId *id);