Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v6.0.2

- name: Install modules
run: yarn install
run: npm ci

- name: Run tests
run: yarn test
run: npm test
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
node_modules
.idea
.vscode
coverage
yarn.lock
package-lock.json
.yarnrc.yml
coverage
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v6.0.2

- name: Lint Markdown
uses: lint-md/github-action@v0.1.1
uses: lint-md/github-action@v0.2.0
with:
files: './docs ./'
configFile: '.lintmdrc'
Expand All @@ -54,8 +54,8 @@ jobs:
{
"excludeFiles": [],
"rules": {
"space-round-alphabet": 1,
"space-round-number": 1,
"space-around-alphabet": 1,
"space-around-number": 1,
"no-empty-code-lang": 1,
"no-trailing-punctuation": 1
}
Expand All @@ -68,8 +68,8 @@ jobs:
module.exports = {
excludeFiles: [],
rules: {
"space-round-alphabet": 1,
"space-round-number": 1,
"space-around-alphabet": 1,
"space-around-number": 1,
"no-empty-code-lang": 1,
"no-trailing-punctuation": 1
}
Expand All @@ -84,7 +84,7 @@ module.exports = {

```yaml
- name: Lint Markdown
uses: lint-md/github-action@v0.1.1
uses: lint-md/github-action@v0.2.0
with:
configFile: './config/.lintmdrc'
```
Expand Down
60 changes: 46 additions & 14 deletions __tests__/github-action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Email: yuzl1123@163.com
*/


import * as path from 'path'

import { LintMdAction } from '../src/lint-md-action'
Expand All @@ -26,9 +25,9 @@ describe('lint-md GitHub action 测试', () => {
lintMdAction.showErrorOrPassInfo()
const totalErrors = lintMdAction.getErrors()
expect(totalErrors.length).toStrictEqual(1)
expect(totalErrors[0].path).toStrictEqual(process.env.GITHUB_WORKSPACE)
expect(totalErrors[0].errors.map((tmp: any) => tmp.type)).toStrictEqual([
'space-round-alphabet',
expect(totalErrors[0].path).toStrictEqual(path.resolve(process.env.GITHUB_WORKSPACE!, 'bad.md'))
expect(totalErrors[0].errors.map((tmp: any) => tmp.name)).toStrictEqual([
'space-around-alphabet',
'no-empty-list'
])
})
Expand All @@ -41,13 +40,13 @@ describe('lint-md GitHub action 测试', () => {
await lintMdAction.lint()
const totalErrors = lintMdAction.getErrors()
expect(totalErrors.length).toStrictEqual(1)
expect(totalErrors[0].path).toStrictEqual(process.env.GITHUB_WORKSPACE)
expect(totalErrors[0].errors.map((tmp: any) => tmp.level)).toStrictEqual([
'warning',
'error'
expect(totalErrors[0].path).toStrictEqual(path.resolve(process.env.GITHUB_WORKSPACE!, 'bad.md'))
expect(totalErrors[0].errors.map((tmp: any) => tmp.severity)).toStrictEqual([
1,
2
])
expect(totalErrors[0].errors.map((tmp: any) => tmp.type)).toStrictEqual([
'space-round-alphabet',
expect(totalErrors[0].errors.map((tmp: any) => tmp.name)).toStrictEqual([
'space-around-alphabet',
'no-empty-list'
])
})
Expand All @@ -60,10 +59,10 @@ describe('lint-md GitHub action 测试', () => {
await lintMdAction.lint()
const totalErrors = lintMdAction.getErrors()
expect(totalErrors.length).toStrictEqual(1)
expect(totalErrors[0].path).toStrictEqual(process.env.GITHUB_WORKSPACE)
expect(totalErrors[0].errors.map((tmp: any) => tmp.level)).toStrictEqual([
'warning',
'error'
expect(totalErrors[0].path).toStrictEqual(path.resolve(process.env.GITHUB_WORKSPACE!, 'bad.md'))
expect(totalErrors[0].errors.map((tmp: any) => tmp.severity)).toStrictEqual([
1,
2
])
})

Expand Down Expand Up @@ -106,4 +105,37 @@ describe('lint-md GitHub action 测试', () => {
const totalErrors = lintMdAction.getErrors()
expect(totalErrors.length).toStrictEqual(2)
})

test('目录递归展开:files 为目录时自动扫描子目录', async () => {
process.env.GITHUB_WORKSPACE = path.resolve(process.cwd(), 'examples')
mockAction('./no-config-file ./use-config-file')
const lintMdAction = new LintMdAction()
await lintMdAction.lint()
const errors = lintMdAction.getErrors()
expect(errors.length).toStrictEqual(2)
expect(errors.every(e => e.path.endsWith('bad.md'))).toBe(true)
})

test('glob pattern 匹配:files 为具体文件路径', async () => {
process.env.GITHUB_WORKSPACE = path.resolve(process.cwd(), 'examples')
mockAction('./no-config-file/bad.md')
const lintMdAction = new LintMdAction()
await lintMdAction.lint()
const errors = lintMdAction.getErrors()
expect(errors.length).toStrictEqual(1)
expect(errors[0].path).toStrictEqual(
path.resolve(process.cwd(), 'examples', 'no-config-file', 'bad.md')
)
})

test('excludeFiles 排除指定目录', async () => {
process.env.GITHUB_WORKSPACE = path.resolve(process.cwd(), 'examples')
mockAction('./', '.lintmdrc')
const lintMdAction = new LintMdAction()
await lintMdAction.lint()
const errors = lintMdAction.getErrors()
const paths = errors.map(e => e.path)
expect(paths.every(p => !p.includes('only-warning'))).toBe(true)
expect(errors.length).toBeGreaterThan(0)
})
})
28 changes: 21 additions & 7 deletions __tests__/linter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@
* Email: yuzl1123@163.com
*/


import * as path from 'path'
import { Lint } from '@lint-md/cli'
import * as fs from 'fs'
import { lintMarkdown } from '@lint-md/core'
import { glob } from 'glob'

describe('lint 继承对象测试集合', () => {
test('有 error 出现 (see examples/)', async () => {
const newLinter = new Lint([path.resolve(process.cwd(), 'examples')], {
rules: {}
const mdFiles = await glob(path.resolve(process.cwd(), 'examples') + '/**/*.md', {
absolute: true
})

await newLinter.start()
newLinter.printOverview()
expect(newLinter.countError()).toStrictEqual({
let errorCount = 0
let warningCount = 0

for (const file of mdFiles) {
const content = fs.readFileSync(file, 'utf-8')
const result = lintMarkdown(content, {}, false)
for (const item of result.lintResult) {
if (item.severity === 2) {
errorCount++
} else if (item.severity === 1) {
warningCount++
}
}
}

expect({ error: errorCount, warning: warningCount }).toStrictEqual({
'error': 8,
'warning': 0
})
Expand Down
242 changes: 111 additions & 131 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/.lintmdrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"excludeFiles": ["**/only-warning/**"],
"rules": {}
}
2 changes: 1 addition & 1 deletion examples/js-config/.lintmdrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"excludeFiles": [],
"rules": {
"space-round-alphabet": 1
"space-around-alphabet": 1
}
}
2 changes: 1 addition & 1 deletion examples/only-warning/.lintmdrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"excludeFiles": [],
"rules": {
"space-round-alphabet": 1
"space-around-alphabet": 1
}
}
2 changes: 1 addition & 1 deletion examples/use-config-file/.lintmdrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"excludeFiles": [],
"rules": {
"space-round-alphabet": 1
"space-around-alphabet": 1
}
}
2 changes: 1 addition & 1 deletion examples/use-custom-config/hello
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"excludeFiles": [],
"rules": {
"space-round-alphabet": 1
"space-around-alphabet": 1
}
}
Loading