From deed8577884501bdeeac35f43cacd39aabf9cbc5 Mon Sep 17 00:00:00 2001 From: q1anx1 <55543743+qianxi0410@users.noreply.github.com> Date: Mon, 8 Aug 2022 23:35:24 +0800 Subject: [PATCH] chore(style): allow case declarations and ban `var` (#987) * chore(style): allow case declarations * chore(style): ban `var` and prefer `const` --- web/.eslintrc | 10 +++++-- web/src/AccountTable.js | 4 +-- web/src/App.js | 8 +++--- web/src/ApplicationEditPage.js | 12 ++++---- web/src/ApplicationListPage.js | 4 +-- web/src/CertEditPage.js | 4 +-- web/src/CertListPage.js | 2 +- web/src/LdapSyncPage.js | 20 ++++++------- web/src/ModelEditPage.js | 4 +-- web/src/ModelListPage.js | 2 +- web/src/OrganizationEditPage.js | 4 +-- web/src/OrganizationListPage.js | 2 +- web/src/PasswordModal.js | 2 +- web/src/PaymentEditPage.js | 4 +-- web/src/PaymentListPage.js | 2 +- web/src/PermissionEditPage.js | 4 +-- web/src/PermissionListPage.js | 2 +- web/src/ProductEditPage.js | 6 ++-- web/src/ProductListPage.js | 2 +- web/src/ProviderEditPage.js | 14 ++++----- web/src/ProviderListPage.js | 2 +- web/src/ProviderTable.js | 2 +- web/src/RecordListPage.js | 2 +- web/src/ResourceListPage.js | 4 +-- web/src/RoleEditPage.js | 4 +-- web/src/RoleListPage.js | 2 +- web/src/Setting.js | 24 ++++++++-------- web/src/SignupTable.js | 2 +- web/src/SyncerEditPage.js | 6 ++-- web/src/SyncerListPage.js | 2 +- web/src/SyncerTableColumnTable.js | 2 +- web/src/TestEmailWidget.js | 2 +- web/src/TokenEditPage.js | 4 +-- web/src/TokenListPage.js | 4 +-- web/src/UrlTable.js | 2 +- web/src/UserEditPage.js | 4 +-- web/src/UserListPage.js | 8 +++--- web/src/WebhookEditPage.js | 6 ++-- web/src/WebhookHeaderTable.js | 2 +- web/src/WebhookListPage.js | 2 +- web/src/auth/AuthCallback.js | 4 +-- web/src/auth/CasLogout.js | 2 +- web/src/auth/ForgetPage.js | 2 +- web/src/auth/LoginPage.js | 40 +++++++++++++------------- web/src/auth/PromptPage.js | 4 +-- web/src/auth/ResultPage.js | 2 +- web/src/auth/SamlCallback.js | 4 +-- web/src/auth/SignupPage.js | 2 +- web/src/backend/ApplicationBackend.js | 6 ++-- web/src/backend/CertBackend.js | 6 ++-- web/src/backend/ModelBackend.js | 6 ++-- web/src/backend/OrganizationBackend.js | 6 ++-- web/src/backend/PaymentBackend.js | 6 ++-- web/src/backend/PermissionBackend.js | 6 ++-- web/src/backend/ProductBackend.js | 6 ++-- web/src/backend/ProviderBackend.js | 6 ++-- web/src/backend/ResourceBackend.js | 8 +++--- web/src/backend/RoleBackend.js | 6 ++-- web/src/backend/SyncerBackend.js | 6 ++-- web/src/backend/TokenBackend.js | 6 ++-- web/src/backend/UserBackend.js | 14 ++++----- web/src/backend/UserWebauthnBackend.js | 10 +++---- web/src/backend/WebhookBackend.js | 6 ++-- web/src/common/CaptchaWidget.js | 4 +-- web/src/i18n.js | 3 +- 65 files changed, 187 insertions(+), 182 deletions(-) diff --git a/web/.eslintrc b/web/.eslintrc index e4a43f0c..0985071a 100644 --- a/web/.eslintrc +++ b/web/.eslintrc @@ -42,7 +42,13 @@ "space-before-function-paren": ["error", "never"], "no-trailing-spaces": ["error", { "ignoreComments": true }], "eol-last": ["error", "always"], - // "no-var": ["error"], + "no-var": ["error"], + "prefer-const": [ + "error", + { + "destructuring": "all" + } + ], "curly": ["error", "all"], "brace-style": ["error", "1tbs", { "allowSingleLine": true }], "no-mixed-spaces-and-tabs": "error", @@ -89,7 +95,7 @@ // don't use strict mod now, otherwise there are a lot of errors in the codebase "no-unused-vars": "off", "react/no-deprecated": "warn", - "no-case-declarations": "warn", + "no-case-declarations": "off", "react/jsx-key": "warn" } } diff --git a/web/src/AccountTable.js b/web/src/AccountTable.js index 77c9557b..dd2dd7e5 100644 --- a/web/src/AccountTable.js +++ b/web/src/AccountTable.js @@ -38,7 +38,7 @@ class AccountTable extends React.Component { } addRow(table) { - let row = {name: Setting.getNewRowNameForTable(table, "Please select an account item"), visible: true, viewRule: "Public", modifyRule: "Self"}; + const row = {name: Setting.getNewRowNameForTable(table, "Please select an account item"), visible: true, viewRule: "Public", modifyRule: "Self"}; if (table === undefined) { table = []; } @@ -141,7 +141,7 @@ class AccountTable extends React.Component { return null; } - let options = [ + const options = [ {id: "Public", name: "Public"}, {id: "Self", name: "Self"}, {id: "Admin", name: "Admin"}, diff --git a/web/src/App.js b/web/src/App.js index d17c015f..2ca8c857 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -182,7 +182,7 @@ class App extends Component { } setLanguage(account) { - let language = account?.language; + const language = account?.language; if (language !== "" && language !== i18next.language) { Setting.setLanguage(language); } @@ -242,7 +242,7 @@ class App extends Component { }); Setting.showMessage("success", "Logged out successfully"); - let redirectUri = res.data2; + const redirectUri = res.data2; if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") { Setting.goToLink(redirectUri); } else if (owner !== "built-in") { @@ -322,7 +322,7 @@ class App extends Component { } renderAccount() { - let res = []; + const res = []; if (this.state.account === undefined) { return null; @@ -349,7 +349,7 @@ class App extends Component { } renderMenu() { - let res = []; + const res = []; if (this.state.account === null || this.state.account === undefined) { return []; diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index 89c3f076..755958e2 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -120,7 +120,7 @@ class ApplicationEditPage extends React.Component { updateApplicationField(key, value) { value = this.parseApplicationField(key, value); - let application = this.state.application; + const application = this.state.application; application[key] = value; this.setState({ application: application, @@ -566,8 +566,8 @@ class ApplicationEditPage extends React.Component { renderSignupSigninPreview() { let signUpUrl = `/signup/${this.state.application.name}`; - let signInUrl = `/login/oauth/authorize?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`; - let maskStyle = {position: "absolute", top: "0px", left: "0px", zIndex: 10, height: "100%", width: "100%", background: "rgba(0,0,0,0.4)"}; + const signInUrl = `/login/oauth/authorize?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`; + const maskStyle = {position: "absolute", top: "0px", left: "0px", zIndex: 10, height: "100%", width: "100%", background: "rgba(0,0,0,0.4)"}; if (!this.state.application.enablePassword) { signUpUrl = signInUrl.replace("/login/oauth/authorize", "/signup/oauth/authorize"); } @@ -613,8 +613,8 @@ class ApplicationEditPage extends React.Component { } renderPromptPreview() { - let promptUrl = `/prompt/${this.state.application.name}`; - let maskStyle = {position: "absolute", top: "0px", left: "0px", zIndex: 10, height: "100%", width: "100%", background: "rgba(0,0,0,0.4)"}; + const promptUrl = `/prompt/${this.state.application.name}`; + const maskStyle = {position: "absolute", top: "0px", left: "0px", zIndex: 10, height: "100%", width: "100%", background: "rgba(0,0,0,0.4)"}; return (