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.
- Loading branch information
Showing
11 changed files
with
179 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.md | ||
*.md | ||
data/stylelint/test.css |
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 { StyleLintTransformer } from "../../src/transformer/stylelint"; | ||
import { LintResult } from "../../src/lint-result"; | ||
import * as fs from "fs"; | ||
|
||
test("transform", async () => { | ||
const text = fs.readFileSync("data/stylelint.json", "utf-8"); | ||
const transformer = new StyleLintTransformer(); | ||
const result = transformer.parse(text); | ||
|
||
expect(result.length).toBe(3); | ||
expect(result[0]).toMatchObject({ | ||
path: "test/test.css", | ||
rule: "block-opening-brace-space-before", | ||
message: 'Expected single space before "{"', | ||
startLine: 1, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: "failure", | ||
} as LintResult); | ||
expect(result[1]).toMatchObject({ | ||
path: "test/test.css", | ||
rule: "no-missing-end-of-source-newline", | ||
message: "Unexpected missing end-of-source newline", | ||
startLine: 3, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: "failure", | ||
} as LintResult); | ||
expect(result[2]).toMatchObject({ | ||
path: "test/test.css", | ||
rule: "indentation", | ||
message: "Expected indentation of 2 spaces", | ||
startLine: 2, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: "failure", | ||
} 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,32 @@ | ||
[ | ||
{ | ||
"source": "test/test.css", | ||
"deprecations": [], | ||
"invalidOptionWarnings": [], | ||
"parseErrors": [], | ||
"errored": true, | ||
"warnings": [ | ||
{ | ||
"line": 1, | ||
"column": 5, | ||
"rule": "block-opening-brace-space-before", | ||
"severity": "error", | ||
"text": "Expected single space before \"{\" (block-opening-brace-space-before)" | ||
}, | ||
{ | ||
"line": 3, | ||
"column": 1, | ||
"rule": "no-missing-end-of-source-newline", | ||
"severity": "error", | ||
"text": "Unexpected missing end-of-source newline (no-missing-end-of-source-newline)" | ||
}, | ||
{ | ||
"line": 2, | ||
"column": 5, | ||
"rule": "indentation", | ||
"severity": "error", | ||
"text": "Expected indentation of 2 spaces (indentation)" | ||
} | ||
] | ||
} | ||
] |
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 @@ | ||
{ | ||
"extends": "stylelint-config-standard" | ||
} |
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 @@ | ||
1. `npm install -g stylelint stylelint-config-standard` | ||
1. `stylelint data/stylelint/test.css --config data/stylelint/.stylelintrc.json --output-file data/stylelint.json --formatter json` | ||
1. replace filepath |
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 @@ | ||
.test{ | ||
background-color: blue; | ||
} |
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,20 @@ | ||
# Transformer of stylelint | ||
```yml | ||
- uses: MeilCli/common-lint-reporter/transformer/stylelint@v0 | ||
with: | ||
report_files: | | ||
stylelint_report.json | ||
``` | ||
## 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,53 @@ | ||
import * as core from "@actions/core"; | ||
import { getOption } from "./option"; | ||
import { LintResult } from "../lint-result"; | ||
import { Transformer } from "./transformer"; | ||
|
||
interface StyleLintReport { | ||
source: string; | ||
warnings: StyleLintReportMessage[]; | ||
} | ||
|
||
interface StyleLintReportMessage { | ||
rule: string; | ||
severity: string; | ||
text: string; | ||
line: number; | ||
} | ||
|
||
export class StyleLintTransformer extends Transformer { | ||
parse(body: string): LintResult[] { | ||
const lintResults: LintResult[] = []; | ||
const styleLintReports = JSON.parse(body) as StyleLintReport[]; | ||
for (const styleLintReport of styleLintReports) { | ||
for (const message of styleLintReport.warnings) { | ||
const level = message.severity == "error" ? "failure" : "warning"; | ||
lintResults.push({ | ||
path: styleLintReport.source, | ||
rule: message.rule, | ||
message: message.text.replace(/^(.+)\s(\(.+?\))$/, "$1"), | ||
startLine: message.line, | ||
endLine: undefined, | ||
startColumn: undefined, | ||
endColumn: undefined, | ||
level: level, | ||
}); | ||
} | ||
} | ||
return lintResults; | ||
} | ||
} | ||
|
||
async function run() { | ||
try { | ||
const option = getOption(); | ||
const transformer = new StyleLintTransformer(); | ||
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: 'stylelint transformer of common lint reporter' | ||
description: 'transformer of stylelint 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-stylelint.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