Skip to content

Commit ac395a0

Browse files
authored
feat(eslint): Add new eslint rules (#3545)
* feat(eslint): Add naming convention for typeLike * feat(eslint): Make class member accessibility explicit
1 parent a626e6f commit ac395a0

File tree

8 files changed

+27
-14
lines changed

8 files changed

+27
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"fix": "lerna run --parallel fix",
1010
"link:yarn": "lerna run --stream --concurrency 1 link:yarn",
1111
"lint": "lerna run --parallel lint",
12+
"lint:eslint": "lerna run --parallel lint:eslint",
1213
"test": "lerna run --stream --concurrency 1 --sort test",
1314
"codecov": "codecov",
1415
"pack:changed": "lerna run pack --since",

packages/browser/src/transports/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class FetchTransport extends BaseTransport {
8181
*/
8282
private _fetch: typeof fetch;
8383

84-
constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
84+
public constructor(options: TransportOptions, fetchImpl: FetchImpl = getNativeFetchImplementation()) {
8585
super(options);
8686
this._fetch = fetchImpl;
8787
}

packages/eslint-config-sdk/src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ module.exports = {
5252
// in SDKs, we should make sure that we are correctly preserving class scope.
5353
'@typescript-eslint/unbound-method': 'error',
5454

55-
// Private and protected members of a class should be prefixed with a leading underscore
55+
// Private and protected members of a class should be prefixed with a leading underscore.
56+
// typeLike declarations (class, interface, typeAlias, enum, typeParameter) should be
57+
// PascalCase.
5658
'@typescript-eslint/naming-convention': [
5759
'error',
5860
{
@@ -67,6 +69,10 @@ module.exports = {
6769
format: ['camelCase'],
6870
leadingUnderscore: 'require',
6971
},
72+
{
73+
selector: 'typeLike',
74+
format: ['PascalCase'],
75+
},
7076
],
7177

7278
// Prefer for-of loop over for loop if index is only used to access array
@@ -98,6 +104,10 @@ module.exports = {
98104
// instead of any. This is especially important for methods that expose a public API, as users
99105
// should know exactly what they have to provide to use those methods. Turned off in tests.
100106
'@typescript-eslint/no-unsafe-member-access': 'error',
107+
108+
// Be explicit about class member accessibility (public, private, protected). Turned off
109+
// on tests for ease of use.
110+
'@typescript-eslint/explicit-member-accessibility': ['error'],
101111
},
102112
},
103113
{
@@ -134,6 +144,7 @@ module.exports = {
134144
'no-unused-expressions': 'off',
135145
'@typescript-eslint/no-unused-expressions': 'off',
136146
'@typescript-eslint/no-unsafe-member-access': 'off',
147+
'@typescript-eslint/explicit-member-accessibility': 'off',
137148
},
138149
},
139150
{

packages/gatsby/test/integration.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { render } from '@testing-library/react';
33
import { useEffect } from 'react';
4+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
45
import * as React from 'react';
56

67
import { onClientEntry } from '../gatsby-browser';

packages/hub/src/session.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export class Session implements SessionInterface {
2929
public ipAddress?: string;
3030
public init: boolean = true;
3131

32-
constructor(context?: Omit<SessionContext, 'started' | 'status'>) {
32+
public constructor(context?: Omit<SessionContext, 'started' | 'status'>) {
3333
if (context) {
3434
this.update(context);
3535
}
3636
}
3737

3838
/** JSDoc */
3939
// eslint-disable-next-line complexity
40-
update(context: SessionContext = {}): void {
40+
public update(context: SessionContext = {}): void {
4141
if (context.user) {
4242
if (context.user.ip_address) {
4343
this.ipAddress = context.user.ip_address;
@@ -89,7 +89,7 @@ export class Session implements SessionInterface {
8989
}
9090

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

102102
/** JSDoc */
103-
toJSON(): {
103+
public toJSON(): {
104104
init: boolean;
105105
sid: string;
106106
did?: string;
@@ -151,7 +151,7 @@ export class SessionFlusher implements SessionFlusherLike {
151151
private _isEnabled: boolean = true;
152152
private _transport: Transport;
153153

154-
constructor(transport: Transport, attrs: ReleaseHealthAttributes) {
154+
public constructor(transport: Transport, attrs: ReleaseHealthAttributes) {
155155
this._transport = transport;
156156
// Call to setInterval, so that flush is called every 60 seconds
157157
this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000);

packages/nextjs/src/utils/metadataBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class MetadataBuilder {
1313
private _options: NextjsOptions;
1414
private _packageNames: string[];
1515

16-
constructor(options: NextjsOptions, packages: string[]) {
16+
public constructor(options: NextjsOptions, packages: string[]) {
1717
this._options = options;
1818
this._packageNames = packages;
1919
}

packages/node/src/integrations/onuncaughtexception.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logger } from '@sentry/utils';
55
import { NodeClient } from '../client';
66
import { logAndExitProcess } from './utils/errorhandling';
77

8+
type OnFatalErrorHandler = (firstError: Error, secondError?: Error) => void;
9+
810
/** Global Promise Rejection handler */
911
export class OnUncaughtException implements Integration {
1012
/**
@@ -53,17 +55,15 @@ export class OnUncaughtException implements Integration {
5355
let firstError: Error;
5456

5557
return (error: Error): void => {
56-
type onFatalErrorHandlerType = (firstError: Error, secondError?: Error) => void;
57-
58-
let onFatalError: onFatalErrorHandlerType = logAndExitProcess;
58+
let onFatalError: OnFatalErrorHandler = logAndExitProcess;
5959
const client = getCurrentHub().getClient<NodeClient>();
6060

6161
if (this._options.onFatalError) {
6262
// eslint-disable-next-line @typescript-eslint/unbound-method
6363
onFatalError = this._options.onFatalError;
6464
} else if (client && client.getOptions().onFatalError) {
6565
// eslint-disable-next-line @typescript-eslint/unbound-method
66-
onFatalError = client.getOptions().onFatalError as onFatalErrorHandlerType;
66+
onFatalError = client.getOptions().onFatalError as OnFatalErrorHandler;
6767
}
6868

6969
if (!caughtFirstError) {

packages/tracing/test/integrations/mongo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class Collection {
1010
public namespace: string = 'mockedNamespace';
1111

1212
// Method that can have a callback as last argument, or return a promise otherwise.
13-
insertOne(_doc: unknown, _options: unknown, callback?: () => void) {
13+
public insertOne(_doc: unknown, _options: unknown, callback?: () => void) {
1414
if (typeof callback === 'function') {
1515
callback();
1616
return;
1717
}
1818
return Promise.resolve();
1919
}
2020
// Method that has no callback as last argument, and doesnt return promise.
21-
initializeOrderedBulkOp() {
21+
public initializeOrderedBulkOp() {
2222
return {};
2323
}
2424
}

0 commit comments

Comments
 (0)