File tree 9 files changed +63
-8
lines changed
9 files changed +63
-8
lines changed Original file line number Diff line number Diff line change @@ -143,7 +143,10 @@ module.exports = {
143
143
} ,
144
144
] ,
145
145
146
+ // We want to prevent optional chaining & nullish coalescing usage in our files
147
+ // to prevent uncessary bundle size. Turned off in tests.
146
148
'@sentry-internal/sdk/no-optional-chaining' : 'error' ,
149
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'error' ,
147
150
148
151
// JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation,
149
152
// even if it may seems excessive at times, is important to emphasize. Turned off in tests.
@@ -177,6 +180,7 @@ module.exports = {
177
180
'@typescript-eslint/no-non-null-assertion' : 'off' ,
178
181
'@typescript-eslint/no-empty-function' : 'off' ,
179
182
'@sentry-internal/sdk/no-optional-chaining' : 'off' ,
183
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'off' ,
180
184
} ,
181
185
} ,
182
186
{
Original file line number Diff line number Diff line change 11
11
module . exports = {
12
12
rules : {
13
13
'no-optional-chaining' : require ( './rules/no-optional-chaining' ) ,
14
+ 'no-nullish-coalescing' : require ( './rules/no-nullish-coalescing' ) ,
14
15
'no-eq-empty' : require ( './rules/no-eq-empty' ) ,
15
16
} ,
16
17
} ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview disallow nullish coalescing operators as they were introduced only in ES2020 and hence require
3
+ * us to add a polyfill. This increases bundle size more than avoiding nullish coalescing operators all together.
4
+ *
5
+ * @author Lukas Stracke
6
+ *
7
+ * Based on: https://github.com/mysticatea/eslint-plugin-es/blob/v4.1.0/lib/rules/no-nullish-coalescing-operators.js
8
+ */
9
+ 'use strict' ;
10
+
11
+ // ------------------------------------------------------------------------------
12
+ // Rule Definition
13
+ // ------------------------------------------------------------------------------
14
+
15
+ module . exports = {
16
+ meta : {
17
+ type : 'problem' ,
18
+ docs : {
19
+ description : 'disallow nullish coalescing operators.' ,
20
+ category : 'Best Practices' ,
21
+ recommended : true ,
22
+ } ,
23
+ messages : {
24
+ forbidden : 'Avoid using nullish coalescing operators.' ,
25
+ } ,
26
+ fixable : null ,
27
+ schema : [ ] ,
28
+ } ,
29
+ create ( context ) {
30
+ return {
31
+ "LogicalExpression[operator='??']" ( node ) {
32
+ context . report ( {
33
+ node : context . getSourceCode ( ) . getTokenAfter ( node . left , isNullishCoalescingOperator ) ,
34
+ messageId : 'forbidden' ,
35
+ } ) ;
36
+ } ,
37
+ } ;
38
+ } ,
39
+ } ;
40
+
41
+ /**
42
+ * Checks if the given token is a nullish coalescing operator or not.
43
+ * @param {Token } token - The token to check.
44
+ * @returns {boolean } `true` if the token is a nullish coalescing operator.
45
+ */
46
+ function isNullishCoalescingOperator ( token ) {
47
+ return token . value === '??' && token . type === 'Punctuator' ;
48
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module.exports = {
10
10
extends : [ '../../.eslintrc.js' ] ,
11
11
rules : {
12
12
'@sentry-internal/sdk/no-optional-chaining' : 'off' ,
13
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'off' ,
13
14
} ,
14
15
overrides : [
15
16
{
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ module.exports = {
5
5
extends : [ '../../.eslintrc.js' ] ,
6
6
rules : {
7
7
'@sentry-internal/sdk/no-optional-chaining' : 'off' ,
8
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'off' ,
8
9
} ,
9
10
} ;
Original file line number Diff line number Diff line change @@ -317,7 +317,7 @@ export class BrowserTracing implements Integration {
317
317
op,
318
318
trimEnd : true ,
319
319
metadata : {
320
- source : this . _latestRouteSource ?? 'url' ,
320
+ source : this . _latestRouteSource || 'url' ,
321
321
} ,
322
322
} ;
323
323
Original file line number Diff line number Diff line change @@ -304,7 +304,7 @@ function _addPerformanceNavigationTiming(
304
304
}
305
305
_startChild ( transaction , {
306
306
op : 'browser' ,
307
- description : description ?? event ,
307
+ description : description || event ,
308
308
startTimestamp : timeOrigin + msToSec ( start ) ,
309
309
endTimestamp : timeOrigin + msToSec ( end ) ,
310
310
} ) ;
Original file line number Diff line number Diff line change @@ -294,17 +294,17 @@ export class Span implements SpanInterface {
294
294
* @inheritDoc
295
295
*/
296
296
public updateWithContext ( spanContext : SpanContext ) : this {
297
- this . data = spanContext . data ?? { } ;
297
+ this . data = spanContext . data || { } ;
298
298
this . description = spanContext . description ;
299
299
this . endTimestamp = spanContext . endTimestamp ;
300
300
this . op = spanContext . op ;
301
301
this . parentSpanId = spanContext . parentSpanId ;
302
302
this . sampled = spanContext . sampled ;
303
- this . spanId = spanContext . spanId ?? this . spanId ;
304
- this . startTimestamp = spanContext . startTimestamp ?? this . startTimestamp ;
303
+ this . spanId = spanContext . spanId || this . spanId ;
304
+ this . startTimestamp = spanContext . startTimestamp || this . startTimestamp ;
305
305
this . status = spanContext . status ;
306
- this . tags = spanContext . tags ?? { } ;
307
- this . traceId = spanContext . traceId ?? this . traceId ;
306
+ this . tags = spanContext . tags || { } ;
307
+ this . traceId = spanContext . traceId || this . traceId ;
308
308
309
309
return this ;
310
310
}
Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
238
238
public updateWithContext ( transactionContext : TransactionContext ) : this {
239
239
super . updateWithContext ( transactionContext ) ;
240
240
241
- this . name = transactionContext . name ?? '' ;
241
+ this . name = transactionContext . name || '' ;
242
242
243
243
this . _trimEnd = transactionContext . trimEnd ;
244
244
You can’t perform that action at this time.
0 commit comments