Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-129307

qmllint: implement .qml warnings from qmljsstaticanalysismessage.cpp

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P2: Important
    • 6.9
    • 6.8
    • QML: Tooling
    • None
    • bbce9ea73 (dev), ce69cc78c (dev), 276a5a875 (dev), 343fcd23a (dev), 53ccd3213 (dev), 4fbd77e5c (dev), 0b0690b9c (dev), fdab91dc4 (6.9), 934831b06 (dev), bf6b29fbe (dev), 6dcd494ca (dev), 051cabf58 (dev), 57a638d66 (dev), f4f9d2897 (6.8), 672e181cc (dev)

    Description

      Implement warnings in qmlls from QtC's codemodel for .qml files:

       
      done to be done in progress won't do
       

      • UnknownType not in use as warning
      • ErrInvalidEnumValue
      • ErrEnumValueMustBeStringOrNumber (Already covered by current parser)
        • complains about enum values (not keys)
      • ErrNumberValueExpected (Already covered by qmllint)
        • complains about binding to properties expecting a number type
      • ErrBooleanValueExpected (Already covered by qmllint)
        • complains about binding to properties expecting a boolean type
      • ErrStringValueExpected (Already covered by qmllint)
        • complains about binding to properties expecting a string type
      • ErrInvalidUrl (Already covered by qmllint)
        • is never triggered by QtC
        • seems to have complained in the past about binding to properties expecting an url type
      • WarnFileOrDirectoryDoesNotExist
        • is never triggered by QtC
        • seems to have complained in the past about paths not existing locally
      • ErrInvalidColor
        • uses the predecessor of "QColor::isValidColorName" to check the string value
      • ErrAnchorLineExpected (Already covered by qmllint)
        • seems to have complained in the past about bindings to anchor lines
      • ErrPropertiesCanOnlyHaveOneBinding Covered by QTBUG-118148.
      • ErrIdExpected (Already covered by qmllint)
        • complains about ids not being strings or identifiers
      • ErrInvalidId
        • complains about ids starting with an upper case letter
      • ErrDuplicateId (Already covered by qmllint)
        • complains for ids already used in the document
      • ErrInvalidPropertyName (Already covered by qmllint)
        • complains about properties that don't exist
      • ErrDoesNotHaveMembers (Already covered by qmllint)
        • complains about member accesses "notAnObject.member" on non-objects
      • ErrInvalidMember (Already covered by qmllint)
        • complains about member accesses on non-existing members "object.notAMember"
      • WarnAssignmentInCondition
        • complains about if (x = 3), to avoid mismatches between = and ==
      • WarnCaseWithoutFlowControl
        • complains about case statements that don't break/continue/return and also don't have a "fall through", "fall-through" or "fallthrough" comment
      • WarnEval
        • complains of the usage of the eval function
      • WarnUnreachable
        • complains about unreachable code (behind return statements for example)
      • WarnWith (Already covered by qmllint)
        • complains about usage of "with" statements
      • WarnComma
        • complains about the usage of "," comma expressions, except when inside a for-loop
      • WarnUnnecessaryMessageSuppression (Not sure if really needed)
        • warn about comments that suppress warnings that actually don't suppress warnings, for example the eval warning is M23, but trying to suppress M25 (an unrelated warning) leads to WarnUnnecessaryMessageSuppression:
          // @disable-check M25
          eval("asdf")
          // @enable-check M25
          
        • maybe we should warn about qmllint comments that don't do anything? For example
          property string foo
          Item {
              property string bar: foo // qmllint disable syntax // this does not suppress any warning
          }
          
      • WarnAlreadyFormalParameter
        • when trying to redeclarae a parameter of a function:
          function f(a) {
              const a = 3; // a already is a formal parameter
          }
          
      • WarnAlreadyFunction
        • when trying to redeclare a function:
          function f() {
              function fff() {}
              const fff = 3
          }
          
      • WarnVarUsedBeforeDeclaration (Already covered by qmllint)
      • WarnAlreadyVar
        const fff = 123
        function fff(a,a,a) {} // already a var, can't be a function
        
      • WarnDuplicateDeclaration same as QTBUG-127107
      • WarnFunctionUsedBeforeDeclaration
        fff(a,a,a) // used before declaration
        function fff(a,a,a) {} 
        
      • WarnBooleanConstructor
        • complains about new Boolean() usages
      • WarnStringConstructor
        • complains about new String() usages
      • WarnObjectConstructor (it seems that the linked explanation at https://doc.qt.io/qtcreator/creator-reference-js-and-qml-error-codes.html#javascript-and-qml-error-codes that points to https://github.com/jamesallardice/jslint-error-explanations/blob/master/message-articles/bad-constructor.md, https://github.com/jamesallardice/jslint-error-explanations/blob/master/message-articles/literal-constructor.md and https://github.com/jamesallardice/jslint-error-explanations/blob/master/message-articles/function-constructor.md does not seem to mention Object constructors
        • complains about new Object() usages
      • WarnArrayConstructor
        • complains about new Array() usages
      • WarnFunctionConstructor
        • complains about new Function() usages
      • HintAnonymousFunctionSpacing (is disabled by default)
        • complains about function() I think, where the space is missing between function and ()
      • WarnBlock
        • complains about blocks inside of JS code that contains a var-declaration
          {
              var xxx = 4
          }
          
      • WarnVoid
        • complains about using void expressions
           void 5
          
      • WarnConfusingPluses
        • warns about "+ +" and "- -", like:
          var xxx = 4 + ++x + // here once for `+ ++`
          x++ + 3 // here once of `++ +`
          
      • WarnConfusingMinuses
        • see above
      • HintDeclareVarsInOneLine (disabled by default + warning is never emitted)
      • HintExtraParentheses (disabled by default)
        • complains about nested expressions inside of DeleteExpression, ThrowStatement, ReturnStatement and TypeOfExpression
      • MaybeWarnEqualityTypeCoercion
        • complain about == and Unable to render embedded object: File ( they should be {{===}} and {{) not found.==
      • WarnConfusingExpressionStatement
        • complains about expression statements without side-effects (like {{ 1 + 2; }} for example)
      • StateCannotHaveChildItem
        • complains about children in States
          State {
              property var i: Item {}
          }
          
      • ErrTypeIsInstantiatedRecursively
        • complain about
          // Main.qml
          import QtQuick
          Item { Main{} }
          
        • the QML engine complains about Main is instantiated recursively at runtime
      • HintDeclarationsShouldBeAtStartOfFunction (disabled by default)
      • HintOneStatementPerLine (disabled by default)
      • ErrUnknownComponent (qmllint already complains about unresolved types)
      • ErrCouldNotResolvePrototypeOf (qmllint already complains about unresolved base types)
      • ErrCouldNotResolvePrototype (qmllint already complains about unresolved base types)
        • same as ErrCouldNotResolvePrototypeOf but for types without names
      • ErrPrototypeCycle (qmllint already complains about cyclic inheritances)
      • ErrInvalidPropertyType (not in use by Qt Creator)
      • WarnEqualityTypeCoercion (not in use by Qt Creator)
        • to not be confused with MaybeWarnEqualityTypeCoercion
      • WarnExpectedNewWithUppercaseFunction
        • complains about property var x: MyObject() (with "new" being missing)
      • WarnNewWithLowercaseFunction
        • complains about property var x: new date() (with "date" being lowercase)
      • WarnNumberConstructor
        • complains about using new Number, like property var x: new Number();
      • HintBinaryOperatorSpacing (disabled by default)
      • WarnUnintentinalEmptyBlock
        • complains about empty blocks like property var x: {}
      • HintPreferNonVarPropertyType
        • complains about using "var" for certain types, like strings in property var x: "asfd" for example
      • ErrMissingRequiredProperty (qmllint already complains about required properties not being bound/set)
      • ErrObjectValueExpected (Unused in QtC)
      • ErrArrayValueExpected (Unused in QtC)
      • ErrDifferentValueExpected (Unused in QtC for qml, only used in the json linter)
      • ErrSmallerNumberValueExpected (Unused in QtC for qml, only used in the json linter)
      • ErrLargerNumberValueExpected (Unused in QtC for qml, only used in the json linter)
      • ErrMaximumNumberValueIsExclusive (Unused in QtC for qml, only used in the json linter)
      • ErrMinimumNumberValueIsExclusive (Unused in QtC for qml, only used in the json linter)
      • ErrInvalidStringValuePattern (Unused in QtC for qml, only used in the json linter)
      • ErrLongerStringValueExpected (Unused in QtC for qml, only used in the json linter)
      • ErrShorterStringValueExpected (Unused in QtC for qml, only used in the json linter)
      • ErrInvalidArrayValueLength (Unused in QtC for qml, only used in the json linter)
      • ErrHitMaximumRecursion (qmllint already complains about too much recursion)
      • ErrToManyComponentChildren
        • complains about components with more than one child: Component {Item{} Item {}}
      • WarnComponentRequiresChildren
        • complains about components with no child: Component {}
      • WarnDuplicateImport
        • complains about:
          import QtQuick
          import QtQuick
          Item {}
          
      • ErrAliasReferRoot
      • WarnAliasReferRootHierarchy

      Also, you can find all qtc codemodel warnings in qmljsstaticanalysismessage.cpp's StaticAnalysisMessages::StaticAnalysisMessages() and qmljsstaticanalysismessage.h definition of Type enum (each enum value corresponds to a warning, see also their description in the StaticAnalysisMessages::StaticAnalysisMessages() constructor!)

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-129307
          # Subject Branch Project Status CR V

          Activity

            People

              sami.shalayel Sami Shalayel
              sami.shalayel Sami Shalayel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are 7 open Gerrit changes