From 9470424bcb4f0e715f8ddd2680f841b31019f43b Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 23 Jan 2019 18:32:36 -0600 Subject: [PATCH] Enable linting for all auth related files --- .eslintignore.errorfiles | 9 --- src/Login.js | 5 +- src/UiEffects.js | 2 +- src/components/views/auth/CountryDropdown.js | 2 +- .../auth/InteractiveAuthEntryComponents.js | 3 +- src/components/views/auth/PasswordLogin.js | 4 +- src/components/views/auth/RegistrationForm.js | 72 ++++++++++--------- src/components/views/auth/ServerConfig.js | 8 +-- .../structures/auth/Registration-test.js | 1 - .../views/auth/RegistrationForm-test.js | 1 - 10 files changed, 52 insertions(+), 55 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 4376439012..2ccf83489c 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -1,7 +1,6 @@ # autogenerated file: run scripts/generate-eslint-error-ignore-file to update. src/component-index.js -src/components/structures/auth/ForgotPassword.js src/components/structures/BottomLeftMenu.js src/components/structures/CreateRoom.js src/components/structures/MessagePanel.js @@ -13,11 +12,6 @@ src/components/structures/ScrollPanel.js src/components/structures/SearchBox.js src/components/structures/TimelinePanel.js src/components/structures/UploadBar.js -src/components/views/auth/CountryDropdown.js -src/components/views/auth/InteractiveAuthEntryComponents.js -src/components/views/auth/PasswordLogin.js -src/components/views/auth/RegistrationForm.js -src/components/views/auth/ServerConfig.js src/components/views/avatars/BaseAvatar.js src/components/views/avatars/MemberAvatar.js src/components/views/create_room/RoomAlias.js @@ -68,7 +62,6 @@ src/HtmlUtils.js src/ImageUtils.js src/languageHandler.js src/linkify-matrix.js -src/Login.js src/Markdown.js src/MatrixClientPeg.js src/Modal.js @@ -96,11 +89,9 @@ src/VectorConferenceHandler.js src/Velociraptor.js src/WhoIsTyping.js src/wrappers/withMatrixClient.js -test/components/structures/auth/Registration-test.js test/components/structures/MessagePanel-test.js test/components/structures/ScrollPanel-test.js test/components/structures/TimelinePanel-test.js -test/components/views/auth/RegistrationForm-test.js test/components/views/dialogs/InteractiveAuthDialog-test.js test/components/views/rooms/MessageComposerInput-test.js test/components/views/rooms/RoomSettings-test.js diff --git a/src/Login.js b/src/Login.js index ca045e36cd..893ec42097 100644 --- a/src/Login.js +++ b/src/Login.js @@ -49,6 +49,7 @@ export default class Login { /** * Get a temporary MatrixClient, which can be used for login or register * requests. + * @returns {MatrixClient} */ _createTemporaryClient() { return Matrix.createClient({ @@ -144,8 +145,8 @@ export default class Login { const tryFallbackHs = (originalError) => { return sendLoginRequest( self._fallbackHsUrl, this._isUrl, 'm.login.password', loginParams, - ).catch((fallback_error) => { - console.log("fallback HS login failed", fallback_error); + ).catch((fallbackError) => { + console.log("fallback HS login failed", fallbackError); // throw the original error throw originalError; }); diff --git a/src/UiEffects.js b/src/UiEffects.js index 76db0b7f12..06b0a0e3b7 100644 --- a/src/UiEffects.js +++ b/src/UiEffects.js @@ -22,6 +22,6 @@ limitations under the License. import Velocity from 'velocity-vector'; import 'velocity-vector/velocity.ui'; -export function field_input_incorrect(element) { +export function fieldInputIncorrect(element) { Velocity(element, "callout.shake", 300); } diff --git a/src/components/views/auth/CountryDropdown.js b/src/components/views/auth/CountryDropdown.js index 5f5dbf41a4..3a71d5d1c8 100644 --- a/src/components/views/auth/CountryDropdown.js +++ b/src/components/views/auth/CountryDropdown.js @@ -21,7 +21,7 @@ import sdk from '../../../index'; import { COUNTRIES } from '../../../phonenumber'; -const COUNTRIES_BY_ISO2 = new Object(null); +const COUNTRIES_BY_ISO2 = {}; for (const c of COUNTRIES) { COUNTRIES_BY_ISO2[c.iso2] = c; } diff --git a/src/components/views/auth/InteractiveAuthEntryComponents.js b/src/components/views/auth/InteractiveAuthEntryComponents.js index 6a78898179..1df0a487cc 100644 --- a/src/components/views/auth/InteractiveAuthEntryComponents.js +++ b/src/components/views/auth/InteractiveAuthEntryComponents.js @@ -294,7 +294,7 @@ export const TermsAuthEntry = React.createClass({ _trySubmit: function() { let allChecked = true; for (const policy of this.state.policies) { - let checked = this.state.toggledPolicies[policy.id]; + const checked = this.state.toggledPolicies[policy.id]; allChecked = allChecked && checked; } @@ -440,7 +440,6 @@ export const MsisdnAuthEntry = React.createClass({ clientSecret: PropTypes.func, submitAuthDict: PropTypes.func.isRequired, matrixClient: PropTypes.object, - submitAuthDict: PropTypes.func, }, getInitialState: function() { diff --git a/src/components/views/auth/PasswordLogin.js b/src/components/views/auth/PasswordLogin.js index 1d36c52a24..f641d0fd8e 100644 --- a/src/components/views/auth/PasswordLogin.js +++ b/src/components/views/auth/PasswordLogin.js @@ -20,7 +20,7 @@ import PropTypes from 'prop-types'; import classNames from 'classnames'; import sdk from '../../../index'; import { _t } from '../../../languageHandler'; -import {field_input_incorrect} from '../../../UiEffects'; +import {fieldInputIncorrect} from '../../../UiEffects'; import SdkConfig from '../../../SdkConfig'; /** @@ -71,7 +71,7 @@ class PasswordLogin extends React.Component { componentWillReceiveProps(nextProps) { if (!this.props.loginIncorrect && nextProps.loginIncorrect) { - field_input_incorrect(this.isLoginEmpty() ? this._loginField : this._passwordField); + fieldInputIncorrect(this.isLoginEmpty() ? this._loginField : this._passwordField); } } diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index a0fc79b947..873442e122 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -18,7 +18,7 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; -import { field_input_incorrect } from '../../../UiEffects'; +import { fieldInputIncorrect } from '../../../UiEffects'; import sdk from '../../../index'; import Email from '../../../email'; import { looksValid as phoneNumberLooksValid } from '../../../phonenumber'; @@ -28,7 +28,6 @@ import SdkConfig from '../../../SdkConfig'; import { SAFE_LOCALPART_REGEX } from '../../../Registration'; const FIELD_EMAIL = 'field_email'; -const FIELD_PHONE_COUNTRY = 'field_phone_country'; const FIELD_PHONE_NUMBER = 'field_phone_number'; const FIELD_USERNAME = 'field_username'; const FIELD_PASSWORD = 'field_password'; @@ -139,8 +138,7 @@ module.exports = React.createClass({ }, /** - * Returns true if all fields were valid last time - * they were validated. + * @returns {boolean} true if all fields were valid last time they were validated. */ allFieldsValid: function() { const keys = Object.keys(this.state.fieldValid); @@ -156,12 +154,12 @@ module.exports = React.createClass({ return email.endsWith('.ac.uk') || email.endsWith('.edu') || email.endsWith('matrix.org'); }, - validateField: function(field_id) { + validateField: function(fieldID) { const pwd1 = this.refs.password.value.trim(); const pwd2 = this.refs.passwordConfirm.value.trim(); - switch (field_id) { - case FIELD_EMAIL: + switch (fieldID) { + case FIELD_EMAIL: { const email = this.refs.email.value; if (this.props.teamsConfig && this._isUniEmail(email)) { const matchingTeam = this.props.teamsConfig.teams.find( @@ -183,72 +181,75 @@ module.exports = React.createClass({ } const emailValid = email === '' || Email.looksValid(email); if (this._authStepIsRequired('m.login.email.identity') && (!emailValid || email === '')) { - this.markFieldValid(field_id, false, "RegistrationForm.ERR_MISSING_EMAIL"); - } else this.markFieldValid(field_id, emailValid, "RegistrationForm.ERR_EMAIL_INVALID"); + this.markFieldValid(fieldID, false, "RegistrationForm.ERR_MISSING_EMAIL"); + } else this.markFieldValid(fieldID, emailValid, "RegistrationForm.ERR_EMAIL_INVALID"); break; - case FIELD_PHONE_NUMBER: + } + case FIELD_PHONE_NUMBER: { const phoneNumber = this.refs.phoneNumber ? this.refs.phoneNumber.value : ''; const phoneNumberValid = phoneNumber === '' || phoneNumberLooksValid(phoneNumber); if (this._authStepIsRequired('m.login.msisdn') && (!phoneNumberValid || phoneNumber === '')) { - this.markFieldValid(field_id, false, "RegistrationForm.ERR_MISSING_PHONE_NUMBER"); - } else this.markFieldValid(field_id, phoneNumberValid, "RegistrationForm.ERR_PHONE_NUMBER_INVALID"); + this.markFieldValid(fieldID, false, "RegistrationForm.ERR_MISSING_PHONE_NUMBER"); + } else this.markFieldValid(fieldID, phoneNumberValid, "RegistrationForm.ERR_PHONE_NUMBER_INVALID"); break; - case FIELD_USERNAME: + } + case FIELD_USERNAME: { const username = this.refs.username.value.trim(); if (!SAFE_LOCALPART_REGEX.test(username)) { this.markFieldValid( - field_id, + fieldID, false, "RegistrationForm.ERR_USERNAME_INVALID", ); } else if (username == '') { this.markFieldValid( - field_id, + fieldID, false, "RegistrationForm.ERR_USERNAME_BLANK", ); } else { - this.markFieldValid(field_id, true); + this.markFieldValid(fieldID, true); } break; + } case FIELD_PASSWORD: if (pwd1 == '') { this.markFieldValid( - field_id, + fieldID, false, "RegistrationForm.ERR_PASSWORD_MISSING", ); } else if (pwd1.length < this.props.minPasswordLength) { this.markFieldValid( - field_id, + fieldID, false, "RegistrationForm.ERR_PASSWORD_LENGTH", ); } else { - this.markFieldValid(field_id, true); + this.markFieldValid(fieldID, true); } break; case FIELD_PASSWORD_CONFIRM: this.markFieldValid( - field_id, pwd1 == pwd2, + fieldID, pwd1 == pwd2, "RegistrationForm.ERR_PASSWORD_MISMATCH", ); break; } }, - markFieldValid: function(field_id, val, error_code) { + markFieldValid: function(fieldID, val, errorCode) { const fieldValid = this.state.fieldValid; - fieldValid[field_id] = val; + fieldValid[fieldID] = val; this.setState({fieldValid: fieldValid}); if (!val) { - field_input_incorrect(this.fieldElementById(field_id)); - this.props.onError(error_code); + fieldInputIncorrect(this.fieldElementById(fieldID)); + this.props.onError(errorCode); } }, - fieldElementById(field_id) { - switch (field_id) { + fieldElementById(fieldID) { + switch (fieldID) { case FIELD_EMAIL: return this.refs.email; case FIELD_PHONE_NUMBER: @@ -262,9 +263,9 @@ module.exports = React.createClass({ } }, - _classForField: function(field_id, ...baseClasses) { + _classForField: function(fieldID, ...baseClasses) { let cls = baseClasses.join(' '); - if (this.state.fieldValid[field_id] === false) { + if (this.state.fieldValid[fieldID] === false) { if (cls) cls += ' '; cls += 'error'; } @@ -289,7 +290,9 @@ module.exports = React.createClass({ render: function() { const self = this; - const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ? _t("Email address") : _t("Email address (optional)"); + const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ? + _t("Email address") : + _t("Email address (optional)"); const emailSection = (
@@ -311,13 +314,16 @@ module.exports = React.createClass({ { this.props.teamsConfig.supportEmail }   - to get your university signed up. Or continue to register with Riot to enjoy our open source platform. + to get your university signed up. + Or continue to register with Riot to enjoy our open source platform.

); } else if (this.state.selectedTeam) { belowEmailSection = (

- { _t("You are registering with %(SelectedTeamName)s", {SelectedTeamName: this.state.selectedTeam.name}) } + {_t("You are registering with %(SelectedTeamName)s", { + SelectedTeamName: this.state.selectedTeam.name, + })}

); } @@ -326,7 +332,9 @@ module.exports = React.createClass({ const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown'); let phoneSection; if (!SdkConfig.get().disable_3pid_login) { - const phonePlaceholder = this._authStepIsRequired('m.login.msisdn') ? _t("Mobile phone number") : _t("Mobile phone number (optional)"); + const phonePlaceholder = this._authStepIsRequired('m.login.msisdn') ? + _t("Mobile phone number") : + _t("Mobile phone number (optional)"); phoneSection = (
{ + this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => { let hsUrl = this.state.hs_url.trim().replace(/\/$/, ""); if (hsUrl === "") hsUrl = this.props.defaultHsUrl; this.props.onServerConfigChange({ @@ -101,8 +101,8 @@ module.exports = React.createClass({ }, onIdentityServerChanged: function(ev) { - this.setState({is_url: ev.target.value}, function() { - this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, function() { + this.setState({is_url: ev.target.value}, () => { + this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => { let isUrl = this.state.is_url.trim().replace(/\/$/, ""); if (isUrl === "") isUrl = this.props.defaultIsUrl; this.props.onServerConfigChange({ diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js index 4827bf4c12..8ce0301128 100644 --- a/test/components/structures/auth/Registration-test.js +++ b/test/components/structures/auth/Registration-test.js @@ -16,7 +16,6 @@ limitations under the License. const jest = require('jest-mock'); const React = require('react'); -const ReactDOM = require('react-dom'); const ReactTestUtils = require('react-addons-test-utils'); const expect = require('expect'); diff --git a/test/components/views/auth/RegistrationForm-test.js b/test/components/views/auth/RegistrationForm-test.js index 265f158bb9..4e7db9a230 100644 --- a/test/components/views/auth/RegistrationForm-test.js +++ b/test/components/views/auth/RegistrationForm-test.js @@ -16,7 +16,6 @@ limitations under the License. const jest = require('jest-mock'); const React = require('react'); -const ReactDOM = require("react-dom"); const ReactTestUtils = require('react-addons-test-utils'); const expect = require('expect');