Skip to content

Commit

Permalink
Lint code and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fyc09 committed Jul 18, 2024
1 parent c5b9c27 commit 8a30e08
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 86 deletions.
12 changes: 7 additions & 5 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ module.exports.getLineMetadata = getLineMetadata;
* @param {boolean} inTable Iff in a table.
* @param {boolean} inItem Iff in a list item.
* @param {boolean} inBreak Iff in semantic break.
* @param {boolean} inHTML Iff in HTML.
* @param {boolean} inHtml Iff in HTML block.
* @returns {void}
*/

Expand Down Expand Up @@ -4216,8 +4216,9 @@ module.exports = {
"tags": [ "headings", "atx", "spaces" ],
"parser": "none",
"function": function MD018(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHTML) => {
if (!inCode && !inHTML &&
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHtml) => {
if (!inCode &&
!inHtml &&
/^#+[^# \t]/.test(line) &&
!/#\s*$/.test(line) &&
!line.startsWith("#️⃣")) {
Expand Down Expand Up @@ -4359,8 +4360,9 @@ module.exports = {
"tags": [ "headings", "atx_closed", "spaces" ],
"parser": "none",
"function": function MD020(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHTML) => {
if (!inCode && !inHTML) {
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHtml) => {
if (!inCode &&
!inHtml) {
const match =
/^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
if (match) {
Expand Down
2 changes: 1 addition & 1 deletion helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ module.exports.getLineMetadata = getLineMetadata;
* @param {boolean} inTable Iff in a table.
* @param {boolean} inItem Iff in a list item.
* @param {boolean} inBreak Iff in semantic break.
* @param {boolean} inHTML Iff in HTML.
* @param {boolean} inHtml Iff in HTML block.
* @returns {void}
*/

Expand Down
5 changes: 3 additions & 2 deletions lib/md018.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ module.exports = {
"tags": [ "headings", "atx", "spaces" ],
"parser": "none",
"function": function MD018(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHTML) => {
if (!inCode && !inHTML &&
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHtml) => {
if (!inCode &&
!inHtml &&
/^#+[^# \t]/.test(line) &&
!/#\s*$/.test(line) &&
!line.startsWith("#️⃣")) {
Expand Down
5 changes: 3 additions & 2 deletions lib/md020.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ module.exports = {
"tags": [ "headings", "atx_closed", "spaces" ],
"parser": "none",
"function": function MD020(params, onError) {
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHTML) => {
if (!inCode && !inHTML) {
forEachLine(lineMetadata(), (line, lineIndex, inCode, inFence, inTable, inItem, inBreak, inHtml) => {
if (!inCode &&
!inHtml) {
const match =
/^(#+)([ \t]*)([^#]*?[^#\\])([ \t]*)((?:\\#)?)(#+)(\s*)$/.exec(line);
if (match) {
Expand Down
16 changes: 7 additions & 9 deletions test/ignore-html-block.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# ignore-html-block.md

## Title
<style> {MD033}

##Title2 {MD018}
##Heading 1

<div> {MD033}
#foo
</div>
## Heading 2

##Title3 {MD020}##
##Heading 3##

<div> {MD033}
#foo#
</div>
## Heading 4 ##

</style>
77 changes: 10 additions & 67 deletions test/snapshots/markdownlint-test-scenarios.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -17219,70 +17219,15 @@ Generated by [AVA](https://avajs.dev).

{
errors: [
{
errorContext: '##Title2 {MD018}',
errorDetail: null,
errorRange: [
1,
3,
],
fixInfo: {
editColumn: 3,
insertText: ' ',
},
lineNumber: 5,
ruleDescription: 'No space after hash on atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md018.md',
ruleNames: [
'MD018',
'no-missing-space-atx',
],
},
{
errorContext: '##Title3 {MD020}##',
errorDetail: null,
errorRange: [
1,
3,
],
fixInfo: {
deleteCount: 18,
editColumn: 1,
insertText: '## Title3 {MD020} ##',
},
lineNumber: 11,
ruleDescription: 'No space inside hashes on closed atx style heading',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md020.md',
ruleNames: [
'MD020',
'no-missing-space-closed-atx',
],
},
{
errorContext: null,
errorDetail: 'Element: div',
errorDetail: 'Element: style',
errorRange: [
1,
5,
],
fixInfo: null,
lineNumber: 7,
ruleDescription: 'Inline HTML',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md033.md',
ruleNames: [
'MD033',
'no-inline-html',
],
},
{
errorContext: null,
errorDetail: 'Element: div',
errorRange: [
1,
5,
7,
],
fixInfo: null,
lineNumber: 13,
lineNumber: 3,
ruleDescription: 'Inline HTML',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md033.md',
ruleNames: [
Expand All @@ -17293,19 +17238,17 @@ Generated by [AVA](https://avajs.dev).
],
fixed: `# ignore-html-block.md␊
## Title
<style> {MD033}
## Title2 {MD018}
##Heading 1
<div> {MD033}␊
#foo␊
</div>␊
## Heading 2␊
## Title3 {MD020} ##␊
##Heading 3##␊
<div> {MD033}
#foo#
</div>␊
## Heading 4 ##
</style>␊
`,
}

Expand Down
Binary file modified test/snapshots/markdownlint-test-scenarios.js.snap
Binary file not shown.

0 comments on commit 8a30e08

Please sign in to comment.