Skip to content

Commit 18d773e

Browse files
committed
Add QML EOL semicolon usage rules to Coding Standards
1 parent adbf59f commit 18d773e

File tree

1 file changed

+61
-0
lines changed
  • 04.build-guide/08.coding-standards

1 file changed

+61
-0
lines changed

04.build-guide/08.coding-standards/docs.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,3 +1047,64 @@ These types of comments are explicitly not allowed. If you need to break up sect
10471047
//--------------------------------------------------------------------------------
10481048
```
10491049

1050+
## 5 QML Standards
1051+
1052+
### 5.1 Semicolon Usage
1053+
1054+
QT's official [http://doc.qt.io/qt-5/qml-codingconventions.html](QML Coding Standards guide) and QML documentation isn't always consistent with respect to end-of-line semicolon usage. When writing QML code for High Fidelity, follow these rules with respect to semicolons:
1055+
1056+
#### Multi-Line Property Expressions
1057+
1058+
*DO* use semicolons at the end of lines when defining multi-line property expressions:
1059+
1060+
```
1061+
height: {
1062+
if (parent.height > 100) {
1063+
return parent.height;
1064+
} else {
1065+
return parent.height / 2;
1066+
}
1067+
}
1068+
```
1069+
1070+
#### Signal Handlers
1071+
1072+
*DO* use semicolons at the end of lines when defining signal handlers:
1073+
1074+
```
1075+
onRepositionLockedChanged: {
1076+
if (!repositionLocked) {
1077+
d.handleSizeChanged();
1078+
}
1079+
}
1080+
```
1081+
1082+
#### JavaScript Functions within QML
1083+
1084+
*DO* use semicolons at the end of lines when defining JavaScript functions and signals from within QML:
1085+
1086+
```
1087+
function fromScript(message) {
1088+
console.log("Hello world!");
1089+
console.log(JSON.stringify(message));
1090+
}
1091+
```
1092+
1093+
```
1094+
signal sendToScript(var message);
1095+
```
1096+
1097+
#### All Other Cases
1098+
1099+
*DO NOT* use semicolons at the end of lines in all other cases:
1100+
1101+
```
1102+
id: root
1103+
height: parent.height > 100 ? parent.height : parent.height/2
1104+
width: 25
1105+
1106+
Text {
1107+
text: "hello"
1108+
font.bold: true; font.italic: true; font.pixelSize: 20; font.capitalization: Font.AllUppercase
1109+
}
1110+
```

0 commit comments

Comments
 (0)