Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a0edf53

Browse files
committedFeb 15, 2017
Code style
1 parent e6723ec commit a0edf53

9 files changed

+176
-24
lines changed
 

‎.eslintrc.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
parserOptions:
2+
ecmaVersion: 6
3+
env:
4+
node: true
5+
extends: 'eslint:recommended'
6+
globals:
7+
api: true
8+
global: true
9+
rules:
10+
indent:
11+
- error
12+
- 2
13+
- SwitchCase: 1
14+
VariableDeclarator:
15+
var: 2
16+
let: 2
17+
const: 3
18+
MemberExpression: 1
19+
linebreak-style:
20+
- error
21+
- unix
22+
quotes:
23+
- error
24+
- single
25+
semi:
26+
- error
27+
- always
28+
eqeqeq:
29+
- error
30+
- always
31+
no-loop-func:
32+
- error
33+
strict:
34+
- error
35+
- global
36+
block-spacing:
37+
- error
38+
- always
39+
brace-style:
40+
- error
41+
- 1tbs
42+
- allowSingleLine: true
43+
camelcase:
44+
- error
45+
comma-style:
46+
- error
47+
- last
48+
comma-spacing:
49+
- error
50+
- before: false
51+
after: true
52+
eol-last:
53+
- error
54+
func-call-spacing:
55+
- error
56+
- never
57+
key-spacing:
58+
- error
59+
- beforeColon: false
60+
afterColon: true
61+
mode: minimum
62+
keyword-spacing:
63+
- error
64+
- before: true
65+
after: true
66+
overrides:
67+
function:
68+
after: false
69+
max-len:
70+
- error
71+
- code: 80
72+
ignoreUrls: true
73+
max-nested-callbacks:
74+
- error
75+
- max: 5
76+
new-cap:
77+
- error
78+
- newIsCap: true
79+
capIsNew: true
80+
properties: true
81+
new-parens:
82+
- error
83+
no-lonely-if:
84+
- error
85+
no-trailing-spaces:
86+
- error
87+
no-unneeded-ternary:
88+
- error
89+
no-whitespace-before-property:
90+
- error
91+
object-curly-spacing:
92+
- error
93+
- always
94+
operator-assignment:
95+
- error
96+
- always
97+
operator-linebreak:
98+
- error
99+
- after
100+
semi-spacing:
101+
- error
102+
- before: false
103+
after: true
104+
space-before-blocks:
105+
- error
106+
- always
107+
space-before-function-paren:
108+
- error
109+
- never
110+
space-in-parens:
111+
- error
112+
- never
113+
space-infix-ops:
114+
- error
115+
space-unary-ops:
116+
- error
117+
- words: true
118+
nonwords: false
119+
overrides:
120+
typeof: false
121+
no-unreachable:
122+
- error
123+
no-global-assign:
124+
- error
125+
no-self-compare:
126+
- error
127+
no-unmodified-loop-condition:
128+
- error
129+
no-constant-condition:
130+
- error
131+
- checkLoops: false
132+
no-console:
133+
- off
134+
no-useless-concat:
135+
- error
136+
no-useless-escape:
137+
- error
138+
no-shadow-restricted-names:
139+
- error
140+
no-use-before-define:
141+
- error
142+
- functions: false

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
*.log
3+
.DS_Store

‎.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esversion": 6,
3+
"node": true
4+
}

‎1-extract-metadata/filter-metaprogramming.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Data
44
//
5-
let names = [
5+
const names = [
66
'Marcus Aurelius Antoninus Augustus',
77
'Darth Vader',
88
'Victor Michailovich Glushkov',
@@ -19,7 +19,7 @@ let names = [
1919

2020
// Metadata
2121
//
22-
let conditions = {
22+
const conditions = {
2323
length: [10, 200],
2424
contains: 'Mich',
2525
starts: 'V',
@@ -35,12 +35,12 @@ let conditions = {
3535
// Metamodel
3636
//
3737
function filter(names, conditions) {
38-
let operations = {
38+
const operations = {
3939
length: (s, v) => s.length >= v[0] && s.length <= v[1],
4040
contains: (s, v) => s.indexOf(v) > -1,
4141
starts: (s, v) => s.indexOf(v) === 0,
4242
ends: (s, v) => s.slice(-v.length) === v,
43-
not: (s, v) => !check(s,v)
43+
not: (s, v) => !check(s, v)
4444
};
4545
function check(s, conditions) {
4646
let valid = true;

‎1-extract-metadata/filter-simple.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Data
44
//
5-
let names = [
5+
const names = [
66
'Marcus Aurelius Antoninus Augustus',
77
'Darth Vader',
88
'Victor Michailovich Glushkov',
@@ -20,7 +20,8 @@ let names = [
2020
// Logic
2121
//
2222
function filter(names) {
23-
let result = [], name;
23+
const result = [];
24+
let name;
2425
for (let i = 0; i < names.length; i++) {
2526
name = names[i];
2627
if (

‎2-level-up/metametaprogramming.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ api.request = require('request');
99
//
1010
function duration(s) {
1111
if (typeof(s) === 'number') return s;
12-
let units = {
12+
const units = {
1313
days: { rx: /(\d+)\s*d/, mul: 86400 },
1414
hours: { rx: /(\d+)\s*h/, mul: 3600 },
1515
minutes: { rx: /(\d+)\s*m/, mul: 60 },
@@ -26,7 +26,7 @@ function duration(s) {
2626

2727
// Metadata
2828
//
29-
let tasks = [
29+
const tasks = [
3030
{ interval: 5000, get: 'http://127.0.0.1/api/method1.json', save: 'file1.json' },
3131
{ interval: '8s', get: 'http://127.0.0.1/api/method2.json', put: 'http://127.0.0.1/api/method4.json', save: 'file2.json' },
3232
{ interval: '7s', get: 'http://127.0.0.1/api/method3.json', post: 'http://127.0.0.1/api/method5.json' },
@@ -41,11 +41,11 @@ function iterate(tasks) {
4141

4242
// Metamodel configuration metadata
4343
//
44-
let sources = {
44+
const sources = {
4545
get: api.request.get,
4646
load: api.fs.createReadStream
4747
};
48-
let destinations = {
48+
const destinations = {
4949
save: api.fs.createWriteStream,
5050
post: api.request.post,
5151
put: api.request.put
@@ -56,9 +56,13 @@ function iterate(tasks) {
5656
function closureTask(task) {
5757
return () => {
5858
console.dir(task);
59-
let key, verb, source, destination;
60-
for (key in sources) if (task[key]) source = sources[key](task[key]);
61-
for (key in destinations) if (task[key]) source.pipe(destinations[key](task[key]));
59+
let key, source;
60+
for (key in sources) {
61+
if (task[key]) source = sources[key](task[key]);
62+
}
63+
for (key in destinations) {
64+
if (task[key]) source.pipe(destinations[key](task[key]));
65+
}
6266
};
6367
}
6468
for (let i = 0; i < tasks.length; i++) {

‎2-level-up/metaprogramming.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ api.request = require('request');
1010
function duration(s) {
1111
let result = 0;
1212
if (typeof(s) === 'string') {
13-
let days = s.match(/(\d+)\s*d/),
14-
hours = s.match(/(\d+)\s*h/),
15-
minutes = s.match(/(\d+)\s*m/),
16-
seconds = s.match(/(\d+)\s*s/);
13+
const days = s.match(/(\d+)\s*d/);
14+
const hours = s.match(/(\d+)\s*h/);
15+
const minutes = s.match(/(\d+)\s*m/);
16+
const seconds = s.match(/(\d+)\s*s/);
1717
if (days) result += parseInt(days[1]) * 86400;
1818
if (hours) result += parseInt(hours[1]) * 3600;
1919
if (minutes) result += parseInt(minutes[1]) * 60;
2020
if (seconds) result += parseInt(seconds[1]);
21-
result = result * 1000;
22-
} if (typeof(s) === 'number') result = s;
21+
result *= 1000;
22+
} else if (typeof(s) === 'number') result = s;
2323
return result;
2424
}
2525

2626
// Metadata
2727
//
28-
let tasks = [
28+
const tasks = [
2929
{ interval: 5000, get: 'http://127.0.0.1/api/method1.json', save: 'file1.json' },
3030
{ interval: '8s', get: 'http://127.0.0.1/api/method2.json', put: 'http://127.0.0.1/api/method4.json', save: 'file2.json' },
3131
{ interval: '7s', get: 'http://127.0.0.1/api/method3.json', post: 'http://127.0.0.1/api/method5.json' },

‎4-class-factory/class-inheritance-metaprogramming.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Ground.prototype.calculateCost = function(price) {
1616
//
1717
function inheritGround(mixin) {
1818

19-
let DescendantGround = function(area) {
19+
const DescendantGround = function(area) {
2020
this.constructor.apply(this, arguments);
2121
this.isEmpty = parseInt(area) <= 0;
2222
};
@@ -34,7 +34,7 @@ function inheritGround(mixin) {
3434

3535
// Create descendant class dynamically
3636
//
37-
let LandOwnership = inheritGround({
37+
const LandOwnership = inheritGround({
3838
category: 'land',
3939
type: 'ownership',
4040
// Add method to descendant class prototype
@@ -45,6 +45,6 @@ let LandOwnership = inheritGround({
4545

4646
// Create and use instance
4747
//
48-
let land = new LandOwnership(50);
48+
const land = new LandOwnership(50);
4949
console.dir(land);
5050
console.log('Cost is: ' + land.calculateCost(7) + ' for ' + land.toString());

‎4-class-factory/class-inheritance-simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ LandOwnership.prototype.toString = function(price) {
3636

3737
// Create and use instance
3838
//
39-
let land = new LandOwnership(50);
39+
const land = new LandOwnership(50);
4040
console.dir(land);
4141
console.log('Cost is: ' + land.calculateCost(7) + ' for ' + land.toString());

0 commit comments

Comments
 (0)
Please sign in to comment.