Skip to content

Commit f87e8d6

Browse files
authored
chore: introduce jsdoc linter (#6899)
The linter ensures that our added JSDoc is using valid types that can be picked up by the IDE. A couple of rules are either manually fixed or are deactivated that would be too strict for now. Activate more rules over time. The linter is actually producing warnings instead of errors. This is helpful to differentiate the JSDoc issues from other linter errors. It will still fail the CI due to not accepting warnings.
1 parent ca4a561 commit f87e8d6

File tree

43 files changed

+308
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+308
-110
lines changed

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ dev,chai,MIT,Copyright 2017 Chai.js Assertion Library
5656
dev,eslint,MIT,Copyright JS Foundation and other contributors https://js.foundation
5757
dev,eslint-plugin-cypress,MIT,Copyright (c) 2019 Cypress.io
5858
dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
59+
dev,eslint-plugin-jsdoc,BSD-3-Clause,Copyright Gajus Kuizinas
5960
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
6061
dev,eslint-plugin-n,MIT,Copyright 2015 Toru Nagashima
6162
dev,eslint-plugin-promise,ISC,jden and other contributors

eslint.config.mjs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import eslintPluginJs from '@eslint/js'
22
import eslintPluginStylistic from '@stylistic/eslint-plugin'
33
import eslintPluginCypress from 'eslint-plugin-cypress'
44
import eslintPluginImport from 'eslint-plugin-import'
5+
import eslintPluginJSDoc from 'eslint-plugin-jsdoc'
56
import eslintPluginMocha from 'eslint-plugin-mocha'
67
import eslintPluginN from 'eslint-plugin-n'
78
import eslintPluginPromise from 'eslint-plugin-promise'
@@ -35,6 +36,7 @@ export default [
3536
{
3637
name: 'dd-trace/global-ignore',
3738
ignores: [
39+
'**/.bun', // Ignore autogenerated bun files
3840
'**/coverage', // Just coverage reports.
3941
'**/dist', // Generated
4042
'**/docs', // Any JS here is for presentation only.
@@ -55,7 +57,8 @@ export default [
5557
'packages/datadog-plugin-graphql/src/tools/transforms.js' // Inlined from apollo-graphql
5658
]
5759
},
58-
{ name: '@eslint/js/recommended', ...eslintPluginJs.configs.recommended },
60+
eslintPluginJs.configs.recommended,
61+
eslintPluginJSDoc.configs['flat/recommended'],
5962
{
6063
// The following config and rules have been inlined from `eslint-config-standard` with the following modifications:
6164
// - Rules that were overridden elsewhere in this file have been removed.
@@ -85,6 +88,7 @@ export default [
8588
},
8689
plugins: {
8790
'@stylistic': eslintPluginStylistic,
91+
jsdoc: eslintPluginJSDoc,
8892
import: eslintPluginImport,
8993
n: eslintPluginN,
9094
promise: eslintPluginPromise
@@ -215,6 +219,22 @@ export default [
215219
'import/no-duplicates': 'error',
216220
'import/no-named-default': 'error',
217221
'import/no-webpack-loader-syntax': 'error',
222+
'jsdoc/check-tag-names': ['error', { definedTags: ['datadog'] }],
223+
// TODO: Enable the rules that we want to use.
224+
'jsdoc/check-types': 'off', // Should be activated, but it needs a couple of fixes.
225+
// no-defaults: This should be activated, since the defaults will not be picked up in a description.
226+
'jsdoc/no-defaults': 'off',
227+
'jsdoc/no-undefined-types': 'off',
228+
'jsdoc/reject-any-type': 'off', // Should be activated, but it needs a couple of fixes.
229+
'jsdoc/reject-function-type': 'off',
230+
'jsdoc/require-jsdoc': 'off',
231+
'jsdoc/require-param-description': 'off', // Having a description is not crucial for now.
232+
'jsdoc/require-param': 'off',
233+
'jsdoc/require-property-description': 'off',
234+
'jsdoc/require-returns-description': 'off',
235+
'jsdoc/require-returns-type': 'off',
236+
'jsdoc/require-returns': 'off',
237+
'jsdoc/tag-lines': 'off', // Alignment is not important for us.
218238
'n/handle-callback-err': ['error', '^(err|error)$'],
219239
'n/no-callback-literal': 'error',
220240
'n/no-deprecated-api': 'error',

initialize.mjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* This file serves one of two purposes, depending on how it's used.
3-
*
4-
* If used with --import, it will import init.js and register the loader hook.
5-
* If used with --loader, it will act as the loader hook, except that it will
6-
* also import init.js inside the source code of the entrypoint file.
7-
*
8-
* The result is that no matter how this file is used, so long as it's with
9-
* one of the two flags, the tracer will always be initialized, and the loader
10-
* hook will always be active for ESM support.
11-
*/
2+
* This file serves one of two purposes, depending on how it's used.
3+
*
4+
* If used with --import, it will import init.js and register the loader hook.
5+
* If used with --loader, it will act as the loader hook, except that it will
6+
* also import init.js inside the source code of the entrypoint file.
7+
*
8+
* The result is that no matter how this file is used, so long as it's with
9+
* one of the two flags, the tracer will always be initialized, and the loader
10+
* hook will always be active for ESM support.
11+
*/
1212

1313
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */
1414

integration-tests/ci-visibility/unskippable-test/test-unskippable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** Some comment */
2+
/* eslint-disable jsdoc/valid-types */
23
/**
34
* @datadog {"unskippable": true}
45
*/

integration-tests/cypress/e2e/spec.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
/* eslint-disable */
12
/**
23
* @datadog {"unskippable": true}
34
*/
4-
/* eslint-disable */
55
describe('context', () => {
66
it('passes', () => {
77
cy.visit('/')

integration-tests/helpers/fake-agent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ module.exports = class FakeAgent extends EventEmitter {
171171
* @param {number} [timeout=30_000] - The timeout in milliseconds.
172172
* @param {number} [expectedMessageCount=1] - The number of messages to expect.
173173
* @returns {Promise<void>} A promise that resolves when the telemetry message of type `requestType` is received.
174-
*
174+
*/
175+
/**
175176
* @overload
176177
* @param {Function} fn - The function to call with the telemetry message of type `requestType`.
177178
* @param {string} requestType - The request type to assert.

integration-tests/helpers/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let shouldKill
2525
/**
2626
* @param {string} filename
2727
* @param {string} cwd
28-
* @param {string|function} expectedOut
28+
* @param {string|((out: Promise<string>) => void)} expectedOut
2929
* @param {string} expectedSource
3030
*/
3131
async function runAndCheckOutput (filename, cwd, expectedOut, expectedSource) {
@@ -69,7 +69,7 @@ let sandbox
6969
* This _must_ be used with the useSandbox function
7070
*
7171
* @param {string} filename
72-
* @param {string|function} expectedOut
72+
* @param {string|((out: Promise<string>) => void)} expectedOut
7373
* @param {string[]} expectedTelemetryPoints
7474
* @param {string} expectedSource
7575
*/
@@ -494,7 +494,7 @@ async function curl (url) {
494494
/**
495495
* @param {FakeAgent} agent
496496
* @param {string|{ then: (callback: () => Promise<string>) => Promise<string> }|URL} procOrUrl
497-
* @param {function} fn
497+
* @param {(res: { headers: Record<string, string>, payload: unknown[] }) => void} fn
498498
* @param {number} [timeout]
499499
* @param {number} [expectedMessageCount]
500500
* @param {boolean} [resolveAtFirstSuccess]
@@ -557,7 +557,7 @@ function checkSpansForServiceName (spans, name) {
557557
* @param {string} cwd
558558
* @param {string} serverFile
559559
* @param {string|number} agentPort
560-
* @param {function} [stdioHandler]
560+
* @param {(data: Buffer) => void} [stdioHandler]
561561
* @param {Record<string, string|undefined>} [additionalEnvArgs]
562562
*/
563563
async function spawnPluginIntegrationTestProc (cwd, serverFile, agentPort, stdioHandler, additionalEnvArgs) {
@@ -594,8 +594,7 @@ function useEnv (env) {
594594
}
595595

596596
/**
597-
* @param {unknown[]} args
598-
* @returns {object}
597+
* @param {Parameters<createSandbox>} args
599598
*/
600599
function useSandbox (...args) {
601600
before(async function () {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
"eslint": "^9.39.0",
183183
"eslint-plugin-cypress": "^5.2.0",
184184
"eslint-plugin-import": "^2.32.0",
185+
"eslint-plugin-jsdoc": "^61.1.12",
185186
"eslint-plugin-mocha": "^11.2.0",
186187
"eslint-plugin-n": "^17.23.1",
187188
"eslint-plugin-promise": "^7.2.1",

packages/datadog-core/src/storage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { AsyncLocalStorage } = require('async_hooks')
1515
class DatadogStorage extends AsyncLocalStorage {
1616
/**
1717
*
18-
* @param store {Store}
18+
* @param {Store} [store]
1919
* @override
2020
*/
2121
enterWith (store) {
@@ -47,7 +47,7 @@ class DatadogStorage extends AsyncLocalStorage {
4747
* retrieved through `getHandle()` can also be passed in to be used as the
4848
* key. This is useful if you've stashed a handle somewhere and want to
4949
* retrieve the store with it.
50-
* @param {{}} [handle]
50+
* @param {object} [handle]
5151
* @returns {Store | undefined}
5252
* @override
5353
*/
@@ -87,7 +87,7 @@ class DatadogStorage extends AsyncLocalStorage {
8787

8888
/**
8989
* This is the map from handles to real stores, used in the class above.
90-
* @type {WeakMap<WeakKey, Store>}
90+
* @type {WeakMap<WeakKey, Store|undefined>}
9191
*/
9292
const stores = new WeakMap()
9393

@@ -101,7 +101,7 @@ const storages = Object.create(null)
101101

102102
/**
103103
*
104-
* @param namespace {string} the namespace to use
104+
* @param {string} namespace The namespace to use
105105
* @returns {DatadogStorage}
106106
*/
107107
function storage (namespace) {

packages/datadog-esbuild/src/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ function getSource (url, { format }) {
6565
/**
6666
* Generates the pieces of code for the proxy module before the path
6767
*
68-
* @param {Object} moduleData { path, internal, context, excludeDefault }
68+
* @param {object} moduleData
69+
* @param {string} moduleData.path
70+
* @param {boolean} moduleData.internal
71+
* @param {object} moduleData.context
72+
* @param {boolean} moduleData.excludeDefault
6973
* @returns {Promise<Map>}
7074
*/
7175
async function processModule ({ path, internal, context, excludeDefault }) {

0 commit comments

Comments
 (0)