Skip to content

Commit e0e01cf

Browse files
jmetev1trentm
authored andcommitted
chore: upgrade to eslint@8 (elastic#3409)
We have turned *off* the "no-var" rule that was added to the "standard" config with this upgrade. See .eslintrc.json for justification. We are applying "no-var" in examples/... Using eslint@8 bumps the min node for linting to 12.20.0. Co-authored-by: Trent Mick <trent.mick@elastic.co>
1 parent c8641d5 commit e0e01cf

21 files changed

+889
-921
lines changed

.eslintrc.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
"license-header"
99
],
1010
"rules": {
11-
"license-header/header": [ "error", "./dev-utils/license-header.js" ]
11+
"license-header/header": ["error", "./dev-utils/license-header.js"],
12+
// Regarding "no-var": The opinion of this repository's maintainers is that
13+
// while const/let are useful, the use of `var` is not bad and therefore
14+
// does not need to be ruled out. Eliminating the use of `var` would be a
15+
// large diff that (a) could theoretically cause bugs due to lexical scoping
16+
// changes and (b) could theoretically impact perf (e.g. see
17+
// https://github.com/microsoft/TypeScript/issues/52924). New code MAY
18+
// prefer const/let over `var`. Code in "examples/" MUST use const/let --
19+
// this is enforced by "examples/.eslintrc.json".
20+
"no-var": "off"
1221
},
1322
"ignorePatterns": [
1423
"/*.example.js", // a pattern for uncommited local dev files to avoid linting

dev-utils/bitrot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function loadSupportedDoc () {
136136
var state = null // null | 'thead' | 'tbody'
137137
html.split(/\n/g).forEach(function (line) {
138138
if (!line.startsWith('|')) {
139-
139+
// no op
140140
} else if (state === null) {
141141
if (line.startsWith('|===')) {
142142
state = 'thead'
@@ -181,7 +181,7 @@ function loadSupportedDoc () {
181181
let match
182182
rows.forEach(function (row) {
183183
if (row[1] === 'N/A') {
184-
184+
// skip
185185
} else if (row[0].includes('<<')) {
186186
match = /^\s*<<([\w-]+),(.*?)>>/.exec(row[0])
187187
if (!match) {

examples/.eslintrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"no-var": ["error"]
4+
}
5+
}

examples/trace-graphql.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
const apm = require('../').start({ // elastic-apm-node
1111
serviceName: 'example-trace-graphql'
1212
})
13-
var { graphql, buildSchema } = require('graphql')
13+
const { graphql, buildSchema } = require('graphql')
1414

1515
// Construct a schema, using GraphQL schema language
16-
var schema = buildSchema(`
16+
const schema = buildSchema(`
1717
type Query {
1818
hello: String
1919
bye: String
2020
}
2121
`)
2222

2323
// The root provides a resolver function for each API endpoint
24-
var root = {
24+
const root = {
2525
hello: () => {
2626
return 'Hello world!'
2727
},

examples/trace-handlebars.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const handlebars = require('handlebars')
2121
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
2222
const t1 = apm.startTransaction('t1')
2323

24-
var template = handlebars.compile('Hello, {{name}}!')
24+
const template = handlebars.compile('Hello, {{name}}!')
2525
console.log(template({ name: 'world' }))
2626
console.log(template({ name: 'Bob' }))
2727

examples/trace-pg.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ client.query('SELECT $1::text as message', ['bye'], (err, res) => {
4343

4444
// 2. Using streaming style, i.e. using a `Submittable` as node-postgres calls it.
4545
const t2 = apm.startTransaction('t2')
46-
var q = client.query(new Query('select 1 + 1 as solution'))
46+
const q = client.query(new Query('select 1 + 1 as solution'))
4747
q.on('error', (err) => {
4848
console.log('[t2] Failure: err is', err)
4949
t2.end()

examples/trace-pug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const pug = require('pug')
2121
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/custom-transactions.html
2222
const t1 = apm.startTransaction('t1')
2323

24-
var template = pug.compile('p Hello, #{name}!')
24+
const template = pug.compile('p Hello, #{name}!')
2525
console.log(template({ name: 'world' }))
2626
console.log(template({ name: 'Bob' }))
2727

examples/trace-tedious.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const conn2 = new tedious.Connection(connOpts)
6565
conn2.on('connect', onConnect2)
6666
conn2.connect()
6767
function onConnect2 () {
68-
var req = new tedious.Request("select @mynum=42, @mystr='qaz'", function (err, rowCount) {
68+
const req = new tedious.Request("select @mynum=42, @mystr='qaz'", function (err, rowCount) {
6969
console.log('select @mynum ...: err=%s rowCount=%s', err && err.message, rowCount)
7070
conn2.close()
7171
})

examples/trace-ws.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const apm = require('../').start({ // elastic-apm-node
2020
serviceName: 'example-trace-ws'
2121
})
2222

23-
var WebSocket = require('ws')
24-
var PORT = 4567
23+
const WebSocket = require('ws')
24+
const PORT = 4567
2525

2626
// Server
2727
const wss = new WebSocket.Server({ port: PORT })

lib/instrumentation/modules/elasticsearch.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function getTargetUrlFromTransportConfig (config) {
2929
}
3030

3131
let firstTransportHost = Array.isArray(transportHosts)
32-
? transportHosts[0] : transportHosts
32+
? transportHosts[0]
33+
: transportHosts
3334
if (!firstTransportHost) {
3435
return null
3536
}

lib/instrumentation/modules/graphql.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ module.exports = function (graphql, agent, { version, enabled }) {
173173

174174
if (document && Array.isArray(document.definitions)) {
175175
document.definitions.some(function (definition) {
176-
if (!definition || definition.kind !== graphql.Kind.OPERATION_DEFINITION) return
177-
if (!operationName && operation) return
176+
if (!definition || definition.kind !== graphql.Kind.OPERATION_DEFINITION) return false
177+
if (!operationName && operation) return false
178178
if (!operationName || (definition.name && definition.name.value === operationName)) {
179179
operation = definition
180180
return true
181181
}
182+
return false
182183
})
183184

184185
var selections = operation && operation.selectionSet && operation.selectionSet.selections

lib/instrumentation/modules/mysql.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = function (mysql, agent, { version, enabled }) {
8181
var cb = arguments[0]
8282

8383
if (typeof cb === 'function') {
84-
arguments[0] = agent._instrumentation.bindFunction(function wrapedCallback (err, connection) { // eslint-disable-line handle-callback-err
84+
arguments[0] = agent._instrumentation.bindFunction(function wrapedCallback (err, connection) { // eslint-disable-line node/handle-callback-err
8585
if (connection) wrapQueryable(connection, 'getConnection() > connection', agent)
8686
return cb.apply(this, arguments)
8787
})

lib/instrumentation/span-compression.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ class SpanCompression {
115115

116116
const isAlreadyComposite = this.isComposite()
117117
const canBeCompressed = isAlreadyComposite
118-
? this.tryToCompressComposite(compositeSpan, spanToCompress) : this.tryToCompressRegular(compositeSpan, spanToCompress)
118+
? this.tryToCompressComposite(compositeSpan, spanToCompress)
119+
: this.tryToCompressRegular(compositeSpan, spanToCompress)
119120

120121
if (!canBeCompressed) {
121122
return false

lib/tracecontext/tracestate.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,7 @@ class TraceState {
247247
if (key.length > 256 || key.length < 1) {
248248
return false
249249
}
250-
251-
const re = new RegExp(
252-
'^[abcdefghijklmnopqrstuvwxyz0123456789_\\-\\*/]*$'
253-
)
250+
const re = /^[abcdefghijklmnopqrstuvwxyz0123456789_\-*/]*$/
254251
if (!key.match(re)) {
255252
return false
256253
}

0 commit comments

Comments
 (0)