Skip to content

Commit

Permalink
Merge pull request #894 from yutailang0119/action/ignore-warnings
Browse files Browse the repository at this point in the history
Add ability to ignore warnings
  • Loading branch information
yutailang0119 committed Mar 11, 2024
2 parents 7fdd643 + bb7e3fe commit 76b8a39
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 52 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- uses: yutailang0119/action-textlint@v3
with:
textlint-output: ${{ steps.run-textlint.outputs.TEXTLINT_OUTPUT }}
ignore-warnings: true # Ignore Lint Warnings
continue-on-error: false # If annotations contain error of severity, action-textlint exit 1.
```
Expand Down
2 changes: 2 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('test runs with json file', () => {
'resource',
'textlint-report.json'
)
process.env['INPUT_IGNORE-WARNINGS'] = 'false'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
Expand Down Expand Up @@ -43,6 +44,7 @@ test('test runs with textlint output', () => {
}
]`
process.env['INPUT_TEXTLINT-OUTPUT'] = json
process.env['INPUT_IGNORE-WARNINGS'] = 'false'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
Expand Down
112 changes: 68 additions & 44 deletions __tests__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,51 @@ import {expect, test} from '@jest/globals'
import {Annotation} from '../src/annotation'
import {parseReport} from '../src/parser'

test('test parse', () => {
const json = `[
{
"messages":[
{
"type":"lint",
"ruleId":"sample-rule/no-weak-phrase",
"message":"adverbs can weaken meaning",
"index":12,
"line":3,
"column":6,
"severity":1
},
{
"type":"lint",
"ruleId":"sample-rule/misspellings",
"message":"This is a commonly misspelled word. Correct it to useful",
"index":13,
"line":22,
"column":7,
"severity":2
}
],
"filePath":"Foo.md"
},
{
"messages":[
{
"type":"lint",
"ruleId":"sample-rule/sentence:uppercase",
"message":"sentence should start with an uppercase letter",
"index":7,
"line":3,
"column":1,
"severity":2,
"fix":{
"range":[1,4],
"text":"This"
}
const json = `[
{
"messages":[
{
"type":"lint",
"ruleId":"sample-rule/no-weak-phrase",
"message":"adverbs can weaken meaning",
"index":12,
"line":3,
"column":6,
"severity":1
},
{
"type":"lint",
"ruleId":"sample-rule/misspellings",
"message":"This is a commonly misspelled word. Correct it to useful",
"index":13,
"line":22,
"column":7,
"severity":2
}
],
"filePath":"Foo.md"
},
{
"messages":[
{
"type":"lint",
"ruleId":"sample-rule/sentence:uppercase",
"message":"sentence should start with an uppercase letter",
"index":7,
"line":3,
"column":1,
"severity":2,
"fix":{
"range":[1,4],
"text":"This"
}
],
"filePath":"Bar.md"
}
]`
}
],
"filePath":"Bar.md"
}
]`

test('test parse', () => {
const annotation1 = new Annotation(
1,
'adverbs can weaken meaning (sample-rule/no-weak-phrase)',
Expand All @@ -68,5 +69,28 @@ test('test parse', () => {
1
)

expect(parseReport(json)).toEqual([annotation1, annotation2, annotation3])
expect(parseReport(json, false)).toEqual([
annotation1,
annotation2,
annotation3
])
})

test('test parse and ignore warnings', () => {
const annotation2 = new Annotation(
2,
'This is a commonly misspelled word. Correct it to useful (sample-rule/misspellings)',
'Foo.md',
22,
7
)
const annotation3 = new Annotation(
2,
'sentence should start with an uppercase letter (sample-rule/sentence:uppercase)',
'Bar.md',
3,
1
)

expect(parseReport(json, true)).toEqual([annotation2, annotation3])
})
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
textlint-output:
description: 'The json format output by textlint'
required: false
ignore-warnings:
description: 'Ignore Lint Warnings'
default: false
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
31 changes: 27 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ async function run(): Promise<void> {
} else {
json = textlintOutput
}
const annotations = parseReport(json)
const ignoreWarnings = core.getBooleanInput('ignore-warnings')

const annotations = parseReport(json, ignoreWarnings)
echoMessages(annotations)

const errors = annotations.filter(annotation => {
Expand Down
13 changes: 11 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {TextlintResult} from '@textlint/types/src/Message/TextlintResult'
import {Annotation} from './annotation'

export const parseReport = (json: string): Annotation[] => {
export const parseReport = (
json: string,
ignoreWarnings: boolean
): Annotation[] => {
const results: TextlintResult[] = JSON.parse(json)
const annotations: Annotation[] = results.flatMap(result => {
return result.messages.map(message => {
Expand All @@ -14,5 +17,11 @@ export const parseReport = (json: string): Annotation[] => {
)
})
})
return annotations
if (ignoreWarnings === true) {
return annotations.filter(annotation => {
return annotation.severityLevel !== 'warning'
})
} else {
return annotations
}
}

0 comments on commit 76b8a39

Please sign in to comment.