chore: fix some lint

This commit is contained in:
07akioni 2021-03-15 15:25:11 +08:00
parent 242238e37a
commit 3824247184
4 changed files with 30 additions and 34 deletions

View File

@ -4,20 +4,29 @@ const renderer = createRenderer()
const projectPath = require('./project-path')
function parseMdAsAnchor (tokens) {
const titles = tokens.filter(token => token.type === 'heading' && token.depth === 2).map(token => token.text)
const linkTags = titles.map(title => {
const titles = tokens
.filter((token) => token.type === 'heading' && token.depth === 2)
.map((token) => token.text)
const linkTags = titles.map((title) => {
const href = title.replace(/ /g, '-')
return `<n-anchor-link title="${title}" href="#${href}"/>`
})
return `<n-anchor ignore-gap :top="32" position="absolute" affix style="width: 144px;">${linkTags.join('\n')}</n-anchor>`
return `<n-anchor ignore-gap :top="32" position="absolute" affix style="width: 144px;">${linkTags.join(
'\n'
)}</n-anchor>`
}
function parseComponents (tokens) {
const componentsIndex = tokens.findIndex(token => token.type === 'code' && token.lang === 'component')
const componentsIndex = tokens.findIndex(
(token) => token.type === 'code' && token.lang === 'component'
)
let components = []
if (~componentsIndex) {
components = tokens[componentsIndex].text
components = components.split('\n').map(component => component.trim()).filter(component => component.length)
components = components
.split('\n')
.map((component) => component.trim())
.filter((component) => component.length)
tokens.splice(componentsIndex, 1)
}
return components
@ -30,12 +39,15 @@ module.exports = function (content, path) {
// for marked bug https://github.com/markedjs/marked/issues/1047
content = content.replace(/\n#/g, '\n\n#')
const tokens = marked.lexer(content)
const titleIndex = tokens.findIndex(token => token.type === 'heading' && token.depth === 1)
const titleText = titleIndex > -1 ? JSON.stringify(tokens[titleIndex].text) : null
const titleIndex = tokens.findIndex(
(token) => token.type === 'heading' && token.depth === 1
)
const titleText =
titleIndex > -1 ? JSON.stringify(tokens[titleIndex].text) : null
const anchor = parseMdAsAnchor(tokens)
const components = parseComponents(tokens)
const importStatements = components
.map(component => `import ${component} from './${component}'`)
.map((component) => `import ${component} from './${component}'`)
.join('\n')
let mdContent = marked.parser(tokens, { renderer })
if (titleText) {
@ -50,12 +62,7 @@ module.exports = function (content, path) {
<div style="width: calc(100% - 180px); margin-right: 36px;">
${mdContent}
</div>
${
showAnchor ? `
<div style="width: 144px;">
${anchor}
</div>` : ''
}
${showAnchor ? `<div style="width: 144px;">${anchor}</div>` : ''}
</div>
</component-documentation>
</template>

View File

@ -1,5 +1,5 @@
## Color
--color --color-hover --color-pressed --color-active --color-active-hover --color-disabled --color-disabled-active
--color --color-hover --color-pressed --color-active --color-active-hover --color-active-pressed --color-focus --color-focus-hover --color-focus-active --color-focus-pressed --color-disabled --color-disabled-active
disabled-active > disabled > active-hover > active > pressed > hover > default

View File

@ -1,19 +0,0 @@
import { mount } from '@vue/test-utils'
import create from '../../create'
import { enUS } from '../../locales'
import { cascaderLight } from '../styles'
import { NCascader } from '../index'
describe('n-cascader', () => {
const naive = create({
locales: [enUS],
styles: [cascaderLight]
})
it('should work with import on demand', () => {
mount(NCascader, {
global: {
plugins: [naive]
}
})
})
})

View File

@ -0,0 +1,8 @@
import { mount } from '@vue/test-utils'
import { NCascader } from '../index'
describe('n-cascader', () => {
it('should work with import on demand', () => {
mount(NCascader)
})
})