@@ -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```
@@ -194,7 +194,7 @@ function createMicrobrewery(name) {
194194** [ ⬆ back to top] ( #table-of-contents ) **
195195
196196## ** Functions**
197- ### Function arguments (2 or less ideally)
197+ ### Function arguments (2 or fewer ideally)
198198Limiting the amount of function parameters is incredibly important because it
199199makes testing your function easier. Having more than three leads to a
200200combinatorial explosion where you have to test tons of different cases with
@@ -213,7 +213,7 @@ lot of arguments.
213213** Bad:**
214214``` javascript
215215function createMenu (title , body , buttonText , cancellable ) {
216- ...
216+ // ...
217217}
218218```
219219
@@ -227,7 +227,7 @@ const menuConfig = {
227227}
228228
229229function createMenu (menuConfig ) {
230- ...
230+ // ...
231231}
232232
233233```
@@ -335,7 +335,7 @@ function tokenize(code) {
335335 const tokens = [];
336336 REGEXES .forEach ((REGEX ) => {
337337 statements .forEach ((statement ) => {
338- tokens .push ( // ... );
338+ tokens .push ( /* ... */ );
339339 })
340340 });
341341
@@ -345,7 +345,7 @@ function tokenize(code) {
345345function lexer (tokens ) {
346346 const ast = [];
347347 tokens .forEach ((token ) => {
348- ast .push ( // ... );
348+ ast .push ( /* ... */ );
349349 });
350350
351351 return ast;
@@ -373,7 +373,7 @@ code eligible for refactoring.
373373** Bad:**
374374``` javascript
375375function showDeveloperList (developers ) {
376- developers .forEach ((developers ) => {
376+ developers .forEach ((developer ) => {
377377 const expectedSalary = developer .calculateExpectedSalary ();
378378 const experience = developer .getExperience ();
379379 const githubLink = developer .getGithubLink ();
@@ -441,7 +441,7 @@ function writeForumComment(subject, body) {
441441** Good** :
442442``` javascript
443443function writeForumComment (subject = ' No subject' , body = ' No text' ) {
444- ...
444+ // ...
445445}
446446
447447```
@@ -583,11 +583,11 @@ Array.prototype.diff = function(comparisonArray) {
583583 const values = [];
584584 const hash = {};
585585
586- for (let i of comparisonArray) {
586+ for (const i of comparisonArray) {
587587 hash[i] = true ;
588588 }
589589
590- for (let i of this ) {
590+ for (const i of this ) {
591591 if (! hash[i]) {
592592 values .push (i);
593593 }
@@ -608,11 +608,11 @@ class SuperArray extends Array {
608608 const values = [];
609609 const hash = {};
610610
611- for (let i of comparisonArray) {
611+ for (const i of comparisonArray) {
612612 hash[i] = true ;
613613 }
614614
615- for (let i of this ) {
615+ for (const i of this ) {
616616 if (! hash[i]) {
617617 values .push (i);
618618 }
@@ -683,7 +683,7 @@ const totalOutput = programmerOutput
683683** Bad:**
684684``` javascript
685685if (fsm .state === ' fetching' && isEmpty (listNode)) {
686- // / ...
686+ // ...
687687}
688688```
689689
@@ -737,7 +737,7 @@ just do one thing.
737737** Bad:**
738738``` javascript
739739class Airplane {
740- // ...
740+ // ...
741741 getCruisingAltitude () {
742742 switch (this .type ) {
743743 case ' 777' :
@@ -754,25 +754,25 @@ class Airplane {
754754** Good** :
755755``` javascript
756756class Airplane {
757- // ...
757+ // ...
758758}
759759
760760class Boeing777 extends Airplane {
761- // ...
761+ // ...
762762 getCruisingAltitude () {
763763 return getMaxAltitude () - getPassengerCount ();
764764 }
765765}
766766
767767class AirForceOne extends Airplane {
768- // ...
768+ // ...
769769 getCruisingAltitude () {
770770 return getMaxAltitude ();
771771 }
772772}
773773
774774class Cessna extends Airplane {
775- // ...
775+ // ...
776776 getCruisingAltitude () {
777777 return getMaxAltitude () - getFuelExpenditure ();
778778 }
@@ -914,7 +914,7 @@ server.
914914``` javascript
915915class BankAccount {
916916 constructor () {
917- this .balance = 1000 ;
917+ this .balance = 1000 ;
918918 }
919919}
920920
@@ -928,14 +928,14 @@ bankAccount.balance = bankAccount.balance - 100;
928928``` javascript
929929class BankAccount {
930930 constructor () {
931- this .balance = 1000 ;
931+ this .balance = 1000 ;
932932 }
933933
934934 // It doesn't have to be prefixed with `get` or `set` to be a getter/setter
935935 withdraw (amount ) {
936- if (verifyAmountCanBeDeducted (amount)) {
937- this .balance -= amount;
938- }
936+ if (verifyAmountCanBeDeducted (amount)) {
937+ this .balance -= amount;
938+ }
939939 }
940940}
941941
@@ -1150,12 +1150,12 @@ function renderLargeRectangles(rectangles) {
11501150 rectangles .forEach ((rectangle ) => {
11511151 rectangle .setWidth (4 );
11521152 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.
11541154 rectangle .render (area);
11551155 })
11561156}
11571157
1158- let rectangles = [new Rectangle (), new Rectangle (), new Square ()];
1158+ const rectangles = [new Rectangle (), new Rectangle (), new Square ()];
11591159renderLargeRectangles (rectangles);
11601160```
11611161
@@ -1918,9 +1918,9 @@ class PerformanceReview {
19181918 }
19191919
19201920 perfReview () {
1921- this .getPeerReviews ();
1922- this .getManagerReview ();
1923- this .getSelfReview ();
1921+ this .getPeerReviews ();
1922+ this .getManagerReview ();
1923+ this .getSelfReview ();
19241924 }
19251925
19261926 getManagerReview () {
@@ -1932,7 +1932,7 @@ class PerformanceReview {
19321932 }
19331933}
19341934
1935- let review = new PerformanceReview (user);
1935+ const review = new PerformanceReview (user);
19361936review .perfReview ();
19371937```
19381938
@@ -1944,9 +1944,9 @@ class PerformanceReview {
19441944 }
19451945
19461946 perfReview () {
1947- this .getPeerReviews ();
1948- this .getManagerReview ();
1949- this .getSelfReview ();
1947+ this .getPeerReviews ();
1948+ this .getManagerReview ();
1949+ this .getSelfReview ();
19501950 }
19511951
19521952 getPeerReviews () {
@@ -1971,7 +1971,7 @@ class PerformanceReview {
19711971 }
19721972}
19731973
1974- let review = new PerformanceReview (employee);
1974+ const review = new PerformanceReview (employee);
19751975review .perfReview ();
19761976```
19771977
@@ -2072,7 +2072,7 @@ proper indentation and formatting give the visual structure to your code.
20722072// //////////////////////////////////////////////////////////////////////////////
20732073// Scope Model Instantiation
20742074// //////////////////////////////////////////////////////////////////////////////
2075- const $scope .model = {
2075+ $scope .model = {
20762076 menu: ' foo' ,
20772077 nav: ' bar'
20782078};
@@ -2087,7 +2087,7 @@ const actions = function() {
20872087
20882088** Good** :
20892089``` javascript
2090- const $scope .model = {
2090+ $scope .model = {
20912091 menu: ' foo' ,
20922092 nav: ' bar'
20932093};
0 commit comments