Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Jan 3, 2025
1 parent f1eaef1 commit b21192e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bin/test-naming-rules.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env node
#!/usr/bin/env node
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
Expand Down
1 change: 0 additions & 1 deletion bin/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env node
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
Expand Down
39 changes: 32 additions & 7 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ const header = require('./eslint-plugin-newrelic-header.js')

// The new eslint configuration format is a simple array of configuration
// objects. See https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects.
//
// While working on the config, it can be helpful to run:
// npx @eslint/config-inspector

// This should be used to override rules we don't need applied to our
// test suites.
const testFiles = [
'test/benchmark/**',
'test/integration/**',
'test/unit/**',
'test/smoke/**',
'test/versioned/**',
'bin/test/**'
]

// See https://eslint.org/docs/latest/use/configure/ignore#ignoring-files
const globalIgnores = {
Expand Down Expand Up @@ -66,13 +80,7 @@ const newrelicConfigOverrides = {
}

const sonarjsTestsConfig = {
files: [
'test/benchmark/**',
'test/integration/**',
'test/unit/**',
'test/smoke/**',
'test/versioned/**',
],
files: testFiles,

rules: {
// We sometimes need to shadow things like Promise for testing:
Expand Down Expand Up @@ -157,6 +165,12 @@ const jsdocOverrides = {
}
}

const nodeRecommended = neostandard.plugins.n.configs['flat/recommended']
delete nodeRecommended.languageOptions.sourceType
nodeRecommended.rules['n/no-unsupported-features/node-builtins'] = ['error', { version: '>=18.8.0' }]
nodeRecommended.rules['n/no-process-exit'] = 'off'
nodeRecommended.ignores = testFiles

// Configuration objects are merged in order. That is, the last object in the
// list will merge with objects earlier in the list. This allows for overriding
// any settings by adding objects to the end of the list.
Expand All @@ -177,6 +191,17 @@ module.exports = [
jsdocConfig,
jsdocOverrides,

// Add customized eslint-plugin-n recommended rules:
nodeRecommended,
{
files: [
'bin/*.js'
],
rules: {
'n/hashbang': 'off'
}
},

// Apply local configuration and overrides:
localConfig,
newrelicConfigOverrides,
Expand Down
12 changes: 4 additions & 8 deletions lib/instrumentation/aws-sdk/v3/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ function headerMiddleware(shim, config, next) {
* @param {Shim} shim
* @param {Object} config AWS command configuration
* @param {function} next next function in middleware chain
* @param {Object} contxt AWS command context
* cons
* @param context
* @param {Object} context AWS command context
* @returns {function}
*/
function attrMiddleware(shim, config, next, context) {
Expand All @@ -46,12 +44,10 @@ function attrMiddleware(shim, config, next, context) {
region = await config.region()
} catch (err) {
shim.logger.debug(err, 'Failed to get the AWS region')
} finally {
const result = await next(args)
addAwsAttributes({ result, config, region, shim, context })
// eslint-disable-next-line no-unsafe-finally
return result
}
const result = await next(args)
addAwsAttributes({ result, config, region, shim, context })
return result
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/instrumentation/core/http-outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function getDefaultHostName(opts) {
*/
function parseOpts(opts) {
if (typeof opts === 'string') {
// eslint-disable-next-line n/no-deprecated-api
opts = url.parse(opts)
} else {
opts = copy.shallow(opts)
Expand Down
2 changes: 2 additions & 0 deletions lib/instrumentation/core/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function wrapEmitWithTransaction(agent, emit, isHTTPS) {
tracer.bindEmitter(response, segment)

// the error tracer needs a URL for tracing, even though naming overwrites
// eslint-disable-next-line n/no-deprecated-api
transaction.parsedUrl = url.parse(request.url, true)
transaction.url = urltils.obfuscatePath(agent.config, transaction.parsedUrl.pathname)
transaction.verb = request.method
Expand Down Expand Up @@ -411,6 +412,7 @@ function wrapRequest(agent, request) {
const transaction = agent.tracer.getTransaction()
if (!transaction || internalOnly) {
if (!internalOnly && logger.traceEnabled()) {
// eslint-disable-next-line n/no-deprecated-api
const logOpts = typeof options === 'string' ? url.parse(options) : options
logger.trace(
'No transaction, not recording external to %s:%s',
Expand Down
2 changes: 2 additions & 0 deletions lib/instrumentation/undici.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const recordExternal = require('../metrics/recorders/http_external')
const logger = require('../logger').child({ component: 'undici' })
const NAMES = require('../metrics/names')
const symbols = require('../symbols')
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const { executionAsyncResource } = require('async_hooks')
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const diagnosticsChannel = require('diagnostics_channel')
const synthetics = require('../synthetics')
const urltils = require('../util/urltils')
Expand Down
1 change: 1 addition & 0 deletions lib/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ Transaction.prototype.getScrubbedUrl = function getScrubbedUrl() {
if (!this.url) {
return
}
// eslint-disable-next-line n/no-deprecated-api
this.parsedUrl = url.parse(this.url)
}

Expand Down
3 changes: 3 additions & 0 deletions lib/util/urltils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = {
*/
scrub: function scrub(requestURL) {
if (typeof requestURL === 'string') {
// eslint-disable-next-line n/no-deprecated-api
requestURL = url.parse(requestURL)
}

Expand Down Expand Up @@ -123,6 +124,7 @@ module.exports = {
let parsed = requestURL

if (typeof requestURL === 'string') {
// eslint-disable-next-line n/no-deprecated-api
parsed = url.parse(requestURL, true)
}

Expand Down Expand Up @@ -154,6 +156,7 @@ module.exports = {
*/
scrubAndParseParameters: function scrubAndParseParameters(requestURL) {
if (typeof requestURL === 'string') {
// eslint-disable-next-line n/no-deprecated-api
requestURL = url.parse(requestURL, true)
}
return {
Expand Down
1 change: 1 addition & 0 deletions lib/utilization/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ exports.request = function request(opts, agent, cb) {
// Add default timeout of a second to the request

if (typeof opts === 'string') {
// eslint-disable-next-line n/no-deprecated-api
opts = url.parse(opts)
}

Expand Down
5 changes: 5 additions & 0 deletions test/lib/promise-resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
* @returns {{resolve, reject, promise: Promise<unknown>}}
*/
module.exports = function promiseResolvers() {
// We are disabling this lint rule because it complains about
// `withResolvers` not being available until Node 22. We know that.
// We are doing feature detection.
/* eslint-disable n/no-unsupported-features/es-syntax */
if (typeof Promise.withResolvers === 'function') {
// Node.js >=22 natively supports this.
return Promise.withResolvers()
}
/* eslint-enable n/no-unsupported-features/es-syntax */

let resolve
let reject
Expand Down

0 comments on commit b21192e

Please sign in to comment.