Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test,benchmark,doc: enable dot-notation rule #18749

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ rules:
accessor-pairs: error
array-callback-return: 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 @@ -1220,7 +1220,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 @@ -1303,7 +1303,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 @@ -1410,7 +1410,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 @@ -501,7 +501,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
30 changes: 14 additions & 16 deletions test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,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);
const fileUrl = url.startsWith('file:') ?
url : getURLFromFilePath(url).toString();
Expand All @@ -192,12 +190,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 @@ -243,14 +241,14 @@ class InspectorSession {
}

_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']);
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']);
assert.strictEqual(line, location.lineNumber);
return true;
}
}
Expand All @@ -266,12 +264,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 @@ -392,7 +390,7 @@ class NodeInstance {

async sendUpgradeRequest() {
const response = await this.httpGet(null, '/json/list');
const devtoolsUrl = response[0]['webSocketDebuggerUrl'];
const devtoolsUrl = response[0].webSocketDebuggerUrl;
const port = await this.portPromise;
return http.get({
port,
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 @@ -87,13 +87,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 @@ -252,18 +252,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 @@ -384,10 +384,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 @@ -396,10 +396,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 @@ -68,7 +68,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