Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const lint = require('../lint'); | ||
|
||
describe('no-space-in-links', () => { | ||
test('success', () => { | ||
const md = `[hello world](https://atool.vip)`; | ||
expect(lint(md)).toEqual([]); | ||
}); | ||
|
||
test('fail', () => { | ||
const md = `[ hello, ~~world~~ ](https://atool.vip)`; | ||
expect(lint(md)).toEqual([{ | ||
column: 1, | ||
level: 'error', | ||
line: 1, | ||
text: `Link content can not start / end with space: ' hello, world '`, | ||
type: 'no-space-in-link' | ||
}]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { Plugin } = require('ast-plugin'); | ||
const _ = require('lodash'); | ||
const { astToText } = require('./helper/ast'); | ||
|
||
/** | ||
* Link 内容前后不能有空格 | ||
* no-space-in-link | ||
*/ | ||
module.exports = class extends Plugin { | ||
|
||
static get type() { | ||
return 'no-space-in-link'; | ||
}; | ||
|
||
pre() {} | ||
|
||
visitor() { | ||
return { | ||
link: ast => { | ||
const text = astToText(ast.node); | ||
const line = ast.node.position.start.line; | ||
const column = ast.node.position.start.column; | ||
|
||
if (_.startsWith(text, ' ') || _.endsWith(text, ' ')) { | ||
this.cfg.throwError({ | ||
line, | ||
column, | ||
text: `Link content can not start / end with space: '${text}'`, | ||
}); | ||
} | ||
}, | ||
} | ||
} | ||
|
||
post() {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[hello world](https://atool.vip) | ||
|
||
|
||
[ hello, ~~world~~ ](https://atool.vip) |