Skip to content

Commit 0aa35c1

Browse files
authored
Add code highlighting (#3557)
1 parent f039717 commit 0aa35c1

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

docs/developers/code-style.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ in `pom.xml` directly.
2828

2929
It is recommended to define version of library to separate property in `pom.xml`:
3030

31-
```
31+
```xml
3232
<project>
3333
<properties>
3434
<caffeine.version>2.6.2</caffeine.version>
@@ -48,7 +48,7 @@ It is recommended to define version of library to separate property in `pom.xml`
4848

4949
Do not use wildcard in imports because they hide what exactly is required by the class.
5050

51-
```
51+
```java
5252
// bad
5353
import java.util.*;
5454

@@ -61,7 +61,7 @@ import java.util.Map;
6161

6262
Prefer to use `camelCase` naming convention for variables and methods.
6363

64-
```
64+
```java
6565
// bad
6666
String account_id = "id";
6767

@@ -71,7 +71,7 @@ String accountId = "id";
7171

7272
Name of variable should be self-explanatory:
7373

74-
```
74+
```java
7575
// bad
7676
String s = resolveParamA();
7777

@@ -83,7 +83,7 @@ This helps other developers flesh your code out better without additional questi
8383

8484
For `Map`s it is recommended to use `To` between key and value designation:
8585

86-
```
86+
```java
8787
// bad
8888
Map<Imp, ExtImp> map = getData();
8989

@@ -97,7 +97,7 @@ Make data transfer object(DTO) classes immutable with static constructor.
9797
This can be achieved by using Lombok and `@Value(staticConstructor="of")`. When constructor uses multiple(more than 4) arguments, use builder instead(`@Builder`).
9898
If dto must be modified somewhere, use builders annotation `toBuilder=true` parameter and rebuild instance by calling `toBuilder()` method.
9999

100-
```
100+
```java
101101
// bad
102102
public class MyDto {
103103

@@ -138,7 +138,7 @@ final MyDto updatedDto = myDto.toBuilder().value("newValue").build();
138138
Although Java supports the `var` keyword at the time of writing this documentation, the maintainers have chosen not to utilize it within the PBS codebase.
139139
Instead, write full variable type.
140140

141-
```
141+
```java
142142
// bad
143143
final var result = getResult();
144144

@@ -150,7 +150,7 @@ final Data result = getResult();
150150

151151
Enclosing parenthesis should be placed on expression end.
152152

153-
```
153+
```java
154154
// bad
155155
methodCall(
156156
long list of arguments
@@ -163,7 +163,7 @@ methodCall(
163163

164164
This also applies for nested expressions.
165165

166-
```
166+
```java
167167
// bad
168168
methodCall(
169169
nestedCall(
@@ -181,7 +181,7 @@ methodCall(
181181

182182
Please, place methods inside a class in call order.
183183

184-
```
184+
```java
185185
// bad
186186
public interface Test {
187187

@@ -249,7 +249,7 @@ Define interface first method, then all methods that it is calling, then second
249249
Not strict, but methods with long parameters list, that cannot be placed on single line,
250250
should add empty line before body definition.
251251

252-
```
252+
```java
253253
// bad
254254
public static void method(
255255
parameters definitions) {
@@ -266,7 +266,7 @@ public static void method(
266266

267267
Use collection literals where it is possible to define and initialize collections.
268268

269-
```
269+
```java
270270
// bad
271271
final List<String> foo = new ArrayList();
272272
foo.add("foo");
@@ -278,7 +278,7 @@ final List<String> foo = List.of("foo", "bar");
278278

279279
Also, use special methods of Collections class for empty or single-value one-line collection creation. This makes developer intention clear and code less error-prone.
280280

281-
```
281+
```java
282282
// bad
283283
return List.of();
284284

@@ -296,7 +296,7 @@ return Collections.singletonList("foo");
296296

297297
It is recommended to declare variable as `final`- not strict but rather project convention to keep the code safe.
298298

299-
```
299+
```java
300300
// bad
301301
String value = "value";
302302

@@ -308,7 +308,7 @@ final String value = "value";
308308

309309
Results of long ternary operators should be on separate lines:
310310

311-
```
311+
```java
312312
// bad
313313
boolean result = someVeryVeryLongConditionThatForcesLineWrap ? firstResult
314314
: secondResult;
@@ -321,7 +321,7 @@ boolean result = someVeryVeryLongConditionThatForcesLineWrap
321321

322322
Not so strict, but short ternary operations should be on one line:
323323

324-
```
324+
```java
325325
// bad
326326
boolean result = someShortCondition
327327
? firstResult
@@ -335,7 +335,7 @@ boolean result = someShortCondition ? firstResult : secondResult;
335335

336336
Do not rely on operator precedence in boolean logic, use parenthesis instead. This will make code simpler and less error-prone.
337337

338-
```
338+
```java
339339
// bad
340340
final boolean result = a && b || c;
341341

@@ -347,7 +347,7 @@ final boolean result = (a && b) || c;
347347

348348
Try to avoid hard-readable multiple nested method calls:
349349

350-
```
350+
```java
351351
// bad
352352
int resolvedValue = resolveValue(fetchExternalJson(url, httpClient), populateAdditionalKeys(mainKeys, keyResolver));
353353

@@ -361,7 +361,7 @@ int resolvedValue = resolveValue(externalJson, additionalKeys);
361361

362362
Try not to retrieve same data more than once:
363363

364-
```
364+
```java
365365
// bad
366366
if (getData() != null) {
367367
final Data resolvedData = resolveData(getData());
@@ -380,7 +380,7 @@ if (data != null) {
380380

381381
If you're dealing with incoming data, please be sure to check if the nested object is not null before chaining.
382382
383-
```
383+
```java
384384
// bad
385385
final ExtRequestTargeting targeting = bidRequest.getExt().getPrebid().getTargeting();
386386
@@ -400,7 +400,7 @@ We are trying to get rid of long chains of null checks, which are described in s
400400
401401
Don't leave commented code (don't think about the future).
402402
403-
```
403+
```java
404404
// bad
405405
// String iWillUseThisLater = "never";
406406
```
@@ -426,7 +426,7 @@ The code should be covered over 90%.
426426
427427
The common way for writing tests has to comply with `given-when-then` style.
428428
429-
```
429+
```java
430430
// given
431431
final BidRequest bidRequest = BidRequest.builder().id("").build();
432432
@@ -451,7 +451,7 @@ The team decided to use name `target` for class instance under test.
451451
452452
Unit tests should be as granular as possible. Try to split unit tests into smaller ones until this is impossible to do.
453453
454-
```
454+
```java
455455
// bad
456456
@Test
457457
public void testFooBar() {
@@ -487,7 +487,7 @@ public void testBar() {
487487
This also applies to cases where same method is tested with different arguments inside single unit test.
488488
Note: This represents the replacement we have selected for parameterized testing.
489489
490-
```
490+
```java
491491
// bad
492492
@Test
493493
public void testFooFirstSecond() {
@@ -527,7 +527,7 @@ It is also recommended to structure test method names with this scheme:
527527
name of method that is being tested, word `should`, what a method should return.
528528
If a method should return something based on a certain condition, add word `when` and description of a condition.
529529
530-
```
530+
```java
531531
// bad
532532
@Test
533533
public void doSomethingTest() {
@@ -547,7 +547,7 @@ public void processDataShouldReturnResultWhenInputIsData() {
547547
548548
Place data used in test as close as possible to test code. This will make tests easier to read, review and understand.
549549
550-
```
550+
```java
551551
// bad
552552
@Test
553553
public void testFoo() {
@@ -576,7 +576,7 @@ This point also implies the next one.
576576
Since we are trying to improve test simplicity and readability and place test data close to tests, we decided to avoid usage of top level constants where it is possible.
577577
Instead, just inline constant values.
578578
579-
```
579+
```java
580580
// bad
581581
public class TestClass {
582582
@@ -609,7 +609,7 @@ public class TestClass {
609609
610610
Don't use real information in tests, like existing endpoint URLs, account IDs, etc.
611611

612-
```
612+
```java
613613
// bad
614614
String ENDPOINT_URL = "https://prebid.org";
615615

0 commit comments

Comments
 (0)