Skip to content

Commit d1a634b

Browse files
Aliaksei BychykEduardTrutsyk
authored andcommitted
set up es6 syntax capabilities and linting (#2)
[*] set up es6 syntax capabilities and linting
1 parent e08be71 commit d1a634b

31 files changed

+5892
-4179
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": [ "transform-es2015-modules-commonjs" ]
3+
}

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"parserOptions": {
3+
"sourceType": "module"
4+
},
5+
"env": {
6+
"es6": true,
7+
"node": true,
8+
"mocha": true
9+
},
10+
"extends": ["eslint:recommended"],
11+
"rules": {
12+
"array-bracket-spacing": 0,
13+
"arrow-parens": [2, "as-needed"],
14+
"comma-dangle": [2, "never"],
15+
"comma-spacing": [2, {"after": true}],
16+
"curly": [2, "multi-line"],
17+
"eqeqeq": 2,
18+
"func-names": 0,
19+
"indent": [2, 2],
20+
"max-len": 0,
21+
"no-console": [ 1, {"allow": ["info", "error", "warn"]}],
22+
"no-new-wrappers": 0,
23+
"no-proto": 0,
24+
"no-prototype-builtins": 0,
25+
"no-restricted-syntax": 1,
26+
"no-sparse-arrays": 0,
27+
"no-unreachable": 2,
28+
"no-unused-expressions": 2,
29+
"no-unused-vars": [2, {"args": "none"}],
30+
"semi": 2,
31+
"quotes": [
32+
2,
33+
"single",
34+
{
35+
"avoidEscape": true,
36+
"allowTemplateLiterals": true
37+
}
38+
],
39+
"require-yield": 1
40+
}
41+
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ There is an easier way to debug for beginners with free Visual Studio Code:
113113
## Contribution
114114
Feel free to contribute into this project. New tasks and katas are welcome.
115115

116+
## ESLint
117+
To fix linting execute:
118+
```
119+
npm run lint -- --fix
120+
```

extensions/it-optional.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
'use strict';
2-
31
exports = module.exports = testOptional;
42

53
function testOptional(title, fn) {
6-
7-
it(title, function() {
8-
try {
9-
fn.call(this);
10-
} catch (err) {
11-
if (err.message=="Not implemented") {
12-
this.test.skip();
13-
} else {
14-
throw err;
15-
}
16-
}
17-
});
18-
19-
}
4+
it(title, function() {
5+
try {
6+
fn.call(this);
7+
} catch (err) {
8+
if (err.message === 'Not implemented') {
9+
this.test.skip();
10+
} else {
11+
throw err;
12+
}
13+
}
14+
});
15+
}

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33
"version": "0.9.1",
44
"description": "JS training tasks",
55
"scripts": {
6-
"test": "./node_modules/.bin/mocha",
6+
"lint": "eslint ./**/*.js",
7+
"precommit": "lint-staged",
8+
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register",
79
"test-debug": "./node_modules/.bin/mocha --debug-brk"
810
},
911
"author": "aorgish",
1012
"license": "MIT",
1113
"devDependencies": {
14+
"babel-core": "^6.26.0",
15+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
16+
"eslint": "^4.17.0",
17+
"husky": "^0.14.3",
18+
"lint-staged": "^6.1.1",
1219
"mocha": "^2.3.4"
1320
},
14-
"repository" : {
15-
"type" : "git",
16-
"url" : "https://github.com/it-shark-pro/js-assignments.git"
21+
"repository": {
22+
"type": "git",
23+
"url": "[email protected]:it-shark-pro/js-assignments.git"
24+
},
25+
"lint-staged": {
26+
"*.js": [
27+
"npm run lint",
28+
"git add"
29+
]
1730
}
1831
}

task/01-strings-tasks.js

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
21

3-
/********************************************************************************************
2+
/** *****************************************************************************************
43
* *
54
* Plese read the following tutorial before implementing tasks: *
65
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String *
76
* *
87
********************************************************************************************/
98

109

11-
1210
/**
1311
* Returns the result of concatenation of two strings.
1412
*
@@ -21,11 +19,11 @@
2119
* 'aa','' => 'aa'
2220
* '', 'bb' => 'bb'
2321
*/
24-
function concatenateStrings(value1, value2) {
25-
throw new Error('Not implemented');
22+
export function concatenateStrings(value1, value2) {
23+
/* implement your code here */
24+
throw new Error('Not implemented');
2625
}
2726

28-
2927
/**
3028
* Returns the length of given string.
3129
*
@@ -37,8 +35,9 @@ function concatenateStrings(value1, value2) {
3735
* 'b' => 1
3836
* '' => 0
3937
*/
40-
function getStringLength(value) {
41-
throw new Error('Not implemented');
38+
export function getStringLength(value) {
39+
/* implement your code here */
40+
throw new Error('Not implemented');
4241
}
4342

4443
/**
@@ -54,8 +53,9 @@ function getStringLength(value) {
5453
* 'John','Doe' => 'Hello, John Doe!'
5554
* 'Chuck','Norris' => 'Hello, Chuck Norris!'
5655
*/
57-
function getStringFromTemplate(firstName, lastName) {
58-
throw new Error('Not implemented');
56+
export function getStringFromTemplate(firstName, lastName) {
57+
/* implement your code here */
58+
throw new Error('Not implemented');
5959
}
6060

6161
/**
@@ -68,8 +68,9 @@ function getStringFromTemplate(firstName, lastName) {
6868
* 'Hello, John Doe!' => 'John Doe'
6969
* 'Hello, Chuck Norris!' => 'Chuck Norris'
7070
*/
71-
function extractNameFromTemplate(value) {
72-
throw new Error('Not implemented');
71+
export function extractNameFromTemplate(value) {
72+
/* implement your code here */
73+
throw new Error('Not implemented');
7374
}
7475

7576

@@ -83,8 +84,9 @@ function extractNameFromTemplate(value) {
8384
* 'John Doe' => 'J'
8485
* 'cat' => 'c'
8586
*/
86-
function getFirstChar(value) {
87-
throw new Error('Not implemented');
87+
export function getFirstChar(value) {
88+
/* implement your code here */
89+
throw new Error('Not implemented');
8890
}
8991

9092
/**
@@ -98,8 +100,9 @@ function getFirstChar(value) {
98100
* 'cat' => 'cat'
99101
* '\tHello, World! ' => 'Hello, World!'
100102
*/
101-
function removeLeadingAndTrailingWhitespaces(value) {
102-
throw new Error('Not implemented');
103+
export function removeLeadingAndTrailingWhitespaces(value) {
104+
/* implement your code here */
105+
throw new Error('Not implemented');
103106
}
104107

105108
/**
@@ -113,13 +116,14 @@ function removeLeadingAndTrailingWhitespaces(value) {
113116
* 'A', 5 => 'AAAAA'
114117
* 'cat', 3 => 'catcatcat'
115118
*/
116-
function repeatString(value, count) {
117-
throw new Error('Not implemented');
119+
export function repeatString(value, count) {
120+
/* implement your code here */
121+
throw new Error('Not implemented');
118122
}
119123

120124
/**
121125
* Remove the first occurrence of string inside another string
122-
*
126+
*
123127
* @param {string} str
124128
* @param {string} value
125129
* @return {string}
@@ -129,8 +133,9 @@ function repeatString(value, count) {
129133
* 'I like legends', 'end' => 'I like legs',
130134
* 'ABABAB','BA' => 'ABAB'
131135
*/
132-
function removeFirstOccurrences(str, value) {
133-
throw new Error('Not implemented');
136+
export function removeFirstOccurrences(str, value) {
137+
/* implement your code here */
138+
throw new Error('Not implemented');
134139
}
135140

136141
/**
@@ -144,8 +149,9 @@ function removeFirstOccurrences(str, value) {
144149
* '<span>' => 'span'
145150
* '<a>' => 'a'
146151
*/
147-
function unbracketTag(str) {
148-
throw new Error('Not implemented');
152+
export function unbracketTag(str) {
153+
/* implement your code here */
154+
throw new Error('Not implemented');
149155
}
150156

151157

@@ -159,8 +165,9 @@ function unbracketTag(str) {
159165
* 'Thunderstruck' => 'THUNDERSTRUCK'
160166
* 'abcdefghijklmnopqrstuvwxyz' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
161167
*/
162-
function convertToUpperCase(str) {
163-
throw new Error('Not implemented');
168+
export function convertToUpperCase(str) {
169+
/* implement your code here */
170+
throw new Error('Not implemented');
164171
}
165172

166173
/**
@@ -170,11 +177,13 @@ function convertToUpperCase(str) {
170177
* @return {array}
171178
*
172179
* @example
173-
180+
181+
174182
175183
*/
176-
function extractEmails(str) {
177-
throw new Error('Not implemented');
184+
export function extractEmails(str) {
185+
/* implement your code here */
186+
throw new Error('Not implemented');
178187
}
179188

180189
/**
@@ -200,8 +209,9 @@ function extractEmails(str) {
200209
* '└──────────┘\n'
201210
*
202211
*/
203-
function getRectangleString(width, height) {
204-
throw new Error('Not implemented');
212+
export function getRectangleString(width, height) {
213+
/* implement your code here */
214+
throw new Error('Not implemented');
205215
}
206216

207217

@@ -217,11 +227,13 @@ function getRectangleString(width, height) {
217227
* 'hello' => 'uryyb'
218228
* 'Why did the chicken cross the road?' => 'Jul qvq gur puvpxra pebff gur ebnq?'
219229
* 'Gb trg gb gur bgure fvqr!' => 'To get to the other side!'
220-
* 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' => 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
230+
* 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' =>
231+
* 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
221232
*
222233
*/
223-
function encodeToRot13(str) {
224-
throw new Error('Not implemented');
234+
export function encodeToRot13(str) {
235+
/* implement your code here */
236+
throw new Error('Not implemented');
225237
}
226238

227239
/**
@@ -237,54 +249,37 @@ function encodeToRot13(str) {
237249
* isString('test') => true
238250
* isString(new String('test')) => true
239251
*/
240-
function isString(value) {
241-
throw new Error('Not implemented');
252+
export function isString(value) {
253+
/* implement your code here */
254+
throw new Error('Not implemented');
242255
}
243256

244257

245258
/**
246259
* Returns playid card id.
247-
*
260+
*
248261
* Playing cards inittial deck inclides the cards in the following order:
249-
*
262+
*
250263
* 'A♣','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣',
251264
* 'A♦','2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦',
252265
* 'A♥','2♥','3♥','4♥','5♥','6♥','7♥','8♥','9♥','10♥','J♥','Q♥','K♥',
253266
* 'A♠','2♠','3♠','4♠','5♠','6♠','7♠','8♠','9♠','10♠','J♠','Q♠','K♠'
254-
*
267+
*
255268
* (see https://en.wikipedia.org/wiki/Standard_52-card_deck)
256269
* Function returns the zero-based index of specified card in the initial deck above.
257-
*
270+
*
258271
* @param {string} value
259272
* @return {number}
260273
*
261274
* @example
262275
* 'A♣' => 0
263-
* '2♣' => 1
276+
* '2♣' => 1
264277
* '3♣' => 2
265278
* ...
266279
* 'Q♠' => 50
267280
* 'K♠' => 51
268281
*/
269-
function getCardId(value) {
270-
throw new Error('Not implemented');
282+
export function getCardId(value) {
283+
/* implement your code here */
284+
throw new Error('Not implemented');
271285
}
272-
273-
274-
module.exports = {
275-
concatenateStrings: concatenateStrings,
276-
getStringLength: getStringLength,
277-
getStringFromTemplate: getStringFromTemplate,
278-
extractNameFromTemplate: extractNameFromTemplate,
279-
getFirstChar: getFirstChar,
280-
removeLeadingAndTrailingWhitespaces: removeLeadingAndTrailingWhitespaces,
281-
repeatString: repeatString,
282-
removeFirstOccurrences: removeFirstOccurrences,
283-
unbracketTag: unbracketTag,
284-
convertToUpperCase: convertToUpperCase,
285-
extractEmails: extractEmails,
286-
getRectangleString: getRectangleString,
287-
encodeToRot13: encodeToRot13,
288-
isString: isString,
289-
getCardId: getCardId
290-
};

0 commit comments

Comments
 (0)