Lint scripts

pull/81/head
MillenniumEarl 2021-03-04 13:15:01 +01:00
parent e6f6d5b1b7
commit 2070352ca0
13 changed files with 68 additions and 71 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable no-console */
/*
to use this example, create an .env file
in the project root with the following values:

View File

@ -45,8 +45,8 @@ export { default as ThreadSearchQuery } from "./scripts/classes/query/thread-sea
/**
* Set the logger level for module debugging.
*/
/* istambul ignore next */
export var loggerLevel = shared.logger.level;
// eslint-disable-next-line prefer-const
export let loggerLevel = shared.logger.level;
shared.logger.level = "warn"; // By default log only the warn messages
/**

View File

@ -38,91 +38,91 @@ export default class PlatformUser {
/**
* Unique user ID.
*/
public get id() {
public get id(): number {
return this._id;
}
/**
* Username.
*/
public get name() {
public get name(): string {
return this._name;
}
/**
* Title assigned to the user by the platform.
*/
public get title() {
public get title(): string {
return this._title;
}
/**
* List of banners assigned by the platform.
*/
public get banners() {
public get banners(): string[] {
return this._banners;
}
/**
* Number of messages written by the user.
*/
public get messages() {
public get messages(): number {
return this._messages;
}
/**
* @todo Reaction score.
*/
public get reactionScore() {
public get reactionScore(): number {
return this._reactionScore;
}
/**
* @todo Points.
*/
public get points() {
public get points(): number {
return this._points;
}
/**
* Number of ratings received.
*/
public get ratingsReceived() {
public get ratingsReceived(): number {
return this._ratingsReceived;
}
/**
* Date of joining the platform.
*/
public get joined() {
public get joined(): Date {
return this._joined;
}
/**
* Date of the last connection to the platform.
*/
public get lastSeen() {
public get lastSeen(): Date {
return this._lastSeen;
}
/**
* Indicates whether the user is followed by the currently logged in user.
*/
public get followed() {
public get followed(): boolean {
return this._followed;
}
/**
* Indicates whether the user is ignored by the currently logged on user.
*/
public get ignored() {
public get ignored(): boolean {
return this._ignored;
}
/**
* Indicates that the profile is private and not viewable by the user.
*/
public get private() {
public get private(): boolean {
return this._private;
}
/**
* URL of the image used as the user's avatar.
*/
public get avatar() {
public get avatar(): string {
return this._avatar;
}
/**
* Value of donations made.
*/
public get donation() {
public get donation(): number {
return this._amountDonated;
}
@ -134,11 +134,11 @@ export default class PlatformUser {
//#region Public methods
public setID(id: number) {
public setID(id: number): void {
this._id = id;
}
public async fetch() {
public async fetch(): Promise<void> {
// Check ID
if (!this.id && this.id < 1) throw new Error("Invalid user ID");

View File

@ -35,49 +35,49 @@ export default class Post {
/**
* Represents a post published by a user on the F95Zone platform.
*/
public get id() {
public get id(): number {
return this._id;
}
/**
* Unique ID of the post within the thread in which it is present.
*/
public get number() {
public get number(): number {
return this._number;
}
/**
* Date the post was first published.
*/
public get published() {
public get published(): Date {
return this._published;
}
/**
* Date the post was last modified.
*/
public get lastEdit() {
public get lastEdit(): Date {
return this._lastEdit;
}
/**
* User who owns the post.
*/
public get owner() {
public get owner(): PlatformUser {
return this._owner;
}
/**
* Indicates whether the post has been bookmarked.
*/
public get bookmarked() {
public get bookmarked(): boolean {
return this._bookmarked;
}
/**
* Post message text.
*/
public get message() {
public get message(): string {
return this._message;
}
/**
* Set of the elements that make up the body of the post.
*/
public get body() {
public get body(): IPostElement[] {
return this._body;
}
@ -92,7 +92,7 @@ export default class Post {
/**
* Gets the post data starting from its unique ID for the entire platform.
*/
public async fetch() {
public async fetch(): Promise<void> {
// Fetch HTML page containing the post
const url = new URL(this.id.toString(), urls.F95_POSTS).toString();
const htmlResponse = await fetchHTML(url);

View File

@ -45,7 +45,7 @@ export default class Thread {
/**
* Unique ID of the thread on the platform.
*/
public get id() {
public get id(): number {
return this._id;
}
/**
@ -53,55 +53,55 @@ export default class Thread {
*
* It may vary depending on any versions of the contained product.
*/
public get url() {
public get url(): string {
return this._url;
}
/**
* Thread title.
*/
public get title() {
public get title(): string {
return this._title;
}
/**
* Tags associated with the thread.
*/
public get tags() {
public get tags(): string[] {
return this._tags;
}
/**
* Prefixes associated with the thread
*/
public get prefixes() {
public get prefixes(): string[] {
return this._prefixes;
}
/**
* Rating assigned to the thread.
*/
public get rating() {
public get rating(): TRating {
return this._rating;
}
/**
* Owner of the thread.
*/
public get owner() {
public get owner(): PlatformUser {
return this._owner;
}
/**
* Date the thread was first published.
*/
public get publication() {
public get publication(): Date {
return this._publication;
}
/**
* Date the thread was last modified.
*/
public get modified() {
public get modified(): Date {
return this._modified;
}
/**
* Category to which the content of the thread belongs.
*/
public get category() {
public get category(): TCategory {
return this._category;
}
@ -233,7 +233,7 @@ export default class Thread {
/**
* Gets information about this thread.
*/
public async fetch() {
public async fetch(): Promise<void> {
// Prepare the url
this._url = new URL(this.id.toString(), urls.F95_THREADS).toString();

View File

@ -52,28 +52,28 @@ export default class UserProfile extends PlatformUser {
/**
* List of followed thread data.
*/
public get watched() {
public get watched(): IWatchedThread[] {
return this._watched;
}
/**
* List of bookmarked posts.
* @todo
*/
public get bookmarks() {
public get bookmarks(): Post[] {
return this._bookmarks;
}
/**
* List of alerts.
* @todo
*/
public get alerts() {
public get alerts(): string[] {
return this._alerts;
}
/**
* List of conversations.
* @todo
*/
public get conversation() {
public get conversation(): string[] {
return this._conversations;
}
@ -85,7 +85,7 @@ export default class UserProfile extends PlatformUser {
//#region Public methods
public async fetch() {
public async fetch(): Promise<void> {
// First get the user ID and set it
const id = await this.fetchUserID();
super.setID(id);

View File

@ -6,7 +6,7 @@ import validator from "class-validator";
// Module from files
import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js";
import { GenericAxiosError, UnexpectedResponseContentType } from "../errors.js";
import { GenericAxiosError } from "../errors.js";
import { Result } from "../result.js";
import LatestSearchQuery, { TLatestOrder } from "./latest-search-query.js";
import ThreadSearchQuery, { TThreadOrder } from "./thread-search-query.js";

View File

@ -8,6 +8,9 @@ import { urls } from "../../constants/url.js";
import PrefixParser from "../prefix-parser.js";
import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js";
import { fetchGETResponse } from "../../network-helper.js";
import { AxiosResponse } from "axios";
import { GenericAxiosError } from "../errors.js";
import { Result } from "../result.js";
// Type definitions
export type TLatestOrder = "date" | "likes" | "views" | "title" | "rating";
@ -64,7 +67,9 @@ export default class LatestSearchQuery implements IQuery {
return validator.validateSync(this).length === 0;
}
public async execute() {
public async execute(): Promise<
Result<GenericAxiosError, AxiosResponse<any>>
> {
// Check if the query is valid
if (!this.validate()) {
throw new Error(

View File

@ -37,37 +37,37 @@ export default class Session {
/**
* Path of the session map file on disk.
*/
public get path() {
public get path(): string {
return this._path;
}
/**
* Indicates if the session is mapped on disk.
*/
public get isMapped() {
public get isMapped(): boolean {
return this._isMapped;
}
/**
* Date of creation of the session.
*/
public get created() {
public get created(): Date {
return this._created;
}
/**
* MD5 hash of the username and the password.
*/
public get hash() {
public get hash(): string {
return this._hash;
}
/**
* Token used to login to F95Zone.
*/
public get token() {
public get token(): string {
return this._token;
}
/**
* Cookie holder.
*/
public get cookieJar() {
public get cookieJar(): tough.CookieJar {
return this._cookieJar;
}

View File

@ -84,7 +84,7 @@ export async function fetchHTML(
*/
export async function authenticate(
credentials: credentials,
force = false
force: boolean = false
): Promise<LoginResult> {
shared.logger.info(`Authenticating with user ${credentials.username}`);
if (!credentials.token)
@ -140,7 +140,7 @@ export async function authenticate(
/**
* Obtain the token used to authenticate the user to the platform.
*/
export async function getF95Token() {
export async function getF95Token(): Promise<string> {
// Fetch the response of the platform
const response = await fetchGETResponse(f95url.F95_LOGIN_URL);
@ -167,7 +167,6 @@ export async function fetchGETResponse(
const response = await axios.get(secureURL, commonConfig);
return success(response);
} catch (e) {
console.log(e.response);
shared.logger.error(
`(GET) Error ${e.message} occurred while trying to fetch ${secureURL}`
);
@ -217,7 +216,7 @@ export function isStringAValidURL(url: string): boolean {
*/
export async function urlExists(
url: string,
checkRedirect = false
checkRedirect: boolean = false
): Promise<boolean> {
// Local variables
let valid = false;

View File

@ -90,13 +90,7 @@ function parseCheerioSpoilerNode(
if (element.attr("class") === "bbCodeSpoiler") {
const spoiler = parseCheerioSpoilerNode($, element);
content.content.push(spoiler);
}
//@ts-ignore
// else if (el.name === "br") {
// // Add new line
// content.text += "\n";
// }
else if (el.type === "text") {
} else if (el.type === "text") {
// Append text
content.text += element.text();
}
@ -266,7 +260,7 @@ function parseCheerioNode(
function parsePostElements(elements: IPostElement[]): IPostElement[] {
// Local variables
const pairs: IPostElement[] = [];
const specialCharsRegex = /^[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/;
const specialCharsRegex = /^[-!$%^&*()_+|~=`{}[\]:";'<>?,./]/;
const specialRegex = new RegExp(specialCharsRegex);
for (let i = 0; i < elements.length; i++) {

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-inferrable-types */
"use strict";
// Modules from file
@ -13,15 +14,13 @@ import getURLsFromQuery from "./fetch-data/fetch-query.js";
*/
export default async function search<T extends IBasic>(
query: IQuery,
limit = 30
limit: number = 30
): Promise<T[]> {
// Fetch the URLs
const urls: string[] = await getURLsFromQuery(query, limit);
// Fetch the data
const results = urls.map((url, idx) => {
return getHandiworkInformation<T>(url);
});
const results = urls.map((url) => getHandiworkInformation<T>(url));
return Promise.all(results);
}

View File

@ -14,6 +14,7 @@ import Session from "./classes/session.js";
// Types declaration
export type TPrefixDict = { [n: number]: string };
type TPrefixKey = "engines" | "statuses" | "tags" | "others";
type TPrefixes = { [key in TPrefixKey]: TPrefixDict };
/**
* Class containing variables shared between modules.
@ -22,9 +23,7 @@ export default abstract class Shared {
//#region Fields
private static _isLogged = false;
private static _prefixes: { [key in TPrefixKey]: TPrefixDict } = {} as {
[key in TPrefixKey]: TPrefixDict;
};
private static _prefixes: TPrefixes = {} as TPrefixes;
private static _logger: log4js.Logger = log4js.getLogger();
private static _session = new Session(join(tmpdir(), "f95session.json"));