Skip to content

Commit

Permalink
test,benchmark,doc: enable dot-notation rule
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
BridgeAR authored and MylesBorins committed Aug 16, 2018
1 parent 35e691c commit d55e4ad
Show file tree
Hide file tree
Showing 38 changed files with 132 additions and 131 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ rules:
# http://eslint.org/docs/rules/#best-practices
accessor-pairs: error
dot-location: [error, property]
dot-notation: error
eqeqeq: [error, smart]
no-fallthrough: error
no-global-assign: error
Expand Down
2 changes: 2 additions & 0 deletions benchmark/misc/object-property-bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

/* eslint-disable dot-notation */

const common = require('../common.js');

const bench = common.createBenchmark(main, {
Expand Down
6 changes: 3 additions & 3 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 }, {
getTrailers(trailers) {
trailers['ABC'] = 'some value to send';
trailers.ABC = 'some value to send';
}
});
stream.end('some data');
Expand Down Expand Up @@ -1326,7 +1326,7 @@ server.on('stream', (stream) => {
};
stream.respondWithFD(fd, headers, {
getTrailers(trailers) {
trailers['ABC'] = 'some value to send';
trailers.ABC = 'some value to send';
}
});

Expand Down Expand Up @@ -1435,7 +1435,7 @@ const http2 = require('http2');
const server = http2.createServer();
server.on('stream', (stream) => {
function getTrailers(trailers) {
trailers['ABC'] = 'some value to send';
trailers.ABC = 'some value to send';
}
stream.respondWithFile('/some/file',
{ 'content-type': 'text/plain' },
Expand Down
2 changes: 0 additions & 2 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
rules:
dot-notation: error

# Custom rules in tools/eslint-rules
require-buffer: error
buffer-constructor: error
Expand Down
3 changes: 1 addition & 2 deletions test/addons-napi/test_symbol/test1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ const test_symbol = require(`./build/${common.buildType}/test_symbol`);
const sym = test_symbol.New('test');
assert.strictEqual(sym.toString(), 'Symbol(test)');


const myObj = {};
const fooSym = test_symbol.New('foo');
const otherSym = test_symbol.New('bar');
myObj['foo'] = 'bar';
myObj.foo = 'bar';
myObj[fooSym] = 'baz';
myObj[otherSym] = 'bing';
assert.strictEqual(myObj.foo, 'bar');
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_symbol/test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const test_symbol = require(`./build/${common.buildType}/test_symbol`);

const fooSym = test_symbol.New('foo');
const myObj = {};
myObj['foo'] = 'bar';
myObj.foo = 'bar';
myObj[fooSym] = 'baz';
Object.keys(myObj); // -> [ 'foo' ]
Object.getOwnPropertyNames(myObj); // -> [ 'foo' ]
Expand Down
2 changes: 1 addition & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ exports.canCreateSymLink = function() {
// whoami.exe needs to be the one from System32
// If unix tools are in the path, they can shadow the one we want,
// so use the full path while executing whoami
const whoamiPath = path.join(process.env['SystemRoot'],
const whoamiPath = path.join(process.env.SystemRoot,
'System32', 'whoami.exe');

let err = false;
Expand Down
35 changes: 18 additions & 17 deletions test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ class InspectorSession {
reject(message.error);
} else {
if (message.method === 'Debugger.scriptParsed') {
const script = message['params'];
const scriptId = script['scriptId'];
const url = script['url'];
const { scriptId, url } = message.params;
this._scriptsIdsByUrl.set(scriptId, url);
if (url === _MAINSCRIPT)
this.mainScriptId = scriptId;
Expand All @@ -188,12 +186,12 @@ class InspectorSession {

_sendMessage(message) {
const msg = JSON.parse(JSON.stringify(message)); // Clone!
msg['id'] = this._nextId++;
msg.id = this._nextId++;
if (DEBUG)
console.log('[sent]', JSON.stringify(msg));

const responsePromise = new Promise((resolve, reject) => {
this._commandResponsePromises.set(msg['id'], { resolve, reject });
this._commandResponsePromises.set(msg.id, { resolve, reject });
});

return new Promise(
Expand Down Expand Up @@ -238,12 +236,15 @@ class InspectorSession {
return notification;
}

_isBreakOnLineNotification(message, line, url) {
if ('Debugger.paused' === message['method']) {
const callFrame = message['params']['callFrames'][0];
const location = callFrame['location'];
assert.strictEqual(url, this._scriptsIdsByUrl.get(location['scriptId']));
assert.strictEqual(line, location['lineNumber']);
_isBreakOnLineNotification(message, line, expectedScriptPath) {
if ('Debugger.paused' === message.method) {
const callFrame = message.params.callFrames[0];
const location = callFrame.location;
const scriptPath = this._scriptsIdsByUrl.get(location.scriptId);
assert.strictEqual(scriptPath.toString(),
expectedScriptPath.toString(),
`${scriptPath} !== ${expectedScriptPath}`);
assert.strictEqual(line, location.lineNumber);
return true;
}
}
Expand All @@ -259,12 +260,12 @@ class InspectorSession {
_matchesConsoleOutputNotification(notification, type, values) {
if (!Array.isArray(values))
values = [ values ];
if ('Runtime.consoleAPICalled' === notification['method']) {
const params = notification['params'];
if (params['type'] === type) {
if ('Runtime.consoleAPICalled' === notification.method) {
const params = notification.params;
if (params.type === type) {
let i = 0;
for (const value of params['args']) {
if (value['value'] !== values[i++])
for (const value of params.args) {
if (value.value !== values[i++])
return false;
}
return i === values.length;
Expand Down Expand Up @@ -389,7 +390,7 @@ class NodeInstance {
async connectInspectorSession() {
console.log('[test]', 'Connecting to a child Node process');
const response = await this.httpGet(null, '/json/list');
const url = response[0]['webSocketDebuggerUrl'];
const url = response[0].webSocketDebuggerUrl;
return this.wsHandshake(url);
}

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-cluster-fork-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const cluster = require('cluster');

if (cluster.isWorker) {
const result = cluster.worker.send({
prop: process.env['cluster_test_prop'],
overwrite: process.env['cluster_test_overwrite']
prop: process.env.cluster_test_prop,
overwrite: process.env.cluster_test_overwrite
});

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

// To check that the cluster extend on the process.env we will overwrite a
// property
process.env['cluster_test_overwrite'] = 'old';
process.env.cluster_test_overwrite = 'old';

// Fork worker
const worker = cluster.fork({
Expand Down
30 changes: 15 additions & 15 deletions test/parallel/test-crypto-hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ const wikipedia = [
];

for (let i = 0, l = wikipedia.length; i < l; i++) {
for (const hash in wikipedia[i]['hmac']) {
for (const hash in wikipedia[i].hmac) {
// FIPS does not support MD5.
if (common.hasFipsCrypto && hash === 'md5')
continue;
const expected = wikipedia[i]['hmac'][hash];
const actual = crypto.createHmac(hash, wikipedia[i]['key'])
.update(wikipedia[i]['data'])
const expected = wikipedia[i].hmac[hash];
const actual = crypto.createHmac(hash, wikipedia[i].key)
.update(wikipedia[i].data)
.digest('hex');
assert.strictEqual(
actual,
Expand Down Expand Up @@ -236,18 +236,18 @@ const rfc4231 = [
];

for (let i = 0, l = rfc4231.length; i < l; i++) {
for (const hash in rfc4231[i]['hmac']) {
for (const hash in rfc4231[i].hmac) {
const str = crypto.createHmac(hash, rfc4231[i].key);
str.end(rfc4231[i].data);
let strRes = str.read().toString('hex');
let actual = crypto.createHmac(hash, rfc4231[i]['key'])
.update(rfc4231[i]['data'])
let actual = crypto.createHmac(hash, rfc4231[i].key)
.update(rfc4231[i].data)
.digest('hex');
if (rfc4231[i]['truncate']) {
if (rfc4231[i].truncate) {
actual = actual.substr(0, 32); // first 128 bits == 32 hex chars
strRes = strRes.substr(0, 32);
}
const expected = rfc4231[i]['hmac'][hash];
const expected = rfc4231[i].hmac[hash];
assert.strictEqual(
actual,
expected,
Expand Down Expand Up @@ -368,10 +368,10 @@ const rfc2202_sha1 = [

if (!common.hasFipsCrypto) {
for (let i = 0, l = rfc2202_md5.length; i < l; i++) {
const actual = crypto.createHmac('md5', rfc2202_md5[i]['key'])
.update(rfc2202_md5[i]['data'])
const actual = crypto.createHmac('md5', rfc2202_md5[i].key)
.update(rfc2202_md5[i].data)
.digest('hex');
const expected = rfc2202_md5[i]['hmac'];
const expected = rfc2202_md5[i].hmac;
assert.strictEqual(
actual,
expected,
Expand All @@ -380,10 +380,10 @@ if (!common.hasFipsCrypto) {
}
}
for (let i = 0, l = rfc2202_sha1.length; i < l; i++) {
const actual = crypto.createHmac('sha1', rfc2202_sha1[i]['key'])
.update(rfc2202_sha1[i]['data'])
const actual = crypto.createHmac('sha1', rfc2202_sha1[i].key)
.update(rfc2202_sha1[i].data)
.digest('hex');
const expected = rfc2202_sha1[i]['hmac'];
const expected = rfc2202_sha1[i].hmac;
assert.strictEqual(
actual,
expected,
Expand Down
24 changes: 12 additions & 12 deletions test/parallel/test-event-emitter-check-listener-leaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const events = require('events');
for (let i = 0; i < 10; i++) {
e.on('default', common.mustNotCall());
}
assert.ok(!e._events['default'].hasOwnProperty('warned'));
assert.ok(!e._events.default.hasOwnProperty('warned'));
e.on('default', common.mustNotCall());
assert.ok(e._events['default'].warned);
assert.ok(e._events.default.warned);

// symbol
const symbol = Symbol('symbol');
Expand All @@ -49,9 +49,9 @@ const events = require('events');
for (let i = 0; i < 5; i++) {
e.on('specific', common.mustNotCall());
}
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
assert.ok(!e._events.specific.hasOwnProperty('warned'));
e.on('specific', common.mustNotCall());
assert.ok(e._events['specific'].warned);
assert.ok(e._events.specific.warned);

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

// process-wide
Expand All @@ -76,16 +76,16 @@ const events = require('events');
for (let i = 0; i < 42; ++i) {
e.on('fortytwo', common.mustNotCall());
}
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
assert.ok(!e._events.fortytwo.hasOwnProperty('warned'));
e.on('fortytwo', common.mustNotCall());
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
delete e._events['fortytwo'].warned;
assert.ok(e._events.fortytwo.hasOwnProperty('warned'));
delete e._events.fortytwo.warned;

events.EventEmitter.defaultMaxListeners = 44;
e.on('fortytwo', common.mustNotCall());
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
assert.ok(!e._events.fortytwo.hasOwnProperty('warned'));
e.on('fortytwo', common.mustNotCall());
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
assert.ok(e._events.fortytwo.hasOwnProperty('warned'));
}

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

// chainable
assert.strictEqual(e, e.setMaxListeners(1));
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-automatic-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ server.on('listening', common.mustCall(() => {
assert.strictEqual(res.headers['x-date'], 'foo');
assert.strictEqual(res.headers['x-connection'], 'bar');
assert.strictEqual(res.headers['x-content-length'], 'baz');
assert(res.headers['date']);
assert.strictEqual(res.headers['connection'], 'keep-alive');
assert(res.headers.date);
assert.strictEqual(res.headers.connection, 'keep-alive');
assert.strictEqual(res.headers['content-length'], '0');
server.close();
agent.destroy();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-flush-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const http = require('http');

const server = http.createServer();
server.on('request', function(req, res) {
assert.strictEqual(req.headers['foo'], 'bar');
assert.strictEqual(req.headers.foo, 'bar');
res.end('ok');
server.close();
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-flush-response-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ server.listen(0, common.localhostIPv4, function() {
req.end();

function onResponse(res) {
assert.strictEqual(res.headers['foo'], 'bar');
assert.strictEqual(res.headers.foo, 'bar');
res.destroy();
server.close();
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const proxy = http.createServer(function(req, res) {

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

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

Expand Down Expand Up @@ -81,7 +81,7 @@ function startReq() {
console.error('got res');
assert.strictEqual(200, res.statusCode);

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

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-server-multiheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const srv = http.createServer(function(req, res) {
assert.strictEqual(req.headers['sec-websocket-protocol'], 'chat, share');
assert.strictEqual(req.headers['sec-websocket-extensions'],
'foo; 1, bar; 2, baz');
assert.strictEqual(req.headers['constructor'], 'foo, bar, baz');
assert.strictEqual(req.headers.constructor, 'foo, bar, baz');

res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('EOF');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-write-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ s.listen(0, common.mustCall(runTest));
function runTest() {
http.get({ port: this.address().port }, common.mustCall((response) => {
response.on('end', common.mustCall(() => {
assert.strictEqual(response.headers['test'], '2');
assert.strictEqual(response.headers.test, '2');
assert(response.rawHeaders.includes('Test'));
s.close();
}));
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const server = http.Server(common.mustCall(function(req, res) {
switch (req.url) {
case '/hello':
assert.strictEqual(req.method, 'GET');
assert.strictEqual(req.headers['accept'], '*/*');
assert.strictEqual(req.headers['foo'], 'bar');
assert.strictEqual(req.headers.accept, '*/*');
assert.strictEqual(req.headers.foo, 'bar');
assert.strictEqual(req.headers.cookie, 'foo=bar; bar=baz; baz=quux');
break;
case '/there':
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-compat-expect-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const expectValue = 'meoww';
const server = http2.createServer(common.mustNotCall());

server.once('checkExpectation', common.mustCall((req, res) => {
assert.strictEqual(req.headers['expect'], expectValue);
assert.strictEqual(req.headers.expect, expectValue);
res.statusCode = 417;
res.end();
}));
Expand Down
Loading

0 comments on commit d55e4ad

Please sign in to comment.