Skip to content

Commit 0f51b93

Browse files
committed
fix: fix SonarQube errors
1 parent 1cc2009 commit 0f51b93

11 files changed

Lines changed: 71 additions & 82 deletions

File tree

src/actions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const fetchResource = createAction(
2121
ActionTypes.GET_RESOURCE,
2222
ApiClient.fetchResource,
2323
(resourceType: string, filters?: any, include?: string[], embed?: string[], meta?: any) => {
24-
return Object.assign({}, meta, { resourceType });
24+
return { ...meta, resourceType };
2525
}
2626
);
2727

src/actions/queueHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function queueHandler(store) {
3232
markAndSendObservation(store, item);
3333
});
3434

35-
const shouldRetryImmediately = ((opts && opts.initial === true) || store.getState().updateFlush);
35+
const shouldRetryImmediately = ((opts?.initial === true) || store.getState().updateFlush);
3636
if (shouldRetryImmediately) {
3737
_.each(timers, (_, key) => {
3838
clearTimeout(key);

src/components/LoginScreen.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ class LoginScreen extends React.Component {
3434
}
3535
handleChange(field) {
3636
return (event) => {
37-
this.setState(
38-
Object.assign(
39-
this.state,
40-
{[field]: event.target.value}
41-
));
37+
this.setState(prevState => ({
38+
...prevState,
39+
[field]: event.target.value
40+
}));
4241
};
4342
}
4443
render() {

src/components/NotFound.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const NotFound: React.FC = () => {
77
<div className="list-group facility-return clearfix">
88
<Link to="/" className="list-group-item">
99
<span className="action-icon glyphicon glyphicon-chevron-left"></span>
10-
Takaisin
10+
{' '}Takaisin
1111
</Link>
1212
</div>
1313
<h4>404 - Sivua ei löytynyt</h4>

src/components/UnitDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ interface ObservablePropertyPanelProps {
3030
header: string;
3131
}
3232

33-
export function ObservableProperty({ quality, property, identifier, name, unitId }: ObservablePropertyProps): React.ReactElement {
33+
export function ObservableProperty({ quality, property, identifier, name, unitId }: Readonly<ObservablePropertyProps>): React.ReactElement {
3434
const url = `/unit/${unitId}/update/${property}/${identifier}`;
3535
const color = COLORS[quality] || 'primary';
3636
const icon = ICONS[identifier];
@@ -40,7 +40,7 @@ export function ObservableProperty({ quality, property, identifier, name, unitId
4040
return <Link to={url} className={buttonClassName}><span className={iconClassName}></span><br />{name.fi}</Link>;
4141
}
4242

43-
export function ObservablePropertyPanel({ allowedValues, header }: ObservablePropertyPanelProps): React.ReactElement {
43+
export function ObservablePropertyPanel({ allowedValues, header }: Readonly<ObservablePropertyPanelProps>): React.ReactElement {
4444
const amountOfValues = allowedValues.length;
4545
const cutPoint = (amountOfValues / 2) + (amountOfValues % 2);
4646
const left = allowedValues.slice(0, cutPoint);
@@ -65,7 +65,7 @@ export function ObservablePropertyPanel({ allowedValues, header }: ObservablePro
6565

6666
const UnitDetails: React.FC = () => {
6767
const params = useParams<{ unitId: string }>();
68-
const unitId = params.unitId!;
68+
const unitId = params.unitId;
6969

7070
const unit = useSelector((state: RootState) => state.data.unit[unitId]);
7171
const isLoading = useSelector((state: RootState) => state.data.loading.unit === true);

src/components/UnitHistory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class UnitHistory extends React.Component {
3737
<div className="list-group facility-return clearfix">
3838
<Link to={`/unit/${unit.id}`} className="list-group-item">
3939
<span className="action-icon glyphicon glyphicon-chevron-left"></span>
40-
Takaisin
40+
{' '}Takaisin
4141
</Link>
4242
</div>
4343
<div className="well">

src/components/UnitList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface UnitListElementProps {
1111
unit: Unit;
1212
}
1313

14-
export function UnitListElement(props: UnitListElementProps): React.ReactElement {
14+
export function UnitListElement(props: Readonly<UnitListElementProps>): React.ReactElement {
1515
const { unit } = props;
1616
const url = `/unit/${unit.id}`;
1717
let iconClassName: string;

src/reducers/index.ts

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,25 @@ const authErrorReducer: Reducer<AuthErrorState, ReduxAction> = (state = initialA
113113
};
114114

115115
const authReducer: Reducer<AuthState, ReduxAction> = (state = initialAuthState, action) => {
116-
switch (action.type) {
117-
case ActionTypes.LOGIN: {
118-
const loginAction = action as LoginAction;
119-
if (loginAction.error) {
120-
return {
121-
token: null,
122-
maintenance_organization: null,
123-
login_id: null
124-
};
125-
}
126-
const {maintenance_organization, token, login_identifier} = loginAction.payload;
127-
116+
if (action.type === ActionTypes.LOGIN) {
117+
const loginAction = action as LoginAction;
118+
if (loginAction.error) {
128119
return {
129-
maintenance_organization,
130-
token,
131-
login_id: login_identifier
120+
token: null,
121+
maintenance_organization: null,
122+
login_id: null
132123
};
133124
}
134-
default:
135-
return state;
125+
const {maintenance_organization, token, login_identifier} = loginAction.payload;
126+
127+
return {
128+
maintenance_organization,
129+
token,
130+
login_id: login_identifier
131+
};
136132
}
133+
134+
return state;
137135
};
138136

139137
function observationPath({unitId, property}: {unitId: string; property: string}): string {
@@ -234,66 +232,60 @@ const updateFlushReducer: Reducer<boolean, ReduxAction> = (state = manuallyFlush
234232
};
235233

236234
const serviceGroupReducer: Reducer<string, ReduxAction> = (state = serviceGroup, action) => {
237-
switch (action.type) {
238-
case ActionTypes.SELECT_SERVICE_GROUP:
239-
return (action as SelectServiceGroupAction).payload;
240-
default:
241-
return state;
235+
if (action.type === ActionTypes.SELECT_SERVICE_GROUP) {
236+
return (action as SelectServiceGroupAction).payload;
242237
}
238+
239+
return state;
243240
};
244241

245242
const initialUserLocation: any = null;
246243

247244
const userLocationReducer: Reducer<any, ReduxAction> = (state = initialUserLocation, action) => {
248-
switch (action.type) {
249-
case ActionTypes.SET_USER_LOCATION:
250-
return (action as SetUserLocationAction).payload;
251-
default:
252-
return state;
245+
if (action.type === ActionTypes.SET_USER_LOCATION) {
246+
return (action as SetUserLocationAction).payload;
253247
}
248+
249+
return state;
254250
};
255251

256252
const initialUnitsByUpdateTime: string[] = [];
257253
const unitsByUpdateTimeReducer: Reducer<string[], ReduxAction> = (state = initialUnitsByUpdateTime, action) => {
258-
switch (action.type) {
259-
case ActionTypes.POST_OBSERVATION: {
260-
const postAction = action as PostObservationAction;
261-
262-
if (postAction.error === true) {
263-
return state;
264-
}
265-
266-
return _.uniq([postAction.meta.unitId, ...state]).slice(0, 20);
267-
}
268-
default:
254+
if (action.type === ActionTypes.POST_OBSERVATION) {
255+
const postAction = action as PostObservationAction;
256+
257+
if (postAction.error === true) {
269258
return state;
259+
}
260+
261+
return _.uniq([postAction.meta.unitId, ...state]).slice(0, 20);
270262
}
263+
264+
return state;
271265
};
272266

273267
const initialUnitsByUpdateCount: UnitsByUpdateCountState = {};
274268
const unitsByUpdateCountReducer: Reducer<UnitsByUpdateCountState, ReduxAction> = (
275269
state = initialUnitsByUpdateCount,
276270
action
277271
) => {
278-
switch (action.type) {
279-
case ActionTypes.POST_OBSERVATION: {
280-
const postAction = action as PostObservationAction;
281-
282-
if (postAction.error === true) {
283-
return state;
284-
}
272+
if (action.type === ActionTypes.POST_OBSERVATION) {
273+
const postAction = action as PostObservationAction;
285274

286-
const { unitId } = postAction.meta;
287-
const existingCount = (state[unitId] || {}).count || 0;
288-
289-
return {
290-
...state,
291-
[unitId]: { count: existingCount + 1, id: unitId }
292-
};
293-
}
294-
default:
275+
if (postAction.error === true) {
295276
return state;
277+
}
278+
279+
const { unitId } = postAction.meta;
280+
const existingCount = state[unitId]?.count || 0;
281+
282+
return {
283+
...state,
284+
[unitId]: { count: existingCount + 1, id: unitId }
285+
};
296286
}
287+
288+
return state;
297289
};
298290

299291
export default combineReducers({

src/reducers/types.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action, AnyAction } from 'redux';
1+
import { Action } from 'redux';
22
import { ActionTypes } from '../constants';
33
import { Unit, ObservableProperty } from '../types';
44

@@ -86,8 +86,7 @@ export type ReduxAction =
8686
| PostObservationAction
8787
| FlushUpdateQueueAction
8888
| SelectServiceGroupAction
89-
| SetUserLocationAction
90-
| AnyAction;
89+
| SetUserLocationAction;
9190

9291
// Common data interfaces
9392

@@ -139,7 +138,7 @@ export interface RootState {
139138
updateQueue: PendingObservationsState; // Note: renamed from pendingObservations in actual store
140139
updateFlush: boolean;
141140
serviceGroup: string;
142-
userLocation: any | null;
141+
userLocation: any;
143142
unitsByUpdateTime: string[];
144143
unitsByUpdateCount: UnitsByUpdateCountState;
145144
}

src/util/error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export function CredentialError(message) {
33
this.name = 'CredentialError';
44
this.message = message;
5-
this.stack = (new Error()).stack;
5+
this.stack = (new Error(message)).stack;
66
}
77

8-
CredentialError.prototype = new Error;
8+
CredentialError.prototype = new Error('CredentialError');

0 commit comments

Comments
 (0)