Skip to content

Commit

Permalink
Eslint config update ignores branch (#113)
Browse files Browse the repository at this point in the history
* feat: Improve type safety in adapter functions

- Define a mapping type to constrain functions in adapters
- Ensure adapters comply with the mapping type
- Use type assertion instead of 'any' to enforce type safety

fix: Disable XSS warning for v-html directive in Vue files

- Add rule to disable 'vue/no-v-html' warning in Vue files

chore: Update list of allowed domains in nuxt.config.ts

- Add 'ipfs.crossbell.io' to the list of allowed domains

* refactor: Update Header component props to make url required

Make the `url` prop in the Header component required by changing its type to
`string | null`. This change ensures that a URL is always provided for the
Header component to function correctly.
  • Loading branch information
nexmoe authored May 1, 2024
1 parent 4b5837d commit a44bf27
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/flow/Header.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
interface Props {
url?: string
url: string | null
title: string
id: string
}
Expand Down
13 changes: 11 additions & 2 deletions composables/adapter/useAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ import * as adapters from './adapters'
// Define a type for the adapter functions to improve type safety
type AdapterFunction = (api: API) => Promise<NModule[]>

// 定义一个映射类型来约束 adapters 中的函数
type AdaptersMap = {
[key in keyof typeof adapters]: AdapterFunction;
}

// 确保 adapters 符合这个映射类型
const typedAdapters: AdaptersMap = adapters

export default async function fetchModules(api: API): Promise<NModule[]> {
// Ensure that the adapter function exists and is callable
const adapter: AdapterFunction | undefined = (adapters as any)[api.adapter]
// 使用类型断言替代 any,因为我们已经通过 AdaptersMap 确保了类型安全
const adapter: AdapterFunction | undefined = typedAdapters[api.adapter as keyof typeof typedAdapters]

if (typeof adapter === 'function') {
const items: NModule[] = await adapter(api)
return items
Expand Down
8 changes: 6 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ export default withNuxt(
// ...
// }
{

files: ['**/*.vue'],
rules: {
'vue/no-v-html': 'off', // 关闭 v-html 指令的 XSS 警告
},
},
{
ignores: ['dist', '**/dist/**', 'public', '**/public/**', 'auto-imports.d.ts', '**/auto-imports.d.ts/**', 'components.d.ts', '**/components.d.ts/**', '.output', '**/.output/**', 'node_modules', '**/node_modules/**', 'components/ui', '**/components/ui/**'],

},
)
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default defineNuxtConfig({
'pic4.zhimg.com',
'unavatar.io',
'i.dawnlab.me',
'ipfs.crossbell.io'
'ipfs.crossbell.io',
],
},

Expand Down

0 comments on commit a44bf27

Please sign in to comment.