diff --git a/src/Actions/Github/EventName.ts b/src/Actions/Github/EventName.ts index f058b44..1b87f53 100644 --- a/src/Actions/Github/EventName.ts +++ b/src/Actions/Github/EventName.ts @@ -1 +1 @@ -export type EventName = 'pull_request'|'push'; \ No newline at end of file +export type EventName = 'pull_request' | 'push'; diff --git a/src/format/Format.ts b/src/format/Format.ts index e7f9038..2b6ff29 100644 --- a/src/format/Format.ts +++ b/src/format/Format.ts @@ -61,4 +61,4 @@ export async function format(params: { modifiedFiles: ModifiedFiles, ignoredFile return new FormatResult({ files: fileNotFormatted, }); -} \ No newline at end of file +} diff --git a/src/format/FormatResult.ts b/src/format/FormatResult.ts index a93e840..13d8982 100644 --- a/src/format/FormatResult.ts +++ b/src/format/FormatResult.ts @@ -27,4 +27,4 @@ export class FormatResult { } return comments.join('\n'); } -} \ No newline at end of file +} diff --git a/src/main.ts b/src/main.ts index 895cd58..5e8f2a1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,6 @@ import { Result } from './result/Result'; import { IgnoredFiles } from './utils/IgnoredFiles'; import { ModifiedFiles } from './utils/ModifiedFiles'; - /** * Run the action */ @@ -36,10 +35,9 @@ async function main(): Promise { await result.comment(); } result.log(); - } catch (error) { + } catch (error: any) { core.setFailed(`error: ${error.message}`); } - } main(); diff --git a/src/result/Result.ts b/src/result/Result.ts index 021c221..76b1847 100644 --- a/src/result/Result.ts +++ b/src/result/Result.ts @@ -32,7 +32,7 @@ export class Result { /** * Whether it is a success or not */ - public get success():boolean { + public get success(): boolean { return this.analyze.success && this.format.success; } @@ -41,7 +41,7 @@ export class Result { */ public async comment(): Promise { const messages: string[] = [ - this.issueCountMessage({emojis: true}) + this.issueCountMessage({ emojis: true }) ]; const analyzeBody = this.analyze.commentBody; @@ -53,7 +53,7 @@ export class Result { messages.push(formatBody); } - await comment({message: messages.join('\n---\n')}); + await comment({ message: messages.join('\n---\n') }); } /** @@ -62,7 +62,7 @@ export class Result { * @param params * @returns */ - private issueCountMessage(params?: {emojis?: boolean}): string { + private issueCountMessage(params?: { emojis?: boolean }): string { const messages: string[] = [ this.title(params), this.titleLineAnalyze({ @@ -90,7 +90,7 @@ export class Result { * @param params * @returns */ - private title(params?: {emojis?: boolean}): string { + private title(params?: { emojis?: boolean }): string { const title = `Dart Analyzer found ${this.count} issue${Result.pluralS(this.count)}`; if (params?.emojis && actionOptions.emojis) { let emoji = ':tada:'; @@ -111,7 +111,7 @@ export class Result { * @param params * @returns */ - private titleLineAnalyze(params: {emojis?: boolean, type: DartAnalyzeLogTypeEnum}): string { + private titleLineAnalyze(params: { emojis?: boolean, type: DartAnalyzeLogTypeEnum }): string { const isFail = DartAnalyzeLogType.isFail(params.type); let emoji = ''; let count: number; @@ -146,10 +146,10 @@ export class Result { * @param params * @returns */ - private titleLineFormat(params: {emojis?: boolean}):string { + private titleLineFormat(params: { emojis?: boolean }): string { let emoji = `:${this.format.count ? 'poop' : 'art'}: `; const highlight = params.emojis && this.format.count && actionOptions.failOn === FailOnEnum.Format ? '**' : ''; - return `- ${params.emojis && actionOptions.emojis ? emoji : '' }${highlight}${this.format.count} formatting issue${Result.pluralS(this.format.count)}${highlight}`; + return `- ${params.emojis && actionOptions.emojis ? emoji : ''}${highlight}${this.format.count} formatting issue${Result.pluralS(this.format.count)}${highlight}`; } /** @@ -158,7 +158,7 @@ export class Result { public log(): void { const logger = this.success ? (this.count ? core.warning : core.info) : core.setFailed; logger(this.issueCountMessage()); - + } /** @@ -167,7 +167,7 @@ export class Result { * @returns 's' if count > 1, else '' */ private static pluralS(count: number): string { - return count > 1 ? 's': ''; + return count > 1 ? 's' : ''; } /** @@ -176,4 +176,4 @@ export class Result { private get count() { return this.analyze.counts.total + this.format.count; } -} \ No newline at end of file +} diff --git a/src/utils/ActionOptions.ts b/src/utils/ActionOptions.ts index f254a63..c7290ad 100644 --- a/src/utils/ActionOptions.ts +++ b/src/utils/ActionOptions.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core'; import * as path from 'path'; -import { FailOn, FailOnEnum } from "./FailOn" +import { FailOn, FailOnEnum } from "./FailOn"; /** * Contains all the options of the action @@ -31,4 +31,4 @@ class ActionOptions { /** * Singleton with the option of the action */ -export const actionOptions = new ActionOptions(); \ No newline at end of file +export const actionOptions = new ActionOptions(); diff --git a/src/utils/Comment.ts b/src/utils/Comment.ts index 1f1c21a..6470c76 100644 --- a/src/utils/Comment.ts +++ b/src/utils/Comment.ts @@ -1,16 +1,16 @@ -import * as github from '@actions/github'; import * as core from '@actions/core'; +import * as github from '@actions/github'; import { context } from '@actions/github/lib/utils'; -export type CommentReact = '+1'|'-1'|'laugh'|'confused'|'heart'|'hooray'|'rocket'|'eyes'; +export type CommentReact = '+1' | '-1' | 'laugh' | 'confused' | 'heart' | 'hooray' | 'rocket' | 'eyes'; -export async function comment(params: {message: string, reacts?: CommentReact[]}): Promise { +export async function comment(params: { message: string, reacts?: CommentReact[] }): Promise { if (!github.context.payload.pull_request) { // Can only comment on Pull Requests return; } - const octokit = github.getOctokit(core.getInput('token', {required: true})); + const octokit = github.getOctokit(core.getInput('token', { required: true })); // Create the comment try { @@ -36,6 +36,6 @@ export async function comment(params: {message: string, reacts?: CommentReact[]} } } catch (error) { console.log(`Couldn't comment "${params.message} with reacts ${params.reacts}`); - } + } } diff --git a/src/utils/FailOn.ts b/src/utils/FailOn.ts index 9105ad1..30a77d6 100644 --- a/src/utils/FailOn.ts +++ b/src/utils/FailOn.ts @@ -1,4 +1,4 @@ -export enum FailOnEnum{ +export enum FailOnEnum { Error = 0, Warning = 1, Info = 2, @@ -8,7 +8,7 @@ export enum FailOnEnum{ export class FailOn { static fromInput(input: string) { - switch(input) { + switch (input) { case 'nothing': return FailOnEnum.Nothing; case 'format': diff --git a/src/utils/IgnoredFiles.ts b/src/utils/IgnoredFiles.ts index a67a964..182632b 100644 --- a/src/utils/IgnoredFiles.ts +++ b/src/utils/IgnoredFiles.ts @@ -1,6 +1,5 @@ -import * as yaml from 'js-yaml'; import * as fs from 'fs'; -// import { minimatch } from 'minimatch'; +import * as yaml from 'js-yaml'; import * as minimatch from 'minimatch'; import * as path from 'path'; import { actionOptions } from './ActionOptions'; @@ -13,7 +12,7 @@ export class IgnoredFiles { constructor() { let patterns: string[]; try { - const yamlFile = yaml.load(fs.readFileSync(path.resolve(actionOptions.workingDirectory, './analysis_options.yaml'), 'utf8')) as { analyzer?: { exclude?: string[] } }; + const yamlFile = yaml.load(fs.readFileSync(path.resolve(actionOptions.workingDirectory, 'analysis_options.yaml'), 'utf8')) as { analyzer?: { exclude?: string[] } }; patterns = yamlFile?.analyzer?.exclude ?? []; } catch (error) { console.log(`Could not load analysis_options.yaml:\n${error}`);