Skip to content

Commit

Permalink
feat(eslint): Add new eslint rules (#3545)
Browse files Browse the repository at this point in the history
* feat(eslint): Add naming convention for typeLike
* feat(eslint): Make class member accessibility explicit
  • Loading branch information
AbhiPrasad committed May 17, 2021
1 parent a626e6f commit ac395a0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"fix": "lerna run --parallel fix",
"link:yarn": "lerna run --stream --concurrency 1 link:yarn",
"lint": "lerna run --parallel lint",
"lint:eslint": "lerna run --parallel lint:eslint",
"test": "lerna run --stream --concurrency 1 --sort test",
"codecov": "codecov",
"pack:changed": "lerna run pack --since",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/transports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class FetchTransport extends BaseTransport {
*/
private _fetch: typeof fetch;

constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
public constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
super(options);
this._fetch = fetchImpl;
}
Expand Down
13 changes: 12 additions & 1 deletion packages/eslint-config-sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ module.exports = {
// in SDKs, we should make sure that we are correctly preserving class scope.
'@typescript-eslint/unbound-method': 'error',

// Private and protected members of a class should be prefixed with a leading underscore
// Private and protected members of a class should be prefixed with a leading underscore.
// typeLike declarations (class, interface, typeAlias, enum, typeParameter) should be
// PascalCase.
'@typescript-eslint/naming-convention': [
'error',
{
Expand All @@ -67,6 +69,10 @@ module.exports = {
format: ['camelCase'],
leadingUnderscore: 'require',
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
],

// Prefer for-of loop over for loop if index is only used to access array
Expand Down Expand Up @@ -98,6 +104,10 @@ module.exports = {
// instead of any. This is especially important for methods that expose a public API, as users
// should know exactly what they have to provide to use those methods. Turned off in tests.
'@typescript-eslint/no-unsafe-member-access': 'error',

// Be explicit about class member accessibility (public, private, protected). Turned off
// on tests for ease of use.
'@typescript-eslint/explicit-member-accessibility': ['error'],
},
},
{
Expand Down Expand Up @@ -134,6 +144,7 @@ module.exports = {
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
},
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/test/integration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render } from '@testing-library/react';
import { useEffect } from 'react';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as React from 'react';

import { onClientEntry } from '../gatsby-browser';
Expand Down
10 changes: 5 additions & 5 deletions packages/hub/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export class Session implements SessionInterface {
public ipAddress?: string;
public init: boolean = true;

constructor(context?: Omit<SessionContext, 'started' | 'status'>) {
public constructor(context?: Omit<SessionContext, 'started' | 'status'>) {
if (context) {
this.update(context);
}
}

/** JSDoc */
// eslint-disable-next-line complexity
update(context: SessionContext = {}): void {
public update(context: SessionContext = {}): void {
if (context.user) {
if (context.user.ip_address) {
this.ipAddress = context.user.ip_address;
Expand Down Expand Up @@ -89,7 +89,7 @@ export class Session implements SessionInterface {
}

/** JSDoc */
close(status?: Exclude<SessionStatus, SessionStatus.Ok>): void {
public close(status?: Exclude<SessionStatus, SessionStatus.Ok>): void {
if (status) {
this.update({ status });
} else if (this.status === SessionStatus.Ok) {
Expand All @@ -100,7 +100,7 @@ export class Session implements SessionInterface {
}

/** JSDoc */
toJSON(): {
public toJSON(): {
init: boolean;
sid: string;
did?: string;
Expand Down Expand Up @@ -151,7 +151,7 @@ export class SessionFlusher implements SessionFlusherLike {
private _isEnabled: boolean = true;
private _transport: Transport;

constructor(transport: Transport, attrs: ReleaseHealthAttributes) {
public constructor(transport: Transport, attrs: ReleaseHealthAttributes) {
this._transport = transport;
// Call to setInterval, so that flush is called every 60 seconds
this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000);
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/utils/metadataBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MetadataBuilder {
private _options: NextjsOptions;
private _packageNames: string[];

constructor(options: NextjsOptions, packages: string[]) {
public constructor(options: NextjsOptions, packages: string[]) {
this._options = options;
this._packageNames = packages;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/node/src/integrations/onuncaughtexception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { logger } from '@sentry/utils';
import { NodeClient } from '../client';
import { logAndExitProcess } from './utils/errorhandling';

type OnFatalErrorHandler = (firstError: Error, secondError?: Error) => void;

/** Global Promise Rejection handler */
export class OnUncaughtException implements Integration {
/**
Expand Down Expand Up @@ -53,17 +55,15 @@ export class OnUncaughtException implements Integration {
let firstError: Error;

return (error: Error): void => {
type onFatalErrorHandlerType = (firstError: Error, secondError?: Error) => void;

let onFatalError: onFatalErrorHandlerType = logAndExitProcess;
let onFatalError: OnFatalErrorHandler = logAndExitProcess;
const client = getCurrentHub().getClient<NodeClient>();

if (this._options.onFatalError) {
// eslint-disable-next-line @typescript-eslint/unbound-method
onFatalError = this._options.onFatalError;
} else if (client && client.getOptions().onFatalError) {
// eslint-disable-next-line @typescript-eslint/unbound-method
onFatalError = client.getOptions().onFatalError as onFatalErrorHandlerType;
onFatalError = client.getOptions().onFatalError as OnFatalErrorHandler;
}

if (!caughtFirstError) {
Expand Down
4 changes: 2 additions & 2 deletions packages/tracing/test/integrations/mongo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class Collection {
public namespace: string = 'mockedNamespace';

// Method that can have a callback as last argument, or return a promise otherwise.
insertOne(_doc: unknown, _options: unknown, callback?: () => void) {
public insertOne(_doc: unknown, _options: unknown, callback?: () => void) {
if (typeof callback === 'function') {
callback();
return;
}
return Promise.resolve();
}
// Method that has no callback as last argument, and doesnt return promise.
initializeOrderedBulkOp() {
public initializeOrderedBulkOp() {
return {};
}
}
Expand Down

0 comments on commit ac395a0

Please sign in to comment.