From 2961dc3d123f95cb5f31bccb70fdb2c81ffe5838 Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Thu, 6 Jun 2024 16:57:08 +0200 Subject: [PATCH] Fix linting issues --- .eslintrc.js | 7 +-- .prettierrc | 11 ---- package-lock.json | 2 - package.json | 2 - prettier.config.js | 1 + src/api/hooks.js | 13 ++++- src/bootstrap/Alert.js | 7 ++- src/bootstrap/Button.js | 13 ++--- src/bootstrap/CheckBox.js | 7 ++- src/bootstrap/CopyInput.js | 10 +++- src/bootstrap/DataTimeInput.js | 15 +++-- src/bootstrap/DownloadButton.js | 7 ++- src/bootstrap/EmailInput.js | 9 ++- src/bootstrap/FileInput.js | 9 ++- src/bootstrap/Input.js | 9 ++- src/bootstrap/Modal.js | 5 +- src/bootstrap/NumberInput.js | 9 ++- src/bootstrap/PasswordInput.js | 9 ++- src/bootstrap/RadioSet.js | 55 ++++++++----------- src/bootstrap/Select.js | 7 ++- src/bootstrap/Spinner.js | 1 + src/bootstrap/Switch.js | 11 ++-- src/bootstrap/TextInput.js | 11 +++- src/bootstrap/__tests__/Button.test.js | 2 +- src/bootstrap/constants.js | 9 +-- src/common/RebootButton.js | 16 +++--- src/common/WiFiSettings/ResetWiFiSettings.js | 17 +++--- src/common/WiFiSettings/WiFiForm.js | 20 ++++--- src/common/WiFiSettings/WiFiGuestForm.js | 11 ++-- src/common/WiFiSettings/WiFiQRCode.js | 11 ++-- src/common/WiFiSettings/WiFiSettings.js | 11 ++-- src/context/alertContext/AlertContext.js | 15 +++-- .../CustomizationContext.js | 37 ++++++++----- src/form/__tests__/hooks.test.js | 2 +- src/form/components/ForisForm.js | 28 +++++----- src/form/components/SubmitButton.js | 3 +- src/form/hooks.js | 5 +- src/index.js | 54 +++++++++--------- src/utils/ErrorMessage.js | 7 ++- src/utils/Portal.js | 12 +++- src/utils/conditionalHOCs.js | 21 ++++--- src/utils/datetime.js | 7 +-- src/utils/displayCard.js | 6 +- src/utils/isPluginInstalled.js | 6 +- src/utils/validations.js | 9 ++- src/webSockets/WebSockets.js | 8 +-- src/webSockets/hooks.js | 7 ++- 47 files changed, 318 insertions(+), 236 deletions(-) delete mode 100644 .prettierrc create mode 100644 prettier.config.js diff --git a/.eslintrc.js b/.eslintrc.js index 28be3ff..4805082 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,8 +1,3 @@ module.exports = { - extends: ["eslint-config-reforis", "prettier"], - plugins: ["prettier"], - rules: { - "prettier/prettier": ["error"], - "import/prefer-default-export": "off", - }, + extends: "eslint-config-reforis", }; diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 4bf5696..0000000 --- a/.prettierrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "singleQuote": false, - "printWidth": 80, - "proseWrap": "always", - "tabWidth": 4, - "useTabs": false, - "trailingComma": "es5", - "bracketSpacing": true, - "jsxBracketSameLine": false, - "semi": true -} diff --git a/package-lock.json b/package-lock.json index 3881dd7..2efc39f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,9 +29,7 @@ "bootstrap": "^5.3.3", "css-loader": "^5.2.4", "eslint": "^8.57.0", - "eslint-config-prettier": "^9.1.0", "eslint-config-reforis": "^2.1.1", - "eslint-plugin-prettier": "^5.1.3", "file-loader": "^6.0.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", diff --git a/package.json b/package.json index 7c85179..373c910 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,7 @@ "bootstrap": "^5.3.3", "css-loader": "^5.2.4", "eslint": "^8.57.0", - "eslint-config-prettier": "^9.1.0", "eslint-config-reforis": "^2.1.1", - "eslint-plugin-prettier": "^5.1.3", "file-loader": "^6.0.0", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..b6ff535 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1 @@ +module.exports = require("eslint-config-reforis/prettier.config"); diff --git a/src/api/hooks.js b/src/api/hooks.js index 65a0bb1..cd50959 100644 --- a/src/api/hooks.js +++ b/src/api/hooks.js @@ -111,9 +111,7 @@ const useAPIPatch = createAPIHook("PATCH"); const useAPIPut = createAPIHook("PUT"); const useAPIDelete = createAPIHook("DELETE"); -export { useAPIGet, useAPIPost, useAPIPatch, useAPIPut, useAPIDelete }; - -export function useAPIPolling(endpoint, delay = 1000, until) { +function useAPIPolling(endpoint, until, delay = 1000) { // delay ms const [state, setState] = useState({ state: API_STATE.INIT }); const [getResponse, get] = useAPIGet(endpoint); @@ -133,3 +131,12 @@ export function useAPIPolling(endpoint, delay = 1000, until) { return [state]; } + +export { + useAPIGet, + useAPIPost, + useAPIPatch, + useAPIPut, + useAPIDelete, + useAPIPolling, +}; diff --git a/src/bootstrap/Alert.js b/src/bootstrap/Alert.js index b6a4860..7b7af79 100644 --- a/src/bootstrap/Alert.js +++ b/src/bootstrap/Alert.js @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; export const ALERT_TYPES = Object.freeze({ @@ -35,7 +36,7 @@ Alert.defaultProps = { type: ALERT_TYPES.DANGER, }; -export function Alert({ type, onDismiss, children }) { +function Alert({ type, onDismiss, children }) { return (
); } + +export default Alert; diff --git a/src/bootstrap/Button.js b/src/bootstrap/Button.js index 5817f3a..b609116 100644 --- a/src/bootstrap/Button.js +++ b/src/bootstrap/Button.js @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019-2023 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; Button.propTypes = { @@ -24,13 +25,7 @@ Button.propTypes = { ]).isRequired, }; -export function Button({ - className, - loading, - forisFormSize, - children, - ...props -}) { +function Button({ className, loading, forisFormSize, children, ...props }) { let buttonClass = className ? `btn ${className}` : "btn btn-primary"; if (forisFormSize) { buttonClass = `${buttonClass} col-12 col-md-3 col-lg-2`; @@ -53,3 +48,5 @@ export function Button({ ); } + +export default Button; diff --git a/src/bootstrap/CheckBox.js b/src/bootstrap/CheckBox.js index 890e8b7..0f7da40 100644 --- a/src/bootstrap/CheckBox.js +++ b/src/bootstrap/CheckBox.js @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; import { useUID } from "react-uid"; @@ -22,7 +23,7 @@ CheckBox.defaultProps = { disabled: false, }; -export function CheckBox({ label, helpText, disabled, ...props }) { +function CheckBox({ label, helpText, disabled, ...props }) { const uid = useUID(); return ( @@ -45,3 +46,5 @@ export function CheckBox({ label, helpText, disabled, ...props }) {
); } + +export default CheckBox; diff --git a/src/bootstrap/CopyInput.js b/src/bootstrap/CopyInput.js index c87329b..1e1e1cc 100644 --- a/src/bootstrap/CopyInput.js +++ b/src/bootstrap/CopyInput.js @@ -1,13 +1,15 @@ /* - * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React, { useState, useRef } from "react"; + import PropTypes from "prop-types"; -import { Input } from "./Input"; + +import Input from "./Input"; CopyInput.propTypes = { /** Field label. */ @@ -22,7 +24,7 @@ CopyInput.propTypes = { readOnly: PropTypes.bool, }; -export function CopyInput({ value, ...props }) { +function CopyInput({ value, ...props }) { const inputTextRef = useRef(); const [isCopied, setIsCopied] = useState(false); @@ -58,3 +60,5 @@ export function CopyInput({ value, ...props }) { ); } + +export default CopyInput; diff --git a/src/bootstrap/DataTimeInput.js b/src/bootstrap/DataTimeInput.js index 558ec17..53fe5f6 100644 --- a/src/bootstrap/DataTimeInput.js +++ b/src/bootstrap/DataTimeInput.js @@ -1,18 +1,19 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + +import moment from "moment/moment"; import PropTypes from "prop-types"; import Datetime from "react-datetime"; -import moment from "moment/moment"; import "react-datetime/css/react-datetime.css"; import "./DataTimeInput.css"; -import { Input } from "./Input"; +import Input from "./Input"; DataTimeInput.propTypes = { /** Field label. */ @@ -37,7 +38,7 @@ DataTimeInput.propTypes = { const DEFAULT_DATE_FORMAT = "YYYY-MM-DD"; const DEFAULT_TIME_FORMAT = "HH:mm:ss"; -export function DataTimeInput({ +function DataTimeInput({ value, onChange, isValidDate, @@ -46,13 +47,13 @@ export function DataTimeInput({ children, ...props }) { - function renderInput(datetimeProps) { + const renderInput = (datetimeProps) => { return ( {children} ); - } + }; return ( ); } + +export default DataTimeInput; diff --git a/src/bootstrap/DownloadButton.js b/src/bootstrap/DownloadButton.js index dfd5ef8..1cb0ca7 100644 --- a/src/bootstrap/DownloadButton.js +++ b/src/bootstrap/DownloadButton.js @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; DownloadButton.propTypes = { @@ -21,7 +22,7 @@ DownloadButton.defaultProps = { className: "btn-primary", }; -export function DownloadButton({ href, className, children, ...props }) { +function DownloadButton({ href, className, children, ...props }) { return ( ); } + +export default DownloadButton; diff --git a/src/bootstrap/EmailInput.js b/src/bootstrap/EmailInput.js index 18d3a39..2ce291b 100644 --- a/src/bootstrap/EmailInput.js +++ b/src/bootstrap/EmailInput.js @@ -6,11 +6,14 @@ */ import React from "react"; + import PropTypes from "prop-types"; -import { Input } from "./Input"; +import Input from "./Input"; -export const EmailInput = ({ ...props }) => ; +function EmailInput({ ...props }) { + return ; +} EmailInput.propTypes = { /** Field label. */ @@ -22,3 +25,5 @@ EmailInput.propTypes = { /** Email value. */ value: PropTypes.string, }; + +export default EmailInput; diff --git a/src/bootstrap/FileInput.js b/src/bootstrap/FileInput.js index f40daed..548dfc2 100644 --- a/src/bootstrap/FileInput.js +++ b/src/bootstrap/FileInput.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. @@ -8,7 +8,8 @@ import React from "react"; import PropTypes from "prop-types"; -import { Input } from "./Input"; + +import Input from "./Input"; FileInput.propTypes = { /** Field label. */ @@ -23,7 +24,7 @@ FileInput.propTypes = { multiple: PropTypes.bool, }; -export function FileInput({ ...props }) { +function FileInput({ ...props }) { return ( ); } + +export default FileInput; diff --git a/src/bootstrap/Input.js b/src/bootstrap/Input.js index 32adc66..9f098b0 100644 --- a/src/bootstrap/Input.js +++ b/src/bootstrap/Input.js @@ -6,11 +6,12 @@ */ import React, { forwardRef } from "react"; -import { useUID } from "react-uid"; + import PropTypes from "prop-types"; +import { useUID } from "react-uid"; /** Base bootstrap input component. */ -export const Input = forwardRef( +const Input = forwardRef( ( { type, @@ -60,6 +61,8 @@ export const Input = forwardRef( } ); +Input.displayName = "Input"; + Input.propTypes = { type: PropTypes.string.isRequired, label: PropTypes.string.isRequired, @@ -73,3 +76,5 @@ Input.propTypes = { labelClassName: PropTypes.string, groupClassName: PropTypes.string, }; + +export default Input; diff --git a/src/bootstrap/Modal.js b/src/bootstrap/Modal.js index 6ba1d7c..aee202b 100644 --- a/src/bootstrap/Modal.js +++ b/src/bootstrap/Modal.js @@ -1,15 +1,16 @@ /* - * Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2020-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React, { useRef, useEffect } from "react"; + import PropTypes from "prop-types"; -import { Portal } from "../utils/Portal"; import { useClickOutside } from "../utils/hooks"; +import Portal from "../utils/Portal"; import "./Modal.css"; Modal.propTypes = { diff --git a/src/bootstrap/NumberInput.js b/src/bootstrap/NumberInput.js index 9ba90da..3da4bc6 100644 --- a/src/bootstrap/NumberInput.js +++ b/src/bootstrap/NumberInput.js @@ -1,15 +1,16 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; +import Input from "./Input"; import { useConditionalTimeout } from "../utils/hooks"; -import { Input } from "./Input"; import "./NumberInput.css"; NumberInput.propTypes = { @@ -31,7 +32,7 @@ NumberInput.defaultProps = { value: 0, }; -export function NumberInput({ onChange, inlineText, value, ...props }) { +function NumberInput({ onChange, inlineText, value, ...props }) { function updateValue(initialValue, difference) { onChange({ target: { value: initialValue + difference } }); } @@ -73,3 +74,5 @@ export function NumberInput({ onChange, inlineText, value, ...props }) { ); } + +export default NumberInput; diff --git a/src/bootstrap/PasswordInput.js b/src/bootstrap/PasswordInput.js index 81525f4..104d18a 100644 --- a/src/bootstrap/PasswordInput.js +++ b/src/bootstrap/PasswordInput.js @@ -1,14 +1,15 @@ /* - * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React, { useState } from "react"; + import PropTypes from "prop-types"; -import { Input } from "./Input"; +import Input from "./Input"; PasswordInput.propTypes = { /** Field label. */ @@ -25,7 +26,7 @@ PasswordInput.propTypes = { newPass: PropTypes.bool, }; -export function PasswordInput({ withEye, newPass, ...props }) { +function PasswordInput({ withEye, newPass, ...props }) { const [isHidden, setHidden] = useState(true); return ( @@ -51,3 +52,5 @@ export function PasswordInput({ withEye, newPass, ...props }) { ); } + +export default PasswordInput; diff --git a/src/bootstrap/RadioSet.js b/src/bootstrap/RadioSet.js index e549ebc..b3990c3 100644 --- a/src/bootstrap/RadioSet.js +++ b/src/bootstrap/RadioSet.js @@ -1,11 +1,12 @@ /* - * Copyright (C) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2020-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; import { useUID } from "react-uid"; @@ -36,15 +37,7 @@ RadioSet.propTypes = { inline: PropTypes.bool, }; -export function RadioSet({ - name, - label, - choices, - value, - helpText, - inline, - ...props -}) { +function RadioSet({ name, label, choices, value, helpText, inline, ...props }) { const uid = useUID(); const radios = choices.map((choice, key) => { const id = `${name}-${key}`; @@ -94,27 +87,25 @@ Radio.propTypes = { export function Radio({ label, id, helpText, inline, ...props }) { return ( - <> -
- - -
- +
+ + +
); } + +export default RadioSet; diff --git a/src/bootstrap/Select.js b/src/bootstrap/Select.js index b79297e..71df6c9 100644 --- a/src/bootstrap/Select.js +++ b/src/bootstrap/Select.js @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; import { useUID } from "react-uid"; @@ -20,7 +21,7 @@ Select.propTypes = { helpText: PropTypes.string, }; -export function Select({ label, choices, helpText, ...props }) { +function Select({ label, choices, helpText, ...props }) { const uid = useUID(); const options = Object.keys(choices).map((choice) => ( @@ -45,3 +46,5 @@ export function Select({ label, choices, helpText, ...props }) { ); } + +export default Select; diff --git a/src/bootstrap/Spinner.js b/src/bootstrap/Spinner.js index 0042154..dd9162d 100644 --- a/src/bootstrap/Spinner.js +++ b/src/bootstrap/Spinner.js @@ -6,6 +6,7 @@ */ import React from "react"; + import PropTypes from "prop-types"; import "./Spinner.css"; diff --git a/src/bootstrap/Switch.js b/src/bootstrap/Switch.js index de10cc8..de5180e 100644 --- a/src/bootstrap/Switch.js +++ b/src/bootstrap/Switch.js @@ -1,11 +1,12 @@ /* - * Copyright (c) 2020 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (c) 2020-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; import { useUID } from "react-uid"; @@ -20,7 +21,7 @@ Switch.propTypes = { switchHeading: PropTypes.bool, }; -export function Switch({ label, helpText, switchHeading, ...props }) { +function Switch({ label, helpText, switchHeading, ...props }) { const uid = useUID(); return ( @@ -31,9 +32,7 @@ export function Switch({ label, helpText, switchHeading, ...props }) { > ); } + +export default Switch; diff --git a/src/bootstrap/TextInput.js b/src/bootstrap/TextInput.js index be60bb6..cde593b 100644 --- a/src/bootstrap/TextInput.js +++ b/src/bootstrap/TextInput.js @@ -1,16 +1,19 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. */ import React from "react"; + import PropTypes from "prop-types"; -import { Input } from "./Input"; +import Input from "./Input"; -export const TextInput = ({ ...props }) => ; +function TextInput({ ...props }) { + return ; +} TextInput.propTypes = { /** Field label. */ @@ -20,3 +23,5 @@ TextInput.propTypes = { /** Help text message. */ helpText: PropTypes.string, }; + +export default TextInput; diff --git a/src/bootstrap/__tests__/Button.test.js b/src/bootstrap/__tests__/Button.test.js index 3249526..31c6d16 100644 --- a/src/bootstrap/__tests__/Button.test.js +++ b/src/bootstrap/__tests__/Button.test.js @@ -9,7 +9,7 @@ import React from "react"; import { render } from "customTestRender"; -import { Button } from "../Button"; +import Button from "../Button"; describe("