Skip to content

Commit 66f8d34

Browse files
BridgeARMylesBorins
authored andcommitted
test,benchmark,doc: enable dot-notation rule
This enables the eslint dot-notation rule for all code instead of only in /lib. PR-URL: #18749 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matheus Marchini <[email protected]>
1 parent 7874cb0 commit 66f8d34

39 files changed

+133
-135
lines changed

.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ rules:
4747
accessor-pairs: error
4848
array-callback-return: error
4949
dot-location: [error, property]
50+
dot-notation: error
5051
eqeqeq: [error, smart]
5152
no-fallthrough: error
5253
no-global-assign: error

benchmark/misc/object-property-bench.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* eslint-disable dot-notation */
4+
35
const common = require('../common.js');
46

57
const bench = common.createBenchmark(main, {

doc/api/http2.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ const server = http2.createServer();
12241224
server.on('stream', (stream) => {
12251225
stream.respond({ ':status': 200 }, {
12261226
getTrailers(trailers) {
1227-
trailers['ABC'] = 'some value to send';
1227+
trailers.ABC = 'some value to send';
12281228
}
12291229
});
12301230
stream.end('some data');
@@ -1308,7 +1308,7 @@ server.on('stream', (stream) => {
13081308
};
13091309
stream.respondWithFD(fd, headers, {
13101310
getTrailers(trailers) {
1311-
trailers['ABC'] = 'some value to send';
1311+
trailers.ABC = 'some value to send';
13121312
}
13131313
});
13141314
});
@@ -1416,7 +1416,7 @@ const http2 = require('http2');
14161416
const server = http2.createServer();
14171417
server.on('stream', (stream) => {
14181418
function getTrailers(trailers) {
1419-
trailers['ABC'] = 'some value to send';
1419+
trailers.ABC = 'some value to send';
14201420
}
14211421
stream.respondWithFile('/some/file',
14221422
{ 'content-type': 'text/plain' },

lib/.eslintrc.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
rules:
2-
dot-notation: error
3-
42
# Custom rules in tools/eslint-rules
53
require-buffer: error
64
buffer-constructor: error

test/addons-napi/test_symbol/test1.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ const test_symbol = require(`./build/${common.buildType}/test_symbol`);
88
const sym = test_symbol.New('test');
99
assert.strictEqual(sym.toString(), 'Symbol(test)');
1010

11-
1211
const myObj = {};
1312
const fooSym = test_symbol.New('foo');
1413
const otherSym = test_symbol.New('bar');
15-
myObj['foo'] = 'bar';
14+
myObj.foo = 'bar';
1615
myObj[fooSym] = 'baz';
1716
myObj[otherSym] = 'bing';
1817
assert.strictEqual(myObj.foo, 'bar');

test/addons-napi/test_symbol/test2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const test_symbol = require(`./build/${common.buildType}/test_symbol`);
77

88
const fooSym = test_symbol.New('foo');
99
const myObj = {};
10-
myObj['foo'] = 'bar';
10+
myObj.foo = 'bar';
1111
myObj[fooSym] = 'baz';
1212
Object.keys(myObj); // -> [ 'foo' ]
1313
Object.getOwnPropertyNames(myObj); // -> [ 'foo' ]

test/common/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ exports.canCreateSymLink = function() {
502502
// whoami.exe needs to be the one from System32
503503
// If unix tools are in the path, they can shadow the one we want,
504504
// so use the full path while executing whoami
505-
const whoamiPath = path.join(process.env['SystemRoot'],
505+
const whoamiPath = path.join(process.env.SystemRoot,
506506
'System32', 'whoami.exe');
507507

508508
let err = false;

test/common/inspector-helper.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ class InspectorSession {
168168
reject(message.error);
169169
} else {
170170
if (message.method === 'Debugger.scriptParsed') {
171-
const script = message['params'];
172-
const scriptId = script['scriptId'];
173-
const url = script['url'];
171+
const { scriptId, url } = message.params;
174172
this._scriptsIdsByUrl.set(scriptId, url);
175173
const fileUrl = url.startsWith('file:') ?
176174
url : getURLFromFilePath(url).toString();
@@ -192,12 +190,12 @@ class InspectorSession {
192190

193191
_sendMessage(message) {
194192
const msg = JSON.parse(JSON.stringify(message)); // Clone!
195-
msg['id'] = this._nextId++;
193+
msg.id = this._nextId++;
196194
if (DEBUG)
197195
console.log('[sent]', JSON.stringify(msg));
198196

199197
const responsePromise = new Promise((resolve, reject) => {
200-
this._commandResponsePromises.set(msg['id'], { resolve, reject });
198+
this._commandResponsePromises.set(msg.id, { resolve, reject });
201199
});
202200

203201
return new Promise(
@@ -243,14 +241,14 @@ class InspectorSession {
243241
}
244242

245243
_isBreakOnLineNotification(message, line, expectedScriptPath) {
246-
if ('Debugger.paused' === message['method']) {
247-
const callFrame = message['params']['callFrames'][0];
248-
const location = callFrame['location'];
249-
const scriptPath = this._scriptsIdsByUrl.get(location['scriptId']);
244+
if ('Debugger.paused' === message.method) {
245+
const callFrame = message.params.callFrames[0];
246+
const location = callFrame.location;
247+
const scriptPath = this._scriptsIdsByUrl.get(location.scriptId);
250248
assert.strictEqual(scriptPath.toString(),
251249
expectedScriptPath.toString(),
252250
`${scriptPath} !== ${expectedScriptPath}`);
253-
assert.strictEqual(line, location['lineNumber']);
251+
assert.strictEqual(line, location.lineNumber);
254252
return true;
255253
}
256254
}
@@ -266,12 +264,12 @@ class InspectorSession {
266264
_matchesConsoleOutputNotification(notification, type, values) {
267265
if (!Array.isArray(values))
268266
values = [ values ];
269-
if ('Runtime.consoleAPICalled' === notification['method']) {
270-
const params = notification['params'];
271-
if (params['type'] === type) {
267+
if ('Runtime.consoleAPICalled' === notification.method) {
268+
const params = notification.params;
269+
if (params.type === type) {
272270
let i = 0;
273-
for (const value of params['args']) {
274-
if (value['value'] !== values[i++])
271+
for (const value of params.args) {
272+
if (value.value !== values[i++])
275273
return false;
276274
}
277275
return i === values.length;
@@ -392,7 +390,7 @@ class NodeInstance {
392390

393391
async sendUpgradeRequest() {
394392
const response = await this.httpGet(null, '/json/list');
395-
const devtoolsUrl = response[0]['webSocketDebuggerUrl'];
393+
const devtoolsUrl = response[0].webSocketDebuggerUrl;
396394
const port = await this.portPromise;
397395
return http.get({
398396
port,

test/parallel/test-cluster-fork-env.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const cluster = require('cluster');
3131

3232
if (cluster.isWorker) {
3333
const result = cluster.worker.send({
34-
prop: process.env['cluster_test_prop'],
35-
overwrite: process.env['cluster_test_overwrite']
34+
prop: process.env.cluster_test_prop,
35+
overwrite: process.env.cluster_test_overwrite
3636
});
3737

3838
assert.strictEqual(result, true);
@@ -45,7 +45,7 @@ if (cluster.isWorker) {
4545

4646
// To check that the cluster extend on the process.env we will overwrite a
4747
// property
48-
process.env['cluster_test_overwrite'] = 'old';
48+
process.env.cluster_test_overwrite = 'old';
4949

5050
// Fork worker
5151
const worker = cluster.fork({

test/parallel/test-crypto-hmac.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ const wikipedia = [
8787
];
8888

8989
for (let i = 0, l = wikipedia.length; i < l; i++) {
90-
for (const hash in wikipedia[i]['hmac']) {
90+
for (const hash in wikipedia[i].hmac) {
9191
// FIPS does not support MD5.
9292
if (common.hasFipsCrypto && hash === 'md5')
9393
continue;
94-
const expected = wikipedia[i]['hmac'][hash];
95-
const actual = crypto.createHmac(hash, wikipedia[i]['key'])
96-
.update(wikipedia[i]['data'])
94+
const expected = wikipedia[i].hmac[hash];
95+
const actual = crypto.createHmac(hash, wikipedia[i].key)
96+
.update(wikipedia[i].data)
9797
.digest('hex');
9898
assert.strictEqual(
9999
actual,
@@ -252,18 +252,18 @@ const rfc4231 = [
252252
];
253253

254254
for (let i = 0, l = rfc4231.length; i < l; i++) {
255-
for (const hash in rfc4231[i]['hmac']) {
255+
for (const hash in rfc4231[i].hmac) {
256256
const str = crypto.createHmac(hash, rfc4231[i].key);
257257
str.end(rfc4231[i].data);
258258
let strRes = str.read().toString('hex');
259-
let actual = crypto.createHmac(hash, rfc4231[i]['key'])
260-
.update(rfc4231[i]['data'])
259+
let actual = crypto.createHmac(hash, rfc4231[i].key)
260+
.update(rfc4231[i].data)
261261
.digest('hex');
262-
if (rfc4231[i]['truncate']) {
262+
if (rfc4231[i].truncate) {
263263
actual = actual.substr(0, 32); // first 128 bits == 32 hex chars
264264
strRes = strRes.substr(0, 32);
265265
}
266-
const expected = rfc4231[i]['hmac'][hash];
266+
const expected = rfc4231[i].hmac[hash];
267267
assert.strictEqual(
268268
actual,
269269
expected,
@@ -384,10 +384,10 @@ const rfc2202_sha1 = [
384384

385385
if (!common.hasFipsCrypto) {
386386
for (let i = 0, l = rfc2202_md5.length; i < l; i++) {
387-
const actual = crypto.createHmac('md5', rfc2202_md5[i]['key'])
388-
.update(rfc2202_md5[i]['data'])
387+
const actual = crypto.createHmac('md5', rfc2202_md5[i].key)
388+
.update(rfc2202_md5[i].data)
389389
.digest('hex');
390-
const expected = rfc2202_md5[i]['hmac'];
390+
const expected = rfc2202_md5[i].hmac;
391391
assert.strictEqual(
392392
actual,
393393
expected,
@@ -396,10 +396,10 @@ if (!common.hasFipsCrypto) {
396396
}
397397
}
398398
for (let i = 0, l = rfc2202_sha1.length; i < l; i++) {
399-
const actual = crypto.createHmac('sha1', rfc2202_sha1[i]['key'])
400-
.update(rfc2202_sha1[i]['data'])
399+
const actual = crypto.createHmac('sha1', rfc2202_sha1[i].key)
400+
.update(rfc2202_sha1[i].data)
401401
.digest('hex');
402-
const expected = rfc2202_sha1[i]['hmac'];
402+
const expected = rfc2202_sha1[i].hmac;
403403
assert.strictEqual(
404404
actual,
405405
expected,

test/parallel/test-event-emitter-check-listener-leaks.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const events = require('events');
3232
for (let i = 0; i < 10; i++) {
3333
e.on('default', common.mustNotCall());
3434
}
35-
assert.ok(!e._events['default'].hasOwnProperty('warned'));
35+
assert.ok(!e._events.default.hasOwnProperty('warned'));
3636
e.on('default', common.mustNotCall());
37-
assert.ok(e._events['default'].warned);
37+
assert.ok(e._events.default.warned);
3838

3939
// symbol
4040
const symbol = Symbol('symbol');
@@ -49,9 +49,9 @@ const events = require('events');
4949
for (let i = 0; i < 5; i++) {
5050
e.on('specific', common.mustNotCall());
5151
}
52-
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
52+
assert.ok(!e._events.specific.hasOwnProperty('warned'));
5353
e.on('specific', common.mustNotCall());
54-
assert.ok(e._events['specific'].warned);
54+
assert.ok(e._events.specific.warned);
5555

5656
// only one
5757
e.setMaxListeners(1);
@@ -65,7 +65,7 @@ const events = require('events');
6565
for (let i = 0; i < 1000; i++) {
6666
e.on('unlimited', common.mustNotCall());
6767
}
68-
assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
68+
assert.ok(!e._events.unlimited.hasOwnProperty('warned'));
6969
}
7070

7171
// process-wide
@@ -76,16 +76,16 @@ const events = require('events');
7676
for (let i = 0; i < 42; ++i) {
7777
e.on('fortytwo', common.mustNotCall());
7878
}
79-
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
79+
assert.ok(!e._events.fortytwo.hasOwnProperty('warned'));
8080
e.on('fortytwo', common.mustNotCall());
81-
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
82-
delete e._events['fortytwo'].warned;
81+
assert.ok(e._events.fortytwo.hasOwnProperty('warned'));
82+
delete e._events.fortytwo.warned;
8383

8484
events.EventEmitter.defaultMaxListeners = 44;
8585
e.on('fortytwo', common.mustNotCall());
86-
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
86+
assert.ok(!e._events.fortytwo.hasOwnProperty('warned'));
8787
e.on('fortytwo', common.mustNotCall());
88-
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
88+
assert.ok(e._events.fortytwo.hasOwnProperty('warned'));
8989
}
9090

9191
// but _maxListeners still has precedence over defaultMaxListeners
@@ -94,9 +94,9 @@ const events = require('events');
9494
const e = new events.EventEmitter();
9595
e.setMaxListeners(1);
9696
e.on('uno', common.mustNotCall());
97-
assert.ok(!e._events['uno'].hasOwnProperty('warned'));
97+
assert.ok(!e._events.uno.hasOwnProperty('warned'));
9898
e.on('uno', common.mustNotCall());
99-
assert.ok(e._events['uno'].hasOwnProperty('warned'));
99+
assert.ok(e._events.uno.hasOwnProperty('warned'));
100100

101101
// chainable
102102
assert.strictEqual(e, e.setMaxListeners(1));

test/parallel/test-http-automatic-headers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ server.on('listening', common.mustCall(() => {
2222
assert.strictEqual(res.headers['x-date'], 'foo');
2323
assert.strictEqual(res.headers['x-connection'], 'bar');
2424
assert.strictEqual(res.headers['x-content-length'], 'baz');
25-
assert(res.headers['date']);
26-
assert.strictEqual(res.headers['connection'], 'keep-alive');
25+
assert(res.headers.date);
26+
assert.strictEqual(res.headers.connection, 'keep-alive');
2727
assert.strictEqual(res.headers['content-length'], '0');
2828
server.close();
2929
agent.destroy();

test/parallel/test-http-flush-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const http = require('http');
55

66
const server = http.createServer();
77
server.on('request', function(req, res) {
8-
assert.strictEqual(req.headers['foo'], 'bar');
8+
assert.strictEqual(req.headers.foo, 'bar');
99
res.end('ok');
1010
server.close();
1111
});

test/parallel/test-http-flush-response-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ server.listen(0, common.localhostIPv4, function() {
2020
req.end();
2121

2222
function onResponse(res) {
23-
assert.strictEqual(res.headers['foo'], 'bar');
23+
assert.strictEqual(res.headers.foo, 'bar');
2424
res.destroy();
2525
server.close();
2626
}

test/parallel/test-http-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const proxy = http.createServer(function(req, res) {
5050

5151
console.error(`proxy res headers: ${JSON.stringify(proxy_res.headers)}`);
5252

53-
assert.strictEqual('world', proxy_res.headers['hello']);
53+
assert.strictEqual('world', proxy_res.headers.hello);
5454
assert.strictEqual('text/plain', proxy_res.headers['content-type']);
5555
assert.deepStrictEqual(cookies, proxy_res.headers['set-cookie']);
5656

@@ -81,7 +81,7 @@ function startReq() {
8181
console.error('got res');
8282
assert.strictEqual(200, res.statusCode);
8383

84-
assert.strictEqual('world', res.headers['hello']);
84+
assert.strictEqual('world', res.headers.hello);
8585
assert.strictEqual('text/plain', res.headers['content-type']);
8686
assert.deepStrictEqual(cookies, res.headers['set-cookie']);
8787

test/parallel/test-http-server-multiheaders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const srv = http.createServer(function(req, res) {
3838
assert.strictEqual(req.headers['sec-websocket-protocol'], 'chat, share');
3939
assert.strictEqual(req.headers['sec-websocket-extensions'],
4040
'foo; 1, bar; 2, baz');
41-
assert.strictEqual(req.headers['constructor'], 'foo, bar, baz');
41+
assert.strictEqual(req.headers.constructor, 'foo, bar, baz');
4242

4343
res.writeHead(200, { 'Content-Type': 'text/plain' });
4444
res.end('EOF');

test/parallel/test-http-write-head.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ s.listen(0, common.mustCall(runTest));
6868
function runTest() {
6969
http.get({ port: this.address().port }, common.mustCall((response) => {
7070
response.on('end', common.mustCall(() => {
71-
assert.strictEqual(response.headers['test'], '2');
71+
assert.strictEqual(response.headers.test, '2');
7272
assert(response.rawHeaders.includes('Test'));
7373
s.close();
7474
}));

test/parallel/test-http.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const server = http.Server(common.mustCall(function(req, res) {
3333
switch (req.url) {
3434
case '/hello':
3535
assert.strictEqual(req.method, 'GET');
36-
assert.strictEqual(req.headers['accept'], '*/*');
37-
assert.strictEqual(req.headers['foo'], 'bar');
36+
assert.strictEqual(req.headers.accept, '*/*');
37+
assert.strictEqual(req.headers.foo, 'bar');
3838
assert.strictEqual(req.headers.cookie, 'foo=bar; bar=baz; baz=quux');
3939
break;
4040
case '/there':

test/parallel/test-http2-compat-expect-handling.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const expectValue = 'meoww';
1111
const server = http2.createServer(common.mustNotCall());
1212

1313
server.once('checkExpectation', common.mustCall((req, res) => {
14-
assert.strictEqual(req.headers['expect'], expectValue);
14+
assert.strictEqual(req.headers.expect, expectValue);
1515
res.statusCode = 417;
1616
res.end();
1717
}));

0 commit comments

Comments
 (0)