@@ -21,7 +21,7 @@ Software engineering principles, from Robert C. Martin's book
21
21
adapted for JavaScript. This is not a style guide. It's a guide to producing
22
22
readable, reusable, and refactorable software in JavaScript.
23
23
24
- Not every principle herein has to be strictly followed, and even less will be
24
+ Not every principle herein has to be strictly followed, and even fewer will be
25
25
universally agreed upon. These are guidelines and nothing more, but they are
26
26
ones codified over many years of collective experience by the authors of
27
27
* Clean Code* .
@@ -118,9 +118,9 @@ const locations = ['Austin', 'New York', 'San Francisco'];
118
118
locations .forEach ((l ) => {
119
119
doStuff ();
120
120
doSomeOtherStuff ();
121
- ...
122
- ...
123
- ...
121
+ // ...
122
+ // ...
123
+ // ...
124
124
// Wait, what is `l` for again?
125
125
dispatch (l);
126
126
});
@@ -132,9 +132,9 @@ const locations = ['Austin', 'New York', 'San Francisco'];
132
132
locations .forEach ((location ) => {
133
133
doStuff ();
134
134
doSomeOtherStuff ();
135
- ...
136
- ...
137
- ...
135
+ // ...
136
+ // ...
137
+ // ...
138
138
dispatch (location);
139
139
});
140
140
```
@@ -205,7 +205,7 @@ function createMicrobrewery(breweryName = 'Hipster Brew Co.') {
205
205
** [ ⬆ back to top] ( #table-of-contents ) **
206
206
207
207
## ** Functions**
208
- ### Function arguments (2 or less ideally)
208
+ ### Function arguments (2 or fewer ideally)
209
209
Limiting the amount of function parameters is incredibly important because it
210
210
makes testing your function easier. Having more than three leads to a
211
211
combinatorial explosion where you have to test tons of different cases with
@@ -224,7 +224,7 @@ lot of arguments.
224
224
** Bad:**
225
225
``` javascript
226
226
function createMenu (title , body , buttonText , cancellable ) {
227
- ...
227
+ // ...
228
228
}
229
229
```
230
230
@@ -238,7 +238,7 @@ const menuConfig = {
238
238
}
239
239
240
240
function createMenu (menuConfig ) {
241
- ...
241
+ // ...
242
242
}
243
243
244
244
```
@@ -346,7 +346,7 @@ function tokenize(code) {
346
346
const tokens = [];
347
347
REGEXES .forEach ((REGEX ) => {
348
348
statements .forEach ((statement ) => {
349
- tokens .push ( // ... );
349
+ tokens .push ( /* ... */ );
350
350
})
351
351
});
352
352
@@ -356,7 +356,7 @@ function tokenize(code) {
356
356
function lexer (tokens ) {
357
357
const ast = [];
358
358
tokens .forEach ((token ) => {
359
- ast .push ( // ... );
359
+ ast .push ( /* ... */ );
360
360
});
361
361
362
362
return ast;
@@ -384,7 +384,7 @@ code eligible for refactoring.
384
384
** Bad:**
385
385
``` javascript
386
386
function showDeveloperList (developers ) {
387
- developers .forEach (developers => {
387
+ developers .forEach (developer => {
388
388
const expectedSalary = developer .calculateExpectedSalary ();
389
389
const experience = developer .getExperience ();
390
390
const githubLink = developer .getGithubLink ();
@@ -575,11 +575,11 @@ Array.prototype.diff = function(comparisonArray) {
575
575
const values = [];
576
576
const hash = {};
577
577
578
- for (let i of comparisonArray) {
578
+ for (const i of comparisonArray) {
579
579
hash[i] = true ;
580
580
}
581
581
582
- for (let i of this ) {
582
+ for (const i of this ) {
583
583
if (! hash[i]) {
584
584
values .push (i);
585
585
}
@@ -600,11 +600,11 @@ class SuperArray extends Array {
600
600
const values = [];
601
601
const hash = {};
602
602
603
- for (let i of comparisonArray) {
603
+ for (const i of comparisonArray) {
604
604
hash[i] = true ;
605
605
}
606
606
607
- for (let i of this ) {
607
+ for (const i of this ) {
608
608
if (! hash[i]) {
609
609
values .push (i);
610
610
}
@@ -675,7 +675,7 @@ const totalOutput = programmerOutput
675
675
** Bad:**
676
676
``` javascript
677
677
if (fsm .state === ' fetching' && isEmpty (listNode)) {
678
- // / ...
678
+ // ...
679
679
}
680
680
```
681
681
@@ -729,7 +729,7 @@ just do one thing.
729
729
** Bad:**
730
730
``` javascript
731
731
class Airplane {
732
- // ...
732
+ // ...
733
733
getCruisingAltitude () {
734
734
switch (this .type ) {
735
735
case ' 777' :
@@ -746,25 +746,25 @@ class Airplane {
746
746
** Good** :
747
747
``` javascript
748
748
class Airplane {
749
- // ...
749
+ // ...
750
750
}
751
751
752
752
class Boeing777 extends Airplane {
753
- // ...
753
+ // ...
754
754
getCruisingAltitude () {
755
755
return getMaxAltitude () - getPassengerCount ();
756
756
}
757
757
}
758
758
759
759
class AirForceOne extends Airplane {
760
- // ...
760
+ // ...
761
761
getCruisingAltitude () {
762
762
return getMaxAltitude ();
763
763
}
764
764
}
765
765
766
766
class Cessna extends Airplane {
767
- // ...
767
+ // ...
768
768
getCruisingAltitude () {
769
769
return getMaxAltitude () - getFuelExpenditure ();
770
770
}
@@ -906,7 +906,7 @@ server.
906
906
``` javascript
907
907
class BankAccount {
908
908
constructor () {
909
- this .balance = 1000 ;
909
+ this .balance = 1000 ;
910
910
}
911
911
}
912
912
@@ -920,14 +920,14 @@ bankAccount.balance = bankAccount.balance - 100;
920
920
``` javascript
921
921
class BankAccount {
922
922
constructor () {
923
- this .balance = 1000 ;
923
+ this .balance = 1000 ;
924
924
}
925
925
926
926
// It doesn't have to be prefixed with `get` or `set` to be a getter/setter
927
927
withdraw (amount ) {
928
- if (verifyAmountCanBeDeducted (amount)) {
929
- this .balance -= amount;
930
- }
928
+ if (verifyAmountCanBeDeducted (amount)) {
929
+ this .balance -= amount;
930
+ }
931
931
}
932
932
}
933
933
@@ -1142,12 +1142,12 @@ function renderLargeRectangles(rectangles) {
1142
1142
rectangles .forEach ((rectangle ) => {
1143
1143
rectangle .setWidth (4 );
1144
1144
rectangle .setHeight (5 );
1145
- let area = rectangle .getArea (); // BAD: Will return 25 for Square. Should be 20.
1145
+ const area = rectangle .getArea (); // BAD: Will return 25 for Square. Should be 20.
1146
1146
rectangle .render (area);
1147
1147
})
1148
1148
}
1149
1149
1150
- let rectangles = [new Rectangle (), new Rectangle (), new Square ()];
1150
+ const rectangles = [new Rectangle (), new Rectangle (), new Square ()];
1151
1151
renderLargeRectangles (rectangles);
1152
1152
```
1153
1153
@@ -1910,9 +1910,9 @@ class PerformanceReview {
1910
1910
}
1911
1911
1912
1912
perfReview () {
1913
- this .getPeerReviews ();
1914
- this .getManagerReview ();
1915
- this .getSelfReview ();
1913
+ this .getPeerReviews ();
1914
+ this .getManagerReview ();
1915
+ this .getSelfReview ();
1916
1916
}
1917
1917
1918
1918
getManagerReview () {
@@ -1924,7 +1924,7 @@ class PerformanceReview {
1924
1924
}
1925
1925
}
1926
1926
1927
- let review = new PerformanceReview (user);
1927
+ const review = new PerformanceReview (user);
1928
1928
review .perfReview ();
1929
1929
```
1930
1930
@@ -1936,9 +1936,9 @@ class PerformanceReview {
1936
1936
}
1937
1937
1938
1938
perfReview () {
1939
- this .getPeerReviews ();
1940
- this .getManagerReview ();
1941
- this .getSelfReview ();
1939
+ this .getPeerReviews ();
1940
+ this .getManagerReview ();
1941
+ this .getSelfReview ();
1942
1942
}
1943
1943
1944
1944
getPeerReviews () {
@@ -1963,7 +1963,7 @@ class PerformanceReview {
1963
1963
}
1964
1964
}
1965
1965
1966
- let review = new PerformanceReview (employee);
1966
+ const review = new PerformanceReview (employee);
1967
1967
review .perfReview ();
1968
1968
```
1969
1969
@@ -2064,7 +2064,7 @@ proper indentation and formatting give the visual structure to your code.
2064
2064
// //////////////////////////////////////////////////////////////////////////////
2065
2065
// Scope Model Instantiation
2066
2066
// //////////////////////////////////////////////////////////////////////////////
2067
- const $scope .model = {
2067
+ $scope .model = {
2068
2068
menu: ' foo' ,
2069
2069
nav: ' bar'
2070
2070
};
@@ -2079,7 +2079,7 @@ const actions = function() {
2079
2079
2080
2080
** Good** :
2081
2081
``` javascript
2082
- const $scope .model = {
2082
+ $scope .model = {
2083
2083
menu: ' foo' ,
2084
2084
nav: ' bar'
2085
2085
};
0 commit comments