Skip to content

Commit 4843bfa

Browse files
author
Sasha Sushko
authored
Merge pull request #43 from htmlacademy/feature/add-rules-with-eslint-recommended
Added eslint:recommended config
2 parents 016bd61 + 258c023 commit 4843bfa

File tree

8 files changed

+172
-0
lines changed

8 files changed

+172
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,25 @@ For validating **ECMAScript 2015 (ES6)** in **Node.js** environment project use
6161
}
6262
}
6363
```
64+
65+
For validating **ECMAScript 2018 (ES9)** project use `es9` version:
66+
67+
```json
68+
{
69+
"parserOptions": {
70+
"ecmaVersion": 9,
71+
"sourceType": "module"
72+
},
73+
"env": {
74+
"es2017": true,
75+
"browser": true,
76+
"commonjs": true,
77+
},
78+
"extends": "htmlacademy/basic",
79+
"rules": {
80+
// Additional rules...
81+
}
82+
}
83+
```
6484
[travis-image]: https://travis-ci.org/htmlacademy/eslint-config-htmlacademy.svg?branch=master
6585
[travis-url]: https://travis-ci.org/htmlacademy/eslint-config-htmlacademy

basic.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
extends: 'eslint:recommended',
3+
rules: {
4+
// Possible Errors
5+
// https://eslint.org/docs/rules/#possible-errors
6+
// ---------------------------------------------
7+
'no-console': 'error',
8+
// Stylistic Issues
9+
// https://eslint.org/docs/rules/#stylistic-issues
10+
// ---------------------------------------------
11+
'comma-dangle': ['error', {
12+
'arrays': 'always-multiline',
13+
'objects': 'always-multiline',
14+
'functions': 'always-multiline',
15+
}],
16+
'indent': ['error', 2, {
17+
SwitchCase: 1,
18+
}],
19+
'quotes': ['error', 'single'],
20+
// ECMAScript 6
21+
// https://eslint.org/docs/rules/#ecmascript-6
22+
// ---------------------------------------------
23+
'no-var': ['error'],
24+
},
25+
};

test/basic/.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const config = require('../../basic');
2+
3+
config.parserOptions = {
4+
ecmaVersion: 9,
5+
sourceType: 'module',
6+
};
7+
config.env = {
8+
'es2017': true,
9+
'browser': true,
10+
'commonjs': true,
11+
};
12+
13+
module.exports = config;

test/basic/comma-dangles.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const arr0 = ['a', 'b', 'c'];
2+
const arr1 = [
3+
'a',
4+
'b',
5+
'c',
6+
];
7+
8+
const obj0 = {q: 'q', w: 'w'};
9+
const obj1 = {
10+
q: 'q',
11+
w: 'w',
12+
};
13+
14+
const func0 = (a, b) => {
15+
return a + b;
16+
};
17+
const func1 = (
18+
a,
19+
b,
20+
) => {
21+
return a + b;
22+
};
23+
24+
func0(
25+
obj0.a,
26+
obj0.b,
27+
);
28+
29+
throw new Error(arr0, arr1, obj0, obj1, func0, func1);

test/basic/eslint.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
extends: 'eslint:recommended',
3+
rules: {
4+
// Possible Errors
5+
// https://eslint.org/docs/rules/#possible-errors
6+
// ---------------------------------------------
7+
'no-console': 'error',
8+
// Stylistic Issues
9+
// https://eslint.org/docs/rules/#stylistic-issues
10+
// ---------------------------------------------
11+
'comma-dangle': ['error', {
12+
'arrays': 'always-multiline',
13+
'objects': 'always-multiline',
14+
'functions': 'always-multiline',
15+
}],
16+
'indent': ['error', 2, {
17+
SwitchCase: 1,
18+
}],
19+
'quotes': ['error', 'single'],
20+
// ECMAScript 6
21+
// https://eslint.org/docs/rules/#ecmascript-6
22+
// ---------------------------------------------
23+
'no-var': ['error'],
24+
},
25+
};

test/basic/indent.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// Continuation, aka MemberExpression
4+
const promise = window.Promise.resolve(true);
5+
promise.
6+
then(function (data) {
7+
return data;
8+
}).
9+
then(function (truthy) {
10+
return !truthy;
11+
}).
12+
catch(function () {
13+
return false;
14+
});
15+
16+
// Function expression
17+
const fun = function (first, second) {
18+
return first + second;
19+
};
20+
21+
// Function declaration
22+
function Constructor(first, second) {
23+
this.data = {
24+
first: first,
25+
second: second,
26+
};
27+
}
28+
29+
// Calling site arguments
30+
const myObject = new Constructor(
31+
'Petya',
32+
'Vasya',
33+
);
34+
myObject.toString();
35+
36+
const result = fun(
37+
'one',
38+
'two',
39+
);
40+
result.toString();
41+
42+
// Switch
43+
const a = 'a';
44+
45+
switch(a) {
46+
case 'a':
47+
break;
48+
case 'b':
49+
break;
50+
}

test/basic/no-var.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let a = 0;
2+
const B = 'B';
3+
4+
throw new Error (a, B);

test/basic/quotes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const a = 'Anything string';
2+
const b = `Anything
3+
string`;
4+
const c = `This's a ${a}`;
5+
6+
throw new Error(a, b, c);

0 commit comments

Comments
 (0)