chore: switch on eslint rule: @typescript-eslint/explicit-module-boundary-types

This commit is contained in:
Sándor Levcsák 2020-11-11 00:01:45 +02:00
parent 5bf2a103ed
commit 7c2d0a9df3
23 changed files with 46 additions and 36 deletions

View File

@ -82,7 +82,6 @@
"warn",
"always-multiline"
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
}

View File

@ -12,6 +12,7 @@ import {
getArticlesByTag,
} from '../services/article/getArticles'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function useArticles () {
const { articlesType, tag, username, metaChanged } = getArticlesMeta()
@ -80,6 +81,7 @@ export function useArticles () {
export type ArticlesType = 'global-feed' | 'my-feed' | 'tag-feed' | 'user-feed' | 'user-favorites-feed'
export const articlesTypes: ArticlesType[] = ['global-feed', 'my-feed', 'tag-feed', 'user-feed', 'user-favorites-feed']
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const isArticlesType = (type: any): type is ArticlesType => articlesTypes.includes(type)
const routeNameToArticlesType: Partial<Record<AppRouteNames, ArticlesType>> = ({

View File

@ -14,6 +14,7 @@ interface useFavoriteArticleProps {
onUpdate: (newArticle: Article) => void
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useFavoriteArticle = ({ isFavorited, articleSlug, onUpdate }: useFavoriteArticleProps) => {
const favoriteArticle = async () => {
let response: Either<AuthorizationError, Article>

View File

@ -14,6 +14,7 @@ interface UseFollowProps {
onUpdate: (profile: Profile) => void
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function useFollow ({ username, following, onUpdate }: UseFollowProps) {
async function toggleFollow () {
let response: Either<AuthorizationError, Profile>

View File

@ -6,6 +6,7 @@ interface UseProfileProps {
username: ComputedRef<string>
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function useProfile ({ username }: UseProfileProps) {
const profile = ref<Profile | null>(null)

View File

@ -2,6 +2,7 @@ import { ref } from 'vue'
import { getAllTags } from '../services/tag/getTags'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function useTags () {
const tags = ref<string[]>([])

View File

@ -2,6 +2,6 @@ import type { App } from 'vue'
import AppLink from '../components/AppLink.vue'
export default function registerGlobalComponents (app: App) {
export default function registerGlobalComponents (app: App): void {
app.component('AppLink', AppLink)
}

View File

@ -1,7 +1,7 @@
import { request } from '../services'
import storage from '../utils/storage'
export default function () {
export default function (): void {
const token = storage.get<User>('user')?.token
if (token) request.setAuthorizationHeader(token)
}

View File

@ -74,7 +74,7 @@ export const router = createRouter({
],
})
export function routerPush (name: AppRouteNames, params?: RouteParams) {
export function routerPush (name: AppRouteNames, params?: RouteParams): ReturnType<typeof router.push> {
if (params) return router.push({ name, params })
else return router.push({ name })
}

View File

@ -1,5 +1,5 @@
import { request } from '../index'
export async function getArticle (slug: string) {
export async function getArticle (slug: string): Promise<Article> {
return request.get<ArticleResponse>(`/articles/${slug}`).then(res => res.article)
}

View File

@ -1,26 +1,26 @@
import { limit, request } from '../index'
export async function getArticles (page = 1) {
export async function getArticles (page = 1): Promise<ArticlesResponse> {
const params = { limit, offset: (page - 1) * limit }
return request.get<ArticlesResponse>('/articles', { params })
}
export async function getFavoritedArticles (username: string, page = 1) {
export async function getFavoritedArticles (username: string, page = 1): Promise<ArticlesResponse> {
const params = { limit, offset: (page - 1) * limit, favorited: username }
return request.get<ArticlesResponse>('/articles', { params })
}
export async function getProfileArticles (username: string, page = 1) {
export async function getProfileArticles (username: string, page = 1): Promise<ArticlesResponse> {
const params = { limit, offset: (page - 1) * limit, author: username }
return request.get<ArticlesResponse>('/articles', { params })
}
export async function getFeeds (page = 1) {
export async function getFeeds (page = 1): Promise<ArticlesResponse> {
const params = { limit, offset: (page - 1) * limit }
return request.get<ArticlesResponse>('/articles/feed', { params })
}
export async function getArticlesByTag (tagName: string, page = 1) {
export async function getArticlesByTag (tagName: string, page = 1): Promise<ArticlesResponse> {
const params = { tag: tagName, limit, offset: (page - 1) * limit }
return request.get<ArticlesResponse>('/articles', { params })
}

View File

@ -7,12 +7,12 @@ interface PostArticleForm {
tagList: string[];
}
export async function postArticle (form: PostArticleForm) {
export async function postArticle (form: PostArticleForm): Promise<Article> {
return request.post<ArticleResponse>('/articles', { article: form })
.then(res => res.article)
}
export async function putArticle (slug: string, form: PostArticleForm) {
export async function putArticle (slug: string, form: PostArticleForm): Promise<Article> {
return request.put<ArticleResponse>(`/articles/${slug}`, { article: form })
.then(res => res.article)
}

View File

@ -1,5 +1,5 @@
import { request } from '../index'
export async function getCommentsByArticle (slug: string) {
export async function getCommentsByArticle (slug: string): Promise<ArticleComment[]> {
return request.get<CommentsResponse>(`/articles/${slug}/comments`).then(res => res.comments)
}

View File

@ -1,10 +1,10 @@
import { request } from '../index'
export async function deleteComment (slug: string, commentId: number) {
export async function deleteComment (slug: string, commentId: number): Promise<any> {
return request.delete(`/articles/${slug}/comments/${commentId}`)
}
export async function postComment (slug: string, body: string) {
export async function postComment (slug: string, body: string): Promise<ArticleComment> {
return request.post<CommentResponse>(`/articles/${slug}/comments`, { comment: { body } })
.then(res => res.comment)
}

View File

@ -1,5 +1,5 @@
import { request } from '../index'
export async function getProfile (username: string) {
export async function getProfile (username: string): Promise<Profile> {
return request.get<ProfileResponse>(`/profiles/${username}`).then(res => res.profile)
}

View File

@ -8,6 +8,6 @@ export interface PutProfileForm {
password?: string;
}
export async function putProfile (form: PutProfileForm) {
export async function putProfile (form: PutProfileForm): Promise<User> {
return request.put<UserResponse>('/user', form).then(res => res.user)
}

View File

@ -1,5 +1,5 @@
import { request } from '../index'
export async function getAllTags () {
export async function getAllTags (): Promise<string[]> {
return request.get<TagsResponse>('/tags').then(res => res.tags)
}

View File

@ -24,7 +24,7 @@ export class ValidationError<T extends Partial<Record<string, string[]>>> extend
super('VALIDATION_ERROR', response)
}
getErrors () {
getErrors (): Promise<T> {
return this.response.json().then(json => json.errors as T)
}
}

View File

@ -1,9 +1,14 @@
import { ref } from 'vue'
import { Ref, ref } from 'vue'
export default function createAsyncProcess<T extends (...args: any[]) => any> (fn: T) {
const active = ref<boolean>(false)
interface CreateAsyncProcessReturn<T extends (...args: any[]) => any> {
active: Ref<boolean>
run: (...args : Parameters<T>) => Promise<ReturnType<T>>
}
async function run (...args : Parameters<T>): Promise<ReturnType<T>> {
export default function createAsyncProcess<T extends (...args: any[]) => any> (fn: T): CreateAsyncProcessReturn<T> {
const active: CreateAsyncProcessReturn<T>['active'] = ref(false)
const run: CreateAsyncProcessReturn<T>['run'] = async (...args) => {
active.value = true
const result = await fn(...args)
active.value = false

View File

@ -1,4 +1,4 @@
export const dateFilter = (dateString: string) => {
export const dateFilter = (dateString: string): string => {
const date = new Date(dateString)
return date.toLocaleDateString('en-US', {
month: 'long',

View File

@ -76,43 +76,43 @@ export default class FetchRequest {
return this.runFetch({ method, url, options, data })
}
get<T = any> (url: string, options: Partial<FetchRequestOptions> = {}) {
get<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<T> {
return this.runSafeFetch('GET', url, options).then(r => this.handleCorrectResponse<T>(r))
}
checkableGet<T = any> (url: string, options: Partial<FetchRequestOptions> = {}) {
checkableGet<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
return this.runSafeFetch('GET', url, options).then(r => this.handleResponse<T>(r))
}
post<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
post<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<T> {
return this.runUnsafeFetch('POST', url, data, options).then(r => this.handleCorrectResponse<T>(r))
}
checkablePost<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
checkablePost<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
return this.runUnsafeFetch('POST', url, data, options).then(r => this.handleResponse<T>(r))
}
delete<T = any> (url: string, options: Partial<FetchRequestOptions> = {}) {
delete<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<T> {
return this.runSafeFetch('DELETE', url, options).then(r => this.handleCorrectResponse<T>(r))
}
checkableDelete<T = any> (url: string, options: Partial<FetchRequestOptions> = {}) {
checkableDelete<T = any> (url: string, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
return this.runSafeFetch('DELETE', url, options).then(r => this.handleResponse<T>(r))
}
put<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
put<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<T> {
return this.runUnsafeFetch('PUT', url, data, options).then(r => this.handleCorrectResponse<T>(r))
}
checkablePut<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
checkablePut<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
return this.runUnsafeFetch('PUT', url, data, options).then(r => this.handleResponse<T>(r))
}
patch<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
patch<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<T> {
return this.runUnsafeFetch('PATCH', url, data, options).then(r => this.handleCorrectResponse<T>(r))
}
checkablePatch<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}) {
checkablePatch<T = any> (url: string, data: Record<string, any> = {}, options: Partial<FetchRequestOptions> = {}): Promise<Either<NetworkError, T>> {
return this.runUnsafeFetch('PATCH', url, data, options).then(r => this.handleResponse<T>(r))
}

View File

@ -7,7 +7,7 @@ function get<T = any> (key: string): T | null {
}
}
function set (key: string, value: any): void {
function set <T> (key: string, value: T): void {
const strValue = JSON.stringify(value)
localStorage.setItem(key, strValue)
}

View File

@ -1,7 +1,7 @@
type LocalStorageKey = 'getItem' | 'setItem' | 'removeItem'
export default function mockLocalStorage (key: LocalStorageKey, data?: any, stringify = true): jest.Mock {
export default function mockLocalStorage<T> (key: LocalStorageKey, data?: T, stringify = true): jest.Mock {
const fn = jest.fn().mockReturnValue(stringify ? JSON.stringify(data) : data)
// use __proto__ because jsdom bug: https://github.com/facebook/jest/issues/6798#issuecomment-412871616
// eslint-disable-next-line no-proto