Skip to content

Commit

Permalink
chore: align linter rules with repo open-telemetry/opentelemetry-js (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas authored Nov 8, 2021
1 parent 95306c0 commit 65df36c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 80 deletions.
127 changes: 66 additions & 61 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
module.exports = {
"env": {
"mocha": true,
"commonjs": true,
"shared-node-browser": true
},
plugins: [
"@typescript-eslint",
"header"
plugins: [
"@typescript-eslint",
"header",
"node"
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
"project": "./tsconfig.json"
},
rules: {
"quotes": [2, "single", { "avoidEscape": true }],
"@typescript-eslint/no-floating-promises": 2,
"@typescript-eslint/no-this-alias": "off",
"brace-style": ["error", "1tbs"],
"eqeqeq": [
"error",
"smart"
],
extends: [
"./node_modules/gts",
"prefer-rest-params": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "memberLike",
"modifiers": ["private", "protected"],
"format": ["camelCase"],
"leadingUnderscore": "require"
}
],
parser: "@typescript-eslint/parser",
parserOptions: {
"project": [
"./tsconfig.json"
]
},
ignorePatterns: [
'build',
],
rules: {
"@typescript-eslint/no-this-alias": "off",
"eqeqeq": [
"error",
"smart"
],
"prefer-rest-params": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "memberLike",
"modifiers": ["private", "protected"],
"format": ["camelCase"],
"leadingUnderscore": "require"
}
],
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "args": "after-used" }],
"@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }],
"arrow-parens": ["error", "as-needed"],
"prettier/prettier": ["error", { "singleQuote": true, "arrowParens": "avoid" }],
"prefer-spread": "off",
"node/no-deprecated-api": ["warn"],
"header/header": [2, "block", [{
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,
template:
`\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 `
}]]
},
overrides: [
{
"files": ["test/**/*.ts"],
"rules": {
"no-empty": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off"
}
}
]
}
"no-console": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["warn"],
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "args": "after-used"}],
"@typescript-eslint/no-inferrable-types": ["error", { ignoreProperties: true }],
"@typescript-eslint/no-empty-function": ["off"],
"@typescript-eslint/ban-types": ["warn", {
"types": {
"Function": null,
}
}],
"@typescript-eslint/no-shadow": ["warn"],
"arrow-parens": ["error", "as-needed"],
"node/no-deprecated-api": ["warn"],
"header/header": [2, "block", [{
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,
template:
`\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 `
}]]
},
overrides: [
{
"files": ["test/**/*.ts"],
"rules": {
"no-empty": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": 1,
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-shadow": ["off"],
"@typescript-eslint/no-floating-promises": ["off"],
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/explicit-module-boundary-types": ["off"]
}
}
]
};
9 changes: 4 additions & 5 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@
"@types/node": "14.17.4",
"@types/sinon": "10.0.2",
"@types/webpack-env": "1.16.0",
"@typescript-eslint/eslint-plugin": "4.28.1",
"@typescript-eslint/parser": "4.28.1",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.0.0",
"codecov": "3.8.2",
"dpdm": "3.7.1",
"eslint": "7.30.0",
"eslint": "7.32.0",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-node": "11.1.0",
"gh-pages": "3.2.0",
"gts": "3.1.0",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "5.2.3",
"karma-chrome-launcher": "3.1.0",
Expand Down
9 changes: 2 additions & 7 deletions api/src/api/diag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,11 @@ export class DiagAPI implements DiagLogger {
*/
private constructor() {
function _logProxy(funcName: keyof DiagLogger): DiagLogFunction {
return function () {
return function (...args) {
const logger = getGlobal('diag');
// shortcut if logger not set
if (!logger) return;
return logger[funcName].apply(
logger,
// work around Function.prototype.apply types
// eslint-disable-next-line @typescript-eslint/no-explicit-any
arguments as any
);
return logger[funcName](...args);
};
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/diag/ComponentLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

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

/**
* Component Logger which is meant to be used as part of any component which
Expand Down Expand Up @@ -66,5 +66,5 @@ function logProxy(
}

args.unshift(namespace);
return logger[funcName].apply(logger, args);
return logger[funcName](...(args as Parameters<DiagLogFunction>));
}
12 changes: 7 additions & 5 deletions api/src/diag/consoleLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

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

const consoleMap: { n: keyof DiagLogger; c: keyof Console }[] = [
type ConsoleMapKeys = 'error' | 'warn' | 'info' | 'debug' | 'trace';
const consoleMap: { n: keyof DiagLogger; c: ConsoleMapKeys }[] = [
{ n: 'error', c: 'error' },
{ n: 'warn', c: 'warn' },
{ n: 'info', c: 'info' },
Expand All @@ -31,20 +32,21 @@ const consoleMap: { n: keyof DiagLogger; c: keyof Console }[] = [
*/
export class DiagConsoleLogger implements DiagLogger {
constructor() {
function _consoleFunc(funcName: keyof Console): DiagLogFunction {
return function () {
const orgArguments = arguments;
function _consoleFunc(funcName: ConsoleMapKeys): DiagLogFunction {
return function (...args) {
if (console) {
// Some environments only expose the console when the F12 developer console is open
// eslint-disable-next-line no-console
let theFunc = console[funcName];
if (typeof theFunc !== 'function') {
// Not all environments support all functions
// eslint-disable-next-line no-console
theFunc = console.log;
}

// One last final check
if (typeof theFunc === 'function') {
return theFunc.apply(console, orgArguments);
return theFunc.apply(console, args);
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions api/test/diag/consoleLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

/* eslint-disable no-console */

import * as assert from 'assert';
import { DiagConsoleLogger } from '../../src/diag/consoleLogger';

Expand Down

0 comments on commit 65df36c

Please sign in to comment.