Enable linting for all auth related files

This commit is contained in:
J. Ryan Stinnett 2019-01-23 18:32:36 -06:00
parent 74a5dd4291
commit 9470424bcb
10 changed files with 52 additions and 55 deletions

View file

@ -1,7 +1,6 @@
# autogenerated file: run scripts/generate-eslint-error-ignore-file to update. # autogenerated file: run scripts/generate-eslint-error-ignore-file to update.
src/component-index.js src/component-index.js
src/components/structures/auth/ForgotPassword.js
src/components/structures/BottomLeftMenu.js src/components/structures/BottomLeftMenu.js
src/components/structures/CreateRoom.js src/components/structures/CreateRoom.js
src/components/structures/MessagePanel.js src/components/structures/MessagePanel.js
@ -13,11 +12,6 @@ src/components/structures/ScrollPanel.js
src/components/structures/SearchBox.js src/components/structures/SearchBox.js
src/components/structures/TimelinePanel.js src/components/structures/TimelinePanel.js
src/components/structures/UploadBar.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/BaseAvatar.js
src/components/views/avatars/MemberAvatar.js src/components/views/avatars/MemberAvatar.js
src/components/views/create_room/RoomAlias.js src/components/views/create_room/RoomAlias.js
@ -68,7 +62,6 @@ src/HtmlUtils.js
src/ImageUtils.js src/ImageUtils.js
src/languageHandler.js src/languageHandler.js
src/linkify-matrix.js src/linkify-matrix.js
src/Login.js
src/Markdown.js src/Markdown.js
src/MatrixClientPeg.js src/MatrixClientPeg.js
src/Modal.js src/Modal.js
@ -96,11 +89,9 @@ src/VectorConferenceHandler.js
src/Velociraptor.js src/Velociraptor.js
src/WhoIsTyping.js src/WhoIsTyping.js
src/wrappers/withMatrixClient.js src/wrappers/withMatrixClient.js
test/components/structures/auth/Registration-test.js
test/components/structures/MessagePanel-test.js test/components/structures/MessagePanel-test.js
test/components/structures/ScrollPanel-test.js test/components/structures/ScrollPanel-test.js
test/components/structures/TimelinePanel-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/dialogs/InteractiveAuthDialog-test.js
test/components/views/rooms/MessageComposerInput-test.js test/components/views/rooms/MessageComposerInput-test.js
test/components/views/rooms/RoomSettings-test.js test/components/views/rooms/RoomSettings-test.js

View file

@ -49,6 +49,7 @@ export default class Login {
/** /**
* Get a temporary MatrixClient, which can be used for login or register * Get a temporary MatrixClient, which can be used for login or register
* requests. * requests.
* @returns {MatrixClient}
*/ */
_createTemporaryClient() { _createTemporaryClient() {
return Matrix.createClient({ return Matrix.createClient({
@ -144,8 +145,8 @@ export default class Login {
const tryFallbackHs = (originalError) => { const tryFallbackHs = (originalError) => {
return sendLoginRequest( return sendLoginRequest(
self._fallbackHsUrl, this._isUrl, 'm.login.password', loginParams, self._fallbackHsUrl, this._isUrl, 'm.login.password', loginParams,
).catch((fallback_error) => { ).catch((fallbackError) => {
console.log("fallback HS login failed", fallback_error); console.log("fallback HS login failed", fallbackError);
// throw the original error // throw the original error
throw originalError; throw originalError;
}); });

View file

@ -22,6 +22,6 @@ limitations under the License.
import Velocity from 'velocity-vector'; import Velocity from 'velocity-vector';
import 'velocity-vector/velocity.ui'; import 'velocity-vector/velocity.ui';
export function field_input_incorrect(element) { export function fieldInputIncorrect(element) {
Velocity(element, "callout.shake", 300); Velocity(element, "callout.shake", 300);
} }

View file

@ -21,7 +21,7 @@ import sdk from '../../../index';
import { COUNTRIES } from '../../../phonenumber'; import { COUNTRIES } from '../../../phonenumber';
const COUNTRIES_BY_ISO2 = new Object(null); const COUNTRIES_BY_ISO2 = {};
for (const c of COUNTRIES) { for (const c of COUNTRIES) {
COUNTRIES_BY_ISO2[c.iso2] = c; COUNTRIES_BY_ISO2[c.iso2] = c;
} }

View file

@ -294,7 +294,7 @@ export const TermsAuthEntry = React.createClass({
_trySubmit: function() { _trySubmit: function() {
let allChecked = true; let allChecked = true;
for (const policy of this.state.policies) { for (const policy of this.state.policies) {
let checked = this.state.toggledPolicies[policy.id]; const checked = this.state.toggledPolicies[policy.id];
allChecked = allChecked && checked; allChecked = allChecked && checked;
} }
@ -440,7 +440,6 @@ export const MsisdnAuthEntry = React.createClass({
clientSecret: PropTypes.func, clientSecret: PropTypes.func,
submitAuthDict: PropTypes.func.isRequired, submitAuthDict: PropTypes.func.isRequired,
matrixClient: PropTypes.object, matrixClient: PropTypes.object,
submitAuthDict: PropTypes.func,
}, },
getInitialState: function() { getInitialState: function() {

View file

@ -20,7 +20,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import sdk from '../../../index'; import sdk from '../../../index';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import {field_input_incorrect} from '../../../UiEffects'; import {fieldInputIncorrect} from '../../../UiEffects';
import SdkConfig from '../../../SdkConfig'; import SdkConfig from '../../../SdkConfig';
/** /**
@ -71,7 +71,7 @@ class PasswordLogin extends React.Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (!this.props.loginIncorrect && nextProps.loginIncorrect) { if (!this.props.loginIncorrect && nextProps.loginIncorrect) {
field_input_incorrect(this.isLoginEmpty() ? this._loginField : this._passwordField); fieldInputIncorrect(this.isLoginEmpty() ? this._loginField : this._passwordField);
} }
} }

View file

@ -18,7 +18,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { field_input_incorrect } from '../../../UiEffects'; import { fieldInputIncorrect } from '../../../UiEffects';
import sdk from '../../../index'; import sdk from '../../../index';
import Email from '../../../email'; import Email from '../../../email';
import { looksValid as phoneNumberLooksValid } from '../../../phonenumber'; import { looksValid as phoneNumberLooksValid } from '../../../phonenumber';
@ -28,7 +28,6 @@ import SdkConfig from '../../../SdkConfig';
import { SAFE_LOCALPART_REGEX } from '../../../Registration'; import { SAFE_LOCALPART_REGEX } from '../../../Registration';
const FIELD_EMAIL = 'field_email'; const FIELD_EMAIL = 'field_email';
const FIELD_PHONE_COUNTRY = 'field_phone_country';
const FIELD_PHONE_NUMBER = 'field_phone_number'; const FIELD_PHONE_NUMBER = 'field_phone_number';
const FIELD_USERNAME = 'field_username'; const FIELD_USERNAME = 'field_username';
const FIELD_PASSWORD = 'field_password'; const FIELD_PASSWORD = 'field_password';
@ -139,8 +138,7 @@ module.exports = React.createClass({
}, },
/** /**
* Returns true if all fields were valid last time * @returns {boolean} true if all fields were valid last time they were validated.
* they were validated.
*/ */
allFieldsValid: function() { allFieldsValid: function() {
const keys = Object.keys(this.state.fieldValid); 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'); 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 pwd1 = this.refs.password.value.trim();
const pwd2 = this.refs.passwordConfirm.value.trim(); const pwd2 = this.refs.passwordConfirm.value.trim();
switch (field_id) { switch (fieldID) {
case FIELD_EMAIL: case FIELD_EMAIL: {
const email = this.refs.email.value; const email = this.refs.email.value;
if (this.props.teamsConfig && this._isUniEmail(email)) { if (this.props.teamsConfig && this._isUniEmail(email)) {
const matchingTeam = this.props.teamsConfig.teams.find( const matchingTeam = this.props.teamsConfig.teams.find(
@ -183,72 +181,75 @@ module.exports = React.createClass({
} }
const emailValid = email === '' || Email.looksValid(email); const emailValid = email === '' || Email.looksValid(email);
if (this._authStepIsRequired('m.login.email.identity') && (!emailValid || email === '')) { if (this._authStepIsRequired('m.login.email.identity') && (!emailValid || email === '')) {
this.markFieldValid(field_id, false, "RegistrationForm.ERR_MISSING_EMAIL"); this.markFieldValid(fieldID, false, "RegistrationForm.ERR_MISSING_EMAIL");
} else this.markFieldValid(field_id, emailValid, "RegistrationForm.ERR_EMAIL_INVALID"); } else this.markFieldValid(fieldID, emailValid, "RegistrationForm.ERR_EMAIL_INVALID");
break; break;
case FIELD_PHONE_NUMBER: }
case FIELD_PHONE_NUMBER: {
const phoneNumber = this.refs.phoneNumber ? this.refs.phoneNumber.value : ''; const phoneNumber = this.refs.phoneNumber ? this.refs.phoneNumber.value : '';
const phoneNumberValid = phoneNumber === '' || phoneNumberLooksValid(phoneNumber); const phoneNumberValid = phoneNumber === '' || phoneNumberLooksValid(phoneNumber);
if (this._authStepIsRequired('m.login.msisdn') && (!phoneNumberValid || phoneNumber === '')) { if (this._authStepIsRequired('m.login.msisdn') && (!phoneNumberValid || phoneNumber === '')) {
this.markFieldValid(field_id, false, "RegistrationForm.ERR_MISSING_PHONE_NUMBER"); this.markFieldValid(fieldID, false, "RegistrationForm.ERR_MISSING_PHONE_NUMBER");
} else this.markFieldValid(field_id, phoneNumberValid, "RegistrationForm.ERR_PHONE_NUMBER_INVALID"); } else this.markFieldValid(fieldID, phoneNumberValid, "RegistrationForm.ERR_PHONE_NUMBER_INVALID");
break; break;
case FIELD_USERNAME: }
case FIELD_USERNAME: {
const username = this.refs.username.value.trim(); const username = this.refs.username.value.trim();
if (!SAFE_LOCALPART_REGEX.test(username)) { if (!SAFE_LOCALPART_REGEX.test(username)) {
this.markFieldValid( this.markFieldValid(
field_id, fieldID,
false, false,
"RegistrationForm.ERR_USERNAME_INVALID", "RegistrationForm.ERR_USERNAME_INVALID",
); );
} else if (username == '') { } else if (username == '') {
this.markFieldValid( this.markFieldValid(
field_id, fieldID,
false, false,
"RegistrationForm.ERR_USERNAME_BLANK", "RegistrationForm.ERR_USERNAME_BLANK",
); );
} else { } else {
this.markFieldValid(field_id, true); this.markFieldValid(fieldID, true);
} }
break; break;
}
case FIELD_PASSWORD: case FIELD_PASSWORD:
if (pwd1 == '') { if (pwd1 == '') {
this.markFieldValid( this.markFieldValid(
field_id, fieldID,
false, false,
"RegistrationForm.ERR_PASSWORD_MISSING", "RegistrationForm.ERR_PASSWORD_MISSING",
); );
} else if (pwd1.length < this.props.minPasswordLength) { } else if (pwd1.length < this.props.minPasswordLength) {
this.markFieldValid( this.markFieldValid(
field_id, fieldID,
false, false,
"RegistrationForm.ERR_PASSWORD_LENGTH", "RegistrationForm.ERR_PASSWORD_LENGTH",
); );
} else { } else {
this.markFieldValid(field_id, true); this.markFieldValid(fieldID, true);
} }
break; break;
case FIELD_PASSWORD_CONFIRM: case FIELD_PASSWORD_CONFIRM:
this.markFieldValid( this.markFieldValid(
field_id, pwd1 == pwd2, fieldID, pwd1 == pwd2,
"RegistrationForm.ERR_PASSWORD_MISMATCH", "RegistrationForm.ERR_PASSWORD_MISMATCH",
); );
break; break;
} }
}, },
markFieldValid: function(field_id, val, error_code) { markFieldValid: function(fieldID, val, errorCode) {
const fieldValid = this.state.fieldValid; const fieldValid = this.state.fieldValid;
fieldValid[field_id] = val; fieldValid[fieldID] = val;
this.setState({fieldValid: fieldValid}); this.setState({fieldValid: fieldValid});
if (!val) { if (!val) {
field_input_incorrect(this.fieldElementById(field_id)); fieldInputIncorrect(this.fieldElementById(fieldID));
this.props.onError(error_code); this.props.onError(errorCode);
} }
}, },
fieldElementById(field_id) { fieldElementById(fieldID) {
switch (field_id) { switch (fieldID) {
case FIELD_EMAIL: case FIELD_EMAIL:
return this.refs.email; return this.refs.email;
case FIELD_PHONE_NUMBER: 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(' '); let cls = baseClasses.join(' ');
if (this.state.fieldValid[field_id] === false) { if (this.state.fieldValid[fieldID] === false) {
if (cls) cls += ' '; if (cls) cls += ' ';
cls += 'error'; cls += 'error';
} }
@ -289,7 +290,9 @@ module.exports = React.createClass({
render: function() { render: function() {
const self = this; 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 = ( const emailSection = (
<div> <div>
@ -311,13 +314,16 @@ module.exports = React.createClass({
<a href={"mailto:" + this.props.teamsConfig.supportEmail}> <a href={"mailto:" + this.props.teamsConfig.supportEmail}>
{ this.props.teamsConfig.supportEmail } { this.props.teamsConfig.supportEmail }
</a>&nbsp; </a>&nbsp;
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.
</p> </p>
); );
} else if (this.state.selectedTeam) { } else if (this.state.selectedTeam) {
belowEmailSection = ( belowEmailSection = (
<p className="mx_Login_support"> <p className="mx_Login_support">
{ _t("You are registering with %(SelectedTeamName)s", {SelectedTeamName: this.state.selectedTeam.name}) } {_t("You are registering with %(SelectedTeamName)s", {
SelectedTeamName: this.state.selectedTeam.name,
})}
</p> </p>
); );
} }
@ -326,7 +332,9 @@ module.exports = React.createClass({
const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown'); const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown');
let phoneSection; let phoneSection;
if (!SdkConfig.get().disable_3pid_login) { 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 = ( phoneSection = (
<div className="mx_Login_phoneSection"> <div className="mx_Login_phoneSection">
<CountryDropdown ref="phone_country" onOptionChange={this._onPhoneCountryChange} <CountryDropdown ref="phone_country" onOptionChange={this._onPhoneCountryChange}

View file

@ -88,8 +88,8 @@ module.exports = React.createClass({
}, },
onHomeserverChanged: function(ev) { onHomeserverChanged: function(ev) {
this.setState({hs_url: ev.target.value}, function() { this.setState({hs_url: ev.target.value}, () => {
this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, function() { this._hsTimeoutId = this._waitThenInvoke(this._hsTimeoutId, () => {
let hsUrl = this.state.hs_url.trim().replace(/\/$/, ""); let hsUrl = this.state.hs_url.trim().replace(/\/$/, "");
if (hsUrl === "") hsUrl = this.props.defaultHsUrl; if (hsUrl === "") hsUrl = this.props.defaultHsUrl;
this.props.onServerConfigChange({ this.props.onServerConfigChange({
@ -101,8 +101,8 @@ module.exports = React.createClass({
}, },
onIdentityServerChanged: function(ev) { onIdentityServerChanged: function(ev) {
this.setState({is_url: ev.target.value}, function() { this.setState({is_url: ev.target.value}, () => {
this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, function() { this._isTimeoutId = this._waitThenInvoke(this._isTimeoutId, () => {
let isUrl = this.state.is_url.trim().replace(/\/$/, ""); let isUrl = this.state.is_url.trim().replace(/\/$/, "");
if (isUrl === "") isUrl = this.props.defaultIsUrl; if (isUrl === "") isUrl = this.props.defaultIsUrl;
this.props.onServerConfigChange({ this.props.onServerConfigChange({

View file

@ -16,7 +16,6 @@ limitations under the License.
const jest = require('jest-mock'); const jest = require('jest-mock');
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-addons-test-utils'); const ReactTestUtils = require('react-addons-test-utils');
const expect = require('expect'); const expect = require('expect');

View file

@ -16,7 +16,6 @@ limitations under the License.
const jest = require('jest-mock'); const jest = require('jest-mock');
const React = require('react'); const React = require('react');
const ReactDOM = require("react-dom");
const ReactTestUtils = require('react-addons-test-utils'); const ReactTestUtils = require('react-addons-test-utils');
const expect = require('expect'); const expect = require('expect');