JavaScript and QML Checks | Qt Creator Documentation
Description: Run static checks on the QML and JavaScript code in your project to find common problems.

- Qt Creator Documentation
- JavaScript and QML Checks
- Qt Creator 17.0.1

Reference

# JavaScript and QML Checks

To run static checks, go to Tools > QML/JS > Run Checks or select Ctrl+Shift+C.

View the results in the QML and QML Analysis filters in Issues.

Note: If you turn on QML Language Server for a project, it uses qmllint to check QML and JavaScript code and to generate warnings, so the error codes and messages differ from those in JavaScript and QML Error Codes.

## Enabling and Disabling Messages

To enable and disable QML and JavaScript messages of the static analyzer:

1. Go to Preferences > Qt Quick > QML/JS Editing.
2. Select Use customized static analyzer.

3. In Enabled, select the messages that you want to see.
4. To show particular messages only for Qt Quick UI files, select them in Only for Qt Quick UI. You cannot enable messages just for non-Qt Quick UI files.

## JavaScript and QML Error Codes

Many of the error messages are similar to the ones in Douglas Crockford's JSLint tool. For more information about JSLint errors, see JSLint Error Explanations.

Id | Severity | Message | Description
--- | --- | --- | ---
M1 | Error | Invalid value for enum |
M2 | Error | Enum value must be a string or a number |
M3 | Error | Number value expected |
M4 | Error | Boolean value expected |
M5 | Error | String value expected |
M6 | Error | Invalid URL |
M7 | Warning | File or directory does not exist |
M8 | Error | Invalid color |
M9 | Error | Anchor line expected |
M10 | Error | Duplicate property binding | For more information, see Duplicate key '{a}' in JSLint Error Explanations.
M11 | Error | Id expected | For more information, see Expected an identifier and instead saw '{a}' (a reserved word) in JSLint Error Explanations.
M14 | Error | Invalid id | For more information, see Expected an identifier and instead saw '{a}' (a reserved word).
M15 | Error | Duplicate id | Ids in a file must be unique. For more information, see Duplicate key '{a}'.
M16 | Error | Invalid property name `name` |
M17 | Error | `Name` does not have members |
M18 | Error | `Field` is not a member of `object` |
M19 | Warning | Assignment in condition | It could be a typing error. If it is intentional, wrap the assignment in parentheses.
M20 | Warning | Unterminated non-empty case block | Case blocks should either be empty or end in a flow control statement such as `break`, `return` or `continue`. Alternatively you can indicate intentional fall through by ending with a `// fall through` comment.
M23 | Warning | Do not use `eval` | For more information, see eval is evil in JSLint Error Explanations.
M28 | Warning | Unreachable | Indicates that the underlined statement will never be executed.
M29 | Warning | Do not use `with` | For more information, see Unexpected 'with' in JSLint Error Explanations.
M30 | Warning | Do not use comma expressions |
M31 | Warning | Unnecessary message suppression |
M103 | Warning | `Name` is already a formal parameter |
M104 | Warning | `Name` is already a function |
M105 | Warning | Var `name` is used before its declaration |
M106 | Warning | `Name` already is a var |
M107 | Warning | `Name` is declared more than once | Variables declared in a function are always visible everywhere in the function, even when declared in nested blocks or `for` statement conditions. Redeclaring a variable has no effect.
M108 | Warning | Function `name` is used before its declaration | For more information, see {a} was used before it was defined in JSLint Error Explanations.
M109 | Warning | Do not use `Boolean` as a constructor | For more information, see Do not use {a} as a constructor in JSLint Error Explanations.
M110 | Warning | Do not use `String` as a constructor | For more information, see Do not use {a} as a constructor.
M111 | Warning | Do not use `Object` as a constructor | For more information, see Do not use {a} as a constructor.
M112 | Warning | Do not use `Array` as a constructor | For more information, see Do not use {a} as a constructor.
M113 | Warning | Do not use `Function` as a constructor | For more information, see Do not use {a} as a constructor.
M114 | Hint | The `function` keyword and the opening parenthesis should be separated by a single space | For more information, see Expected exactly one space between {a} and {b} in JSLint Error Explanations.
M115 | Warning | Do not use stand-alone blocks | Blocks do not affect variable scoping. Thus blocks that are not associated to `if`, `while`, etc. have no effect and should be avoided.
M116 | Warning | Do not use void expressions |
M117 | Warning | Confusing pluses | For more information, see Confusing pluses in JSLint Error Explanations.
M119 | Warning | Confusing minuses | For more information, see Confusing minuses in JSLint Error Explanations.
M121 | Hint | Declare all function vars on a single line |
M123 | Hint | Unnecessary parentheses |
M126 | Warning | `==` and `!=` may perform type coercion, use `===` or `!==` to avoid it | The non-strict equality comparison is allowed to convert its arguments to a common type. That can lead to unexpected results such as `' \t\r\n' == 0` being true. Use the strict equality operators `===` and `!==` and be explicit about conversions you require.
M127 | Warning | Expression statements should be assignments, calls or delete expressions only |
M128 | Error | A state cannot have the specified child item |
M129 | Error | Type cannot be instantiated recursively |
M201 | Hint | Place var declarations at the start of a function | For more information, see Move 'var' declarations to the top of the function in JSLint Error Explanations.
M202 | Hint | Use only one statement per line |
M220 | Error | This type (type name) is not supported as a root element of a UI file (.ui.qml) | For more information about supported QML types, see UI files.
M221 | Error | This type (type name) is not supported in a UI file (.ui.qml) | For more information about supported QML types, see UI files.
M222 | Error | Functions are not supported in a UI file (.ui.qml) | For a list of supported JavaScript functions, see Supported Methods.
M223 | Error | JavaScript blocks are not supported in a UI file (.ui.qml) | For more information about supported features, see UI files.
M224 | Error | Behavior type is not supported in a UI file (.ui.qml) | For more information about supported QML types, see UI files.
M225 | Error | States are only supported in the root item in a UI file (.ui.qml) | For more information about supported features, see UI files.
M226 | Error | Referencing the parent of the root item is not supported in a UI file (.ui.qml) | For more information about supported features, see UI files.
M227 | Error | Do not mix translation functions in a UI file (.ui.qml) | Even though several different translation functions, such as `qsTr` and `qsTrId` are supported, you should pick one and use it consistently within a UI file. For more information, see Qt QML Methods.
M300 | Error | Unknown component |
M301 | Error | Could not resolve the prototype `name` of `object` |
M302 | Error | Could not resolve the prototype `name` |
M303 | Error | Prototype cycle, the last non-repeated component is `name` |
M304 | Error | Invalid property type `name` |
M305 | Warning | `==` and `!=` perform type coercion, use `===` or `!==` to avoid it | See M126.
M306 | Warning | Calls of functions that start with an uppercase letter should use `new` | By convention, functions that start with an uppercase letter are constructor functions that should only be used with `new`.
M307 | Warning | Use `new` only with functions that start with an uppercase letter | For more information, see Do not use {a} as a constructor in JSLint Error Explanations.
M308 | Warning | Do not use `Number` as a constructor | For more information, see Do not use {a} as a constructor.
M309 | Hint | Use spaces around binary operators |
M310 | Warning | Unintentional empty block, use ({}) for empty object literal |
M311 | Hint | Use `type` instead of `var` or `variant` to improve performance |
M312 | Error | Missing property `number` |
M313 | Error | Object value expected |
M314 | Error | Array value expected |
M315 | Error | `Value` value expected |
M316 | Error | Maximum number value is `number` |
M317 | Error | Minimum number value is `number` |
M318 | Error | Maximum number value is exclusive |
M319 | Error | Minimum number value is exclusive |
M320 | Error | String value does not match required pattern |
M321 | Error | Minimum string value length is `number` |
M322 | Error | Maximum string value length is `number` |
M323 | Error | `Number` elements expected in array value | For more information, see The array literal notation [] is preferable in JSLint Error Explanations.
M324 | Error | Hit maximum recursion limit visiting AST, the code model will be unreliable and most likely invalid |
M326 | Error | Components are only allowed to have a single child element | For more information, see Component.
M327 | Warning | Components require a child element | For more information, see Component.
M400 | Warning | Duplicate import | An import statement has been added twice. For more information, see Import Statements.
M401 | Error | Do not reference the root item as alias | The alias property cannot reference the root component directly. Create an instance of the component instead.
M402 | Warning | Avoid referencing the root item in a hierarchy | The alias property cannot reference the root component in a hierarchy. Create an instance of the component instead.
M403 | Error | A when condition cannot contain an object | Set the `when` condition to an expression that evaluates to `true` when the condition is met.

## Resetting the Code Model

If you see the following error messages after you add a new QML module, try building the project and then resetting the code model:

- QML module not found.
- Unknown Component (M300).

To see an error message, move the mouse pointer over code that Qt Creator underlines in the code editor or when you open a QML file in Qt Design Studio.

To reset the code model, select Tools > QML/JS > Reset Code Model.

See also Check code syntax, Using QML modules with plugins, and Analyzing Code.

Reference