From a1b76fce167475ebdae6a9fc571a7ca6c2821a5e Mon Sep 17 00:00:00 2001 From: Medzik <87065584+MedzikUser@users.noreply.github.com> Date: Mon, 9 Aug 2021 14:21:08 +0000 Subject: [PATCH] feat(lint): add eslint --- .eslintrc.json | 25 +++++++++++++++++++++++++ .github/workflows/lint.yml | 21 +++++++++++++++++++++ .gitpod.Dockerfile | 2 +- package.json | 7 ++++++- src/axios.js | 4 ++-- src/pages/add.js | 14 +++++++------- src/pages/delete.js | 12 ++++++------ yarn.lock | 4 ++-- 8 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .github/workflows/lint.yml diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..d0fc778 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "env": { + "browser": true, + "es2021": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended" + ], + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "react" + ], + "rules": { + "semi": [ "error", "never" ], + "quotes": [ "error", "double" ] + } +} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..7c9cc90 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +name: Lint + +on: + pull_request: + push: + +jobs: + eslint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup node + uses: actions/setup-node@v2 + with: + node-version: '14' + cache: 'yarn' + - name: Install dependencies + run: yarn + - name: ESLint + run: yarn run eslint . diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 1356497..b5f63db 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1,7 +1,7 @@ FROM gitpod/workspace-full # Install cli tools -RUN yarn global add gatsby vercel +RUN yarn global add gatsby vercel eslint RUN echo "export PATH=\$PATH:`yarn global bin`" >> ~/.bashrc diff --git a/package.json b/package.json index 2a3fe6f..782db6c 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "start": "gatsby develop", "build": "gatsby build", "serve": "gatsby serve", - "clean": "gatsby clean" + "clean": "gatsby clean", + "lint": "eslint . --fix" }, "dependencies": { "axios": "0.21.1", @@ -29,5 +30,9 @@ "react-helmet": "6.1.0", "react-notifications": "1.7.2", "sass": "1.37.5" + }, + "devDependencies": { + "eslint": "^7.32.0", + "eslint-plugin-react": "^7.24.0" } } diff --git a/src/axios.js b/src/axios.js index 71c0097..f0f77f4 100644 --- a/src/axios.js +++ b/src/axios.js @@ -1,7 +1,7 @@ -import axios from 'axios' +import axios from "axios" const instance = axios.create({ - baseURL: process.env.API_URL || 'https://backend.pingbot.cf/api', + baseURL: process.env.API_URL || "https://backend.pingbot.cf/api", }) export default instance diff --git a/src/pages/add.js b/src/pages/add.js index d1bfb11..5be99a7 100644 --- a/src/pages/add.js +++ b/src/pages/add.js @@ -9,7 +9,7 @@ import "../css/url.sass" import "../css/notifications.sass" const AddURLPage = () => { - const [url, setURL] = React.useState('') + const [url, setURL] = React.useState("") const handleKeypress = e => { if (e.charCode === 13 || e.keyCode === 13) { @@ -23,22 +23,22 @@ const AddURLPage = () => { } const addURL = async () => { - setURL('') + setURL("") - if (url === '') { - return NotificationManager.error('Empty') + if (url === "") { + return NotificationManager.error("Empty") } try { - const res = await axios.post('/url', { + const res = await axios.post("/url", { url: url, }) const data = res.data - NotificationManager.success(data.url, 'Added') + NotificationManager.success(data.url, "Added") } catch (err) { - let e = '' + let e = "" if (err.response && err.response.data.message) { e = err.response.data.message diff --git a/src/pages/delete.js b/src/pages/delete.js index 81595fb..bfe5420 100644 --- a/src/pages/delete.js +++ b/src/pages/delete.js @@ -9,7 +9,7 @@ import "../css/url.sass" import "../css/notifications.sass" const DeleteURLPage = () => { - const [url, setURL] = React.useState('') + const [url, setURL] = React.useState("") const handleKeypress = e => { if (e.charCode === 13 || e.keyCode === 13) { @@ -23,10 +23,10 @@ const DeleteURLPage = () => { } const deleteURL = async () => { - setURL('') + setURL("") - if (url === '') { - return NotificationManager.error('Empty') + if (url === "") { + return NotificationManager.error("Empty") } try { @@ -38,9 +38,9 @@ const DeleteURLPage = () => { const data = res.data - NotificationManager.success(data.url, 'Deleted') + NotificationManager.success(data.url, "Deleted") } catch (err) { - let e = '' + let e = "" if (err.response && err.response.data.message) { e = err.response.data.message diff --git a/yarn.lock b/yarn.lock index 3c7c387..1745b33 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4175,7 +4175,7 @@ eslint-plugin-react-hooks@^4.2.0: resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.2.0.tgz#8c229c268d468956334c943bb45fc860280f5556" integrity sha512-623WEiZJqxR7VdxFCKLI6d6LLpwJkGPYKODnkH3D7WpOG5KM8yWueBd8TLsNAetEJNF5iJmolaAKO3F8yzyVBQ== -eslint-plugin-react@^7.23.1: +eslint-plugin-react@^7.23.1, eslint-plugin-react@^7.24.0: version "7.24.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.24.0.tgz#eadedfa351a6f36b490aa17f4fa9b14e842b9eb4" integrity sha512-KJJIx2SYx7PBx3ONe/mEeMz4YE0Lcr7feJTCMyyKb/341NcjuAgim3Acgan89GfPv7nxXK2+0slu0CWXYM4x+Q== @@ -4237,7 +4237,7 @@ eslint-webpack-plugin@^2.5.3: normalize-path "^3.0.0" schema-utils "^3.0.0" -eslint@^7.20.0: +eslint@^7.20.0, eslint@^7.32.0: version "7.32.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d" integrity sha512-VHZ8gX+EDfz+97jGcgyGCyRia/dPOd6Xh9yPv8Bl1+SoaIwD+a/vlrOmGRUyOYu7MwUhc7CxqeaDZU13S4+EpA==