Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ESLint warnings (1) #1060

Merged
merged 1 commit into from
Sep 26, 2023
Merged

Fix ESLint warnings (1) #1060

merged 1 commit into from
Sep 26, 2023

Conversation

axelboc
Copy link
Collaborator

@axelboc axelboc commented Sep 26, 2023

No better time than the present! I'll split things up a bit so it's easier to digest. Starting count is 365 warnings.

In this PR, I'm knocking down 36 warnings in the reducers, bringing the count down to 329.

I'll add comments to point to the relevant rules.

@marcus-oscarsson
Copy link
Member

Wow, wonderful and great initiate, we like ! :)

@marcus-oscarsson
Copy link
Member

💯

@marcus-oscarsson
Copy link
Member

By the way still working on the e2e test, which apparently run fine here on fresh develop branches, ... scratch scratch

@@ -7,7 +7,7 @@ import Form from '@rjsf/core';
import {
showGphlWorkflowParametersDialog,
gphlWorkflowSubmitParameters,
} from '../actions/gphl_workflow';
} from '../actions/gphlWorkflow';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ESLint warning here, it's just for consistency.

@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-duplicate-string */
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonarjs/no-duplicate-string: I'm disabling the rule in a couple of files — the rule can be a bit noisy but helps spot duplicated identifiers and such, so I prefer to not disable it globally

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -141,7 +142,7 @@ export const INITIAL_STATE = {
energyScanElements: [],
};

export default (state = INITIAL_STATE, action) => {
function beamlineReducer(state = INITIAL_STATE, action = {}) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super, thanks

@@ -1,5 +1,4 @@
/* eslint-disable import/no-anonymous-default-export */
const initialState = {
const INITIAL_STATE = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant case by convention

};
}
case 'ADD_SAMPLES_TO_QUEUE': {
const sampleIDList = action.samplesData.map((s) => s.sampleID);
return { ...state, queue: state.queue.concat(sampleIDList) };
return { ...state, queue: [...state.queue, ...sampleIDList] };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer-spread: foo.concat(bar) => [...foo, ...bar] – this is just a stylistic rule, useful to ensure consistency in the codebase

@@ -26,7 +26,7 @@ export default (state = initialState, action) => {
const newNodes = [];

action.sampleOrder.forEach((sampleID) => {
if (action.sampleList.hasOwnProperty(sampleID)) {
if (sampleID in action.sampleList) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-prototype-builtins reports that foo.hasOwnProperty("bar") should be replaced with Object.prototype.hasOwnProperty.call(foo, "bar") to account for potential edge cases.

However, in the cases reported, hasOwnProperty can simply be replaced with the in operator, since we're only dealing with plain objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !

sampleList[sampleID].tasks.concat(action.samplesData[i].tasks);
} else {
sampleList[sampleID].tasks = action.samplesData[i].tasks;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-unused-expressions — ternaries are expressions that resolve to a value, so using a ternary just to trigger side effects is counter-intuitive. if/else blocks are better suited.

This change actually reveals a more serious issue, which is that the array returned by concat is not used (concat does not mutate the arrays) — so the expression in the if block has no effect at all. Not sure what the correct behaviour should be. ESLint warns about it, so I decided to leave it as is for now.

selectedShapes: [],
};
}
case 'CLEAR_ALL':
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-duplicated-branches — duplicated case blocks

if (
(record.state === 1 && !taskCollapsed) ||
(record.state >= 2 && taskCollapsed)
) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@rhfogh rhfogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good (to my very inexpert eye).

@marcus-oscarsson
Copy link
Member

👍 Thanks alot Axel !

@marcus-oscarsson marcus-oscarsson merged commit ff573df into develop Sep 26, 2023
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants