From 3748a2ebbda98467b7c553599f18a03e79fa0c30 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sun, 18 Apr 2021 10:42:57 +0100 Subject: [PATCH] Switch to eslint. --- .babelrc | 0 .eslintrc.yml | 24 +++++++++++++++++++++++ .jshintrc | 22 --------------------- package.json | 3 +++ runLinter.sh | 3 +++ src/PageState.js | 10 +++++----- src/pages/KeyValue/KeyValueSecrets.js | 6 +++--- src/pages/KeyValue/KeyValueSecretsEdit.js | 2 +- src/pages/Login.js | 2 +- src/pages/PwGen.js | 2 +- src/pages/TOTP/NewTOTP.js | 2 +- src/pages/TOTP/TOTPView.js | 2 +- src/pages/Transit/TransitEncrypt.js | 2 +- src/pages/Unseal.js | 2 +- src/scss/main.scss | 1 - 15 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 .babelrc create mode 100644 .eslintrc.yml delete mode 100644 .jshintrc create mode 100755 runLinter.sh diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..e69de29 diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..e1c36d1 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,24 @@ +--- +extends: + - eslint:recommended + - plugin:import/errors + - plugin:import/warnings + +parserOptions: + ecmaVersion: 8 + sourceType: module + +globals: + pageState: writable + pageContent: writable + realPages: writable + + +rules: + no-unused-vars: + - 2 + - argsIgnorePattern: ^_ + +env: + browser: true + es6: true diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 76d41ad..0000000 --- a/.jshintrc +++ /dev/null @@ -1,22 +0,0 @@ -{ - "esversion": 8, - "browser": true, - "onevar": true, - "passfail": false, - "white": true, - "maxerr": 100, - "predef": [ - "define", - "require", - "console", - "ClipboardJS", - "UIkit", - "Prism", - "CodeJar", - "moment" - ], - "indent": 2, - "globals": { - - } -} \ No newline at end of file diff --git a/package.json b/package.json index e6f9575..6afddfd 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,12 @@ { "devDependencies": { + "@babel/eslint-parser": "^7.13.14", "clipboard": "^2.0.8", "codejar": "^3.4.0", "css-loader": "^5.2.1", "date-fns": "^2.21.1", + "eslint": "^7.24.0", + "eslint-plugin-import": "^2.22.1", "file-saver": "^2.0.5", "html-webpack-plugin": "^5.3.1", "mini-css-extract-plugin": "^1.4.1", diff --git a/runLinter.sh b/runLinter.sh new file mode 100755 index 0000000..b707134 --- /dev/null +++ b/runLinter.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +npx eslint -c .eslintrc.yml src diff --git a/src/PageState.js b/src/PageState.js index 0cc8a54..0c7ebfc 100644 --- a/src/PageState.js +++ b/src/PageState.js @@ -22,7 +22,7 @@ export class PageState extends Page { return localStorage.getItem('currentBaseMount') || ""; } set currentBaseMount(value) { - return localStorage.setItem('currentBaseMount', value); + localStorage.setItem('currentBaseMount', value); } @@ -43,28 +43,28 @@ export class PageState extends Page { return JSON.parse(localStorage.getItem('currentSecretPath') || "[]"); } set currentSecretPath(value) { - return localStorage.setItem('currentSecretPath', JSON.stringify(value)); + localStorage.setItem('currentSecretPath', JSON.stringify(value)); } get currentSecretVersion() { return localStorage.getItem('currentSecretVersion') || "0"; } set currentSecretVersion(value) { - return localStorage.setItem('currentSecretVersion', value); + localStorage.setItem('currentSecretVersion', value); } get currentSecret() { return localStorage.getItem('currentSecret') || ""; } set currentSecret(value) { - return localStorage.setItem('currentSecret', value); + localStorage.setItem('currentSecret', value); } get currentMountType() { return localStorage.getItem('currentMountType') || ""; } set currentMountType(value) { - return localStorage.setItem('currentMountType', value); + localStorage.setItem('currentMountType', value); } get currentPage() { let curPage = localStorage.getItem('currentPage') || "HOME"; diff --git a/src/pages/KeyValue/KeyValueSecrets.js b/src/pages/KeyValue/KeyValueSecrets.js index a1f6c3f..ef7eaf5 100644 --- a/src/pages/KeyValue/KeyValueSecrets.js +++ b/src/pages/KeyValue/KeyValueSecrets.js @@ -108,7 +108,7 @@ export class KeyValueSecretsPage extends Page { pageState.currentSecretPath, pageState.currentSecret, pageState.currentSecretVersion - ).then(resp => { + ).then(_ => { changePage(pageState.currentPage); }); }, @@ -118,7 +118,7 @@ export class KeyValueSecretsPage extends Page { const secretsMap = new Map(Object.entries(secretInfo).sort()); - for (let [key, value] of secretsMap) { + for (let value of secretsMap.values()) { if (typeof value == 'object') isSecretNestedJson = true; } @@ -130,7 +130,7 @@ export class KeyValueSecretsPage extends Page { html: Prism.highlight(jsonText, Prism.languages.json, 'json') })); } else { - secretsMap.forEach(function (value, key) { + secretsMap.forEach((value, key) => { let kvListElement = this.makeKVListElement(key, value); kvList.appendChild(kvListElement); }, this); diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.js b/src/pages/KeyValue/KeyValueSecretsEdit.js index 80ea306..62de13d 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.js +++ b/src/pages/KeyValue/KeyValueSecretsEdit.js @@ -54,7 +54,7 @@ export class KeyValueSecretsEditPage extends Page { pageState.currentSecretPath, pageState.currentSecret, JSON.parse(jar.toString()) - ).then(resp => { + ).then(_ => { changePage("KEY_VALUE_SECRETS"); return; }).catch(e => { diff --git a/src/pages/Login.js b/src/pages/Login.js index 281706c..4388de6 100644 --- a/src/pages/Login.js +++ b/src/pages/Login.js @@ -122,7 +122,7 @@ export class LoginPage extends Page { let formData = new FormData(tokenLoginForm); const token = formData.get("token"); localStorage.setItem('token', token); - lookupSelf().then(res => { + lookupSelf().then(_ => { changePage("HOME"); }).catch(e => { document.getElementById("tokenInput").classList.add("uk-form-danger"); diff --git a/src/pages/PwGen.js b/src/pages/PwGen.js index 77ec984..54e8222 100644 --- a/src/pages/PwGen.js +++ b/src/pages/PwGen.js @@ -20,7 +20,7 @@ function random() { function genPw(len) { let pw = ""; - const pwArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\]^_{|}~".split(''); + const pwArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'()*+,-./:;<=>?@[]^_{|}~".split(''); for (let i = 0; i < len; i++) { pw = pw.concat(pwArray[Math.floor(random() * pwArray.length)]); } diff --git a/src/pages/TOTP/NewTOTP.js b/src/pages/TOTP/NewTOTP.js index a89ad31..1d1a9ac 100644 --- a/src/pages/TOTP/NewTOTP.js +++ b/src/pages/TOTP/NewTOTP.js @@ -77,7 +77,7 @@ export class NewTOTPPage extends Page { name: formData.get("name"), generate: false }; - addNewTOTP(pageState.currentBaseMount, parms).then(res => { + addNewTOTP(pageState.currentBaseMount, parms).then(_ => { changePage("TOTP"); }).catch(e => { setErrorText(`API Error: ${e.message}`); diff --git a/src/pages/TOTP/TOTPView.js b/src/pages/TOTP/TOTPView.js index 3de4b47..8a2a2b8 100644 --- a/src/pages/TOTP/TOTPView.js +++ b/src/pages/TOTP/TOTPView.js @@ -1,6 +1,6 @@ import { Page } from "../../types/Page.js"; import { getTOTPKeys, getTOTPCode, DoesNotExistError } from "../../api.js"; -import { setTitleElement, setPageContent, changePage } from "../../pageUtils.js"; +import { setTitleElement, setPageContent, changePage, setErrorText } from "../../pageUtils.js"; import { CopyableInputBox } from "../../elements/CopyableInputBox.js"; import { makeElement } from "../../htmlUtils.js"; diff --git a/src/pages/Transit/TransitEncrypt.js b/src/pages/Transit/TransitEncrypt.js index 2cf2d71..66d06a0 100644 --- a/src/pages/Transit/TransitEncrypt.js +++ b/src/pages/Transit/TransitEncrypt.js @@ -73,7 +73,7 @@ export class TransitEncryptPage extends Page { transitEncryptFormHandler() { let formData = new FormData(this.transitEncryptForm); - let encodedData = + let encodedData = formData.get("base64Checkbox") == "on" ? formData.get("plaintext") : btoa(formData.get("plaintext")); transitEncrypt(pageState.currentBaseMount, pageState.currentSecret, encodedData).then(res => { console.log(res); diff --git a/src/pages/Unseal.js b/src/pages/Unseal.js index ba8c3fd..99bfb0f 100644 --- a/src/pages/Unseal.js +++ b/src/pages/Unseal.js @@ -76,7 +76,7 @@ export class UnsealPage extends Page { async handleKeySubmit() { let formData = new FormData(this.unsealKeyForm); - submitUnsealKey(formData.get("key")).then(resp => { + submitUnsealKey(formData.get("key")).then(_ => { getSealStatus().then(data => { this.updateSealProgress(data); }); diff --git a/src/scss/main.scss b/src/scss/main.scss index 9957fae..fd6eaae 100644 --- a/src/scss/main.scss +++ b/src/scss/main.scss @@ -10,7 +10,6 @@ padding-bottom: 10px !important; padding-left: 10px !important; } - .wrap-pre { white-space: pre-wrap; }