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

Add react eslint config #135

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion demo/src/TreeViewFinderConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';

import PropTypes from 'prop-types';
import Radio from '@mui/material/Radio';
import RadioGroup from '@mui/material/RadioGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
Expand Down Expand Up @@ -148,4 +148,15 @@ const TreeViewFinderConfig = (props) => {
);
};

TreeViewFinderConfig.propTypes = {
dynamicData: PropTypes.bool,
dataFormat: PropTypes.string,
multiselect: PropTypes.bool,
onlyLeaves: PropTypes.bool,
onDynamicDataChange: PropTypes.func,
onDataFormatChange: PropTypes.func,
onSelectionTypeChange: PropTypes.func,
onOnlyLeavesChange: PropTypes.func,
};

export default TreeViewFinderConfig;
17 changes: 14 additions & 3 deletions demo/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';

import TopBar from '../../src/components/TopBar';
import SnackbarProvider from '../../src/components/SnackbarProvider';
Expand Down Expand Up @@ -197,6 +198,11 @@ const MyButton = (props) => {
);
};

MyButton.propTypes = {
variant: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
};

const AppContent = ({ language, onLanguageClick }) => {
const history = useHistory();
const location = useLocation();
Expand Down Expand Up @@ -372,11 +378,11 @@ const AppContent = ({ language, onLanguageClick }) => {
onSearchTermChange={searchMatchingEquipments}
onSelectionChange={displayEquipment}
elementsFound={equipmentsFound}
renderElement={(props) => (
renderElement={(args) => (
<EquipmentItem
classes={equipmentClasses}
{...props}
key={props.element.key}
{...args}
key={args.element.key}
/>
)}
onLanguageClick={onLanguageClick}
Expand Down Expand Up @@ -582,6 +588,11 @@ const AppContent = ({ language, onLanguageClick }) => {
);
};

AppContent.propTypes = {
language: PropTypes.string.isRequired,
onLanguageClick: PropTypes.func.isRequired,
};

const App = () => {
const [computedLanguage, setComputedLanguage] = useState(LANG_ENGLISH);
const [language, setLanguage] = useState(LANG_ENGLISH);
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@
"eslintConfig": {
"extends": [
"react-app",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:react/recommended"
],
"rules": {
"prettier/prettier": "warn",
"import/no-webpack-loader-syntax": "off"
"import/no-webpack-loader-syntax": "off",
"react/prop-types": 1
}
},
"author": "gridsuite team",
Expand Down
10 changes: 10 additions & 0 deletions src/components/AuthenticationRouter/AuthenticationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import { Redirect, Route, Switch } from 'react-router-dom';
import SignInCallbackHandler from '../SignInCallbackHandler';
import {
Expand Down Expand Up @@ -73,4 +74,13 @@ const AuthenticationRouter = ({
</React.Fragment>
);
};

AuthenticationRouter.propTypes = {
userManager: PropTypes.object,
signInCallbackError: PropTypes.func,
dispatch: PropTypes.func,
history: PropTypes.object,
location: PropTypes.object,
};

export default AuthenticationRouter;
13 changes: 11 additions & 2 deletions src/components/ElementSearchDialog/equipment-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { TagRenderer } from './index';
import match from 'autosuggest-highlight/match';
import parse from 'autosuggest-highlight/parse';
import clsx from 'clsx';
import { FormattedMessage } from 'react-intl';
import OverflowableText from '../OverflowableText';
import React from 'react';

import { EQUIPMENT_TYPE } from '../../utils/EquipmentType';

export const EquipmentItem = ({
Expand Down Expand Up @@ -53,8 +55,15 @@ export const EquipmentItem = ({
</span>
))}
</OverflowableText>
{suffixRenderer({ props, element })}
{suffixRenderer({ element, ...props })}
</div>
</li>
);
};

EquipmentItem.propTypes = {
inputValue: PropTypes.string,
element: PropTypes.any,
suffixRenderer: PropTypes.node,
classes: PropTypes.object,
};
8 changes: 4 additions & 4 deletions src/components/ElementSearchDialog/tag-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React from 'react';
import PropTypes from 'prop-types';
import OverflowableText from '../OverflowableText';
import clsx from 'clsx';
import React from 'react';
import { EQUIPMENT_TYPE } from '../../utils/EquipmentType';
import PropTypes from 'prop-types';

export const TagRenderer = ({ props, element }) => {
export const TagRenderer = ({ element, ...props }) => {
if (
element.type !== EQUIPMENT_TYPE.SUBSTATION.name &&
element.type !== EQUIPMENT_TYPE.VOLTAGE_LEVEL.name
Expand All @@ -29,5 +29,5 @@ export const TagRenderer = ({ props, element }) => {

TagRenderer.propTypes = {
element: PropTypes.object,
props: PropTypes.object,
classes: PropTypes.object.isRequired,
};
6 changes: 6 additions & 0 deletions src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React from 'react';
import PropTypes from 'prop-types';
import Avatar from '@mui/material/Avatar';
import Button from '@mui/material/Button';
import Link from '@mui/material/Link';
Expand Down Expand Up @@ -87,4 +88,9 @@ const Login = ({ onLoginClick, disabled }) => {
);
};

Login.propTypes = {
onLoginClick: PropTypes.func,
disabled: PropTypes.bool,
};

export default Login;
2 changes: 2 additions & 0 deletions src/components/MuiVirtualizedTable/MuiVirtualizedTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ MuiVirtualizedTable.propTypes = {
maxWidth: PropTypes.number,
unit: PropTypes.string,
fractionDigits: PropTypes.number,
clickable: PropTypes.bool,
})
).isRequired,
enableExportCSV: PropTypes.bool,
Expand All @@ -558,6 +559,7 @@ MuiVirtualizedTable.propTypes = {
rowHeight: PropTypes.number,
filter: PropTypes.func,
sort: PropTypes.func,
rowCount: PropTypes.number,
};

export default withStyles(defaultStyles)(MuiVirtualizedTable);
5 changes: 3 additions & 2 deletions src/components/OverflowableText/overflowable-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ export const OverflowableText = ({ text, className, children, ...props }) => {
<div
{...props}
ref={element}
children={children || text}
className={clsx(className, classes.overflow)}
/>
>
{children || text}
</div>
</Tooltip>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/components/ReportViewer/log-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import withStyles from '@mui/styles/withStyles';
import TableCell from '@mui/material/TableCell';
Expand Down Expand Up @@ -96,4 +97,8 @@ const LogTable = ({ logs }) => {
);
};

LogTable.propTypes = {
logs: PropTypes.array.isRequired,
};

export default memo(LogTable);
1 change: 1 addition & 0 deletions src/components/ReportViewer/report-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ReportItem.propTypes = {
color: PropTypes.string,
labelInfo: PropTypes.string,
labelText: PropTypes.string.isRequired,
labelIconColor: PropTypes.string,
};

export default ReportItem;
6 changes: 6 additions & 0 deletions src/components/ReportViewer/report-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { useCallback, useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import makeStyles from '@mui/styles/makeStyles';
import TreeView from '@mui/lab/TreeView';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
Expand Down Expand Up @@ -130,3 +131,8 @@ export default function ReportViewer({
)
);
}

ReportViewer.propTypes = {
jsonReport: PropTypes.object.isRequired,
maxSubReports: PropTypes.number,
};
8 changes: 8 additions & 0 deletions src/components/ReportViewerDialog/report-viewer-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { useState } from 'react';
import PropTypes from 'prop-types';
import makeStyles from '@mui/styles/makeStyles';
import DialogTitle from '@mui/material/DialogTitle';
import DialogActions from '@mui/material/DialogActions';
Expand Down Expand Up @@ -74,3 +75,10 @@ export default function ReportViewerDialog(props) {
</Dialog>
);
}

ReportViewerDialog.propTypes = {
title: PropTypes.string,
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
jsonReport: PropTypes.object.isRequired,
};
7 changes: 7 additions & 0 deletions src/components/SignInCallbackHandler/SignInCallbackHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { useEffect } from 'react';
import PropTypes from 'prop-types';

const SignInCallbackHandler = ({ userManager, handleSignInCallback }) => {
useEffect(() => {
Expand All @@ -16,4 +17,10 @@ const SignInCallbackHandler = ({ userManager, handleSignInCallback }) => {

return <h1> </h1>;
};

SignInCallbackHandler.propTypes = {
userManager: PropTypes.object,
handleSignInCallback: PropTypes.func,
};

export default SignInCallbackHandler;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { useEffect } from 'react';
import PropTypes from 'prop-types';

const SilentRenewCallbackHandler = ({
userManager,
Expand All @@ -20,4 +21,9 @@ const SilentRenewCallbackHandler = ({
return <h1>Technical token renew window, you should not see this</h1>;
};

SilentRenewCallbackHandler.propTypes = {
userManager: PropTypes.object,
handleSilentRenewCallback: PropTypes.func,
};

export default SilentRenewCallbackHandler;
2 changes: 2 additions & 0 deletions src/components/SnackbarProvider/SnackbarProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ const SnackbarProvider = React.forwardRef((props, ref) => {
);
});

SnackbarProvider.displayName = 'SnackbarProvider';

export default SnackbarProvider;
1 change: 1 addition & 0 deletions src/components/TopBar/TopBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ TopBar.propTypes = {
onSearchTermChange: PropTypes.func,
onSelectionChange: PropTypes.func,
elementsFound: PropTypes.array,
renderElement: PropTypes.func,
onLanguageClick: PropTypes.func.isRequired,
language: PropTypes.string.isRequired,
};
Expand Down