Skip to content

Commit 1fbb1b4

Browse files
Merge pull request #15 from it-shark-pro/check-lines-of-code
Check lines of code
2 parents 2f28cee + 8d06814 commit 1fbb1b4

25 files changed

+232
-133
lines changed

.eslintrc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
},
55
"env": {
66
"es6": true,
7-
"node": true,
8-
"mocha": true
7+
"node": true
98
},
109
"extends": ["eslint:recommended"],
1110
"rules": {
@@ -17,7 +16,10 @@
1716
"eqeqeq": 2,
1817
"func-names": 0,
1918
"indent": [2, 2],
20-
"max-len": 0,
19+
"max-len": ["error", {
20+
"code": 80,
21+
"ignoreComments": true
22+
}],
2123
"no-console": [ 1, {"allow": ["info", "error", "warn"]}],
2224
"no-new-wrappers": 0,
2325
"no-proto": 0,
@@ -36,6 +38,21 @@
3638
"allowTemplateLiterals": true
3739
}
3840
],
39-
"require-yield": 1
40-
}
41+
"require-yield": 1,
42+
"prefer-const": 2
43+
},
44+
"overrides": [
45+
{
46+
"files": [
47+
"**/test/**",
48+
"**/extensions/**"
49+
],
50+
"env": {
51+
"mocha": true
52+
},
53+
"rules": {
54+
"max-len": 0
55+
}
56+
}
57+
]
4158
}

extensions/assert-linesOfCode.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import assert from 'assert';
2+
3+
function linesOfCode(fn, expected, recommended) {
4+
const actualLinesOfCode = fn.toString().split('\n').filter(s => s.trim()).length - 2;
5+
const isValid = actualLinesOfCode <= expected;
6+
if (actualLinesOfCode <= expected && actualLinesOfCode > recommended) {
7+
console.log(`Recommended lines of code for ${fn.name} is ${recommended}`);
8+
}
9+
const message = `
10+
"${fn.name}" should have maximum ${expected} line(s) of code but it ${actualLinesOfCode}.
11+
Recommended lines of code for ${fn.name} is ${recommended}
12+
`;
13+
14+
assert.ok(isValid, message);
15+
}
16+
17+
assert.linesOfCode = linesOfCode;

task/01-strings-tasks.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* '', 'bb' => 'bb'
2121
*/
2222
export function concatenateStrings(value1, value2) {
23-
/* implement your code here */
2423
throw new Error('Not implemented');
2524
}
2625

@@ -36,7 +35,6 @@ export function concatenateStrings(value1, value2) {
3635
* '' => 0
3736
*/
3837
export function getStringLength(value) {
39-
/* implement your code here */
4038
throw new Error('Not implemented');
4139
}
4240

@@ -54,7 +52,6 @@ export function getStringLength(value) {
5452
* 'Chuck','Norris' => 'Hello, Chuck Norris!'
5553
*/
5654
export function getStringFromTemplate(firstName, lastName) {
57-
/* implement your code here */
5855
throw new Error('Not implemented');
5956
}
6057

@@ -69,7 +66,6 @@ export function getStringFromTemplate(firstName, lastName) {
6966
* 'Hello, Chuck Norris!' => 'Chuck Norris'
7067
*/
7168
export function extractNameFromTemplate(value) {
72-
/* implement your code here */
7369
throw new Error('Not implemented');
7470
}
7571

@@ -85,7 +81,6 @@ export function extractNameFromTemplate(value) {
8581
* 'cat' => 'c'
8682
*/
8783
export function getFirstChar(value) {
88-
/* implement your code here */
8984
throw new Error('Not implemented');
9085
}
9186

@@ -101,7 +96,6 @@ export function getFirstChar(value) {
10196
* '\tHello, World! ' => 'Hello, World!'
10297
*/
10398
export function removeLeadingAndTrailingWhitespaces(value) {
104-
/* implement your code here */
10599
throw new Error('Not implemented');
106100
}
107101

@@ -117,7 +111,6 @@ export function removeLeadingAndTrailingWhitespaces(value) {
117111
* 'cat', 3 => 'catcatcat'
118112
*/
119113
export function repeatString(value, count) {
120-
/* implement your code here */
121114
throw new Error('Not implemented');
122115
}
123116

@@ -134,7 +127,6 @@ export function repeatString(value, count) {
134127
* 'ABABAB','BA' => 'ABAB'
135128
*/
136129
export function removeFirstOccurrences(str, value) {
137-
/* implement your code here */
138130
throw new Error('Not implemented');
139131
}
140132

@@ -150,7 +142,6 @@ export function removeFirstOccurrences(str, value) {
150142
* '<a>' => 'a'
151143
*/
152144
export function unbracketTag(str) {
153-
/* implement your code here */
154145
throw new Error('Not implemented');
155146
}
156147

@@ -166,7 +157,6 @@ export function unbracketTag(str) {
166157
* 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
167158
*/
168159
export function convertToUpperCase(str) {
169-
/* implement your code here */
170160
throw new Error('Not implemented');
171161
}
172162

@@ -182,7 +172,6 @@ export function convertToUpperCase(str) {
182172
183173
*/
184174
export function extractEmails(str) {
185-
/* implement your code here */
186175
throw new Error('Not implemented');
187176
}
188177

@@ -210,7 +199,6 @@ export function extractEmails(str) {
210199
*
211200
*/
212201
export function getRectangleString(width, height) {
213-
/* implement your code here */
214202
throw new Error('Not implemented');
215203
}
216204

@@ -232,7 +220,6 @@ export function getRectangleString(width, height) {
232220
*
233221
*/
234222
export function encodeToRot13(str) {
235-
/* implement your code here */
236223
throw new Error('Not implemented');
237224
}
238225

@@ -250,7 +237,6 @@ export function encodeToRot13(str) {
250237
* isString(new String('test')) => true
251238
*/
252239
export function isString(value) {
253-
/* implement your code here */
254240
throw new Error('Not implemented');
255241
}
256242

@@ -280,6 +266,5 @@ export function isString(value) {
280266
* 'K♠' => 51
281267
*/
282268
export function getCardId(value) {
283-
/* implement your code here */
284269
throw new Error('Not implemented');
285270
}

task/02-numbers-tasks.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* 5, 5 => 25
2222
*/
2323
export function getRectangleArea(width, height) {
24-
/* implement your code here */
2524
throw new Error('Not implemented');
2625
}
2726

@@ -38,7 +37,6 @@ export function getRectangleArea(width, height) {
3837
* 0 => 0
3938
*/
4039
export function getCicleCircumference(radius) {
41-
/* implement your code here */
4240
throw new Error('Not implemented');
4341
}
4442

@@ -55,7 +53,6 @@ export function getCicleCircumference(radius) {
5553
* -3, 3 => 0
5654
*/
5755
export function getAverage(value1, value2) {
58-
/* implement your code here */
5956
throw new Error('Not implemented');
6057
}
6158

@@ -75,7 +72,6 @@ export function getAverage(value1, value2) {
7572
* (-5,0) (10,-10) => 18.027756377319946
7673
*/
7774
export function getDistanceBetweenPoints(x1, y1, x2, y2) {
78-
/* implement your code here */
7975
throw new Error('Not implemented');
8076
}
8177

@@ -92,7 +88,6 @@ export function getDistanceBetweenPoints(x1, y1, x2, y2) {
9288
* 5*x = 0 => 0
9389
*/
9490
export function getLinearEquationRoot(a, b) {
95-
/* implement your code here */
9691
throw new Error('Not implemented');
9792
}
9893

@@ -116,7 +111,6 @@ export function getLinearEquationRoot(a, b) {
116111
* (0,1) (1,2) => 0
117112
*/
118113
export function getAngleBetweenVectors(x1, y1, x2, y2) {
119-
/* implement your code here */
120114
throw new Error('Not implemented');
121115
}
122116

@@ -133,7 +127,6 @@ export function getAngleBetweenVectors(x1, y1, x2, y2) {
133127
* 0 => 0
134128
*/
135129
export function getLastDigit(value) {
136-
/* implement your code here */
137130
throw new Error('Not implemented');
138131
}
139132

@@ -150,7 +143,6 @@ export function getLastDigit(value) {
150143
* '-525.5' => -525.5
151144
*/
152145
export function parseNumberFromString(value) {
153-
/* implement your code here */
154146
throw new Error('Not implemented');
155147
}
156148

@@ -168,7 +160,6 @@ export function parseNumberFromString(value) {
168160
* 1,2,3 => 3.741657386773941
169161
*/
170162
export function getParallelipidedDiagonal(a, b, c) {
171-
/* implement your code here */
172163
throw new Error('Not implemented');
173164
}
174165

@@ -190,7 +181,6 @@ export function getParallelipidedDiagonal(a, b, c) {
190181
* 1678, 3 => 2000
191182
*/
192183
export function roundToPowerOfTen(num, pow) {
193-
/* implement your code here */
194184
throw new Error('Not implemented');
195185
}
196186

@@ -212,7 +202,6 @@ export function roundToPowerOfTen(num, pow) {
212202
* 17 => true
213203
*/
214204
export function isPrime(n) {
215-
/* implement your code here */
216205
throw new Error('Not implemented');
217206
}
218207

@@ -232,6 +221,5 @@ export function isPrime(n) {
232221
* toNumber(new Number(42), 0) => 42
233222
*/
234223
export function toNumber(value, def) {
235-
/* implement your code here */
236224
throw new Error('Not implemented');
237225
}

task/03-date-tasks.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* 'Sun, 17 May 1998 03:00:00 GMT+01' => Date()
2222
*/
2323
export function parseDataFromRfc2822(value) {
24-
/* implement your code here */
2524
throw new Error('Not implemented');
2625
}
2726

@@ -37,7 +36,6 @@ export function parseDataFromRfc2822(value) {
3736
* '2016-01-19T08:07:37Z' => Date()
3837
*/
3938
export function parseDataFromIso8601(value) {
40-
/* implement your code here */
4139
throw new Error('Not implemented');
4240
}
4341

@@ -57,7 +55,6 @@ export function parseDataFromIso8601(value) {
5755
* Date(2015,1,1) => false
5856
*/
5957
export function isLeapYear(date) {
60-
/* implement your code here */
6158
throw new Error('Not implemented');
6259
}
6360

@@ -78,7 +75,6 @@ export function isLeapYear(date) {
7875
* Date(2000,1,1,10,0,0), Date(2000,1,1,15,20,10,453) => "05:20:10.453"
7976
*/
8077
export function timeSpanToString(startDate, endDate) {
81-
/* implement your code here */
8278
throw new Error('Not implemented');
8379
}
8480

@@ -98,6 +94,5 @@ export function timeSpanToString(startDate, endDate) {
9894
* Date.UTC(2016,3,5,21, 0) => Math.PI/2
9995
*/
10096
export function angleBetweenClockHands(date) {
101-
/* implement your code here */
10297
throw new Error('Not implemented');
10398
}

0 commit comments

Comments
 (0)