As you write code, Qt Creator checks code syntax. When Qt Creator spots a syntax error in your code it underlines it and shows error details when you move the mouse pointer over the error. Similarly, when you are working on an instance of a JavaScript object notation (JSON) entity, Qt Creator underlines errors in JSON data structure.
In the following figure, a semicolon is missing at the end of the line.
In the following figure, the variable is not used.
In addition, you can run static checks on the QML and JavaScript code in your project to find common problems.
Qt Creator validates instances of JSON entities against A JSON Media Type for Describing the Structure and Meaning of JSON Documents. However, this feature is still under development, and Qt Creator does not yet understand the entire specification.
A JSON schema defines the structure of JSON data. It determines what JSON data is required for an application and how to interact with it.
The specification does not define how to map JSON instances with JSON schemas. As a temporary solution, Qt Creator looks for a JSON schema file with a name that matches the name of the JSON instance file in the user configuration folder. For example, ~/config/QtProject/qtcreator/json on Linux and Mac OS and C:\Users\username\AppData\Roaming\QtCreator\qtcreator\json in Windows. To check JSON data structure, copy the JSON schema file to the above folder.
To run the checks, select Tools > QML/JS > Run Checks or press Ctrl+Shift+C. The results are shown in the QML Analysis filter of the Issues output pane.
Many of the JavaScript checks are similar to the ones in Douglas Crockford's JSLint tool and are explained well on the JSLint website.
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 | |
M11 | Error | Id expected | |
M14 | Error | Invalid id | |
M15 | Error | Duplicate id | Ids in a file must be unique. |
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' | |
M28 | Warning | Unreachable | Indicates that the underlined statement will never be executed. |
M29 | Warning | Do not use 'with' | |
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' is already 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 | |
M109 | Warning | Do not use 'Boolean' as a constructor | |
M110 | Warning | Do not use 'String' as a constructor | |
M111 | Warning | Do not use 'Object' as a constructor | |
M112 | Warning | Do not use 'Array' as a constructor | |
M113 | Warning | Do not use 'Function' as a constructor | |
M114 | Hint | The 'function' keyword and the opening parenthesis should be separated by a single space | |
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 | |
M119 | Warning | Confusing minuses | |
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 | 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. Prefer to use the strict equality operators === and !== and be explicit about conversions you require. |
M305 | Warning | == and != perform type coercion, use === or !== to avoid | (see above) |
M127 | Warning | Expression statements should be assignments, calls or delete expressions only | |
M201 | Hint | Var declarations should be at the start of a function | |
M202 | Hint | Only use one statement per line | |
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' | |
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 | 'new' should only be used with functions that start with an uppercase letter | |
M308 | Warning | Do not use 'Number' 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 |