Skip to content

Commit

Permalink
chore: more strict eqeqeq
Browse files Browse the repository at this point in the history
  • Loading branch information
Flarna committed Mar 1, 2021
1 parent ae39969 commit 31f88c3
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 21 deletions.
4 changes: 0 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ module.exports = {
},
rules: {
"@typescript-eslint/no-this-alias": "off",
"eqeqeq": [
"error",
"smart"
],
"prefer-rest-params": "off",
"@typescript-eslint/naming-convention": [
"error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextMa
thisArg?: ThisParameterType<F>,
...args: A
): ReturnType<F> {
const cb = thisArg == null ? fn : fn.bind(thisArg);
const cb =
thisArg === null || thisArg === undefined ? fn : fn.bind(thisArg);
return this._asyncLocalStorage.run(context, cb as never, ...args);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-core/src/common/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SpanAttributeValue, SpanAttributes } from '@opentelemetry/api';
export function sanitizeAttributes(attributes: unknown): SpanAttributes {
const out: SpanAttributes = {};

if (attributes == null || typeof attributes !== 'object') {
if (attributes === null || typeof attributes !== 'object') {
return out;
}

Expand All @@ -36,7 +36,7 @@ export function sanitizeAttributes(attributes: unknown): SpanAttributes {
}

export function isAttributeValue(val: unknown): val is SpanAttributeValue {
if (val == null) {
if (val === null || val === undefined) {
return true;
}

Expand All @@ -52,7 +52,7 @@ function isHomogeneousAttributeValueArray(arr: unknown[]): boolean {

for (const element of arr) {
// null/undefined elements are allowed
if (element == null) continue;
if (element === null || element === undefined) continue;

if (!type) {
if (isValidPrimitiveAttributeValue(element)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function setLogLevelFromEnv(
const value = values[key];
if (typeof value === 'string') {
const theLevel = logLevelMap[value.toUpperCase()];
if (theLevel != null) {
if (typeof theLevel === 'number') {
environment[key] = theLevel;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class FetchInstrumentation extends InstrumentationBase<
): void {
const parsedUrl = web.parseUrl(response.url);
span.setAttribute(HttpAttribute.HTTP_STATUS_CODE, response.status);
if (response.statusText != null) {
if (typeof response.statusText === 'string') {
span.setAttribute(HttpAttribute.HTTP_STATUS_TEXT, response.statusText);
}
span.setAttribute(HttpAttribute.HTTP_HOST, parsedUrl.host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('HttpInstrumentation Integration tests', () => {

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
if (addr === null || addr === undefined) {
done(new Error('unexpected addr null'));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('HttpsInstrumentation Integration tests', () => {

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
if (addr === null || addr === undefined) {
done(new Error('unexpected addr null'));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function get(input: any, options?: any): GetResult {
});
}
req =
options != null
options !== null && options !== undefined
? http.get(input, options, onGetResponseCb)
: http.get(input, onGetResponseCb);
req.on('error', err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function get(input: any, options?: any): GetResult {
});
}
req =
options != null
options !== null && options !== undefined
? https.get(input, options, onGetResponseCb)
: https.get(input, onGetResponseCb);
req.on('error', err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Packages', () => {

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
if (addr === null || addr === undefined) {
done(new Error('unexpected addr null'));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('HttpPlugin Integration tests', () => {

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
if (addr === null || addr === undefined) {
done(new Error('unexpected addr null'));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function get(input: any, options?: any): GetResult {
});
}
req =
options != null
options !== null && options !== undefined
? http.get(input, options, onGetResponseCb)
: http.get(input, onGetResponseCb);
req.on('error', err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Packages', () => {

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
if (addr === null || addr === undefined) {
done(new Error('unexpected addr null'));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('HttpsPlugin Integration tests', () => {

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
if (addr === null || addr === undefined) {
done(new Error('unexpected addr null'));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function get(input: any, options?: any): GetResult {
});
}
req =
options != null
options !== null && options !== undefined
? https.get(input, options, onGetResponseCb)
: https.get(input, onGetResponseCb);
req.on('error', err => {
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-tracing/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export class Span implements api.Span, ReadableSpan {

setAttribute(key: string, value?: SpanAttributeValue): this;
setAttribute(key: string, value: unknown): this {
if (value == null || this._isSpanEnded()) return this;
if (value === null || value === undefined || this._isSpanEnded())
return this;
if (key.length === 0) {
api.diag.warn(`Invalid attribute key: ${key}`);
return this;
Expand Down

0 comments on commit 31f88c3

Please sign in to comment.