Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSnow committed Apr 2, 2024
1 parent a3f3d10 commit ff38f8c
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 38 deletions.
8 changes: 5 additions & 3 deletions packages/karbon/playground/pages/indexes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const resourceKey = ['articles', 'desks', 'tags', 'authors'] as const
<div class="font-bold capitalize">{{ resource }}:</div>
<ul>
<li v-for="item in resources[resource].value" :key="item.meta.id">
<NuxtLink :href="item.url" class="underline text-teal-500">{{
(item.meta as any).title || (item.meta as any).name || (item.meta as any).full_name
}}</NuxtLink>
<NuxtLink :href="item.url" class="underline text-teal-500">
{{
(item.meta as any).title || (item.meta as any).name || (item.meta as any).full_name
}}
</NuxtLink>
</li>
</ul>
</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/karbon/src/runtime/api/__tests__/helper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect, test, vi } from 'vitest'
import { expect, it, vi } from 'vitest'
import type { PaginationData } from '../helper'
import { getAllWithPaginationViaGetPage, getRemainingPages } from '../helper'

test('getRemainingPage', () => {
it('getRemainingPage', () => {
expect(getRemainingPages(3)).toEqual([2, 3])
expect(getRemainingPages(4)).toEqual([2, 3, 4])
expect(getRemainingPages(1)).toEqual([])
})

test('getAllWithPaginationViaGetPage', async () => {
it('getAllWithPaginationViaGetPage', async () => {
const fn = vi.fn(async (page: number): Promise<PaginationData> => {
if (page === 1) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect, test, vi } from 'vitest'
import { expect, it, vi } from 'vitest'
import { normalizeArticle } from '../normalize-article'
import { mockQueryArticle, mockTypesenseArticle } from './article.mock'

vi.mock('#imports', async () => await vi.importActual('../../../normalize-helper'))

test('mockTypesenseArticle', () => {
it('mockTypesenseArticle', () => {
expect(normalizeArticle(mockTypesenseArticle)).toMatchSnapshot()
expect(normalizeArticle(mockQueryArticle)).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Mock } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'
import { usePagination } from '../pagination'

test('usePagination with remaining page', () => {
it('usePagination with remaining page', () => {
const res = usePagination(ref([1, 2, 3]), 2)
expect(res.page.value).toBe(1)
expect(res.total.value).toBe(2)
Expand Down Expand Up @@ -45,7 +45,7 @@ test('usePagination with remaining page', () => {
expect(res.page.value).toBe(2)
})

test('usePagination with exactly page', () => {
it('usePagination with exactly page', () => {
const res = usePagination(ref([1, 2, 3, 4]), 2)
expect(res.page.value).toBe(1)
expect(res.total.value).toBe(2)
Expand Down Expand Up @@ -79,7 +79,7 @@ test('usePagination with exactly page', () => {
expect(res.page.value).toBe(2)
})

test('usePagination with empty list', () => {
it('usePagination with empty list', () => {
const res = usePagination(ref([]), 2)
expect(res.page.value).toBe(0)
expect(res.total.value).toBe(0)
Expand All @@ -102,13 +102,13 @@ describe('preconditon validation', () => {
vi.restoreAllMocks()
})

test('usePagination throw when limit is 0', () => {
it('usePagination throw when limit is 0', () => {
expect(() => {
usePagination(ref([]), 0)
}).toThrowErrorMatchingInlineSnapshot('"Invariant failed: `limit` must not be negative or 0"')
})

test('usePagination throw when limit is < 0', () => {
it('usePagination throw when limit is < 0', () => {
expect(() => {
usePagination(ref([]), -1)
}).toThrowErrorMatchingInlineSnapshot('"Invariant failed: `limit` must not be negative or 0"')
Expand Down
4 changes: 2 additions & 2 deletions packages/karbon/src/runtime/lib/__tests__/condition.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertType, test } from 'vitest'
import { assertType, it } from 'vitest'
import type { ConditionInput } from '../article-filter'

test('ConditionInput', () => {
it('conditionInput', () => {
assertType<ConditionInput>({ type: 'featured' })
assertType<ConditionInput>({ key: 'slug', value: 'foo' })
assertType<ConditionInput>({ type: 'desk', key: 'id', value: 'foo' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { expect, it } from 'vitest'
import { splitPaidContent } from '../split-paid-content'

test('splitPaidContent should extract first 3 paragraph by default', () => {
it('splitPaidContent should extract first 3 paragraph by default', () => {
const [preview, paid] = splitPaidContent('<p>foo</p><p>bar</p><p>baz</p><p>paid</p>')
expect(preview).not.toContain('paid')
expect(preview).toMatchInlineSnapshot('"<p>foo</p><p>bar</p><p>baz</p>"')
Expand All @@ -13,7 +13,7 @@ test('splitPaidContent should extract first 3 paragraph by default', () => {
expect(paid2).toMatchInlineSnapshot('"<p>paid</p><p>paid2</p>"')
})

test('splitPaidContent should make every thing paid if length not enough', () => {
it('splitPaidContent should make every thing paid if length not enough', () => {
const [preview, paid] = splitPaidContent('<p>paid</p>')
expect(preview).not.toContain('paid')
expect(preview).toMatchInlineSnapshot('""')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export interface ResourcePageContext {
export interface ResourcePage<Meta extends Identifiable> {
route: string
enable: boolean
getIdentity(params: Record<string, string>, _context: ResourcePageContext, deskMetas?: Meta[]): ResourceID
isValid(params: Record<string, string>, resource: Meta, _context: ResourcePageContext): boolean
toURL(resource: Meta, _context: ResourcePageContext): string
getIdentity: (params: Record<string, string>, _context: ResourcePageContext, deskMetas?: Meta[]) => ResourceID
isValid: (params: Record<string, string>, resource: Meta, _context: ResourcePageContext) => boolean
toURL: (resource: Meta, _context: ResourcePageContext) => string
_context?: ResourcePageContext
groupKey?: string
}
Expand Down
6 changes: 3 additions & 3 deletions packages/karbon/src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export interface ResourcePageContext {
export interface ResourcePage<Meta extends Identifiable, Ctx = ResourcePageContext> {
route: string
enable: boolean
getIdentity(params: Record<string, string>, _context: Ctx, deskMetas?: Meta[]): ResourceID
isValid(params: Record<string, string>, resource: Meta, _context: Ctx): boolean
toURL(resource: Meta, _context: Ctx): string
getIdentity: (params: Record<string, string>, _context: Ctx, deskMetas?: Meta[]) => ResourceID
isValid: (params: Record<string, string>, resource: Meta, _context: Ctx) => boolean
toURL: (resource: Meta, _context: Ctx) => string
_context?: Ctx
groupKey?: string
meta?: PageMeta
Expand Down
8 changes: 4 additions & 4 deletions packages/karbon/src/url/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { expect, it } from 'vitest'
import { createResourceRoute } from '..'

test('createResourceRoute', () => {
it('createResourceRoute', () => {
const route = createResourceRoute({
resource: 'article',
url: '/posts/{desk.slug}/{slug}',
Expand All @@ -23,7 +23,7 @@ test('createResourceRoute', () => {
)
})

test('createResourceRoute with optional', () => {
it('createResourceRoute with optional', () => {
const route = createResourceRoute({
resource: 'article',
url: '/posts/{root_desk.slug}/{?sub_desk.slug}/{slug}',
Expand Down Expand Up @@ -58,7 +58,7 @@ test('createResourceRoute with optional', () => {
expect(route.toURL(metaWithoutSubdesk, route._context)).toBe('/posts/root-slug/article-slug')
})

test('with static param', () => {
it('with static param', () => {
const route = createResourceRoute({
resource: 'article',
url: '/{#foo}/{id}',
Expand Down
6 changes: 3 additions & 3 deletions packages/karbon/src/url/__tests__/parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { expect, it } from 'vitest'
import { parse, toRoute } from '../parser'

test('parse url work', () => {
it('parse url work', () => {
expect(parse('/posts/{slug}')).toMatchInlineSnapshot(`
[
{
Expand Down Expand Up @@ -195,7 +195,7 @@ test('parse url work', () => {
`)
})

test('toRoute', () => {
it('toRoute', () => {
expect(
toRoute([
{
Expand Down
8 changes: 4 additions & 4 deletions packages/karbon/src/url/__tests__/to-options.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { expect, it } from 'vitest'
import { convertToOption } from '../to-options'

test('convertToOption basic', () => {
it('convertToOption basic', () => {
const opt = convertToOption('article', [
{
type: 'static',
Expand Down Expand Up @@ -86,7 +86,7 @@ test('convertToOption basic', () => {
expect(opt.toURL({ desk: { slug: 'desk' }, slug: 'article-slug' }, opt._context)).toBe('/desk/article-slug')
})

test('convertToOption with optional and optional param exist', () => {
it('convertToOption with optional and optional param exist', () => {
const opt = convertToOption('article', [
{
type: 'static',
Expand Down Expand Up @@ -199,7 +199,7 @@ test('convertToOption with optional and optional param exist', () => {
expect(opt.toURL(meta, opt._context)).toBe('/parent-desk/sub-desk/article-slug')
})

test('convertToOption with optional and optional param non-exist', () => {
it('convertToOption with optional and optional param non-exist', () => {
const opt = convertToOption('article', [
{
type: 'static',
Expand Down
4 changes: 2 additions & 2 deletions packages/karbon/src/url/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from 'vitest'
import { expect, it } from 'vitest'
import { paramNameToParamKey } from '../utils'

test('paramNameToParamKey', () => {
it('paramNameToParamKey', () => {
expect(paramNameToParamKey(':foo')).toBe('foo')
expect(paramNameToParamKey(':foo?')).toBe('foo')
})

0 comments on commit ff38f8c

Please sign in to comment.