Skip to content

Commit

Permalink
Merge pull request #1973 from AntaresSimulatorTeam/feature/add_eslint…
Browse files Browse the repository at this point in the history
…_rules
  • Loading branch information
skamril authored Mar 8, 2024
2 parents add0c63 + 7616429 commit 5dcfcbb
Show file tree
Hide file tree
Showing 25 changed files with 270 additions and 76 deletions.
8 changes: 8 additions & 0 deletions webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ module.exports = {
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jsdoc/recommended-typescript",
"plugin:prettier/recommended",
],
plugins: ["react-refresh"],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
parserOptions: {
// `ecmaVersion` is automatically sets by `esXXXX` in `env`
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
Expand All @@ -41,6 +43,10 @@ module.exports = {
],
},
],
curly: "error",
"jsdoc/require-hyphen-before-param-description": "warn",
"jsdoc/require-jsdoc": "off",
"jsdoc/tag-lines": ["warn", "any", { "startLines": 1 }], // Expected 1 line after block description
"no-param-reassign": [
"error",
{
Expand All @@ -65,6 +71,8 @@ module.exports = {
"warn",
{ allowConstantExport: true },
],
"react/hook-use-state": "error",
"react/prop-types": "off",
"react/self-closing-comp": "error",
},
};
120 changes: 117 additions & 3 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"@vitejs/plugin-react-swc": "3.5.0",
"eslint": "8.55.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-jsdoc": "48.2.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/components/App/Data/DatasetCreationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ function DatasetCreationDialog(props: PropTypes) {
const [name, setName] = useState<string>("");
const [isJson, setIsJson] = useState(false);
const [uploadProgress, setUploadProgress] = useState<number>(0);
const [currentFile, setFile] = useState<File | undefined>();
const [currentFile, setCurrentFile] = useState<File | undefined>();
const [importing, setImporting] = useState(false);
const [publicStatus, setPublic] = useState<boolean>(false);
const [publicStatus, setPublicStatus] = useState<boolean>(false);

const onSave = async () => {
let closeModal = true;
Expand Down Expand Up @@ -93,7 +93,7 @@ function DatasetCreationDialog(props: PropTypes) {
const onUpload = (e: ChangeEvent<HTMLInputElement>) => {
const { target } = e;
if (target && target.files && target.files.length === 1) {
setFile(target.files[0]);
setCurrentFile(target.files[0]);
}
};

Expand All @@ -116,7 +116,7 @@ function DatasetCreationDialog(props: PropTypes) {

if (data) {
setSelectedGroupList(data.groups);
setPublic(data.public);
setPublicStatus(data.public);
setName(data.name);
}
} catch (e) {
Expand Down Expand Up @@ -249,7 +249,7 @@ function DatasetCreationDialog(props: PropTypes) {
<ParamTitle>{t("global.public")}</ParamTitle>
<Checkbox
checked={publicStatus}
onChange={() => setPublic(!publicStatus)}
onChange={() => setPublicStatus(!publicStatus)}
inputProps={{ "aria-label": "primary checkbox" }}
/>
</BoxParamHeader>
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/components/App/Data/MatrixDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function MatrixDialog(props: PropTypes) {
const [t] = useTranslation();
const enqueueErrorSnackbar = useEnqueueErrorSnackbar();
const [loading, setLoading] = useState(false);
const [matrix, setCurrentMatrix] = useState<MatrixType>({
const [matrix, setMatrix] = useState<MatrixType>({
index: [],
columns: [],
data: [],
Expand All @@ -34,7 +34,7 @@ function MatrixDialog(props: PropTypes) {
columns: matrix ? res.columns : [],
data: matrix ? res.data : [],
};
setCurrentMatrix(matrixContent);
setMatrix(matrixContent);
}
} catch (error) {
enqueueErrorSnackbar(t("data.error.matrix"), error as AxiosError);
Expand All @@ -44,7 +44,7 @@ function MatrixDialog(props: PropTypes) {
};
init();
return () => {
setCurrentMatrix({ index: [], columns: [], data: [] });
setMatrix({ index: [], columns: [], data: [] });
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [enqueueErrorSnackbar, matrixInfo, t]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Json({ path, studyId }: Props) {
const { enqueueSnackbar } = useSnackbar();
const enqueueErrorSnackbar = useEnqueueErrorSnackbar();
const [jsonData, setJsonData] = useState<string | null>(null);
const [isSaveAllowed, setSaveAllowed] = useState(false);
const [isSaveAllowed, setIsSaveAllowed] = useState(false);

const res = usePromiseWithSnackbarError(
() => getStudyData(studyId, path, -1),
Expand All @@ -34,7 +34,7 @@ function Json({ path, studyId }: Props) {

// Reset save button when path changes
useUpdateEffect(() => {
setSaveAllowed(false);
setIsSaveAllowed(false);
}, [studyId, path]);

////////////////////////////////////////////////////////////////
Expand All @@ -48,7 +48,7 @@ function Json({ path, studyId }: Props) {
enqueueSnackbar(t("studies.success.saveData"), {
variant: "success",
});
setSaveAllowed(false);
setIsSaveAllowed(false);
} catch (e) {
enqueueErrorSnackbar(t("studies.error.saveData"), e as AxiosError);
}
Expand All @@ -57,7 +57,7 @@ function Json({ path, studyId }: Props) {

const handleJsonChange = (newJson: string) => {
setJsonData(newJson);
setSaveAllowed(true);
setIsSaveAllowed(true);
};

////////////////////////////////////////////////////////////////
Expand Down
19 changes: 10 additions & 9 deletions webapp/src/components/App/Singlestudy/explore/Debug/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export type TreeData = Record<string, any> | string;
// Utils
////////////////////////////////////////////////////////////////

/**
* Maps file types and folder to their corresponding icon components.
*/
//Maps file types and folder to their corresponding icon components.
const iconByFileType: Record<FileType | "folder", SvgIconComponent> = {
matrix: DatasetIcon,
json: DataObjectIcon,
Expand All @@ -34,17 +32,19 @@ const iconByFileType: Record<FileType | "folder", SvgIconComponent> = {

/**
* Gets the icon component for a given file type or folder.
* @param {FileType | "folder"} type - The type of the file or "folder".
* @returns {SvgIconComponent} The corresponding icon component.
*
* @param type - The type of the file or "folder".
* @returns The corresponding icon component.
*/
export const getFileIcon = (type: FileType | "folder"): SvgIconComponent => {
return iconByFileType[type] || TextSnippetIcon;
};

/**
* Determines the file type based on the tree data.
* @param {TreeData} treeData - The data of the tree item.
* @returns {FileType | "folder"} The determined file type or "folder".
*
* @param treeData - The data of the tree item.
* @returns The determined file type or "folder".
*/
export const determineFileType = (treeData: TreeData): FileType | "folder" => {
if (typeof treeData === "string") {
Expand All @@ -63,8 +63,9 @@ export const determineFileType = (treeData: TreeData): FileType | "folder" => {

/**
* Filters out specific keys from the tree data.
* @param {TreeData} data - The original tree data.
* @returns {TreeData} The filtered tree data.
*
* @param data - The original tree data.
* @returns The filtered tree data.
*/
export const filterTreeData = (data: TreeData): TreeData => {
const excludedKeys = new Set(["Desktop", "study", "logs"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ export const MATRICES: Matrices = {

/**
* Generates an array of column names from 0 to 100, optionally with a suffix.
* @param columnSuffix The suffix to append to the column names.
*
* @param columnSuffix - The suffix to append to the column names.
* @returns An array of strings representing column names from 0 to 100.
*/
function generateColumns(columnSuffix = ""): string[] {
Expand Down
Loading

0 comments on commit 5dcfcbb

Please sign in to comment.