Skip to content

fix: trailing quotations (close #126) #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/parser/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ export const isShorthand = (
if (!status.lastToken || status.lastToken.type !== CharType.WESTERN_LETTER) {
return false
}
if (str.length <= index + 1) {
return false
}
const nextChar = str[index + 1]
const nextType = checkCharType(nextChar)
if (nextType === CharType.WESTERN_LETTER || nextType === CharType.SPACE) {
Expand Down
7 changes: 7 additions & 0 deletions src/rules/case-pure-western.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const findNonWestern = (group: MutableGroupToken): boolean => {
return findNonWestern(token)
}
if (isFullwidthType(token.type)) {
if (token.value.match(/[‘’“”]/)) {
return false
}
return true
}
})
Expand All @@ -36,7 +39,11 @@ const resetValidation = (group: MutableGroupToken): void => {
for (const target in ValidationTarget) {
removeValidationOnTarget(token, target as ValidationTarget)
}
token.modifiedSpaceAfter = token.spaceAfter
token.modifiedType = token.type
token.modifiedValue = token.value
if (token.type === GroupTokenType.GROUP) {
token.modifiedInnerSpaceBefore = token.innerSpaceBefore
resetValidation(token)
}
})
Expand Down
10 changes: 5 additions & 5 deletions test/md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describe('parser with markdown', () => {

describe('markdown lint', () => {
test('[md] single paragraph', () => {
expect(getOutput('X[ xxx ](xxx)X`hello`world')).toBe(
'X [xxx](xxx) X `hello` world'
expect(getOutput('中文 X[ xxx ](xxx)X`hello`world')).toBe(
'中文 X [xxx](xxx) X `hello` world'
)
})
test('[md] frontmatter', () => {
Expand Down Expand Up @@ -129,11 +129,11 @@ describe('markdown lint', () => {
test('[md] raw content', () => {
// {% raw %}<div id="app" class="demo">...</div>{% raw %}
expect(
getOutput('{% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
).toBe('{% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
getOutput('中文 {% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
).toBe('中文 {% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
})
test('[md] empty lines', () => {
expect(getOutput('a\n\nb\n\nc')).toBe('a\n\nb\n\nc')
expect(getOutput('中文 a\n\nb\n\nc')).toBe('中文 a\n\nb\n\nc')
})
test('[md] inline code', () => {
expect(getOutput(`改进 \`<todo-item>\` 组件`)).toBe(
Expand Down
48 changes: 47 additions & 1 deletion test/uncategorized.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('lint by issues', () => {

// https://github.com/zhlint-project/zhlint/issues/35
test('#35 parse error', () => {
expect(getOutput('x‘x’x', options)).toBe('x ‘x’ x')
expect(getOutput('中文 x‘x’x', options)).toBe('中文 x ‘x’ x')
})

// https://github.com/zhlint-project/zhlint/issues/36
Expand All @@ -57,6 +57,52 @@ describe('lint by issues', () => {
expect(getOutput('中文 ;-)', options)).toBe('中文 ;-)')
expect(getOutput('1) 项目符号', options)).toBe('1) 项目符号')
})

// https://github.com/zhlint-project/zhlint/issues/126
test('#126 (1)', () => {
expect(getOutput(
`使用 \`||\` 时,title 会先转化为布尔值判断,为 true 时返回 title,false 返回 'title'`,
options
)).toBe(
`使用 \`||\` 时,title 会先转化为布尔值判断,为 true 时返回 title,false 返回 ‘title’`
)
})

// https://github.com/zhlint-project/zhlint/issues/126
test('#126 (1) extended', () => {
expect(getOutput(
`中文‘中文’中文‘English’中文'中文'中文'English'中文`,
options
)).toBe(
`中文 ‘中文’ 中文 ‘English’ 中文 ‘中文’ 中文 ‘English’ 中文`
)
expect(getOutput(
`中文‘中文’中文‘English’中文'中文'中文'English'`,
options
)).toBe(
`中文 ‘中文’ 中文 ‘English’ 中文 ‘中文’ 中文 ‘English’`
)
})

// https://github.com/zhlint-project/zhlint/issues/126
test('#126 (2)', () => {
expect(getOutput(
`### 5.1 “Attention Is All You Need”`,
options
)).toBe(
`### 5.1 “Attention Is All You Need”`
)
})

// https://github.com/zhlint-project/zhlint/issues/126
test('#126 (3)', () => {
expect(getOutput(
`How it works: The novel HTTP/2 ‘Rapid Reset’ DDoS attack`,
options
)).toBe(
`How it works: The novel HTTP/2 ‘Rapid Reset’ DDoS attack`
)
})
})

describe('lint from v3.cn.vuejs.org', () => {
Expand Down