frontend linting

This commit is contained in:
realaravinth
2021-10-08 15:24:29 +05:30
parent f7afc72d81
commit 53720ff740
91 changed files with 2158 additions and 1677 deletions

View File

@@ -14,6 +14,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import * as lib from 'mcaptcha-glue';
import * as lib from "mcaptcha-glue";
export const register = () => lib.init();
export const register = (): void => lib.init();

View File

@@ -14,38 +14,38 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {init} from 'mcaptcha-glue';
import {init} from "mcaptcha-glue";
import VIEWS from '../../../views/v1/routes';
import VIEWS from "../../../views/v1/routes";
import isBlankString from '../../../utils/isBlankString';
import genJsonPayload from '../../../utils/genJsonPayload';
import getFormUrl from '../../../utils/getFormUrl';
import registerShowPassword from '../../../components/showPassword';
import createError from '../../../components/error/index';
import isBlankString from "../../../utils/isBlankString";
import genJsonPayload from "../../../utils/genJsonPayload";
import getFormUrl from "../../../utils/getFormUrl";
import registerShowPassword from "../../../components/showPassword";
import createError from "../../../components/error/index";
//import '../forms.scss';
export const getPassword = () => {
const passwordElement = <HTMLInputElement>document.getElementById('password');
export const getPassword = (): string | null => {
const passwordElement = <HTMLInputElement>document.getElementById("password");
if (passwordElement === null) {
console.debug('Password is null');
console.debug("Password is null");
return;
}
return passwordElement.value;
};
const login = async (e: Event) => {
const login = async (e: Event): Promise<void> => {
e.preventDefault();
const loginElement = <HTMLInputElement>document.getElementById('login');
const loginElement = <HTMLInputElement>document.getElementById("login");
if (loginElement === null) {
console.debug('login element element is null');
console.debug("login element element is null");
return;
}
const login = loginElement.value;
isBlankString(login, 'username', e);
isBlankString(login, "username", e);
const password = getPassword();
@@ -65,9 +65,9 @@ const login = async (e: Event) => {
}
};
export const index = () => {
const form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', login, true);
export const index = (): void => {
const form = <HTMLFontElement>document.getElementById("form");
form.addEventListener("submit", login, true);
registerShowPassword();
init();
};

View File

@@ -15,13 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import fetchMock from 'jest-fetch-mock';
import fetchMock from "jest-fetch-mock";
import emailExists from './emailExists';
import emailExists from "./emailExists";
import {mockAlert, getRegistrationFormHtml} from '../../../setUpTests';
import {mockAlert, getRegistrationFormHtml} from "../../../setUpTests";
import setup from '../../../components/error/setUpTests';
import setup from "../../../components/error/setUpTests";
fetchMock.enableMocks();
mockAlert();
@@ -30,14 +30,14 @@ beforeEach(() => {
fetchMock.resetMocks();
});
it('finds exchange', async () => {
it("finds exchange", async () => {
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
document.body.innerHTML = getRegistrationFormHtml();
document.querySelector('body').appendChild(setup());
document.querySelector("body").appendChild(setup());
const emailField = <HTMLInputElement>document.getElementById('email');
emailField.setAttribute('value', 'test@a.com');
const emailField = <HTMLInputElement>document.getElementById("email");
emailField.setAttribute("value", "test@a.com");
expect(await emailExists()).toBe(true);

View File

@@ -15,15 +15,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../../api/v1/routes';
import ROUTES from "../../../api/v1/routes";
import genJsonPayload from '../../../utils/genJsonPayload';
import createError from '../../../components/error/index';
import genJsonPayload from "../../../utils/genJsonPayload";
import createError from "../../../components/error/index";
const emailExists = async (element?: HTMLInputElement) => {
const emailExists = async (element?: HTMLInputElement): Promise<boolean> => {
let email;
if (element === undefined || element === null) {
email = <HTMLInputElement>document.getElementById('email');
email = <HTMLInputElement>document.getElementById("email");
} else {
email = element;
}
@@ -37,7 +37,7 @@ const emailExists = async (element?: HTMLInputElement) => {
if (res.ok) {
const data = await res.json();
if (data.exists) {
email.className += ' form__in-field--warn';
email.className += " form__in-field--warn";
createError(`Email "${val}" is already used`);
return data.exists;
}

View File

@@ -15,33 +15,33 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import VIEWS from '../../../views/v1/routes';
import VIEWS from "../../../views/v1/routes";
import isBlankString from '../../../utils/isBlankString';
import genJsonPayload from '../../../utils/genJsonPayload';
import isBlankString from "../../../utils/isBlankString";
import genJsonPayload from "../../../utils/genJsonPayload";
import userExists from './userExists';
import emailExists from './emailExists';
import getFormUrl from '../../../utils/getFormUrl';
import registerShowPassword from '../../../components/showPassword';
import createError from '../../../components/error/index';
import userExists from "./userExists";
import emailExists from "./emailExists";
import getFormUrl from "../../../utils/getFormUrl";
import registerShowPassword from "../../../components/showPassword";
import createError from "../../../components/error/index";
//import '../forms.scss';
const usernameElement = <HTMLInputElement>document.getElementById('username');
const emailElement = <HTMLInputElement>document.getElementById('email');
const passwordElement = <HTMLInputElement>document.getElementById('password');
const usernameElement = <HTMLInputElement>document.getElementById("username");
const emailElement = <HTMLInputElement>document.getElementById("email");
const passwordElement = <HTMLInputElement>document.getElementById("password");
const registerUser = async (e: Event) => {
const registerUser = async (e: Event): Promise<void> => {
e.preventDefault();
const username = usernameElement.value;
isBlankString(username, 'username', e);
isBlankString(username, "username", e);
//isBlankString(e);//, username, 'username');
const password = passwordElement.value;
const passwordCheckElement = <HTMLInputElement>(
document.getElementById('password-check')
document.getElementById("password-check")
);
const passwordCheck = passwordCheckElement.value;
if (password != passwordCheck) {
@@ -54,7 +54,7 @@ const registerUser = async (e: Event) => {
}
let email: string | null = emailElement.value;
if (!email.replace(/\s/g, '').length) {
if (!email.replace(/\s/g, "").length) {
email = null;
} else {
exists = await emailExists();
@@ -80,11 +80,11 @@ const registerUser = async (e: Event) => {
}
};
export const index = () => {
const form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', registerUser, true);
export const index = (): void => {
const form = <HTMLFontElement>document.getElementById("form");
form.addEventListener("submit", registerUser, true);
usernameElement.addEventListener(
'input',
"input",
async () => await userExists(),
false,
);

View File

@@ -14,13 +14,13 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import fetchMock from 'jest-fetch-mock';
import fetchMock from "jest-fetch-mock";
import userExists from './userExists';
import userExists from "./userExists";
import {mockAlert, getLoginFormHtml} from '../../../setUpTests';
import {mockAlert, getLoginFormHtml} from "../../../setUpTests";
import setup from '../../../components/error/setUpTests';
import setup from "../../../components/error/setUpTests";
fetchMock.enableMocks();
mockAlert();
@@ -29,16 +29,16 @@ beforeEach(() => {
fetchMock.resetMocks();
});
it('finds exchange', async () => {
it("finds exchange", async () => {
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
document.body.innerHTML = getLoginFormHtml();
document.querySelector('body').appendChild(setup());
const usernameField = <HTMLInputElement>document.querySelector('#username');
usernameField.value = 'test';
document.querySelector("body").appendChild(setup());
const usernameField = <HTMLInputElement>document.querySelector("#username");
usernameField.value = "test";
expect(await userExists()).toBe(true);
usernameField.value = 'test';
usernameField.value = "test";
fetchMock.mockResponseOnce(JSON.stringify({exists: true}));
expect(await userExists(usernameField)).toBe(true);

View File

@@ -15,16 +15,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../../api/v1/routes';
import ROUTES from "../../../api/v1/routes";
import genJsonPayload from '../../../utils/genJsonPayload';
import createError from '../../../components/error/index';
import genJsonPayload from "../../../utils/genJsonPayload";
import createError from "../../../components/error/index";
const userExists = async (element?: HTMLInputElement) => {
const userExists = async (element?: HTMLInputElement): Promise<boolean> => {
console.log(element);
let username;
if (element === undefined) {
username = <HTMLInputElement>document.getElementById('username');
username = <HTMLInputElement>document.getElementById("username");
} else {
username = element;
}
@@ -37,7 +37,7 @@ const userExists = async (element?: HTMLInputElement) => {
if (res.ok) {
const data = await res.json();
if (data.exists) {
username.className += ' form__in-field--warn';
username.className += " form__in-field--warn";
createError(`Username "${val}" taken`);
}
return data.exists;

View File

@@ -15,17 +15,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import form from './index';
import form from "./index";
it('sudo form works', () => {
it("sudo form works", () => {
try {
form.get();
} catch (e) {
expect(e.message).toBe('Element form is undefined');
expect(e.message).toBe("Element form is undefined");
}
const element = document.createElement('form');
element.id = 'form';
const element = document.createElement("form");
element.id = "form";
document.body.appendChild(element);
expect(form.get()).toBe(element);
});

View File

@@ -14,9 +14,9 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import LazyElement from '../../utils/lazyElement';
import LazyElement from "../../utils/lazyElement";
const ID = 'form';
const ID = "form";
const FORM = new LazyElement(ID);
export default FORM;