Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit 50db1c2

Browse files
authored
chore: align linter rules with repo open-telemetry/opentelemetry-js (#127)
1 parent a752e7f commit 50db1c2

File tree

6 files changed

+83
-80
lines changed

6 files changed

+83
-80
lines changed

.eslintrc.js

+66-61
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,69 @@
11
module.exports = {
2-
"env": {
3-
"mocha": true,
4-
"commonjs": true,
5-
"shared-node-browser": true
6-
},
7-
plugins: [
8-
"@typescript-eslint",
9-
"header"
2+
plugins: [
3+
"@typescript-eslint",
4+
"header",
5+
"node"
6+
],
7+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
8+
parser: "@typescript-eslint/parser",
9+
parserOptions: {
10+
"project": "./tsconfig.json"
11+
},
12+
rules: {
13+
"quotes": [2, "single", { "avoidEscape": true }],
14+
"@typescript-eslint/no-floating-promises": 2,
15+
"@typescript-eslint/no-this-alias": "off",
16+
"brace-style": ["error", "1tbs"],
17+
"eqeqeq": [
18+
"error",
19+
"smart"
1020
],
11-
extends: [
12-
"./node_modules/gts",
21+
"prefer-rest-params": "off",
22+
"@typescript-eslint/naming-convention": [
23+
"error",
24+
{
25+
"selector": "memberLike",
26+
"modifiers": ["private", "protected"],
27+
"format": ["camelCase"],
28+
"leadingUnderscore": "require"
29+
}
1330
],
14-
parser: "@typescript-eslint/parser",
15-
parserOptions: {
16-
"project": [
17-
"./tsconfig.json"
18-
]
19-
},
20-
ignorePatterns: [
21-
'build',
22-
],
23-
rules: {
24-
"@typescript-eslint/no-this-alias": "off",
25-
"eqeqeq": [
26-
"error",
27-
"smart"
28-
],
29-
"prefer-rest-params": "off",
30-
"@typescript-eslint/naming-convention": [
31-
"error",
32-
{
33-
"selector": "memberLike",
34-
"modifiers": ["private", "protected"],
35-
"format": ["camelCase"],
36-
"leadingUnderscore": "require"
37-
}
38-
],
39-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "args": "after-used" }],
40-
"@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }],
41-
"arrow-parens": ["error", "as-needed"],
42-
"prettier/prettier": ["error", { "singleQuote": true, "arrowParens": "avoid" }],
43-
"prefer-spread": "off",
44-
"node/no-deprecated-api": ["warn"],
45-
"header/header": [2, "block", [{
46-
pattern: / \* Copyright The OpenTelemetry Authors[\r\n]+ \*[\r\n]+ \* Licensed under the Apache License, Version 2\.0 \(the \"License\"\);[\r\n]+ \* you may not use this file except in compliance with the License\.[\r\n]+ \* You may obtain a copy of the License at[\r\n]+ \*[\r\n]+ \* https:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0[\r\n]+ \*[\r\n]+ \* Unless required by applicable law or agreed to in writing, software[\r\n]+ \* distributed under the License is distributed on an \"AS IS\" BASIS,[\r\n]+ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.[\r\n]+ \* See the License for the specific language governing permissions and[\r\n]+ \* limitations under the License\./gm,
47-
template:
48-
`\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n `
49-
}]]
50-
},
51-
overrides: [
52-
{
53-
"files": ["test/**/*.ts"],
54-
"rules": {
55-
"no-empty": "off",
56-
"@typescript-eslint/ban-ts-ignore": "off",
57-
"@typescript-eslint/no-empty-function": "off",
58-
"@typescript-eslint/no-explicit-any": "off",
59-
"@typescript-eslint/no-unused-vars": "off",
60-
"@typescript-eslint/no-var-requires": "off"
61-
}
62-
}
63-
]
64-
}
31+
"no-console": "error",
32+
"no-shadow": "off",
33+
"@typescript-eslint/no-shadow": ["warn"],
34+
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "args": "after-used"}],
35+
"@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }],
36+
"@typescript-eslint/no-empty-function": ["off"],
37+
"@typescript-eslint/ban-types": ["warn", {
38+
"types": {
39+
"Function": null,
40+
}
41+
}],
42+
"@typescript-eslint/no-shadow": ["warn"],
43+
"arrow-parens": ["error", "as-needed"],
44+
"node/no-deprecated-api": ["warn"],
45+
"header/header": [2, "block", [{
46+
pattern: / \* Copyright The OpenTelemetry Authors[\r\n]+ \*[\r\n]+ \* Licensed under the Apache License, Version 2\.0 \(the \"License\"\);[\r\n]+ \* you may not use this file except in compliance with the License\.[\r\n]+ \* You may obtain a copy of the License at[\r\n]+ \*[\r\n]+ \* https:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0[\r\n]+ \*[\r\n]+ \* Unless required by applicable law or agreed to in writing, software[\r\n]+ \* distributed under the License is distributed on an \"AS IS\" BASIS,[\r\n]+ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.[\r\n]+ \* See the License for the specific language governing permissions and[\r\n]+ \* limitations under the License\./gm,
47+
template:
48+
`\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n `
49+
}]]
50+
},
51+
overrides: [
52+
{
53+
"files": ["test/**/*.ts"],
54+
"rules": {
55+
"no-empty": "off",
56+
"@typescript-eslint/ban-ts-ignore": "off",
57+
"@typescript-eslint/no-empty-function": "off",
58+
"@typescript-eslint/no-explicit-any": "off",
59+
"@typescript-eslint/no-floating-promises": 1,
60+
"@typescript-eslint/no-unused-vars": "off",
61+
"@typescript-eslint/no-var-requires": "off",
62+
"@typescript-eslint/no-shadow": ["off"],
63+
"@typescript-eslint/no-floating-promises": ["off"],
64+
"@typescript-eslint/no-non-null-assertion": ["off"],
65+
"@typescript-eslint/explicit-module-boundary-types": ["off"]
66+
}
67+
}
68+
]
69+
};

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@
6161
"@types/node": "14.17.4",
6262
"@types/sinon": "10.0.2",
6363
"@types/webpack-env": "1.16.0",
64-
"@typescript-eslint/eslint-plugin": "4.28.1",
65-
"@typescript-eslint/parser": "4.28.1",
64+
"@typescript-eslint/eslint-plugin": "5.0.0",
65+
"@typescript-eslint/parser": "5.0.0",
6666
"codecov": "3.8.2",
6767
"dpdm": "3.7.1",
68-
"eslint": "7.30.0",
68+
"eslint": "7.32.0",
6969
"eslint-plugin-header": "3.1.1",
70-
"eslint-plugin-import": "2.23.4",
70+
"eslint-plugin-node": "11.1.0",
7171
"gh-pages": "3.2.0",
72-
"gts": "3.1.0",
7372
"istanbul-instrumenter-loader": "3.0.1",
7473
"karma": "5.2.3",
7574
"karma-chrome-launcher": "3.1.0",

src/api/diag.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,11 @@ export class DiagAPI implements DiagLogger {
5252
*/
5353
private constructor() {
5454
function _logProxy(funcName: keyof DiagLogger): DiagLogFunction {
55-
return function () {
55+
return function (...args) {
5656
const logger = getGlobal('diag');
5757
// shortcut if logger not set
5858
if (!logger) return;
59-
return logger[funcName].apply(
60-
logger,
61-
// work around Function.prototype.apply types
62-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
63-
arguments as any
64-
);
59+
return logger[funcName](...args);
6560
};
6661
}
6762

src/diag/ComponentLogger.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { getGlobal } from '../internal/global-utils';
18-
import { ComponentLoggerOptions, DiagLogger } from './types';
18+
import { ComponentLoggerOptions, DiagLogger, DiagLogFunction } from './types';
1919

2020
/**
2121
* Component Logger which is meant to be used as part of any component which
@@ -66,5 +66,5 @@ function logProxy(
6666
}
6767

6868
args.unshift(namespace);
69-
return logger[funcName].apply(logger, args);
69+
return logger[funcName](...(args as Parameters<DiagLogFunction>));
7070
}

src/diag/consoleLogger.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
import { DiagLogger, DiagLogFunction } from './types';
1818

19-
const consoleMap: { n: keyof DiagLogger; c: keyof Console }[] = [
19+
type ConsoleMapKeys = 'error' | 'warn' | 'info' | 'debug' | 'trace';
20+
const consoleMap: { n: keyof DiagLogger; c: ConsoleMapKeys }[] = [
2021
{ n: 'error', c: 'error' },
2122
{ n: 'warn', c: 'warn' },
2223
{ n: 'info', c: 'info' },
@@ -31,20 +32,21 @@ const consoleMap: { n: keyof DiagLogger; c: keyof Console }[] = [
3132
*/
3233
export class DiagConsoleLogger implements DiagLogger {
3334
constructor() {
34-
function _consoleFunc(funcName: keyof Console): DiagLogFunction {
35-
return function () {
36-
const orgArguments = arguments;
35+
function _consoleFunc(funcName: ConsoleMapKeys): DiagLogFunction {
36+
return function (...args) {
3737
if (console) {
3838
// Some environments only expose the console when the F12 developer console is open
39+
// eslint-disable-next-line no-console
3940
let theFunc = console[funcName];
4041
if (typeof theFunc !== 'function') {
4142
// Not all environments support all functions
43+
// eslint-disable-next-line no-console
4244
theFunc = console.log;
4345
}
4446

4547
// One last final check
4648
if (typeof theFunc === 'function') {
47-
return theFunc.apply(console, orgArguments);
49+
return theFunc.apply(console, args);
4850
}
4951
}
5052
};

test/diag/consoleLogger.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
/* eslint-disable no-console */
18+
1719
import * as assert from 'assert';
1820
import { DiagConsoleLogger } from '../../src/diag/consoleLogger';
1921

0 commit comments

Comments
 (0)