@@ -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
```
@@ -194,7 +194,7 @@ function createMicrobrewery(name) {
194
194
** [ ⬆ back to top] ( #table-of-contents ) **
195
195
196
196
## ** Functions**
197
- ### Function arguments (2 or less ideally)
197
+ ### Function arguments (2 or fewer ideally)
198
198
Limiting the amount of function parameters is incredibly important because it
199
199
makes testing your function easier. Having more than three leads to a
200
200
combinatorial explosion where you have to test tons of different cases with
@@ -213,7 +213,7 @@ lot of arguments.
213
213
** Bad:**
214
214
``` javascript
215
215
function createMenu (title , body , buttonText , cancellable ) {
216
- ...
216
+ // ...
217
217
}
218
218
```
219
219
@@ -227,7 +227,7 @@ const menuConfig = {
227
227
}
228
228
229
229
function createMenu (menuConfig ) {
230
- ...
230
+ // ...
231
231
}
232
232
233
233
```
@@ -335,7 +335,7 @@ function tokenize(code) {
335
335
const tokens = [];
336
336
REGEXES .forEach ((REGEX ) => {
337
337
statements .forEach ((statement ) => {
338
- tokens .push ( // ... );
338
+ tokens .push ( /* ... */ );
339
339
})
340
340
});
341
341
@@ -345,7 +345,7 @@ function tokenize(code) {
345
345
function lexer (tokens ) {
346
346
const ast = [];
347
347
tokens .forEach ((token ) => {
348
- ast .push ( // ... );
348
+ ast .push ( /* ... */ );
349
349
});
350
350
351
351
return ast;
@@ -373,7 +373,7 @@ code eligible for refactoring.
373
373
** Bad:**
374
374
``` javascript
375
375
function showDeveloperList (developers ) {
376
- developers .forEach ((developers ) => {
376
+ developers .forEach ((developer ) => {
377
377
const expectedSalary = developer .calculateExpectedSalary ();
378
378
const experience = developer .getExperience ();
379
379
const githubLink = developer .getGithubLink ();
@@ -441,7 +441,7 @@ function writeForumComment(subject, body) {
441
441
** Good** :
442
442
``` javascript
443
443
function writeForumComment (subject = ' No subject' , body = ' No text' ) {
444
- ...
444
+ // ...
445
445
}
446
446
447
447
```
@@ -583,11 +583,11 @@ Array.prototype.diff = function(comparisonArray) {
583
583
const values = [];
584
584
const hash = {};
585
585
586
- for (let i of comparisonArray) {
586
+ for (const i of comparisonArray) {
587
587
hash[i] = true ;
588
588
}
589
589
590
- for (let i of this ) {
590
+ for (const i of this ) {
591
591
if (! hash[i]) {
592
592
values .push (i);
593
593
}
@@ -608,11 +608,11 @@ class SuperArray extends Array {
608
608
const values = [];
609
609
const hash = {};
610
610
611
- for (let i of comparisonArray) {
611
+ for (const i of comparisonArray) {
612
612
hash[i] = true ;
613
613
}
614
614
615
- for (let i of this ) {
615
+ for (const i of this ) {
616
616
if (! hash[i]) {
617
617
values .push (i);
618
618
}
@@ -683,7 +683,7 @@ const totalOutput = programmerOutput
683
683
** Bad:**
684
684
``` javascript
685
685
if (fsm .state === ' fetching' && isEmpty (listNode)) {
686
- // / ...
686
+ // ...
687
687
}
688
688
```
689
689
@@ -737,7 +737,7 @@ just do one thing.
737
737
** Bad:**
738
738
``` javascript
739
739
class Airplane {
740
- // ...
740
+ // ...
741
741
getCruisingAltitude () {
742
742
switch (this .type ) {
743
743
case ' 777' :
@@ -754,25 +754,25 @@ class Airplane {
754
754
** Good** :
755
755
``` javascript
756
756
class Airplane {
757
- // ...
757
+ // ...
758
758
}
759
759
760
760
class Boeing777 extends Airplane {
761
- // ...
761
+ // ...
762
762
getCruisingAltitude () {
763
763
return getMaxAltitude () - getPassengerCount ();
764
764
}
765
765
}
766
766
767
767
class AirForceOne extends Airplane {
768
- // ...
768
+ // ...
769
769
getCruisingAltitude () {
770
770
return getMaxAltitude ();
771
771
}
772
772
}
773
773
774
774
class Cessna extends Airplane {
775
- // ...
775
+ // ...
776
776
getCruisingAltitude () {
777
777
return getMaxAltitude () - getFuelExpenditure ();
778
778
}
@@ -914,7 +914,7 @@ server.
914
914
``` javascript
915
915
class BankAccount {
916
916
constructor () {
917
- this .balance = 1000 ;
917
+ this .balance = 1000 ;
918
918
}
919
919
}
920
920
@@ -928,14 +928,14 @@ bankAccount.balance = bankAccount.balance - 100;
928
928
``` javascript
929
929
class BankAccount {
930
930
constructor () {
931
- this .balance = 1000 ;
931
+ this .balance = 1000 ;
932
932
}
933
933
934
934
// It doesn't have to be prefixed with `get` or `set` to be a getter/setter
935
935
withdraw (amount ) {
936
- if (verifyAmountCanBeDeducted (amount)) {
937
- this .balance -= amount;
938
- }
936
+ if (verifyAmountCanBeDeducted (amount)) {
937
+ this .balance -= amount;
938
+ }
939
939
}
940
940
}
941
941
@@ -1150,12 +1150,12 @@ function renderLargeRectangles(rectangles) {
1150
1150
rectangles .forEach ((rectangle ) => {
1151
1151
rectangle .setWidth (4 );
1152
1152
rectangle .setHeight (5 );
1153
- let area = rectangle .getArea (); // BAD: Will return 25 for Square. Should be 20.
1153
+ const area = rectangle .getArea (); // BAD: Will return 25 for Square. Should be 20.
1154
1154
rectangle .render (area);
1155
1155
})
1156
1156
}
1157
1157
1158
- let rectangles = [new Rectangle (), new Rectangle (), new Square ()];
1158
+ const rectangles = [new Rectangle (), new Rectangle (), new Square ()];
1159
1159
renderLargeRectangles (rectangles);
1160
1160
```
1161
1161
@@ -1918,9 +1918,9 @@ class PerformanceReview {
1918
1918
}
1919
1919
1920
1920
perfReview () {
1921
- this .getPeerReviews ();
1922
- this .getManagerReview ();
1923
- this .getSelfReview ();
1921
+ this .getPeerReviews ();
1922
+ this .getManagerReview ();
1923
+ this .getSelfReview ();
1924
1924
}
1925
1925
1926
1926
getManagerReview () {
@@ -1932,7 +1932,7 @@ class PerformanceReview {
1932
1932
}
1933
1933
}
1934
1934
1935
- let review = new PerformanceReview (user);
1935
+ const review = new PerformanceReview (user);
1936
1936
review .perfReview ();
1937
1937
```
1938
1938
@@ -1944,9 +1944,9 @@ class PerformanceReview {
1944
1944
}
1945
1945
1946
1946
perfReview () {
1947
- this .getPeerReviews ();
1948
- this .getManagerReview ();
1949
- this .getSelfReview ();
1947
+ this .getPeerReviews ();
1948
+ this .getManagerReview ();
1949
+ this .getSelfReview ();
1950
1950
}
1951
1951
1952
1952
getPeerReviews () {
@@ -1971,7 +1971,7 @@ class PerformanceReview {
1971
1971
}
1972
1972
}
1973
1973
1974
- let review = new PerformanceReview (employee);
1974
+ const review = new PerformanceReview (employee);
1975
1975
review .perfReview ();
1976
1976
```
1977
1977
@@ -2072,7 +2072,7 @@ proper indentation and formatting give the visual structure to your code.
2072
2072
// //////////////////////////////////////////////////////////////////////////////
2073
2073
// Scope Model Instantiation
2074
2074
// //////////////////////////////////////////////////////////////////////////////
2075
- const $scope .model = {
2075
+ $scope .model = {
2076
2076
menu: ' foo' ,
2077
2077
nav: ' bar'
2078
2078
};
@@ -2087,7 +2087,7 @@ const actions = function() {
2087
2087
2088
2088
** Good** :
2089
2089
``` javascript
2090
- const $scope .model = {
2090
+ $scope .model = {
2091
2091
menu: ' foo' ,
2092
2092
nav: ' bar'
2093
2093
};
0 commit comments