Skip to content

Commit

Permalink
chore: improve linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Aug 20, 2024
1 parent 4e5e2a4 commit a48ce72
Show file tree
Hide file tree
Showing 26 changed files with 146 additions and 75 deletions.
4 changes: 2 additions & 2 deletions docs/.vuepress/configs/navbar/en.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NavbarConfig } from '@vuepress/theme-default'
import type { NavbarOptions } from '@vuepress/theme-default'

export const navbarEn: NavbarConfig = [
export const navbarEn: NavbarOptions = [
{
text: 'Themes',
prefix: '/themes/',
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/configs/navbar/zh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NavbarConfig } from '@vuepress/theme-default'
import type { NavbarOptions } from '@vuepress/theme-default'

export const navbarZh: NavbarConfig = [
export const navbarZh: NavbarOptions = [
{
text: '主题',
prefix: '/zh/themes/',
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/configs/sidebar/en.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SidebarConfig } from '@vuepress/theme-default'
import type { SidebarOptions } from '@vuepress/theme-default'

export const sidebarEn: SidebarConfig = {
export const sidebarEn: SidebarOptions = {
'/plugins/': [
{
text: 'Common Features',
Expand Down
4 changes: 2 additions & 2 deletions docs/.vuepress/configs/sidebar/zh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SidebarConfig } from '@vuepress/theme-default'
import type { SidebarOptions } from '@vuepress/theme-default'

export const sidebarZh: SidebarConfig = {
export const sidebarZh: SidebarOptions = {
'/zh/plugins/': [
{
text: '常用功能',
Expand Down
19 changes: 8 additions & 11 deletions docs/plugins/development/sass-palette/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ You must invoke `useSassPalettePlugin` function during plugin initialization to
npm i -D @vuepress/plugin-sass-palette@next
```

```ts title="Your plugin or theme entry"
import type { PluginFunction } from 'vuepress/core'
```js title="Your plugin or theme entry"
import { useSassPalettePlugin } from 'vuepress-plugin-sass-palette'

export const yourPlugin =
(options): PluginFunction =>
(app) => {
useSassPalettePlugin(app, {
// plugin options
})
export const yourPlugin = (options) => (app) => {
useSassPalettePlugin(app, {
// plugin options
})

return {
// your plugin api
}
return {
// your plugin api
}
}
```
2 changes: 1 addition & 1 deletion docs/plugins/markdown/markdown-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default {
type MarkdownItContainerRenderFunction = (
tokens: Token[],
index: number,
options: any,
options: unknown,
env: MarkdownEnv,
self: Renderer,
) => string
Expand Down
10 changes: 5 additions & 5 deletions docs/plugins/pwa/pwa/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Special settings for Microsoft tiles, ignoring these options are safe.
import { usePwaEvent } from '@vuepress/plugin-pwa/client'
export default {
setup() {
setup(): void {
const event = usePwaEvent()
event.on('ready', (registration) => {
console.log('Service worker is active.')
Expand All @@ -330,7 +330,7 @@ import { forceUpdate } from '@vuepress/plugin-pwa/client'
import { onMounted } from 'vue'
export default {
setup() {
setup(): void {
onMounted(() => {
forceUpdate()
})
Expand Down Expand Up @@ -372,7 +372,7 @@ import { registerSW } from '@vuepress/plugin-pwa/client'
import { onMounted } from 'vue'
export default {
setup() {
setup(): void {
onMounted(() => {
registerSW('/service-worker.js', {
ready(registration) {
Expand Down Expand Up @@ -402,7 +402,7 @@ export default {
import { skipWaiting, usePwaEvent } from '@vuepress/plugin-pwa/client'
export default {
setup() {
setup(): void {
const event = usePwaEvent()
event.on('updated', (registration) => {
Expand All @@ -427,7 +427,7 @@ import { unregisterSW } from '@vuepress/plugin-pwa/client'
import { onMounted } from 'vue'
export default {
setup() {
setup(): void {
onMounted(() => {
unregisterSW()
})
Expand Down
5 changes: 2 additions & 3 deletions docs/zh/plugins/development/sass-palette/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
npm i -D @vuepress/plugin-sass-palette@next
```

```ts title="你的插件或主题入口"
import type { Plugin } from 'vuepress/core'
```js title="你的插件或主题入口"
import { useSassPalettePlugin } from 'vuepress-plugin-sass-palette'

export const yourPlugin: Plugin = (options) => (app) => {
export const yourPlugin = (options) => (app) => {
useSassPalettePlugin(app, {
// 插件选项
})
Expand Down
30 changes: 16 additions & 14 deletions docs/zh/plugins/features/photo-swipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,36 +219,38 @@ export default {}

```vue
<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue';
import { createPhotoSwipe } from "@vuepress/plugin-photo-swipe/client";
import { createPhotoSwipe } from '@vuepress/plugin-photo-swipe/client'
import { onMounted, onUnmounted } from 'vue'
let state: PhotoSwipeState | null = null;
let state: PhotoSwipeState | null = null
const openPhotoSwipe = (index: number) => {
state?.open(index - 1);
};
const openPhotoSwipe = (index: number): void => {
state?.open(index - 1)
}
onMounted(async () => {
// 通过图片链接创建一个新的 photoswipe 实例
state= await createPhotoSwipe(
state = await createPhotoSwipe(
[
'https://exmaple.com/image1.png'
'https://exmaple.com/image2.png'
'https://exmaple.com/image3.png'
'https://exmaple.com/image1.png',
'https://exmaple.com/image2.png',
'https://exmaple.com/image3.png',
],
{
// photoswipe 选项
}
);
});
},
)
})
onUnmounted(() => {
state?.destroy()
})
</script>
<template>
<button v-for="i in 3" @click="openPhotoSwipe(i)">open photo {{ i }}</button>
<button v-for="i in 3" :key="i" type="button" @click="openPhotoSwipe(i)">
open photo {{ i }}
</button>
</template>
```

Expand Down
2 changes: 1 addition & 1 deletion docs/zh/plugins/markdown/markdown-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default {
type MarkdownItContainerRenderFunction = (
tokens: Token[],
index: number,
options: any,
options: unknown,
env: MarkdownEnv,
self: Renderer,
) => string
Expand Down
61 changes: 61 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,64 @@ export default vuepress(
},
typescript: {
overrides: {
'@typescript-eslint/naming-convention': [
'warn',

{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allow',
},
// allow global variables like __VUEPRESS_DEV__
{
selector: ['variable'],
filter: '^__.*__$',
format: ['UPPER_CASE'],
leadingUnderscore: 'requireDouble',
trailingUnderscore: 'requireDouble',
},
{
selector: ['variable'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allowSingleOrDouble',
},
// stop checking object literal properties type properties
// the format can be `og:title` `line-width` `__raw` `__VUEPRESS_DEV` `++` ...
{
selector: ['objectLiteralProperty', 'typeProperty'],
format: null,
},
// allow slots like `navbar-start`
{
selector: ['typeMethod'],
filter: '^[a-z]+(?:-[a-z]+)*?$',
format: null,
},
{
selector: ['property'],
format: ['camelCase', 'PascalCase'],
},
{
selector: ['parameter'],
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'import',
format: ['PascalCase', 'camelCase'],
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'enumMember',
format: ['PascalCase'],
},
],
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
Expand All @@ -54,6 +112,8 @@ export default vuepress(
},
],
'@typescript-eslint/promise-function-async': 'off',
// FIXME: Fail positives
'import/no-extraneous-dependencies': 'off',
'no-underscore-dangle': 'off',
},
},
Expand All @@ -69,6 +129,7 @@ export default vuepress(
},
},
},

{
files: ['**/tests/**'],
rules: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ declare global {
interface Window {
umami: {
track: {
(payload?: Record<any, any>): void
(name: string, data?: Record<any, any>): void
(payload?: Record<string, unknown>): void
(name: string, data?: Record<string, unknown>): void
}
}
}
Expand All @@ -27,6 +27,7 @@ export const useUmamiAnalytics = ({
hostUrl,
}: UmamiOptions): void => {
// avoid duplicated import
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (window.umami) return

const script = document.createElement('script')
Expand Down
4 changes: 3 additions & 1 deletion plugins/blog/plugin-feed/src/node/generator/json/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const getJSONFeed = (feedStore: FeedStore): string => {
: channel.author
? [channel.author]
: []
).filter((author) => Boolean(author?.name))
)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
.filter((author) => author?.name)

if (channelAuthors.length)
content.authors = channelAuthors.map((author) => getJSONAuthor(author))
Expand Down
1 change: 1 addition & 0 deletions plugins/development/plugin-theme-data/src/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default defineClientConfig({
setupDevtoolsPlugin(
{
// fix recursive reference
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
app: app as any,
id: 'org.vuejs.vuepress.plugin-theme-data',
label: 'VuePress Theme Data Plugin',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-shadow */
import {
endsWith,
ensureEndingSlash,
Expand Down
28 changes: 17 additions & 11 deletions plugins/markdown/plugin-prismjs/src/node/parser/getCodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const NEWLINE_RE = /(\r?\n)/g
const CLASS_RE = /class="([^]*)"/
const CODE_ESCAPE_RE = /\[\\!code/g

const uniq = <T>(array: T[]): T[] => [...new Set(array)]

export interface OpenTag {
/**
* @example <tag
Expand Down Expand Up @@ -68,8 +70,9 @@ const createOpenTag = (
after: hashHtml ? snippet.slice(-1) : '',
content,
toString() {
const className = uniq(this.classList).join(' ')
const { before, after, content } = this
// eslint-disable-next-line @typescript-eslint/no-shadow
const { before, after, classList, content } = this
const className = uniq(classList).join(' ')

return `${before}${className && before ? ` class="${className}"` : ''}${after}${content}`
},
Expand All @@ -82,29 +85,32 @@ const createOpenTag = (
after: snippet.slice(match.index! + match[0].length),
content,
toString() {
const className = uniq(this.classList).join(' ')
const { before, after, content } = this
// eslint-disable-next-line @typescript-eslint/no-shadow
const { before, after, classList, content } = this
const className = uniq(classList).join(' ')

return `${before}${className && before ? ` class="${className}"` : ''}${after}${content}`
},
}
}

const uniq = <T>(array: T[]): T[] => [...new Set(array)]

export const getCodeParser = (html: string): CodeParser => {
let content = html
const preOpen = html.match(PRE_OPEN_TAG_RE)?.[1] ?? ''

html = html.slice(preOpen.length)
content = content.slice(preOpen.length)

const code = html.match(CODE_OPEN_TAG_RE)?.[1] ?? ''
const endLine = html.match(FENCE_CLOSE_TAG_RE)?.[1] ?? ''
const code = content.match(CODE_OPEN_TAG_RE)?.[1] ?? ''
const endLine = content.match(FENCE_CLOSE_TAG_RE)?.[1] ?? ''

html = html.slice(code.length, endLine.length ? -endLine.length : html.length)
content = content.slice(
code.length,
endLine.length ? -endLine.length : content.length,
)

const preOpenTag = createOpenTag(preOpen)
const codeOpenTag = createOpenTag(code)
const lineNodeList = splitLines(html).map((line) =>
const lineNodeList = splitLines(content).map((line) =>
createOpenTag('<span>', line, ['line']),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
notationWordHighlight,
} from '../src/node/index.js'

const genCode = (code: string) => `<pre><code>${code}</code></pre>`
const genCode = (code: string): string => `<pre><code>${code}</code></pre>`

describe('@vuepress/plugin-prismjs > parser', () => {
it('normal parse', () => {
Expand Down
Loading

0 comments on commit a48ce72

Please sign in to comment.