generated from MeilCli/action-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add markdownlint transformer
- Loading branch information
Showing
9 changed files
with
148 additions
and
0 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,41 @@ | ||
import { MarkdownLintTransformer } from "../../src/transformer/markdownlint"; | ||
import { LintResult } from "../../src/lint-result"; | ||
import * as fs from "fs"; | ||
|
||
test("transform", async () => { | ||
const text = fs.readFileSync("data/markdownlint.txt", "utf-8"); | ||
const transformer = new MarkdownLintTransformer(); | ||
const result = transformer.parse(text); | ||
|
||
expect(result.length).toBe(3); | ||
expect(result[0]).toMatchObject({ | ||
path: "data/markdownlint/test.md", | ||
rule: "MD022/blanks-around-headings/blanks-around-headers", | ||
message: "Headings should be surrounded by blank lines", | ||
startLine: 1, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: "warning", | ||
} as LintResult); | ||
expect(result[1]).toMatchObject({ | ||
path: "data/markdownlint/test.md", | ||
rule: "MD041/first-line-heading/first-line-h1", | ||
message: "First line in a file should be a top-level heading", | ||
startLine: 1, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: "warning", | ||
} as LintResult); | ||
expect(result[2]).toMatchObject({ | ||
path: "data/markdownlint/test.md", | ||
rule: "MD047/single-trailing-newline", | ||
message: "Files should end with a single newline character", | ||
startLine: 3, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: "warning", | ||
} as LintResult); | ||
}); |
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,3 @@ | ||
data/markdownlint/test.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Summary"] | ||
data/markdownlint/test.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## Summary"] | ||
data/markdownlint/test.md:3:13 MD047/single-trailing-newline Files should end with a single newline character |
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,2 @@ | ||
1. `npm install -g markdownlint-cli` | ||
1. `markdownlint -o data/markdownlint.txt data/markdownlint/test.md ` |
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,3 @@ | ||
## Summary | ||
test message | ||
test`message` |
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,22 @@ | ||
# Transformer of markdownlint | ||
```yml | ||
- uses: MeilCli/common-lint-reporter/transformer/markdownlint@v0 | ||
with: | ||
report_files: | | ||
markdownlint_report.txt | ||
``` | ||
**must save markdownlint result to file** | ||
## Option | ||
### Input | ||
- `report_files`: | ||
- report file glob pattern | ||
- required | ||
- `report_files_follow_symbolic_links`: | ||
- report file glob pattern option | ||
- value: `true` or `false` | ||
- `output_path`: | ||
- output path | ||
- required | ||
- default: `common_lint.json` |
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,55 @@ | ||
import * as core from "@actions/core"; | ||
import { getOption } from "./option"; | ||
import { LintResult } from "../lint-result"; | ||
import { Transformer } from "./transformer"; | ||
|
||
export class MarkdownLintTransformer extends Transformer { | ||
parse(body: string): LintResult[] { | ||
const lintResults: LintResult[] = []; | ||
for (const line of body.split(/(\r\n)|\n|\r/g)) { | ||
if (line == undefined || line.length == 0) { | ||
continue; | ||
} | ||
const pathAndLineAndColumnEndIndex = line.indexOf(" "); | ||
if (pathAndLineAndColumnEndIndex < 0) { | ||
continue; | ||
} | ||
const pathAndLineAndColumn = line.slice(0, pathAndLineAndColumnEndIndex); | ||
const locations = pathAndLineAndColumn.split(":"); | ||
const path = locations[0]; | ||
const startLine = | ||
1 <= locations.length && Number.isInteger(parseInt(locations[1])) ? parseInt(locations[1]) : undefined; | ||
const ruleEndIndex = line.indexOf(" ", pathAndLineAndColumnEndIndex + 1); | ||
if (ruleEndIndex < 0) { | ||
continue; | ||
} | ||
const rule = line.slice(pathAndLineAndColumnEndIndex + 1, ruleEndIndex); | ||
const message = line.slice(ruleEndIndex + 1).replace(/^(.+?)\s?(\[.+\])*?$/, "$1"); | ||
lintResults.push({ | ||
path: path, | ||
message: message, | ||
rule: rule, | ||
startLine: startLine, | ||
startColumn: undefined, | ||
endLine: undefined, | ||
endColumn: undefined, | ||
level: "warning", | ||
}); | ||
} | ||
return lintResults; | ||
} | ||
} | ||
|
||
async function run() { | ||
try { | ||
const option = getOption(); | ||
const transformer = new MarkdownLintTransformer(); | ||
await transformer.transform(option); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
if (process.env.NODE_ENV != "test") { | ||
run(); | ||
} |
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 @@ | ||
name: 'markdownlint transformer of common lint reporter' | ||
description: 'transformer of markdownlint report file to common lint report' | ||
author: 'MeilCli' | ||
branding: | ||
icon: layers | ||
color: orange | ||
inputs: | ||
report_files: | ||
description: 'report file glob pattern' | ||
required: true | ||
report_files_follow_symbolic_links: | ||
description: 'report file glob pattern option' | ||
output_path: | ||
description: 'output path' | ||
required: true | ||
default: 'common_lint.json' | ||
runs: | ||
using: 'node12' | ||
main: '../../dist/transformer-markdownlint.js' |
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