File tree 4 files changed +54
-1
lines changed
4 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -143,9 +143,11 @@ module.exports = {
143
143
} ,
144
144
] ,
145
145
146
- // We want to prevent async await & optional chaining usage in our files to prevent uncessary bundle size. Turned off in tests.
146
+ // We want to prevent async await & optional chaining & nullish coalescing usage in our files
147
+ // to prevent uncessary bundle size. Turned off in tests.
147
148
'@sentry-internal/sdk/no-async-await' : 'error' ,
148
149
'@sentry-internal/sdk/no-optional-chaining' : 'error' ,
150
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'error' ,
149
151
150
152
// JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation,
151
153
// even if it may seems excessive at times, is important to emphasize. Turned off in tests.
@@ -180,6 +182,7 @@ module.exports = {
180
182
'@typescript-eslint/no-empty-function' : 'off' ,
181
183
'@sentry-internal/sdk/no-async-await' : 'off' ,
182
184
'@sentry-internal/sdk/no-optional-chaining' : 'off' ,
185
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'off' ,
183
186
} ,
184
187
} ,
185
188
{
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module.exports = {
12
12
rules : {
13
13
'no-async-await' : require ( './rules/no-async-await' ) ,
14
14
'no-optional-chaining' : require ( './rules/no-optional-chaining' ) ,
15
+ 'no-nullish-coalescing' : require ( './rules/no-nullish-coalescing' ) ,
15
16
'no-eq-empty' : require ( './rules/no-eq-empty' ) ,
16
17
} ,
17
18
} ;
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 @@ -6,5 +6,6 @@ module.exports = {
6
6
rules : {
7
7
'@sentry-internal/sdk/no-async-await' : 'off' ,
8
8
'@sentry-internal/sdk/no-optional-chaining' : 'off' ,
9
+ '@sentry-internal/sdk/no-nullish-coalescing' : 'off' ,
9
10
} ,
10
11
} ;
You can’t perform that action at this time.
0 commit comments