Skip to content

Commit f1122e9

Browse files
committed
chore(eslint): lint examples/bunyan and prepare for linting .js and .mjs files
This adds support for 'npm run lint' in examples/bunyan, using the same base eslint.config.js used by most of the repo. There are ulterior motives: - This is a first step to linting all the examples using the same base config (rather than the spotty linting of examples using the separate "examples/.eslintrc". - The eslint.config.js changes support being used to lint .ts, .js, and .mjs files reasonably. I'll follow-up with a separate PR adding linting of .mjs files used for some ESM testing (e.g. "instrumentation-ioredis/test/fixtures/use-ioredis.mjs") Hattip to the following for some of the eslint config changes: https://github.com/open-telemetry/opentelemetry-js/pull/4446/files#diff-1a88e8e72db982c999acf146817a416a02d93547458e6525610cf69b24751af9
1 parent 0fc1ed3 commit f1122e9

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
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/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": {

0 commit comments

Comments
 (0)