chore: switch on eslint rule: @typescript-eslint/explicit-function-return-type

This commit is contained in:
Sándor Levcsák 2020-11-11 03:06:01 +02:00 committed by plumrx
parent f114698e8d
commit 9412aca012
8 changed files with 36 additions and 22 deletions

View File

@ -23,7 +23,6 @@
"warn",
"always-multiline"
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/promise-function-async": "off"
}
}

View File

@ -1,4 +1,4 @@
import { computed, ref, watch } from 'vue'
import { computed, ComputedRef, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import type { AppRouteNames } from '../router'
@ -12,7 +12,7 @@ import {
getArticlesByTag,
} from '../services/article/getArticles'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function useArticles () {
const { articlesType, tag, username, metaChanged } = getArticlesMeta()
@ -20,7 +20,7 @@ export function useArticles () {
const articlesCount = ref(0)
const page = ref(1)
async function fetchArticles () {
async function fetchArticles (): Promise<void> {
articles.value = []
let responsePromise: null | Promise<ArticlesResponse> = null
@ -49,11 +49,11 @@ export function useArticles () {
}
}
const changePage = (value: number) => {
const changePage = (value: number): void => {
page.value = value
}
const updateArticle = (index: number, article: Article) => {
const updateArticle = (index: number, article: Article): void => {
articles.value[index] = article
}
@ -92,7 +92,13 @@ const routeNameToArticlesType: Partial<Record<AppRouteNames, ArticlesType>> = ({
'profile-favorites': 'user-favorites-feed',
})
function getArticlesMeta () {
interface GetArticlesMetaReturn {
tag: ComputedRef<string>
username: ComputedRef<string>
articlesType: ComputedRef<ArticlesType>
metaChanged: ComputedRef<string>
}
function getArticlesMeta (): GetArticlesMetaReturn {
const route = useRoute()
const tag = ref('')

View File

@ -14,9 +14,9 @@ interface useFavoriteArticleProps {
onUpdate: (newArticle: Article) => void
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const useFavoriteArticle = ({ isFavorited, articleSlug, onUpdate }: useFavoriteArticleProps) => {
const favoriteArticle = async () => {
const favoriteArticle = async (): Promise<void> => {
let response: Either<AuthorizationError, Article>
if (isFavorited.value) {
response = await deleteFavoriteArticle(articleSlug.value)

View File

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

View File

@ -6,17 +6,17 @@ interface UseProfileProps {
username: ComputedRef<string>
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function useProfile ({ username }: UseProfileProps) {
const profile = ref<Profile | null>(null)
async function fetchProfile () {
async function fetchProfile (): Promise<void> {
updateProfile(null)
const profileData = await getProfile(username.value)
updateProfile(profileData)
}
function updateProfile (profileData: Profile | null) {
function updateProfile (profileData: Profile | null): void {
profile.value = profileData
}

View File

@ -2,11 +2,11 @@ import { ref } from 'vue'
import { getAllTags } from '../services/tag/getTags'
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function useTags () {
const tags = ref<string[]>([])
async function fetchTags () {
async function fetchTags (): Promise<void> {
tags.value = []
tags.value = await getAllTags()
}

View File

@ -2,7 +2,7 @@ import { isRef } from 'vue'
import createAsyncProcess from './create-async-process'
describe('# Create async process', function () {
const someProcess = () => Promise.resolve(null)
const someProcess = (): Promise<null> => Promise.resolve(null)
it('should expect active as Vue Ref type', function () {
const { active } = createAsyncProcess(someProcess)

View File

@ -24,7 +24,7 @@ export default class FetchRequest {
this.options = merge(this.defaultOptions, options)
}
private readonly generateFinalUrl = (url: string, options: Partial<FetchRequestOptions> = {}) => {
private readonly generateFinalUrl = (url: string, options: Partial<FetchRequestOptions> = {}): string => {
const prefix = options.prefix ?? this.options.prefix
const params = merge(this.options.params, options.params ?? {})
@ -34,7 +34,7 @@ export default class FetchRequest {
return finalUrl
}
private readonly generateFinalHeaders = (options: Partial<FetchRequestOptions> = {}) => {
private readonly generateFinalHeaders = (options: Partial<FetchRequestOptions> = {}): FetchRequestOptions['headers'] => {
return merge(this.options.headers, options.headers ?? {})
}
@ -59,7 +59,7 @@ export default class FetchRequest {
url: string
data?: unknown
options?: Partial<FetchRequestOptions>
}) {
}): Promise<Response> {
const finalUrl = this.generateFinalUrl(url, options)
const headers = this.generateFinalHeaders(options)
@ -69,11 +69,20 @@ export default class FetchRequest {
return fetch(finalUrl, fetchOptions)
}
private runSafeFetch (method: 'GET' | 'DELETE', url: string, options?: Partial<FetchRequestOptions>) {
private runSafeFetch (
method: 'GET' | 'DELETE',
url: string,
options?: Partial<FetchRequestOptions>,
): Promise<Response> {
return this.runFetch({ method, url, options })
}
private runUnsafeFetch (method: 'POST' | 'PUT' | 'PATCH', url: string, data?: unknown, options?: Partial<FetchRequestOptions>) {
private runUnsafeFetch (
method: 'POST' | 'PUT' | 'PATCH',
url: string,
data?: unknown,
options?: Partial<FetchRequestOptions>,
): Promise<Response> {
return this.runFetch({ method, url, options, data })
}