Skip to content

Commit

Permalink
chore(eslint): no-console error rule (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
skjindal93 authored Mar 22, 2021
1 parent 6025749 commit f045eef
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
"leadingUnderscore": "require"
}
],
"no-console": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["warn"],
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "args": "after-used"}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { ExportResult, ExportResultCode } from '@opentelemetry/core';
* This is implementation of {@link MetricExporter} that prints metrics data to
* the console. This class can be used for diagnostic purposes.
*/

/* eslint-disable no-console */
export class ConsoleMetricExporter implements MetricExporter {
export(
metrics: MetricRecord[],
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ describe('Meter', () => {
let counter = 0;

function getValue() {
console.log('getting value, counter:', counter);
diag.info('getting value, counter:', counter);
if (++counter % 2 === 0) {
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as sinon from 'sinon';
import { ConsoleMetricExporter, MeterProvider, MetricKind } from '../../src';
import { ValueType } from '@opentelemetry/api-metrics';

/* eslint-disable no-console */
describe('ConsoleMetricExporter', () => {
let consoleExporter: ConsoleMetricExporter;
let previousConsoleLog: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
* This is implementation of {@link SpanExporter} that prints spans to the
* console. This class can be used for diagnostic purposes.
*/

/* eslint-disable no-console */
export class ConsoleSpanExporter implements SpanExporter {
/**
* Export spans.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { diag } from '@opentelemetry/api';
import {
AlwaysOnSampler,
ExportResultCode,
Expand Down Expand Up @@ -237,7 +238,10 @@ describe('BatchSpanProcessor', () => {
clock.tick(defaultBufferConfig.scheduledDelayMillis + 10);
clock.restore();

console.log(exporter.getFinishedSpans().length);
diag.info(
'finished spans count',
exporter.getFinishedSpans().length
);
assert.strictEqual(
exporter.getFinishedSpans().length,
totalSpans + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
SimpleSpanProcessor,
} from '../../src';

/* eslint-disable no-console */
describe('ConsoleSpanExporter', () => {
let consoleExporter: ConsoleSpanExporter;
let previousConsoleLog: any;
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-web/src/WebTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { diag } from '@opentelemetry/api';
import {
BasicTracerProvider,
SDKRegistrationConfig,
Expand Down Expand Up @@ -41,7 +42,7 @@ export class WebTracerProvider extends BasicTracerProvider {
*/
constructor(config: WebTracerConfig = {}) {
if (typeof config.plugins !== 'undefined') {
console.warn(
diag.warn(
'plugins option was removed, please use' +
' "registerInstrumentations" to load plugins'
);
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-web/test/WebTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { diag } from '@opentelemetry/api';
import { context, getSpan, setSpan, ContextManager } from '@opentelemetry/api';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { B3Propagator } from '@opentelemetry/propagator-b3';
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('WebTracerProvider', () => {

it('should show warning when plugins are defined', () => {
const dummyPlugin1 = {};
const spyWarn = sinon.spy(window.console, 'warn');
const spyWarn = sinon.spy(diag, 'warn');

const plugins = [dummyPlugin1];

Expand Down

0 comments on commit f045eef

Please sign in to comment.