Skip to content

Commit 7abd766

Browse files
authored
Forbid using console.error as it is being sent to Sentry (#3532)
* Forbid using console.error as it is being sent to Sentry * Add forwardError
1 parent 19658e2 commit 7abd766

File tree

12 files changed

+44
-17
lines changed

12 files changed

+44
-17
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ module.exports = {
88
'no-undef': 'off',
99
/* Other Rules */
1010
'no-unused-expressions': 'off',
11+
'no-restricted-syntax': [
12+
'error',
13+
{
14+
selector: `CallExpression[callee.object.name='console'][callee.property.name='error']`,
15+
message: 'Using console.error is not allowed as it is sent to Sentry, please use LogService.error instead'
16+
}
17+
],
1118
'arrow-parens': 'off',
1219
// TODO: remove after migration of legacy lifecycle methods
1320
camelcase: 'off',

src/components/card/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {BlurViewPackage} from '../../optionalDependencies';
1414
import Assets from '../../assets';
1515
import CardContext from './CardContext';
1616
import * as CardPresenter from './CardPresenter';
17+
import {LogService} from 'services';
1718

1819
const BlurView = BlurViewPackage?.BlurView;
1920

@@ -122,7 +123,8 @@ class Card extends PureComponent<PropTypes, State> {
122123
this.styles = createStyles(this.props);
123124

124125
if (props.enableBlur && !BlurView) {
125-
console.error(`RNUILib Card's "enableBlur" prop requires installing "@react-native-community/blur" dependency`);
126+
// eslint-disable-next-line max-len
127+
LogService.error(`RNUILib Card's "enableBlur" prop requires installing "@react-native-community/blur" dependency`);
126128
}
127129
}
128130

src/components/connectionStatusBar/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Colors, Typography} from '../../style';
66
import TouchableOpacity from '../touchableOpacity';
77
import View from '../view';
88
import {Constants, asBaseComponent} from '../../commons/new';
9+
import {LogService} from 'services';
910
import {ConnectionStatusBarProps, ConnectionStatusBarState, DEFAULT_PROPS} from './types';
1011
export {ConnectionStatusBarProps};
1112

@@ -47,7 +48,8 @@ class ConnectionStatusBar extends PureComponent<ConnectionStatusBarProps, Connec
4748
if (NetInfo) {
4849
this.getInitialConnectionState();
4950
} else {
50-
console.error(`RNUILib ConnectionStatusBar component requires installing "@react-native-community/netinfo" dependency`);
51+
// eslint-disable-next-line max-len
52+
LogService.error(`RNUILib ConnectionStatusBar component requires installing "@react-native-community/netinfo" dependency`);
5153
}
5254
}
5355

src/components/dateTimePicker/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Button, {ButtonProps} from '../button';
2222
import ExpandableOverlay, {ExpandableOverlayMethods, RenderCustomOverlayProps} from '../../incubator/expandableOverlay';
2323
import useOldApi, {OldApiProps} from './useOldApi';
2424
import {isSameDate, isSameHourAndMinute} from '../../utils/dateUtils';
25+
import {LogService} from 'services';
2526

2627
export type DateTimePickerMode = 'date' | 'time';
2728

@@ -170,7 +171,7 @@ const DateTimePicker = forwardRef((props: DateTimePickerPropsInternal, ref: Forw
170171
useEffect(() => {
171172
if (!RNDateTimePicker) {
172173
// eslint-disable-next-line max-len
173-
console.error(`RNUILib DateTimePicker component requires installing "@react-native-community/datetimepicker" dependency`);
174+
LogService.error(`RNUILib DateTimePicker component requires installing "@react-native-community/datetimepicker" dependency`);
174175
}
175176
}, []);
176177

src/components/dateTimePicker/useOldApi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// TODO: delete whole file in v8
22
import {useEffect} from 'react';
33
import {MomentPackage as moment} from '../../optionalDependencies';
4+
import {LogService} from 'services';
45

56
export interface OldApiProps {
67
/**
@@ -35,7 +36,8 @@ const useOldApi = (props: OldApiProps) => {
3536

3637
useEffect(() => {
3738
if (!moment && (dateFormat || timeFormat)) {
38-
console.error(`RNUILib DateTimePicker component with date/time format requires installing "moment" dependency`);
39+
// eslint-disable-next-line max-len
40+
LogService.error(`RNUILib DateTimePicker component with date/time format requires installing "moment" dependency`);
3941
}
4042
}, [dateFormat, timeFormat]);
4143

src/components/modal/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {BlurViewPackage} from '../../optionalDependencies';
1414
import {Constants, asBaseComponent} from '../../commons/new';
1515
import TopBar, {ModalTopBarProps} from './TopBar';
1616
import View from '../../components/view';
17+
import {LogService} from 'services';
1718

1819
const BlurView = BlurViewPackage?.BlurView;
1920

@@ -73,7 +74,8 @@ class Modal extends Component<ModalProps> {
7374
super(props);
7475

7576
if (props.enableModalBlur && !BlurView) {
76-
console.error(`RNUILib Modal's "enableModalBlur" prop requires installing "@react-native-community/blur" dependency`);
77+
// eslint-disable-next-line max-len
78+
LogService.error(`RNUILib Modal's "enableModalBlur" prop requires installing "@react-native-community/blur" dependency`);
7779
}
7880
}
7981

src/components/pieChart/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import View from '../view';
33
import PieSegment, {PieSegmentProps} from './PieSegment';
44
import {SvgPackage} from '../../optionalDependencies';
55
const {Svg, Path} = SvgPackage;
6+
import {LogService} from 'services';
67

78
export type PieChartSegmentProps = Pick<PieSegmentProps, 'percentage' | 'color'>;
89

@@ -23,7 +24,7 @@ const PieChart = (props: PieChartProps) => {
2324
const {segments, diameter = DEFAULT_DIAMETER, ...others} = props;
2425

2526
if (!Svg || !Path) {
26-
console.error(`RNUILib PieChart requires installing "@react-native-svg" dependency`);
27+
LogService.error(`RNUILib PieChart requires installing "@react-native-svg" dependency`);
2728
return null;
2829
}
2930

src/components/skeletonView/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {BorderRadiuses, Colors, Dividers, Spacings} from '../../style';
66
import {createShimmerPlaceholder, LinearGradientPackage} from 'optionalDeps';
77
import View from '../view';
88
import {Constants, AlignmentModifiers, PaddingModifiers, MarginModifiers} from '../../commons/new';
9+
import {LogService} from 'services';
910

1011
const LinearGradient = LinearGradientPackage?.default;
1112

@@ -174,9 +175,9 @@ class SkeletonView extends Component<SkeletonViewProps, SkeletonState> {
174175
};
175176

176177
if (_.isUndefined(LinearGradientPackage?.default)) {
177-
console.error(`RNUILib SkeletonView's requires installing "react-native-linear-gradient" dependency`);
178+
LogService.error(`RNUILib SkeletonView's requires installing "react-native-linear-gradient" dependency`);
178179
} else if (_.isUndefined(createShimmerPlaceholder)) {
179-
console.error(`RNUILib SkeletonView's requires installing "react-native-shimmer-placeholder" dependency`);
180+
LogService.error(`RNUILib SkeletonView's requires installing "react-native-shimmer-placeholder" dependency`);
180181
} else if (ShimmerPlaceholder === undefined) {
181182
ShimmerPlaceholder = createShimmerPlaceholder(LinearGradient);
182183
}

src/components/svgImage/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import {isSvg, isSvgUri} from '../../utils/imageUtils';
33
import {SvgPackage, SvgCssUri} from '../../optionalDependencies';
4+
import {LogService} from 'services';
45

56
const SvgXml = SvgPackage?.SvgXml;
67
// const SvgProps = SvgPackage?.SvgProps; TODO: not sure how (or if) we can use their props
@@ -20,7 +21,7 @@ function SvgImage(props: SvgImageProps) {
2021

2122
if (!SvgXml) {
2223
// eslint-disable-next-line max-len
23-
console.error(`RNUILib Image "svg" prop requires installing "react-native-svg" and "react-native-svg-transformer" dependencies`);
24+
LogService.error(`RNUILib Image "svg" prop requires installing "react-native-svg" and "react-native-svg-transformer" dependencies`);
2425
return null;
2526
}
2627

src/incubator/slider/SliderPresenter.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {SharedValue, interpolate} from 'react-native-reanimated';
22
import {SliderProps} from './index';
3+
import {LogService} from 'services';
34

45
export function getOffsetForValue(value: number, span: number, minimumValue = 0, maximumValue = 1) {
56
const range = maximumValue - minimumValue;
@@ -43,20 +44,20 @@ export function validateValues(props: SliderProps) {
4344
minimumValue > maximumValue ||
4445
(useRange && initialMinimumValue && initialMaximumValue && initialMinimumValue > initialMaximumValue)
4546
) {
46-
console.error('Your passed values are invalid. Please check if minimum values are not higher than maximum values');
47+
LogService.forwardError({message: 'Your passed values are invalid. Please check if minimum values are not higher than maximum values'});
4748
}
4849
if (value !== undefined && minimumValue && maximumValue && !inRange(value, minimumValue, maximumValue)) {
49-
console.error(`Your passed value (${value}) is invalid.
50-
Please check that it is in range of the minimum (${minimumValue}) and maximum (${maximumValue}) values`);
50+
LogService.forwardError({message: `Your passed value (${value}) is invalid.
51+
Please check that it is in range of the minimum (${minimumValue}) and maximum (${maximumValue}) values`});
5152
}
5253
if (useRange && initialMinimumValue && initialMaximumValue) {
5354
if (
5455
!inRange(initialMinimumValue, minimumValue, maximumValue) ||
5556
!inRange(initialMaximumValue, minimumValue, maximumValue)
5657
) {
57-
console.error(
58-
'Your passed values are invalid. Please check that they are in range of the minimum and maximum values'
59-
);
58+
LogService.forwardError({
59+
message: 'Your passed values are invalid. Please check that they are in range of the minimum and maximum values'
60+
});
6061
}
6162
}
6263
}

0 commit comments

Comments
 (0)