Skip to content

Commit dddbb78

Browse files
authored
chore(eslint): lint examples/bunyan and prepare eslint confing for linting .js and .mjs files (#2567)
Refs: #2891
1 parent 5909ad4 commit dddbb78

File tree

6 files changed

+73
-15
lines changed

6 files changed

+73
-15
lines changed

eslint.config.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ module.exports = {
55
"node",
66
"prettier"
77
],
8-
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
8+
extends: ["eslint:recommended", "plugin:prettier/recommended"],
99
parser: "@typescript-eslint/parser",
1010
parserOptions: {
11-
"project": "./tsconfig.json"
11+
"project": null
1212
},
1313
rules: {
1414
"quotes": ["error", "single", { "avoidEscape": true }],
@@ -28,6 +28,11 @@ module.exports = {
2828
overrides: [
2929
{
3030
files: ['*.ts'],
31+
// Enable typescript-eslint for ts files.
32+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
33+
parserOptions: {
34+
"project": "./tsconfig.json"
35+
},
3136
rules: {
3237
"@typescript-eslint/no-floating-promises": "error",
3338
"@typescript-eslint/no-this-alias": "off",
@@ -49,21 +54,39 @@ module.exports = {
4954
}
5055
}],
5156
"@typescript-eslint/no-shadow": ["warn"],
57+
"prefer-rest-params": "off",
5258
}
5359
},
5460
{
5561
files: ["test/**/*.ts"],
62+
// Enable typescript-eslint for ts files.
63+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
64+
parserOptions: {
65+
"project": "./tsconfig.json"
66+
},
5667
rules: {
5768
"no-empty": "off",
5869
"@typescript-eslint/ban-ts-ignore": "off",
70+
"@typescript-eslint/ban-types": ["warn", {
71+
"types": {
72+
"Function": null,
73+
}
74+
}],
5975
"@typescript-eslint/no-empty-function": "off",
6076
"@typescript-eslint/no-explicit-any": "off",
6177
"@typescript-eslint/no-unused-vars": "off",
6278
"@typescript-eslint/no-var-requires": "off",
6379
"@typescript-eslint/no-shadow": ["off"],
6480
"@typescript-eslint/no-floating-promises": ["off"],
6581
"@typescript-eslint/no-non-null-assertion": ["off"],
66-
"@typescript-eslint/explicit-module-boundary-types": ["off"]
82+
"@typescript-eslint/explicit-module-boundary-types": ["off"],
83+
"prefer-rest-params": "off",
84+
}
85+
},
86+
{
87+
files: ["*.mjs"],
88+
parserOptions: {
89+
sourceType: 'module',
6790
}
6891
}
6992
]

examples/bunyan/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
node: true,
25+
},
26+
};

examples/bunyan/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const log = bunyan.createLogger({ name: 'myapp', level: 'debug' });
2828
log.debug({ foo: 'bar' }, 'hi');
2929

3030
const tracer = otel.trace.getTracer('example');
31-
tracer.startActiveSpan('manual-span', (span) => {
31+
tracer.startActiveSpan('manual-span', span => {
3232
log.info('this record will have trace_id et al fields for the current span');
3333
span.end();
3434
});

examples/bunyan/app.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
import { trace } from '@opentelemetry/api';
2222
import bunyan from 'bunyan';
2323

24-
const log = bunyan.createLogger({name: 'myapp', level: 'debug'});
24+
const log = bunyan.createLogger({ name: 'myapp', level: 'debug' });
2525

26-
log.debug({foo: 'bar'}, 'hi');
26+
log.debug({ foo: 'bar' }, 'hi');
2727

2828
const tracer = trace.getTracer('example');
2929
tracer.startActiveSpan('manual-span', span => {
3030
log.info('this record will have trace_id et al fields for the current span');
3131
span.end();
3232
});
33-

examples/bunyan/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"version": "0.1.0",
55
"description": "Example of Bunyan integration with OpenTelemetry",
66
"scripts": {
7+
"lint": "eslint . --ext=ts,js,mjs",
8+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
79
"start": "node -r ./telemetry.js app.js"
810
},
911
"repository": {

examples/bunyan/telemetry.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
// for viewing and analysis.
2424

2525
const { NodeSDK, tracing, logs } = require('@opentelemetry/sdk-node');
26-
const { envDetector, hostDetector, processDetector } = require('@opentelemetry/resources');
26+
const {
27+
envDetector,
28+
hostDetector,
29+
processDetector,
30+
} = require('@opentelemetry/resources');
2731
// api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.DEBUG);
2832

29-
const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');
33+
const {
34+
BunyanInstrumentation,
35+
} = require('@opentelemetry/instrumentation-bunyan');
3036

3137
const sdk = new NodeSDK({
3238
serviceName: 'bunyan-example',
@@ -40,18 +46,20 @@ const sdk = new NodeSDK({
4046
// default detector of the `NodeSDK`.
4147
hostDetector,
4248
],
43-
spanProcessor: new tracing.SimpleSpanProcessor(new tracing.ConsoleSpanExporter()),
44-
logRecordProcessor: new logs.SimpleLogRecordProcessor(new logs.ConsoleLogRecordExporter()),
45-
instrumentations: [
46-
new BunyanInstrumentation(),
47-
],
49+
spanProcessor: new tracing.SimpleSpanProcessor(
50+
new tracing.ConsoleSpanExporter()
51+
),
52+
logRecordProcessor: new logs.SimpleLogRecordProcessor(
53+
new logs.ConsoleLogRecordExporter()
54+
),
55+
instrumentations: [new BunyanInstrumentation()],
4856
});
4957
process.on('SIGTERM', () => {
5058
sdk
5159
.shutdown()
5260
.then(
5361
() => {},
54-
(err) => console.log('warning: error shutting down OTel SDK', err),
62+
err => console.log('warning: error shutting down OTel SDK', err)
5563
)
5664
.finally(() => process.exit(0));
5765
});

0 commit comments

Comments
 (0)