Skip to content

Commit 3908581

Browse files
authored
Integrate custom_lint (#218)
1 parent 1cda592 commit 3908581

File tree

10 files changed

+95
-23
lines changed

10 files changed

+95
-23
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ jobs:
2525
with:
2626
working-directory: ./dart
2727
annotate-only: true
28+
fatal-warnings: false

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ Thumbs.db
9696

9797
# Ignore built ts files
9898
__tests__/runner/*
99-
lib/**/*
99+
lib/**/*
100+
101+
# Ignore IDEA
102+
.idea

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ jobs:
4545
# (defaults to false).
4646
annotate-only: false
4747

48+
# (Optional) If set to true the GitHub action will run custom_lint
49+
# if it is found as dependency in the pubspec.yaml
50+
# (defaults to false).
51+
custom-lint: false
52+
4853
# (Optional) The working directory to run the Dart analyzer in
4954
# (defaults to `./`).
5055
working-directory: ./

__tests__/main.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import * as path from 'path';
44
import { test } from '@jest/globals';
55

66
test('TODO', async () => {
7-
const result = await dart.analyze(path.resolve(__dirname, '../dart'));
7+
const result = await dart.analyze(path.resolve(__dirname, '../dart'), true);
88
console.dir(result);
99
});

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
required: false
1919
description: "If set to true only annotations will be created and the GitHub action itself will not fail on Dart analyzer problems. (defaults to false)."
2020
default: "false"
21+
custom-lint:
22+
required: false
23+
description: "If set to true the GitHub action will run custom_lint if it is found as dependency in the pubspec.yaml. (defaults to false)."
24+
default: "false"
2125
working-directory:
2226
required: false
2327
description: "The working directory to run the Dart analyzer in (defaults to `./`)."

dist/index.js

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dart.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
3+
import * as fs from 'fs';
4+
import * as util from 'util';
35

46
export interface AnalyzerOptions {
57
fatalInfos: boolean;
68
fatalWarnings: boolean;
79
annotate: boolean;
810
annotateOnly: boolean;
11+
customLint: boolean;
912
workingDirectory: string;
1013
}
1114

@@ -52,8 +55,11 @@ export interface AnalyzerResult {
5255
errors: AnalyzerProblem[];
5356
}
5457

55-
export async function analyze(cwd?: string): Promise<AnalyzerResult> {
56-
const execOutput = await exec.getExecOutput(
58+
export async function analyze(
59+
cwd: string,
60+
customLint: boolean,
61+
): Promise<AnalyzerResult> {
62+
const analyzeOutput = await exec.getExecOutput(
5763
'dart',
5864
['analyze', '--format=json', '.'],
5965
{
@@ -62,7 +68,35 @@ export async function analyze(cwd?: string): Promise<AnalyzerResult> {
6268
ignoreReturnCode: true,
6369
},
6470
);
65-
return parseAnalyzerResult(execOutput.stdout.trim());
71+
const result = parseAnalyzerResult(analyzeOutput.stdout.trim());
72+
if (customLint) {
73+
const pubspec =
74+
cwd == null
75+
? 'pubspec.yaml'
76+
: cwd.endsWith('/')
77+
? cwd
78+
: `${cwd}/pubspec.yaml`;
79+
const readFile = util.promisify(fs.readFile);
80+
const contents = await readFile(pubspec, 'utf8');
81+
if (contents.includes('custom_lint:')) {
82+
const customLintOutput = await exec.getExecOutput(
83+
'dart',
84+
['run', 'custom_lint', '--format=json', '.'],
85+
{
86+
cwd,
87+
silent: false,
88+
ignoreReturnCode: true,
89+
},
90+
);
91+
const customLintResult = parseAnalyzerResult(
92+
customLintOutput.stdout.trim(),
93+
);
94+
result.infos.push(...customLintResult.infos);
95+
result.warnings.push(...customLintResult.warnings);
96+
result.errors.push(...customLintResult.errors);
97+
}
98+
}
99+
return result;
66100
}
67101

68102
export function parseAnalyzerResult(

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async function run(): Promise<void> {
4949
fatalWarnings: core.getBooleanInput('fatal-warnings'),
5050
annotate: core.getBooleanInput('annotate'),
5151
annotateOnly: core.getBooleanInput('annotate-only'),
52+
customLint: core.getBooleanInput('custom-lint'),
5253
workingDirectory: path.resolve(
5354
process.env['GITHUB_WORKSPACE'] || process.cwd(),
5455
core.getInput('working-directory'),
@@ -58,7 +59,7 @@ async function run(): Promise<void> {
5859
core.debug(
5960
`Running Dart analyzer with options: ${JSON.stringify(options)}`,
6061
);
61-
const result = await analyze(options.workingDirectory);
62+
const result = await analyze(options.workingDirectory, options.customLint);
6263

6364
// Report info problems.
6465
core.startGroup('Dart Analyzer - Infos');

0 commit comments

Comments
 (0)