@@ -21,7 +21,7 @@ Software engineering principles, from Robert C. Martin's book
2121adapted for JavaScript. This is not a style guide. It's a guide to producing
2222readable, reusable, and refactorable software in JavaScript.
2323
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
2525universally agreed upon. These are guidelines and nothing more, but they are
2626ones codified over many years of collective experience by the authors of
2727* Clean Code* .
@@ -118,9 +118,9 @@ const locations = ['Austin', 'New York', 'San Francisco'];
118118locations .forEach ((l ) => {
119119 doStuff ();
120120 doSomeOtherStuff ();
121- ...
122- ...
123- ...
121+ // ...
122+ // ...
123+ // ...
124124 // Wait, what is `l` for again?
125125 dispatch (l);
126126});
@@ -132,9 +132,9 @@ const locations = ['Austin', 'New York', 'San Francisco'];
132132locations .forEach ((location ) => {
133133 doStuff ();
134134 doSomeOtherStuff ();
135- ...
136- ...
137- ...
135+ // ...
136+ // ...
137+ // ...
138138 dispatch (location);
139139});
140140```
@@ -205,7 +205,7 @@ function createMicrobrewery(breweryName = 'Hipster Brew Co.') {
205205** [ ⬆ back to top] ( #table-of-contents ) **
206206
207207## ** Functions**
208- ### Function arguments (2 or less ideally)
208+ ### Function arguments (2 or fewer ideally)
209209Limiting the amount of function parameters is incredibly important because it
210210makes testing your function easier. Having more than three leads to a
211211combinatorial explosion where you have to test tons of different cases with
@@ -224,7 +224,7 @@ lot of arguments.
224224** Bad:**
225225``` javascript
226226function createMenu (title , body , buttonText , cancellable ) {
227- ...
227+ // ...
228228}
229229```
230230
@@ -238,7 +238,7 @@ const menuConfig = {
238238}
239239
240240function createMenu (menuConfig ) {
241- ...
241+ // ...
242242}
243243
244244```
@@ -346,7 +346,7 @@ function tokenize(code) {
346346 const tokens = [];
347347 REGEXES .forEach ((REGEX ) => {
348348 statements .forEach ((statement ) => {
349- tokens .push ( // ... );
349+ tokens .push ( /* ... */ );
350350 })
351351 });
352352
@@ -356,7 +356,7 @@ function tokenize(code) {
356356function lexer (tokens ) {
357357 const ast = [];
358358 tokens .forEach ((token ) => {
359- ast .push ( // ... );
359+ ast .push ( /* ... */ );
360360 });
361361
362362 return ast;
@@ -384,7 +384,7 @@ code eligible for refactoring.
384384** Bad:**
385385``` javascript
386386function showDeveloperList (developers ) {
387- developers .forEach (developers => {
387+ developers .forEach (developer => {
388388 const expectedSalary = developer .calculateExpectedSalary ();
389389 const experience = developer .getExperience ();
390390 const githubLink = developer .getGithubLink ();
@@ -575,11 +575,11 @@ Array.prototype.diff = function(comparisonArray) {
575575 const values = [];
576576 const hash = {};
577577
578- for (let i of comparisonArray) {
578+ for (const i of comparisonArray) {
579579 hash[i] = true ;
580580 }
581581
582- for (let i of this ) {
582+ for (const i of this ) {
583583 if (! hash[i]) {
584584 values .push (i);
585585 }
@@ -600,11 +600,11 @@ class SuperArray extends Array {
600600 const values = [];
601601 const hash = {};
602602
603- for (let i of comparisonArray) {
603+ for (const i of comparisonArray) {
604604 hash[i] = true ;
605605 }
606606
607- for (let i of this ) {
607+ for (const i of this ) {
608608 if (! hash[i]) {
609609 values .push (i);
610610 }
@@ -675,7 +675,7 @@ const totalOutput = programmerOutput
675675** Bad:**
676676``` javascript
677677if (fsm .state === ' fetching' && isEmpty (listNode)) {
678- // / ...
678+ // ...
679679}
680680```
681681
@@ -729,7 +729,7 @@ just do one thing.
729729** Bad:**
730730``` javascript
731731class Airplane {
732- // ...
732+ // ...
733733 getCruisingAltitude () {
734734 switch (this .type ) {
735735 case ' 777' :
@@ -746,25 +746,25 @@ class Airplane {
746746** Good** :
747747``` javascript
748748class Airplane {
749- // ...
749+ // ...
750750}
751751
752752class Boeing777 extends Airplane {
753- // ...
753+ // ...
754754 getCruisingAltitude () {
755755 return getMaxAltitude () - getPassengerCount ();
756756 }
757757}
758758
759759class AirForceOne extends Airplane {
760- // ...
760+ // ...
761761 getCruisingAltitude () {
762762 return getMaxAltitude ();
763763 }
764764}
765765
766766class Cessna extends Airplane {
767- // ...
767+ // ...
768768 getCruisingAltitude () {
769769 return getMaxAltitude () - getFuelExpenditure ();
770770 }
@@ -906,7 +906,7 @@ server.
906906``` javascript
907907class BankAccount {
908908 constructor () {
909- this .balance = 1000 ;
909+ this .balance = 1000 ;
910910 }
911911}
912912
@@ -920,14 +920,14 @@ bankAccount.balance = bankAccount.balance - 100;
920920``` javascript
921921class BankAccount {
922922 constructor () {
923- this .balance = 1000 ;
923+ this .balance = 1000 ;
924924 }
925925
926926 // It doesn't have to be prefixed with `get` or `set` to be a getter/setter
927927 withdraw (amount ) {
928- if (verifyAmountCanBeDeducted (amount)) {
929- this .balance -= amount;
930- }
928+ if (verifyAmountCanBeDeducted (amount)) {
929+ this .balance -= amount;
930+ }
931931 }
932932}
933933
@@ -1142,12 +1142,12 @@ function renderLargeRectangles(rectangles) {
11421142 rectangles .forEach ((rectangle ) => {
11431143 rectangle .setWidth (4 );
11441144 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.
11461146 rectangle .render (area);
11471147 })
11481148}
11491149
1150- let rectangles = [new Rectangle (), new Rectangle (), new Square ()];
1150+ const rectangles = [new Rectangle (), new Rectangle (), new Square ()];
11511151renderLargeRectangles (rectangles);
11521152```
11531153
@@ -1910,9 +1910,9 @@ class PerformanceReview {
19101910 }
19111911
19121912 perfReview () {
1913- this .getPeerReviews ();
1914- this .getManagerReview ();
1915- this .getSelfReview ();
1913+ this .getPeerReviews ();
1914+ this .getManagerReview ();
1915+ this .getSelfReview ();
19161916 }
19171917
19181918 getManagerReview () {
@@ -1924,7 +1924,7 @@ class PerformanceReview {
19241924 }
19251925}
19261926
1927- let review = new PerformanceReview (user);
1927+ const review = new PerformanceReview (user);
19281928review .perfReview ();
19291929```
19301930
@@ -1936,9 +1936,9 @@ class PerformanceReview {
19361936 }
19371937
19381938 perfReview () {
1939- this .getPeerReviews ();
1940- this .getManagerReview ();
1941- this .getSelfReview ();
1939+ this .getPeerReviews ();
1940+ this .getManagerReview ();
1941+ this .getSelfReview ();
19421942 }
19431943
19441944 getPeerReviews () {
@@ -1963,7 +1963,7 @@ class PerformanceReview {
19631963 }
19641964}
19651965
1966- let review = new PerformanceReview (employee);
1966+ const review = new PerformanceReview (employee);
19671967review .perfReview ();
19681968```
19691969
@@ -2064,7 +2064,7 @@ proper indentation and formatting give the visual structure to your code.
20642064// //////////////////////////////////////////////////////////////////////////////
20652065// Scope Model Instantiation
20662066// //////////////////////////////////////////////////////////////////////////////
2067- const $scope .model = {
2067+ $scope .model = {
20682068 menu: ' foo' ,
20692069 nav: ' bar'
20702070};
@@ -2079,7 +2079,7 @@ const actions = function() {
20792079
20802080** Good** :
20812081``` javascript
2082- const $scope .model = {
2082+ $scope .model = {
20832083 menu: ' foo' ,
20842084 nav: ' bar'
20852085};
0 commit comments