Skip to content
11 changes: 10 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
"license-header"
],
"rules": {
"license-header/header": [ "error", "./dev-utils/license-header.js" ]
"license-header/header": ["error", "./dev-utils/license-header.js"],
// Regarding "no-var": The opinion of this repository's maintainers is that
// while const/let are useful, the use of `var` is not bad and therefore
// does not need to be ruled out. Eliminating the use of `var` would be a
// large diff that (a) could theoretically cause bugs due to lexical scoping
// changes and (b) could theoretically impact perf (e.g. see
// https://github.com/microsoft/TypeScript/issues/52924). New code MAY
// prefer const/let over `var`. Code in "examples/" MUST use const/let --
// this is enforced by "examples/.eslintrc.json".
"no-var": "off"
},
"ignorePatterns": [
"/*.example.js", // a pattern for uncommited local dev files to avoid linting
Expand Down
4 changes: 2 additions & 2 deletions dev-utils/bitrot.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function loadSupportedDoc () {
var state = null // null | 'thead' | 'tbody'
html.split(/\n/g).forEach(function (line) {
if (!line.startsWith('|')) {

// no op
} else if (state === null) {
if (line.startsWith('|===')) {
state = 'thead'
Expand Down Expand Up @@ -181,7 +181,7 @@ function loadSupportedDoc () {
let match
rows.forEach(function (row) {
if (row[1] === 'N/A') {

// skip
} else if (row[0].includes('<<')) {
match = /^\s*<<([\w-]+),(.*?)>>/.exec(row[0])
if (!match) {
Expand Down
5 changes: 5 additions & 0 deletions examples/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-var": ["error"]
}
}
6 changes: 3 additions & 3 deletions examples/trace-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
const apm = require('../').start({ // elastic-apm-node
serviceName: 'example-trace-graphql'
})
var { graphql, buildSchema } = require('graphql')
const { graphql, buildSchema } = require('graphql')

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
const schema = buildSchema(`
type Query {
hello: String
bye: String
}
`)

// The root provides a resolver function for each API endpoint
var root = {
const root = {
hello: () => {
return 'Hello world!'
},
Expand Down
2 changes: 1 addition & 1 deletion examples/trace-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const handlebars = require('handlebars')
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
const t1 = apm.startTransaction('t1')

var template = handlebars.compile('Hello, {{name}}!')
const template = handlebars.compile('Hello, {{name}}!')
console.log(template({ name: 'world' }))
console.log(template({ name: 'Bob' }))

Expand Down
2 changes: 1 addition & 1 deletion examples/trace-pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ client.query('SELECT $1::text as message', ['bye'], (err, res) => {

// 2. Using streaming style, i.e. using a `Submittable` as node-postgres calls it.
const t2 = apm.startTransaction('t2')
var q = client.query(new Query('select 1 + 1 as solution'))
const q = client.query(new Query('select 1 + 1 as solution'))
q.on('error', (err) => {
console.log('[t2] Failure: err is', err)
t2.end()
Expand Down
2 changes: 1 addition & 1 deletion examples/trace-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const pug = require('pug')
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
const t1 = apm.startTransaction('t1')

var template = pug.compile('p Hello, #{name}!')
const template = pug.compile('p Hello, #{name}!')
console.log(template({ name: 'world' }))
console.log(template({ name: 'Bob' }))

Expand Down
2 changes: 1 addition & 1 deletion examples/trace-tedious.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const conn2 = new tedious.Connection(connOpts)
conn2.on('connect', onConnect2)
conn2.connect()
function onConnect2 () {
var req = new tedious.Request("select @mynum=42, @mystr='qaz'", function (err, rowCount) {
const req = new tedious.Request("select @mynum=42, @mystr='qaz'", function (err, rowCount) {
console.log('select @mynum ...: err=%s rowCount=%s', err && err.message, rowCount)
conn2.close()
})
Expand Down
4 changes: 2 additions & 2 deletions examples/trace-ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const apm = require('../').start({ // elastic-apm-node
serviceName: 'example-trace-ws'
})

var WebSocket = require('ws')
var PORT = 4567
const WebSocket = require('ws')
const PORT = 4567

// Server
const wss = new WebSocket.Server({ port: PORT })
Expand Down
3 changes: 2 additions & 1 deletion lib/instrumentation/modules/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function getTargetUrlFromTransportConfig (config) {
}

let firstTransportHost = Array.isArray(transportHosts)
? transportHosts[0] : transportHosts
? transportHosts[0]
: transportHosts
if (!firstTransportHost) {
return null
}
Expand Down
5 changes: 3 additions & 2 deletions lib/instrumentation/modules/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ module.exports = function (graphql, agent, { version, enabled }) {

if (document && Array.isArray(document.definitions)) {
document.definitions.some(function (definition) {
if (!definition || definition.kind !== graphql.Kind.OPERATION_DEFINITION) return
if (!operationName && operation) return
if (!definition || definition.kind !== graphql.Kind.OPERATION_DEFINITION) return false
if (!operationName && operation) return false
if (!operationName || (definition.name && definition.name.value === operationName)) {
operation = definition
return true
}
return false
})

var selections = operation && operation.selectionSet && operation.selectionSet.selections
Expand Down
2 changes: 1 addition & 1 deletion lib/instrumentation/modules/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function (mysql, agent, { version, enabled }) {
var cb = arguments[0]

if (typeof cb === 'function') {
arguments[0] = agent._instrumentation.bindFunction(function wrapedCallback (err, connection) { // eslint-disable-line handle-callback-err
arguments[0] = agent._instrumentation.bindFunction(function wrapedCallback (err, connection) { // eslint-disable-line node/handle-callback-err
if (connection) wrapQueryable(connection, 'getConnection() > connection', agent)
return cb.apply(this, arguments)
})
Expand Down
3 changes: 2 additions & 1 deletion lib/instrumentation/span-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class SpanCompression {

const isAlreadyComposite = this.isComposite()
const canBeCompressed = isAlreadyComposite
? this.tryToCompressComposite(compositeSpan, spanToCompress) : this.tryToCompressRegular(compositeSpan, spanToCompress)
? this.tryToCompressComposite(compositeSpan, spanToCompress)
: this.tryToCompressRegular(compositeSpan, spanToCompress)

if (!canBeCompressed) {
return false
Expand Down
5 changes: 1 addition & 4 deletions lib/tracecontext/tracestate.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ class TraceState {
if (key.length > 256 || key.length < 1) {
return false
}

const re = new RegExp(
'^[abcdefghijklmnopqrstuvwxyz0123456789_\\-\\*/]*$'
)
const re = /^[abcdefghijklmnopqrstuvwxyz0123456789_\-*/]*$/
if (!key.match(re)) {
return false
}
Expand Down
Loading