diff --git a/examples/.eslintrc b/examples/.eslintrc deleted file mode 100644 index 5feabb97f5..0000000000 --- a/examples/.eslintrc +++ /dev/null @@ -1,16 +0,0 @@ -{ - "env": { - "node": true - }, - "extends": "airbnb-base", - "parserOptions": { - "sourceType": "script" - }, - "rules": { - "strict": ["error", "global"], - "no-use-before-define": ["error", "nofunc"], - "no-console": "off", - "import/no-unresolved": "off", - "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }] - } -} diff --git a/examples/connect/client.js b/examples/connect/client.js index ea0fb965e9..fa959ac0b5 100644 --- a/examples/connect/client.js +++ b/examples/connect/client.js @@ -16,7 +16,6 @@ 'use strict'; -// eslint-disable-next-line import/order const tracing = require('./tracing')('example-connect-client'); const { tracer } = tracing; diff --git a/examples/connect/server.js b/examples/connect/server.js index 2f19b0b771..6c55a61259 100644 --- a/examples/connect/server.js +++ b/examples/connect/server.js @@ -16,7 +16,6 @@ 'use strict'; -// eslint-disable-next-line const tracing = require('./tracing')('example-connect-server'); // Require in rest of modules @@ -27,7 +26,6 @@ const axios = require('axios'); const app = connect(); const PORT = 8080; -// eslint-disable-next-line prefer-arrow-callback app.use(function middleware1(req, res, next) { next(); }); diff --git a/examples/dns/client.js b/examples/dns/client.js index a2d61cd60b..e1465659b1 100644 --- a/examples/dns/client.js +++ b/examples/dns/client.js @@ -18,7 +18,6 @@ const api = require('@opentelemetry/api'); const tracer = require('./tracer')('example-dns'); -// eslint-disable-next-line import/order const dns = require('dns').promises; /** A function which makes a dns lookup and handles response. */ diff --git a/examples/express/src/client.ts b/examples/express/src/client.ts index b23ed83f62..dd07ff4a0a 100644 --- a/examples/express/src/client.ts +++ b/examples/express/src/client.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -// eslint-disable-next-line import/order, import/extensions import { setupTracing } from './tracer'; import * as api from '@opentelemetry/api'; diff --git a/examples/express/src/server.ts b/examples/express/src/server.ts index 424d79790e..3fe9e16f20 100644 --- a/examples/express/src/server.ts +++ b/examples/express/src/server.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -// eslint-disable-next-line import/order, import/extensions import { setupTracing } from './tracer'; // Require in rest of modules diff --git a/examples/express/src/tracer.ts b/examples/express/src/tracer.ts index 92e7a39ecd..617a45cf47 100644 --- a/examples/express/src/tracer.ts +++ b/examples/express/src/tracer.ts @@ -36,7 +36,6 @@ import { import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; -// eslint-disable-next-line import/prefer-default-export export const setupTracing = (serviceName: string) => { const exporter = new OTLPTraceExporter({}); const provider = new NodeTracerProvider({ diff --git a/examples/fastify/server.js b/examples/fastify/server.js index 085070b5fb..afad11a43a 100644 --- a/examples/fastify/server.js +++ b/examples/fastify/server.js @@ -16,7 +16,6 @@ 'use strict'; -// eslint-disable-next-line const api = require('@opentelemetry/api'); const tracer = api.trace.getTracer('fastify-server'); const Fastify = require('fastify'); @@ -32,7 +31,6 @@ async function subsystem(fastify) { span.setAttribute('order', 2); }); - // eslint-disable-next-line prefer-arrow-callback fastify.addHook('onRequest', async function onRequestHook() { const span = api.trace.getSpan(api.context.active()); span.setAttribute('order', 3); diff --git a/examples/graphql/schema.js b/examples/graphql/schema.js index bbb10f80e9..673b94e826 100644 --- a/examples/graphql/schema.js +++ b/examples/graphql/schema.js @@ -14,6 +14,8 @@ * limitations under the License. */ +/* eslint-disable no-unused-vars */ + 'use strict'; const https = require('https'); diff --git a/examples/grpc-census-prop/capitalize_client.js b/examples/grpc-census-prop/capitalize_client.js index e04947a045..1956c7ddad 100644 --- a/examples/grpc-census-prop/capitalize_client.js +++ b/examples/grpc-census-prop/capitalize_client.js @@ -17,7 +17,6 @@ 'use strict'; const api = require('@opentelemetry/api'); -/* eslint-disable global-require */ const binaryPropagator = process.env.BINARY_PROPAGATOR === 'true'; const censusTracer = process.env.CENSUS_TRACER === 'true'; let tracer; diff --git a/examples/grpc-census-prop/capitalize_server.js b/examples/grpc-census-prop/capitalize_server.js index f992994dd7..d0857e9ae7 100644 --- a/examples/grpc-census-prop/capitalize_server.js +++ b/examples/grpc-census-prop/capitalize_server.js @@ -16,7 +16,6 @@ 'use strict'; -/* eslint-disable global-require */ const binaryPropagator = process.env.BINARY_PROPAGATOR === 'true'; const censusTracer = process.env.CENSUS_TRACER === 'true'; diff --git a/examples/hapi/client.js b/examples/hapi/client.js index 9037f4104e..92c002d023 100644 --- a/examples/hapi/client.js +++ b/examples/hapi/client.js @@ -16,7 +16,6 @@ 'use strict'; -// eslint-disable-next-line import/order const tracer = require('./tracer')('example-hapi-client'); const api = require('@opentelemetry/api'); diff --git a/examples/hapi/server.js b/examples/hapi/server.js index bb1de52ece..6f5f79ae42 100644 --- a/examples/hapi/server.js +++ b/examples/hapi/server.js @@ -19,7 +19,6 @@ const api = require('@opentelemetry/api'); require('./tracer')('example-hapi-server'); -// eslint-disable-next-line const Hapi = require('@hapi/hapi'); const PORT = 8081; diff --git a/examples/koa/src/client.ts b/examples/koa/src/client.ts index 705a04e720..648ef117ba 100644 --- a/examples/koa/src/client.ts +++ b/examples/koa/src/client.ts @@ -16,7 +16,6 @@ import * as api from '@opentelemetry/api'; import * as axios from 'axios'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; const tracer = setupTracing('example-koa-client'); diff --git a/examples/koa/src/server.ts b/examples/koa/src/server.ts index 91ff6e552f..5657f058e5 100644 --- a/examples/koa/src/server.ts +++ b/examples/koa/src/server.ts @@ -19,7 +19,6 @@ import * as api from '@opentelemetry/api'; // Adding Koa router (if desired) import * as Router from '@koa/router'; import * as Koa from 'koa'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; setupTracing('example-koa-server'); diff --git a/examples/koa/src/tracer.ts b/examples/koa/src/tracer.ts index 7816edc706..52d28c4291 100644 --- a/examples/koa/src/tracer.ts +++ b/examples/koa/src/tracer.ts @@ -28,7 +28,6 @@ import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; const EXPORTER = process.env.EXPORTER || ''; -// eslint-disable-next-line import/prefer-default-export export const setupTracing = (serviceName: string) => { let exporter; if (EXPORTER === 'jaeger') { diff --git a/examples/meta-node/client.js b/examples/meta-node/client.js index 82d8f8dd0f..c2da1a8514 100644 --- a/examples/meta-node/client.js +++ b/examples/meta-node/client.js @@ -16,7 +16,6 @@ 'use strict'; -// eslint-disable-next-line import/order const tracer = require('./tracer')('example-express-client'); const api = require('@opentelemetry/api'); const axios = require('axios').default; diff --git a/examples/meta-node/server.js b/examples/meta-node/server.js index 883fbbfee8..0f299ad2f4 100644 --- a/examples/meta-node/server.js +++ b/examples/meta-node/server.js @@ -16,7 +16,6 @@ 'use strict'; -// eslint-disable-next-line require('./tracer')('example-meta-node'); // Require in rest of modules diff --git a/examples/mongodb/src/client.ts b/examples/mongodb/src/client.ts index 7b87249576..21798b0aec 100644 --- a/examples/mongodb/src/client.ts +++ b/examples/mongodb/src/client.ts @@ -16,7 +16,6 @@ import * as api from '@opentelemetry/api'; import * as http from 'http'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; const tracer = setupTracing('example-mongodb-http-client'); diff --git a/examples/mongodb/src/server.ts b/examples/mongodb/src/server.ts index a9f406af35..5bb1c9a9aa 100644 --- a/examples/mongodb/src/server.ts +++ b/examples/mongodb/src/server.ts @@ -19,9 +19,7 @@ import * as http from 'http'; import { IncomingMessage, ServerResponse } from 'http'; import * as mongodb from 'mongodb'; import { Collection } from 'mongodb'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; -// eslint-disable-next-line import/extensions import { accessDB } from './utils'; setupTracing('example-mongodb-server'); diff --git a/examples/mongodb/src/tracer.ts b/examples/mongodb/src/tracer.ts index 77abc673ea..b27d0092be 100644 --- a/examples/mongodb/src/tracer.ts +++ b/examples/mongodb/src/tracer.ts @@ -25,7 +25,6 @@ import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb'; import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; -// eslint-disable-next-line import/prefer-default-export export const setupTracing = (serviceName: string): api.Tracer => { const provider = new NodeTracerProvider({ resource: new Resource({ diff --git a/examples/mongodb/src/utils.ts b/examples/mongodb/src/utils.ts index d2dbde98ec..837405ba7c 100644 --- a/examples/mongodb/src/utils.ts +++ b/examples/mongodb/src/utils.ts @@ -22,7 +22,6 @@ import * as mongodb from 'mongodb'; * @param dbName The mongodb database name. * @param options The mongodb client config options. */ -// eslint-disable-next-line import/prefer-default-export export function accessDB( url: string, dbName: string, diff --git a/examples/mysql/src/client.ts b/examples/mysql/src/client.ts index d317a30c04..6936fd0cb6 100644 --- a/examples/mysql/src/client.ts +++ b/examples/mysql/src/client.ts @@ -16,7 +16,6 @@ import * as api from '@opentelemetry/api'; import * as http from 'http'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; const tracer = setupTracing('example-mysql-client'); diff --git a/examples/mysql/src/server.ts b/examples/mysql/src/server.ts index 513e45d6fd..1772732521 100644 --- a/examples/mysql/src/server.ts +++ b/examples/mysql/src/server.ts @@ -18,7 +18,6 @@ import * as api from '@opentelemetry/api'; import * as mysql from 'mysql'; import * as http from 'http'; import { MysqlError, PoolConnection } from 'mysql'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; setupTracing('example-mysql-server'); diff --git a/examples/mysql/src/tracer.ts b/examples/mysql/src/tracer.ts index f90c0c469d..b00fda23dd 100644 --- a/examples/mysql/src/tracer.ts +++ b/examples/mysql/src/tracer.ts @@ -37,7 +37,6 @@ const { const EXPORTER = process.env.EXPORTER || ''; -// eslint-disable-next-line import/prefer-default-export export const setupTracing = (serviceName: string) => { // metrics: const metricExporter = new OTLPMetricExporter(); diff --git a/examples/react-load/preact/.eslintrc.js b/examples/react-load/preact/.eslintrc.js index cc27325c72..08ed1c7809 100644 --- a/examples/react-load/preact/.eslintrc.js +++ b/examples/react-load/preact/.eslintrc.js @@ -22,5 +22,6 @@ module.exports = { ...baseConfig, env: { browser: true, + node: true, }, }; diff --git a/examples/react-load/preact/src/components/Content.js b/examples/react-load/preact/src/components/Content.js index 13357c758f..6af0ee4f7d 100644 --- a/examples/react-load/preact/src/components/Content.js +++ b/examples/react-load/preact/src/components/Content.js @@ -27,7 +27,6 @@ class Content extends BaseOpenTelemetryComponent { }; } - // eslint-disable-next-line class-methods-use-this componentDidMount() { // Example, do something here } diff --git a/examples/react-load/preact/src/components/Home.js b/examples/react-load/preact/src/components/Home.js index 6789351ba8..2a5444aa9f 100644 --- a/examples/react-load/preact/src/components/Home.js +++ b/examples/react-load/preact/src/components/Home.js @@ -20,7 +20,6 @@ import { Link } from 'preact-router/match'; import { BaseOpenTelemetryComponent } from '@opentelemetry/plugin-react-load'; class Home extends BaseOpenTelemetryComponent { - // eslint-disable-next-line class-methods-use-this render() { return (
diff --git a/examples/react-load/react/.eslintrc.js b/examples/react-load/react/.eslintrc.js index cc27325c72..08ed1c7809 100644 --- a/examples/react-load/react/.eslintrc.js +++ b/examples/react-load/react/.eslintrc.js @@ -22,5 +22,6 @@ module.exports = { ...baseConfig, env: { browser: true, + node: true, }, }; diff --git a/examples/redis/src/client.ts b/examples/redis/src/client.ts index 0063f6a460..127eef1e9a 100644 --- a/examples/redis/src/client.ts +++ b/examples/redis/src/client.ts @@ -16,7 +16,6 @@ import * as api from '@opentelemetry/api'; import * as axios from 'axios'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; const tracer = setupTracing('example-redis-client'); diff --git a/examples/redis/src/server.ts b/examples/redis/src/server.ts index b9d1085cd7..41377b8700 100644 --- a/examples/redis/src/server.ts +++ b/examples/redis/src/server.ts @@ -18,13 +18,10 @@ import * as express from 'express'; import * as axios from 'axios'; import { randomBytes } from 'crypto'; -// eslint-disable-next-line import/extensions import { setupTracing } from './tracer'; -// eslint-disable-next-line import/extensions import * as tracerHandlers from './express-tracer-handlers'; const tracer = setupTracing('example-redis-server'); -// eslint-disable-next-line import/extensions const { redisPromise } = require('./setup-redis'); // Setup express diff --git a/examples/redis/src/setup-redis.ts b/examples/redis/src/setup-redis.ts index b7568f9c84..e302c98332 100644 --- a/examples/redis/src/setup-redis.ts +++ b/examples/redis/src/setup-redis.ts @@ -17,7 +17,6 @@ import { createClient } from 'redis'; const client = createClient('redis://localhost:6379'); -// eslint-disable-next-line import/prefer-default-export export const redisPromise = new Promise((resolve, reject) => { client.once('ready', () => { resolve(client); diff --git a/examples/redis/src/tracer.ts b/examples/redis/src/tracer.ts index e5f3c42c4d..5ea3c0f12a 100644 --- a/examples/redis/src/tracer.ts +++ b/examples/redis/src/tracer.ts @@ -27,7 +27,6 @@ import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'; const EXPORTER = process.env.EXPORTER || ''; -// eslint-disable-next-line import/prefer-default-export export const setupTracing = (serviceName: string) => { let exporter; if (EXPORTER.toLowerCase().startsWith('z')) { diff --git a/examples/router/client.js b/examples/router/client.js index b5fb684ee7..5cc5ea84bb 100644 --- a/examples/router/client.js +++ b/examples/router/client.js @@ -18,7 +18,6 @@ // required to initialize the service name for the auto-instrumentation require('./tracer')('example-client'); -// eslint-disable-next-line import/order const http = require('http'); /** A function which makes requests and handles response. */ diff --git a/examples/router/server.js b/examples/router/server.js index f234ce7eb5..4910cc7ca4 100644 --- a/examples/router/server.js +++ b/examples/router/server.js @@ -37,18 +37,15 @@ router.param('name', (req, res, next, name) => { next(); }); -// eslint-disable-next-line prefer-arrow-callback router.get('/hello/:name', function greetingHandler(req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8'); res.end(`Hello, ${req.params.name}!`); }); -// eslint-disable-next-line prefer-arrow-callback router.get('/err', function erroringRoute(req, res, next) { next(new Error('Broken!')); }); -// eslint-disable-next-line prefer-arrow-callback, func-names const server = http.createServer(function (req, res) { router(req, res, error => { if (error) { diff --git a/examples/web/.eslintrc.js b/examples/web/.eslintrc.js index 718b15e08e..ca4a364890 100644 --- a/examples/web/.eslintrc.js +++ b/examples/web/.eslintrc.js @@ -22,5 +22,6 @@ module.exports = { ...baseConfig, env: { browser: true, + node: true, }, }; diff --git a/examples/web/examples/document-load/index.js b/examples/web/examples/document-load/index.js index e89ace47a6..ecd5c28cff 100644 --- a/examples/web/examples/document-load/index.js +++ b/examples/web/examples/document-load/index.js @@ -66,7 +66,6 @@ const tracer = provider.getTracer('example-document-load'); const getData = url => new Promise((resolve, reject) => { - // eslint-disable-next-line no-undef const req = new XMLHttpRequest(); req.open('GET', url, true); req.send(); diff --git a/examples/web/examples/meta/index.js b/examples/web/examples/meta/index.js index c780e5163d..2789e29050 100644 --- a/examples/web/examples/meta/index.js +++ b/examples/web/examples/meta/index.js @@ -73,7 +73,6 @@ function btnAddClick() { } function prepareClickEvents() { - // eslint-disable-next-line no-plusplus for (let i = 0; i < 5; i++) { btnAddClick(); } @@ -106,7 +105,7 @@ function onClick(navigate) { } function getData(url) { - return new Promise((resolve, _reject) => { + return new Promise(resolve => { const req = new XMLHttpRequest(); req.open('GET', url, true); req.setRequestHeader('Content-Type', 'application/json'); diff --git a/examples/web/examples/user-interaction/index.js b/examples/web/examples/user-interaction/index.js index 1907a85360..e2fb45fa33 100644 --- a/examples/web/examples/user-interaction/index.js +++ b/examples/web/examples/user-interaction/index.js @@ -74,7 +74,6 @@ function btnAddClick() { } function prepareClickEvents() { - // eslint-disable-next-line no-plusplus for (let i = 0; i < 5; i++) { btnAddClick(); } @@ -107,7 +106,7 @@ function onClick(navigate) { } function getData(url) { - return new Promise((resolve, _reject) => { + return new Promise(resolve => { const req = new XMLHttpRequest(); req.open('GET', url, true); req.setRequestHeader('Content-Type', 'application/json'); diff --git a/package.json b/package.json index 9d16879251..72f46b91f8 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "test-services:stop": "docker compose -f ./test/docker-compose.yaml down", "test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=./test/test-services.env npm test", "changelog": "lerna-changelog", - "lint": "nx run-many -t lint && npm run lint:deps && npm run lint:readme && npm run lint:markdown && npm run lint:semconv-deps", + "lint": "nx run-many -t lint && npm run lint:deps && npm run lint:readme && npm run lint:markdown && npm run lint:semconv-deps && npm run lint:examples", "lint:fix": "nx run-many -t lint:fix && npm run lint:markdown:fix", "lint:deps": "npx --yes knip@5.33.3 --dependencies --production --tags=-knipignore", - "lint:examples": "eslint ./examples/**/*.js", - "lint:examples:fix": "eslint ./examples/**/*.js --fix", + "lint:examples": "./scripts/npm-run-in-examples.js --if-present lint", + "lint:examples:fix": "./scripts/npm-run-in-examples.js --if-present lint:fix", "lint:markdown": "markdownlint-cli2 $(git ls-files '*.md')", "lint:markdown:fix": "markdownlint-cli2 --fix $(git ls-files '*.md')", "lint:readme": "nx run-many -t lint:readme", diff --git a/scripts/npm-run-in-examples.js b/scripts/npm-run-in-examples.js new file mode 100755 index 0000000000..194a4dfd90 --- /dev/null +++ b/scripts/npm-run-in-examples.js @@ -0,0 +1,88 @@ +#!/usr/bin/env node +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Run `npm run ARGS...` in every "examples/*" subdir. + * + * This script exists because the "examples/*" dirs are *not* part of the npm + * workspace, so we cannot use `nx run-many ...` or `npm run --workspaces ...`. + * + * Example usage: + * ./scripts/npm-run-in-examples.js --if-present lint + */ + +const {spawn, spawnSync} = require('child_process'); +const path = require('path'); + +const TOP = path.resolve(__dirname, '..'); +const USE_COLOR = process.stdout.isTTY && !process.env.NO_COLOR?.length > 0; + +function logInfo(...args) { + if (USE_COLOR) { + process.stdout.write('\x1b[90m'); + } + console.log(...args); + if (USE_COLOR) { + process.stdout.write('\x1b[39m'); + } +} + +function logError(...args) { + if (USE_COLOR) { + process.stdout.write('\x1b[31m'); + } + console.log(...args); + if (USE_COLOR) { + process.stdout.write('\x1b[39m'); + } +} + +function getExamplesPackageDirs() { + const p = spawnSync('git', ['ls-files', path.join(TOP, 'examples')], { + encoding: 'utf8' + }); + return p.stdout + .split('\n') + .filter(f => path.basename(f) === 'package.json') + .map(path.dirname) +} + +async function npmRunInExamples(args) { + const pkgDirs = getExamplesPackageDirs(); + + let finalRetval = 0; + for (let pkgDir of pkgDirs) { + logInfo(`\n> ${pkgDir}`); + const p = spawnSync('npm', ['run'].concat(args), { + cwd: pkgDir, + stdio: 'inherit', + encoding: 'utf8' + }); + if (p.status || p.signal || p.error) { + logError(`"npm run ${args.join(' ')}" failed in "${pkgDir}": status=${p.status} signal=${p.signal} error=${p.error}`); + finalRetval = 1; + } + } + + process.exitCode = finalRetval; +} + +async function main() { + await npmRunInExamples(process.argv.slice(2)); +} + +main();