mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 01:55:40 +00:00
frontend linting
This commit is contained in:
@@ -15,22 +15,22 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import genJsonPayload from './genJsonPayload';
|
||||
import genJsonPayload from "./genJsonPayload";
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
const payload = {
|
||||
username: 'Jhon',
|
||||
username: "Jhon",
|
||||
};
|
||||
|
||||
const value = {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
};
|
||||
|
||||
it('getFromUrl workds', () => {
|
||||
it("getFromUrl workds", () => {
|
||||
expect(genJsonPayload(payload)).toEqual(value);
|
||||
});
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const genJsonPayload = (payload: any) => {
|
||||
const genJsonPayload = (payload: object): object => {
|
||||
const value = {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
};
|
||||
|
||||
@@ -15,27 +15,27 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import getFormUrl from './getFormUrl';
|
||||
import {getLoginFormHtml} from '../setUpTests';
|
||||
import getFormUrl from "./getFormUrl";
|
||||
import {getLoginFormHtml} from "../setUpTests";
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
const formClassName = 'form__box';
|
||||
const formURL = '/api/v1/signin';
|
||||
const formClassName = "form__box";
|
||||
const formURL = "/api/v1/signin";
|
||||
|
||||
const noFormErr = "Can't find form";
|
||||
|
||||
document.body.innerHTML = getLoginFormHtml();
|
||||
|
||||
const form = document.querySelector('form');
|
||||
const form = document.querySelector("form");
|
||||
form.action = formURL;
|
||||
form.className = formClassName;
|
||||
|
||||
it('getFromUrl workds', () => {
|
||||
it("getFromUrl workds", () => {
|
||||
const name = `.${formClassName}`;
|
||||
expect(getFormUrl(name)).toContain(formURL);
|
||||
|
||||
const form = <HTMLFormElement>document.querySelector('form');
|
||||
const form = <HTMLFormElement>document.querySelector("form");
|
||||
expect(getFormUrl(form)).toContain(formURL);
|
||||
|
||||
expect(getFormUrl()).toContain(formURL);
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
* So when using class-names, pass in ".whatever-classname"
|
||||
* and for ID, "#id".
|
||||
* */
|
||||
const getFormUrl = (querySelector?: string | HTMLFormElement) => {
|
||||
const getFormUrl = (querySelector?: string | HTMLFormElement): string => {
|
||||
let form;
|
||||
if (querySelector === undefined) {
|
||||
form = <HTMLFormElement>document.querySelector('form');
|
||||
form = <HTMLFormElement>document.querySelector("form");
|
||||
}
|
||||
if (typeof querySelector == 'string' || querySelector instanceof String) {
|
||||
if (typeof querySelector == "string" || querySelector instanceof String) {
|
||||
form = <HTMLFormElement>document.querySelector(querySelector.toString());
|
||||
}
|
||||
if (querySelector instanceof HTMLFormElement) {
|
||||
|
||||
@@ -15,22 +15,22 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import isBlankString from './isBlankString';
|
||||
import {mockAlert} from '../setUpTests';
|
||||
import isBlankString from "./isBlankString";
|
||||
import {mockAlert} from "../setUpTests";
|
||||
|
||||
|
||||
import setup from '../components/error/setUpTests';
|
||||
import setup from "../components/error/setUpTests";
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
mockAlert();
|
||||
|
||||
it('getFromUrl workds', () => {
|
||||
document.querySelector('body').appendChild(setup());
|
||||
expect(isBlankString('test', 'username')).toBe(false);
|
||||
it("getFromUrl workds", () => {
|
||||
document.querySelector("body").appendChild(setup());
|
||||
expect(isBlankString("test", "username")).toBe(false);
|
||||
try {
|
||||
isBlankString(' ', 'username');
|
||||
isBlankString(" ", "username");
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(`can't be empty`);
|
||||
expect(e.message).toContain("can't be empty");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* 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 createError from '../components/error/';
|
||||
import createError from "../components/error/";
|
||||
|
||||
const isBlankString = (value: string|number, field: string, event?: Event) => {
|
||||
const isBlankString = (value: string|number, field: string, event?: Event): boolean => {
|
||||
value = value.toString();
|
||||
if (!value.replace(/\s/g, '').length) {
|
||||
if (!value.replace(/\s/g, "").length) {
|
||||
if (event !== undefined) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import isNumber from './isNumber';
|
||||
import isNumber from "./isNumber";
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
it('getFromUrl workds', () => {
|
||||
expect(isNumber('test')).toBe(false);
|
||||
expect(isNumber('1test213')).toBe(false);
|
||||
it("getFromUrl workds", () => {
|
||||
expect(isNumber("test")).toBe(false);
|
||||
expect(isNumber("1test213")).toBe(false);
|
||||
|
||||
expect(isNumber('12')).toBe(true);
|
||||
expect(isNumber("12")).toBe(true);
|
||||
expect(isNumber(2)).toBe(true);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const isNumber = (value: string|number) => {
|
||||
const isNumber = (value: string|number): boolean => {
|
||||
value = value.toString();
|
||||
return /^\d+$/.test(value);
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ class LazyElement {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
get() {
|
||||
get(): HTMLElement {
|
||||
if (this.element === null || this.element === undefined) {
|
||||
const element = document.getElementById(this.id);
|
||||
if (element === null || element === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user