Skip to content

Commit da9f14d

Browse files
hs0225yichoi
authored andcommitted
Define and apply new eslint rules (jerryscript-project#1270)
apply only rules that are automatically modified. IoT.js-DCO-1.0-Signed-off-by: Hosung Kim hs852.kim@samsung.com
1 parent 879efc0 commit da9f14d

23 files changed

+199
-125
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/build/**
22
/deps/**
3+
/src/js/ble*

.eslintrc.js

Lines changed: 88 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,91 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
var es6 = {
17+
'generator-star-spacing': [2, 'after'],
18+
'no-var': 2,
19+
'prefer-rest-params': 2,
20+
'prefer-spread': 2,
21+
'rest-spread-spacing': 2,
22+
'yield-star-spacing': [2, 'after'],
23+
}
24+
25+
var eslintRecommended = {
26+
'no-console': 0,
27+
'no-empty': 0, // TODO: remove this feature
28+
}
29+
30+
var style = {
31+
'no-multi-spaces': 2,
32+
'no-multi-str': 2,
33+
'array-bracket-spacing': [2, 'never'],
34+
'block-spacing': [2, 'never'],
35+
'brace-style': 2,
36+
'comma-dangle': [2, 'always-multiline'],
37+
'comma-spacing': 2,
38+
'comma-style': 2,
39+
'computed-property-spacing': 2,
40+
'eol-last': 2,
41+
'func-call-spacing': 2,
42+
'key-spacing': 2,
43+
'keyword-spacing': 2,
44+
'linebreak-style': 2,
45+
'no-multiple-empty-lines': [2, {max: 2}],
46+
'no-tabs': 2,
47+
'no-trailing-spaces': 2,
48+
'semi-spacing': 2,
49+
'space-before-blocks': 2,
50+
'space-before-function-paren': [2, {
51+
anonymous: 'never',
52+
named: 'never',
53+
}],
54+
'spaced-comment': [2, 'always'],
55+
'switch-colon-spacing': 2,
56+
'quotes': [2, 'single'],
57+
}
58+
59+
var syntax = {
60+
'no-plusplus': 0,
61+
'guard-for-in': 2,
62+
'no-caller': 2,
63+
'no-extend-native': 2,
64+
'no-new-wrappers': 2,
65+
'new-cap': 2,
66+
'no-array-constructor': 2,
67+
'no-new-object': 2,
68+
'semi': 2,
69+
}
70+
171
module.exports = {
272
'extends': 'eslint:recommended',
3-
'rules': {
4-
'no-console': 0,
5-
'no-constant-condition': 0,
6-
'no-empty': 0,
7-
'no-undef': 0,
8-
'no-unused-vars': 0,
9-
'no-plusplus': 0,
10-
'no-redeclare': 0,
11-
}
73+
'env': {
74+
'node': true,
75+
'es6': false,
76+
},
77+
'rules': Object.assign(
78+
eslintRecommended,
79+
style,
80+
syntax,
81+
{
82+
// Optional rules
83+
'max-len': [2, {
84+
code: 80,
85+
tabWidth: 2,
86+
ignoreUrls: true,
87+
ignoreTemplateLiterals: true,
88+
ignoreRegExpLiterals: true
89+
}],
90+
}),
1291
}

src/js/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function fail(actual, expected, message, operator) {
6969
message: message,
7070
actual: actual,
7171
expected: expected,
72-
operator: operator
72+
operator: operator,
7373
});
7474
}
7575

src/js/buffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Buffer.prototype.slice = function(start, end) {
214214
// * start - default to 0
215215
// * end - default to buff.length
216216
Buffer.prototype.toString = function(start, end) {
217-
if (util.isString(start) && start === "hex" && end === undefined) {
217+
if (util.isString(start) && start === 'hex' && end === undefined) {
218218
return this._builtin.toHexString();
219219
}
220220
start = start === undefined ? 0 : ~~start;

src/js/dgram.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Socket.prototype.bind = function(port, address, callback) {
152152
});
153153

154154
return self;
155-
}
155+
};
156156

157157

158158
// thin wrapper around `send`, here for compatibility with dgram_legacy.js
@@ -242,11 +242,11 @@ Socket.prototype.send = function(buffer, offset, length, port, address,
242242

243243
if (!util.isArray(buffer)) {
244244
if (util.isString(buffer)) {
245-
list = [ new Buffer(buffer) ];
245+
list = [new Buffer(buffer)];
246246
} else if (!util.isBuffer(buffer)) {
247247
throw new TypeError('First argument must be a buffer or a string');
248248
} else {
249-
list = [ buffer ];
249+
list = [buffer];
250250
}
251251
} else if (!(list = fixBufferList(buffer))) {
252252
throw new TypeError('Buffer list arguments must be buffers or strings');
@@ -298,7 +298,7 @@ function doSend(ex, self, ip, list, address, port, callback) {
298298

299299
var buf = Buffer.concat(list);
300300

301-
var err = self._handle.send(buf, port, ip, function (err, length) {
301+
var err = self._handle.send(buf, port, ip, function(err, length) {
302302
if (err) {
303303
err = util.exceptionWithHostPort(err, 'send', address, port);
304304
} else {

src/js/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ EventEmitter.prototype.emit = function(type) {
3535
if (err instanceof Error) {
3636
throw err;
3737
} else {
38-
throw Error("Uncaught 'error' event");
38+
throw Error('Uncaught \'error\' event');
3939
}
4040
}
4141

src/js/fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var fsBuiltin = process.binding(process.binding.fs);
2121

2222
fs.exists = function(path, callback) {
2323
if (!path || !path.length) {
24-
process.nextTick(function () {
24+
process.nextTick(function() {
2525
if (callback) callback(false);
2626
});
2727
return;
@@ -213,7 +213,7 @@ fs.readFile = function(path, callback) {
213213
fs.close(fd, function(err) {
214214
return callback(err, Buffer.concat(buffers));
215215
});
216-
}
216+
};
217217
};
218218

219219

src/js/gpio.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var util = require('util');
2121
var defaultConfiguration = {
2222
direction: gpio.DIRECTION.OUT,
2323
mode: gpio.MODE.NONE,
24-
edge: gpio.EDGE.NONE
24+
edge: gpio.EDGE.NONE,
2525
};
2626

2727

@@ -53,7 +53,7 @@ function gpioPinOpen(configuration, callback) {
5353
throw new TypeError('Bad configuration - pin is mandatory and number');
5454
}
5555
} else {
56-
throw new TypeError('Bad arguments - configuration should be Object')
56+
throw new TypeError('Bad arguments - configuration should be Object');
5757
}
5858

5959
// validate direction

src/js/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.request = function(options, cb) {
2626
};
2727

2828

29-
exports.createServer = function(requestListener){
29+
exports.createServer = function(requestListener) {
3030
return new Server(requestListener);
3131
};
3232

src/js/http_client.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ function socketOnClose() {
106106
res.emit('close');
107107
});
108108
res.push(null);
109-
}
110-
else if (!req.res) {
109+
} else if (!req.res) {
111110
// socket closed before response starts.
112111
var err = new Error('socket hang up');
113112
req.emit('error', err);
@@ -173,7 +172,6 @@ function socketOnEnd() {
173172
}
174173

175174

176-
177175
// This is called by parserOnHeadersComplete after response header is parsed.
178176
// TODO: keepalive support
179177
function parserOnIncomingClient(res, shouldKeepAlive) {
@@ -194,7 +192,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
194192
req.emit('response', res);
195193

196194
// response to HEAD req has no body
197-
var isHeadResponse = (req.method == 'HEAD');
195+
var isHeadResponse = (req.method == 'HEAD');
198196

199197
return isHeadResponse;
200198

0 commit comments

Comments
 (0)