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

refactor: Replaced instances of substr() with substring() #2274

Merged
merged 1 commit into from
Jun 13, 2024
Merged
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
2 changes: 1 addition & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@
* Only the first 13 chars of the license should be used for hashing with
* the transaction name.
*/
const key = config.license_key.substr(0, 13)
const key = config.license_key.substring(0, 13)
rumHash.transactionName = hashes.obfuscateNameUsingKey(name, key)

rumHash.queueTime = trans.queueTime
Expand Down Expand Up @@ -1548,7 +1548,7 @@
* @param {string} params.traceId Identifier for the feedback event.
* Obtained from {@link getTraceMetadata}.
* @param {string} params.category A tag for the event.
* @param {string} params.rating A indicator of how useful the message was.

Check warning on line 1551 in api.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

The type 'getTraceMetadata' is undefined

Check warning on line 1551 in api.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

The type 'getTraceMetadata' is undefined
* @param {string} [params.message] The message that triggered the event.
* @param {object} [params.metadata] Additional key-value pairs to associate
* with the recorded event.
Expand Down
4 changes: 2 additions & 2 deletions bin/create-docs-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
}
}

/**

Check warning on line 124 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration

Check warning on line 124 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration
* Extracts the relevant changes from the NEWS.md
*
* @param {string} version the new version
Expand Down Expand Up @@ -170,7 +170,7 @@
}
}

/**

Check warning on line 173 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration

Check warning on line 173 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration
* Reads the contents of NEWS.md
*
* @param {string} file path to NEWS.md
Expand Down Expand Up @@ -202,7 +202,7 @@
return git.clone(url, repoPath, cloneOptions)
}

/**

Check warning on line 205 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration

Check warning on line 205 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration
* Creates a branch in your local `docs-website` fork
* That follows the pattern `add-node-<new agent version>`
*
Expand Down Expand Up @@ -241,7 +241,7 @@
'---',
'subject: Node.js agent',
`releaseDate: '${releaseDate}'`,
`version: ${version.substr(1)}`, // remove the `v` from start of version
`version: ${version.substring(1)}`, // remove the `v` from start of version
`downloadLink: 'https://www.npmjs.com/package/newrelic'`,
`security: ${frontmatter.security}`,
`bugs: ${frontmatter.bugfixes}`,
Expand Down Expand Up @@ -279,7 +279,7 @@

function getFileName(version) {
// change `v0.0.0` to `0-0-0`
version = version.substr(1).replace(/\./g, '-')
version = version.substring(1).replace(/\./g, '-')
const FILE = `node-agent-${version}.mdx`
return `${RELEASE_NOTES_PATH}/${FILE}`
}
Expand Down Expand Up @@ -308,7 +308,7 @@
await git.pushToRemote(remote, branch)
}

/**

Check warning on line 311 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration

Check warning on line 311 in bin/create-docs-pr.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Missing JSDoc @returns declaration
* Creates a PR to the newrelic/docs-website with new release notes
*
* @param {string} version version number
Expand Down
2 changes: 1 addition & 1 deletion lib/config/attribute-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function _convertRulesToRegex(rules) {
if (i !== r.length - 1) {
v += '.'
} else if (/\\\*$/.test(v)) {
v = v.substr(0, v.length - 2)
v = v.substring(0, v.length - 2)
}

const idx = c.findIndex(function findV(a) {
Expand Down
2 changes: 1 addition & 1 deletion lib/instrumentation/aws-sdk/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function grabLastUrlSegment(url = '/') {
// string for null, undefined, NaN etc.
url = '' + (url || '/')
const lastSlashIndex = url.lastIndexOf('/')
return url.substr(lastSlashIndex + 1)
return url.substring(lastSlashIndex + 1)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/shim/datastore-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ function parseQuery(query, nodule) {
// strip enclosing special characters from collection (table) name
if (typeof collection === 'string' && collection.length > 2) {
if (/^[\[{'"`]/.test(collection)) {
collection = collection.substr(1)
collection = collection.substring(1)
}
if (/[\]}'"`]$/.test(collection)) {
collection = collection.substr(0, collection.length - 1)
collection = collection.substring(0, collection.length - 1)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/transaction/name-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ NameState.prototype.getPath = function getPath() {
if (a[0] !== '/' && path[path.length - 1] !== '/') {
path += '/'
} else if (a[0] === '/' && path[path.length - 1] === '/') {
a = a.substr(1)
a = a.substring(1)
}
path += a
}
Expand Down
5 changes: 3 additions & 2 deletions lib/util/hashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function calculatePathHash(appName, pathName, referingPathHash) {
const result = (rotated ^ hash) >>> 0

// This is a trick to pad it out to 8 chars regardless of length.
return ('00000000' + result.toString(16)).substr(-8)
const str = '00000000' + result.toString(16)
return str.substring(str.length - 8)
}

function getHash(appName, txName) {
Expand Down Expand Up @@ -78,7 +79,7 @@ function int32ToByteArray(int32) {
// Lookup table for converting byte values to hex
const byteToHex = []
for (let i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1)
byteToHex[i] = (i + 0x100).toString(16).substring(1)
}

function makeId(length = 16) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utilization/docker-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports.getBootId = function getBootId(agent, callback) {
if (data.length !== 36) {
bootIdError()
if (data.length > 128) {
data = data.substr(0, 128)
data = data.substring(0, 128)
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/utilization/gcp-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ function fetchGCPInfo(agent, callback) {
agent.metrics.getOrCreateMetric(NAMES.UTILIZATION.GCP_ERROR).incrementCallCount()
} else {
// normalize
results.machineType = results.machineType.substr(results.machineType.lastIndexOf('/') + 1)
results.zone = results.zone.substr(results.zone.lastIndexOf('/') + 1)
results.machineType = results.machineType.substring(
results.machineType.lastIndexOf('/') + 1
)
results.zone = results.zone.substring(results.zone.lastIndexOf('/') + 1)

resultDict = results
}
Expand Down
16 changes: 8 additions & 8 deletions test/integration/instrumentation/http-rum.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ test('custom naming rules should be applied early for RUM', function (t) {
function done(res) {
res.pipe(
new StreamSink(function (err, header) {
t.equal(header.substr(0, 7), '<script', 'should generate RUM headers')
t.equal(header.substring(0, 7), '<script', 'should generate RUM headers')
header.split(';').forEach(function (element) {
if (element.substr(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substr(DATA_PREFIX.length, element.length)
if (element.substring(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substring(DATA_PREFIX.length, element.length)
const data = JSON.parse(dataString)
const tx = hashes.deobfuscateNameUsingKey(
data.transactionName,
agent.config.license_key.substr(0, 13)
agent.config.license_key.substring(0, 13)
)
t.equal(tx, 'WebTransaction/NormalizedUri/WORKING', 'should normalize url before RUM')
}
Expand Down Expand Up @@ -106,14 +106,14 @@ test('custom web transactions should have rules applied for RUM', function (t) {

api.startWebTransaction('/test', function () {
const header = api.getBrowserTimingHeader()
t.equal(header.substr(0, 7), '<script', 'should generate RUM headers')
t.equal(header.substring(0, 7), '<script', 'should generate RUM headers')
header.split(';').forEach(function (element) {
if (element.substr(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substr(DATA_PREFIX.length, element.length)
if (element.substring(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substring(DATA_PREFIX.length, element.length)
const data = JSON.parse(dataString)
const tx = hashes.deobfuscateNameUsingKey(
data.transactionName,
agent.config.license_key.substr(0, 13)
agent.config.license_key.substring(0, 13)
)
t.equal(tx, 'WebTransaction/NormalizedUri/WORKING', 'url normalized before RUM')
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/rum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ tap.test('the RUM API', function (t) {
t.ok(payload)
const deobf = hashes.deobfuscateNameUsingKey(
payload[1],
agent.config.license_key.substr(0, 13)
agent.config.license_key.substring(0, 13)
)
t.equal(JSON.parse(deobf).u.hello, 1)
t.end()
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/express/render.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function runTests(conf) {

app.get(TEST_PATH, function (req, res) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
res.render('index', { title: 'yo dawg', rum: rum })
})

Expand Down
2 changes: 1 addition & 1 deletion test/versioned/hapi/render.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ tap.test('agent instrumentation of Hapi', function (t) {
path: '/test',
handler: function (req, h) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
return h.view('index', { title: 'yo dawg', rum: rum })
}
})
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/restify/pre-7/rum.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tap.test('Restify router introspection', function (t) {

server.get('/test/:id', function (req, res, next) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
res.send({ status: 'ok' })
next()
})
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/restify/rum.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tap.test('Restify router introspection', function (t) {

server.get('/test/:id', function (req, res, next) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
res.send({ status: 'ok' })
next()
})
Expand Down
Loading