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

ESLint: Require await inside async functions #5263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 benchmark/sirun/get-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async function getResults (gitCommit) {
async function main () {
const ref = process.argv.length > 2 ? process.argv[2] : 'HEAD'
const gitCommit = execSync(`git rev-parse ${ref}`).toString().trim()
console.log(JSON.stringify(getResults(gitCommit), null, 4))
console.log(JSON.stringify(await getResults(gitCommit), null, 4))
}

module.exports = {
Expand Down
6 changes: 4 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default [
'no-console': 'error',
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommnded)
'no-unused-expressions': 'off', // Override (turned on by standard)
'no-var': 'error' // Override (set to warn in standard)
'no-var': 'error', // Override (set to warn in standard)
'require-await': 'error'
}
},
{
Expand Down Expand Up @@ -133,7 +134,8 @@ export default [
'mocha/no-sibling-hooks': 'off',
'mocha/no-skipped-tests': 'off',
'mocha/no-top-level-hooks': 'off',
'n/handle-callback-err': 'off'
'n/handle-callback-err': 'off',
'require-await': 'off'
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ addHook({ name: 'apollo-server-core', file: 'dist/runHttpQuery.js', versions: ['
const HttpQueryError = runHttpQueryModule.HttpQueryError

shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
return async function runHttpQuery () {
// The original function is async, but no need to mark it as such as long as it returns a promise
return function runHttpQuery () {
if (!requestChannel.start.hasSubscribers) {
return originalRunHttpQuery.apply(this, arguments)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/datadog-instrumentations/src/apollo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const requestChannel = dc.tracingChannel('datadog:apollo:request')
let HeaderMap

function wrapExecuteHTTPGraphQLRequest (originalExecuteHTTPGraphQLRequest) {
return async function executeHTTPGraphQLRequest () {
// The original function is async, but no need to mark it as such as long as it returns a promise
return function executeHTTPGraphQLRequest () {
if (!HeaderMap || !requestChannel.start.hasSubscribers) {
return originalExecuteHTTPGraphQLRequest.apply(this, arguments)
}
Expand Down
9 changes: 6 additions & 3 deletions packages/datadog-instrumentations/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ addHook({
}, getTestEnvironment)

function getWrappedScheduleTests (scheduleTests, frameworkVersion) {
return async function (tests) {
// The original function is async, but no need to mark it as such as long as it returns a promise
return function (tests) {
if (!isSuitesSkippingEnabled || hasFilteredSkippableSuites) {
return scheduleTests.apply(this, arguments)
}
Expand Down Expand Up @@ -741,7 +742,8 @@ function coverageReporterWrapper (coverageReporter) {
* This calculation adds no value, so we'll skip it, as long as the user has not manually opted in to code coverage,
* in which case we'll leave it.
*/
shimmer.wrap(CoverageReporter.prototype, '_addUntestedFiles', addUntestedFiles => async function () {
// The original function is async, but no need to mark it as such as long as it returns a promise
shimmer.wrap(CoverageReporter.prototype, '_addUntestedFiles', addUntestedFiles => function () {
// If the user has added coverage manually, they're willing to pay the price of this execution, so
// we will not skip it.
if (isSuitesSkippingEnabled && !isUserCodeCoverageEnabled) {
Expand Down Expand Up @@ -898,7 +900,8 @@ addHook({
}, transformPackage => {
const originalCreateScriptTransformer = transformPackage.createScriptTransformer

transformPackage.createScriptTransformer = async function (config) {
// The original function is async, but no need to mark it as such as long as it returns a promise
transformPackage.createScriptTransformer = function (config) {
const { testEnvironmentOptions, ...restOfConfig } = config
const {
_ddTestModuleId,
Expand Down
3 changes: 2 additions & 1 deletion packages/datadog-instrumentations/src/mocha/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ addHook({
versions: ['>=5.2.0'],
file: 'lib/cli/run-helpers.js'
}, (run) => {
shimmer.wrap(run, 'runMocha', runMocha => async function () {
// The original function is async, but no need to mark it as such as long as it returns a promise
shimmer.wrap(run, 'runMocha', runMocha => function () {
if (!testStartCh.hasSubscribers) {
return runMocha.apply(this, arguments)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/datadog-instrumentations/src/nyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ addHook({
name: 'nyc',
versions: ['>=17']
}, (nycPackage) => {
shimmer.wrap(nycPackage.prototype, 'wrap', wrap => async function () {
// The original function is async, but no need to mark it as such as long as it returns a promise
shimmer.wrap(nycPackage.prototype, 'wrap', wrap => function () {
// Only relevant if the config `all` is set to true
try {
if (JSON.parse(process.env.NYC_CONFIG).all) {
Expand Down
6 changes: 4 additions & 2 deletions packages/datadog-instrumentations/src/vitest.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ addHook({
const { VitestTestRunner } = vitestPackage

// `onBeforeRunTask` is run before any repetition or attempt is run
shimmer.wrap(VitestTestRunner.prototype, 'onBeforeRunTask', onBeforeRunTask => async function (task) {
// The original function is async, but no need to mark it as such as long as it returns a promise
shimmer.wrap(VitestTestRunner.prototype, 'onBeforeRunTask', onBeforeRunTask => function (task) {
const testName = getTestName(task)

const {
Expand Down Expand Up @@ -361,7 +362,8 @@ addHook({
})

// `onAfterRunTask` is run after all repetitions or attempts are run
shimmer.wrap(VitestTestRunner.prototype, 'onAfterRunTask', onAfterRunTask => async function (task) {
// The original function is async, but no need to mark it as such as long as it returns a promise
shimmer.wrap(VitestTestRunner.prototype, 'onAfterRunTask', onAfterRunTask => function (task) {
const { isEarlyFlakeDetectionEnabled, isQuarantinedTestsEnabled } = getProvidedContext()

if (isEarlyFlakeDetectionEnabled && taskToStatuses.has(task)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ async function removeBreakpoint ({ id }) {
if (breakpoints.size === 0) return stop() // return instead of await to reduce number of promises created
}

async function start () {
function start () {
sessionStarted = true
return session.post('Debugger.enable') // return instead of await to reduce number of promises created
}

async function stop () {
function stop () {
sessionStarted = false
return session.post('Debugger.disable') // return instead of await to reduce number of promises created
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function traverseGetPropertiesResult (props, opts, depth) {
return props
}

async function getObjectProperties (subtype, objectId, opts, depth) {
function getObjectProperties (subtype, objectId, opts, depth) {
if (ITERABLE_SUBTYPES.has(subtype)) {
return getIterable(objectId, opts, depth)
} else if (subtype === 'promise') {
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/src/profiling/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Profiler extends EventEmitter {
this._timeoutInterval = this._config.flushInterval
}

async stop () {
stop () {
if (!this._enabled) return

// collect and export current profiles
Expand Down
Loading