Skip to content

Commit daad3a4

Browse files
authored
chore: prepare code style for new version of linter (#1284)
We can't upgrade to the new version of 'standard' currently because we still use the deprecated `url.parse` API in several locations (see issue no #1254). But to ensure fewer merge conflicts between the 2.x and the upcoming 3.x branch, we'll fix as many future linting issues as possible already now.
1 parent dcc98a7 commit daad3a4

File tree

17 files changed

+29
-27
lines changed

17 files changed

+29
-27
lines changed

lib/agent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Agent.prototype.captureError = function (err, opts, cb) {
389389
}
390390

391391
if (agent._transport) {
392-
agent.logger.info(`Sending error to Elastic APM`, { id: error.id })
392+
agent.logger.info('Sending error to Elastic APM', { id: error.id })
393393
agent._transport.sendError(error, function () {
394394
agent.flush(function (err) {
395395
if (cb) cb(err, error.id)

lib/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if (fs.existsSync(confPath)) {
3636

3737
let serviceName, serviceVersion
3838
try {
39-
let pkg = readPkgUp.sync().pkg
39+
const pkg = readPkgUp.sync().pkg
4040
serviceName = pkg.name
4141
serviceVersion = pkg.version
4242
} catch (err) {}
@@ -345,7 +345,7 @@ function readEnv () {
345345

346346
for (const key of Object.keys(ENV_TABLE)) {
347347
let env = ENV_TABLE[key]
348-
if (!Array.isArray(env)) env = [ env ]
348+
if (!Array.isArray(env)) env = [env]
349349
for (const envKey of env) {
350350
if (envKey in process.env) {
351351
opts[key] = process.env[envKey]

lib/instrumentation/http-shared.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) {
108108
agent.logger.debug('intercepted call to %s.%s %o', moduleName, method, { id: id })
109109

110110
var options = {}
111-
var newArgs = [ options ]
111+
var newArgs = [options]
112112
for (const arg of args) {
113113
if (typeof arg === 'function') {
114114
newArgs.push(arg)
@@ -191,6 +191,6 @@ function shouldPropagateTraceContext (opts) {
191191
}
192192

193193
function isAWSSigned (opts) {
194-
const auth = opts.headers && (opts.headers['Authorization'] || opts.headers['authorization'])
194+
const auth = opts.headers && (opts.headers.Authorization || opts.headers.authorization)
195195
return typeof auth === 'string' ? auth.startsWith('AWS4-') : false
196196
}

lib/instrumentation/modules/elasticsearch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function (elasticsearch, agent, { enabled }) {
2727
span.name = `Elasticsearch: ${method} ${path}`
2828

2929
if (queryRegexp.test(path)) {
30-
let statement = Array.isArray(body)
30+
const statement = Array.isArray(body)
3131
? body.map(JSON.stringify).join('\n')
3232
: JSON.stringify(body || query)
3333

lib/instrumentation/modules/http2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ module.exports = function (http2, agent, { enabled }) {
129129
} else if (Array.isArray(target[key])) {
130130
result[key].push(source[key])
131131
} else {
132-
result[key] = [ source[key] ].concat(target[key])
132+
result[key] = [source[key]].concat(target[key])
133133
}
134134
}
135135
return result

lib/instrumentation/transaction.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function spanBreakdownDetails (span) {
271271
}
272272
}
273273

274-
const [ type, subtype ] = span.type.split('.')
274+
const [type, subtype] = span.type.split('.')
275275
return {
276276
type,
277277
subtype
@@ -286,7 +286,7 @@ function captureBreakdown (transaction, labels, time) {
286286
}
287287

288288
function flattenBreakdown (source, target = {}, prefix = '') {
289-
for (const [ key, value ] of entries(source)) {
289+
for (const [key, value] of entries(source)) {
290290
if (typeof value === 'undefined') continue
291291
if (typeof value === 'object') {
292292
flattenBreakdown(value, target, `${prefix}${key}::`)

lib/metrics/platforms/linux/stats.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Stats {
108108
let memTotal = 0
109109

110110
let matches = 0
111-
for (let line of memoryFile.toString().split('\n')) {
111+
for (const line of memoryFile.toString().split('\n')) {
112112
if (/^MemAvailable:/.test(line)) {
113113
memAvailable = parseInt(line.split(whitespace)[1], 10) * 1024
114114
matches++

lib/metrics/reporter.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ function unflattenBreakdown (source) {
6565
tags: {}
6666
}
6767

68-
for (const [ key, value ] of entries(source)) {
68+
for (const [key, value] of entries(source)) {
6969
if (key.includes('::')) {
70-
const [ parent, child ] = key.split('::')
70+
const [parent, child] = key.split('::')
7171
if (!target[parent]) target[parent] = {}
7272
target[parent][child] = value
7373
} else {

test/config.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ optionFixtures.forEach(function (fixture) {
9595
agent.start()
9696

9797
if (array) {
98-
t.deepEqual(agent._conf[fixture[0]], [ value ])
98+
t.deepEqual(agent._conf[fixture[0]], [value])
9999
} else {
100100
t.equal(agent._conf[fixture[0]], bool ? !fixture[2] : value)
101101
}
@@ -134,7 +134,7 @@ optionFixtures.forEach(function (fixture) {
134134
agent.start(opts)
135135

136136
if (array) {
137-
t.deepEqual(agent._conf[fixture[0]], [ value2 ])
137+
t.deepEqual(agent._conf[fixture[0]], [value2])
138138
} else {
139139
t.equal(agent._conf[fixture[0]], value2)
140140
}
@@ -347,7 +347,7 @@ var noPrefixValues = [
347347
]
348348

349349
noPrefixValues.forEach(function (pair) {
350-
const [ key, envVar ] = pair
350+
const [key, envVar] = pair
351351
test(`maps ${envVar} to ${key}`, (t) => {
352352
var agent = Agent()
353353
process.env[envVar] = 'test'
@@ -853,9 +853,11 @@ class CaptureLogger {
853853
warn (message, ...args) {
854854
this._log('warn', message, args)
855855
}
856+
856857
info (message, ...args) {
857858
this._log('info', message, args)
858859
}
860+
859861
debug (message, ...args) {
860862
this._log('debug', message, args)
861863
}

test/instrumentation/modules/http/aws.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ AWS.config.update({
1818

1919
test('non aws-sdk request', function (t) {
2020
const server = http.createServer(function (req, res) {
21-
t.equal(req.headers['authorization'], undefined, 'no authorization header')
21+
t.equal(req.headers.authorization, undefined, 'no authorization header')
2222
t.ok(req.headers['elastic-apm-traceparent'].length > 0, 'elastic-apm-traceparent header')
2323
res.end()
2424
server.close()
@@ -39,7 +39,7 @@ test('non aws-sdk request', function (t) {
3939

4040
test('aws-sdk request', function (t) {
4141
const server = http.createServer(function (req, res) {
42-
t.equal(req.headers['authorization'].substr(0, 5), 'AWS4-', 'AWS authorization header')
42+
t.equal(req.headers.authorization.substr(0, 5), 'AWS4-', 'AWS authorization header')
4343
t.equal(req.headers['elastic-apm-traceparent'], undefined, 'no elastic-apm-traceparent header')
4444
res.end()
4545
server.close()

test/instrumentation/modules/mongodb-core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ test('instrument simple command', function (t) {
123123
t.error(err)
124124
t.equal(results.result.n, 3)
125125

126-
_server.update('elasticapm.test', [{ q: { a: 1 }, u: { '$set': { b: 1 } } }], { writeConcern: { w: 1 }, ordered: true }, function (err, results) {
126+
_server.update('elasticapm.test', [{ q: { a: 1 }, u: { $set: { b: 1 } } }], { writeConcern: { w: 1 }, ordered: true }, function (err, results) {
127127
t.error(err)
128128
t.equal(results.result.n, 1)
129129

test/instrumentation/transaction.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,10 @@ function mockRequest () {
510510
method: 'POST',
511511
url: '/foo?bar=baz',
512512
headers: {
513-
'host': 'example.com',
513+
host: 'example.com',
514514
'user-agent': 'user-agent-header',
515515
'content-length': 42,
516-
'cookie': 'cookie1=foo;cookie2=bar',
516+
cookie: 'cookie1=foo;cookie2=bar',
517517
'x-foo': 'bar',
518518
'x-bar': 'baz'
519519
},

test/metrics/breakdown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const finders = {
5656
return metricsets.find(metricset => metricset.span && metricset.span.type === 'app')
5757
},
5858
span (metricsets, span) {
59-
const [ type, subtype ] = span.type.split('.')
59+
const [type, subtype] = span.type.split('.')
6060
return metricsets.find(v => v.span && v.span.type === type && v.span.subtype === subtype)
6161
}
6262
}

test/metrics/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test('reports expected metrics', function (t) {
126126
for (const name of Object.keys(metrics)) {
127127
const metric = metricset.samples[name]
128128
t.comment(name)
129-
t.ok(metric, `is present`)
129+
t.ok(metric, 'is present')
130130
t.equal(typeof metric.value, 'number', 'is a number')
131131
t.ok(Number.isFinite(metric.value), `is finite (was: ${metric.value})`)
132132
metrics[name](metric.value)

test/parsers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ test('#parseError()', function (t) {
382382
}
383383
try {
384384
var o = {}
385-
o['...']['Derp']()
385+
o['...'].Derp()
386386
} catch (e) {
387387
parsers.parseError(e, fakeAgent, function (err, parsed) {
388388
t.error(err)

test/script/cli.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ var saveConf = function (conf, cb) {
326326
loadConf(function (err, conf) {
327327
if (err) throw err
328328
var questions = [
329-
{ name: 'serviceName', message: 'Service name', 'default': conf.serviceName },
330-
{ name: 'secretToken', message: 'Secret token', 'default': conf.secretToken },
331-
{ name: 'serverUrl', message: 'APM Server URL', 'default': conf.serverUrl },
329+
{ name: 'serviceName', message: 'Service name', default: conf.serviceName },
330+
{ name: 'secretToken', message: 'Secret token', default: conf.secretToken },
331+
{ name: 'serverUrl', message: 'APM Server URL', default: conf.serverUrl },
332332
{ name: 'suite', message: 'Test suite', type: 'list', choices: ['standard', 'http', 'restify', 'connect', 'express', 'transaction'] },
333333
{ name: 'save', message: 'Save answers?', type: 'confirm' }
334334
]

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function run (test, cb) {
1818

1919
console.log('running: ' + fullPath)
2020

21-
var ps = spawn('node', [ test.file ], {
21+
var ps = spawn('node', [test.file], {
2222
stdio: 'inherit',
2323
cwd: test.cwd,
2424
env: test.env

0 commit comments

Comments
 (0)