Skip to content

Commit

Permalink
Merge pull request #35 from planningcenter/ns/misc
Browse files Browse the repository at this point in the history
Miscellaneous cleanup
  • Loading branch information
sheck authored Oct 10, 2024
2 parents 627061e + 3496f8f commit f880489
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
| `failure-level` | The lowest annotation level to fail on ("warning or "error"") | no | `"error"` |
| `conclusion-level` | Action conclusion ("success" or "failure") if annotations of the failure-level were created. | no | `"success"` |
| `working-directory` | Which directory to run the action in | no | `"."` |
| `extensions` | A comma separated list of extensions to run ESLint on. | no | `".js,.ts,.jsx,.tsx,.mjs,.cjs"` |

## Outputs

Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Balto - Eslint"
description: "Run eslint on your repo"
name: "Balto - ESLint"
description: "Run ESLint on your repo"
runs:
using: node20
main: dist/index.js
Expand All @@ -19,6 +19,10 @@ inputs:
description: Which directory to run the action in
required: false
default: "."
extensions:
description: A comma separated list of extensions to run ESLint on.
required: false
default: ".js,.ts,.jsx,.tsx,.mjs,.cjs"
outputs:
warning-count:
description: "Number of relevant warnings found"
Expand Down
6 changes: 3 additions & 3 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"cp test/snapshots/base/* test/v7",
"cp test/snapshots/base/* test/v8",
"cp test/snapshots/base/* test/v9",
"git add . && git commit -m 'Undo simulated changes'",
"git add . && git commit -m 'Automated: Undo simulated changes'",
"echo \"{ \\\"pull_request\\\": { \\\"base\\\": { \\\"sha\\\": \\\"$(git rev-parse HEAD)\\\" } } }\" > test/pull_request_event_payload.json",
"git add . && git commit -m 'Update test target sha'",
"git add . && git commit -m 'Automated: Update test target sha'",
"cp test/snapshots/updates/* test/v6",
"cp test/snapshots/updates/* test/v7",
"cp test/snapshots/updates/* test/v8",
"cp test/snapshots/updates/* test/v9",
"git add . && git commit -m 'Simulate changes'"
"git add . && git commit -m 'Automated: Simulate changes'"
]
}
}
Expand Down
21 changes: 15 additions & 6 deletions dist/index.js

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

12 changes: 6 additions & 6 deletions src/eslint_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { ChangeRange, generateChangeRanges } from "./git_utils"

export type ResultObject = {
filePath: string
messages: EslintMessage[]
messages: ESLintMessage[]
}

type EslintMessage = {
type ESLintMessage = {
ruleId: string
severity: Severity
message: string
Expand All @@ -24,22 +24,22 @@ enum Severity {
Error = 2,
}

export class EslintResult {
export class ESLintResult {
public relevantWarningCount: number = 0
public relevantErrorCount: number = 0
private resultObject: ResultObject
private changeRanges: ChangeRange[]
private relevantMessages: EslintMessage[] = []
private relevantMessages: ESLintMessage[] = []

static async for(
resultObject: ResultObject,
compareSha: string,
): Promise<EslintResult> {
): Promise<ESLintResult> {
const changeRanges = await generateChangeRanges(
resultObject.filePath,
compareSha,
)
return new EslintResult(resultObject, changeRanges)
return new ESLintResult(resultObject, changeRanges)
}

constructor(resultObject: ResultObject, changeRanges: ChangeRange[]) {
Expand Down
24 changes: 19 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from "@actions/core"
import { detectChangedFiles, detectChangedFilesInFolder } from "./git_utils"
import { getExecOutput } from "@actions/exec"
import { ResultObject, EslintResult } from "./eslint_result"
import { ResultObject, ESLintResult } from "./eslint_result"

async function run() {
let workingDirectory = core.getInput("working-directory")
Expand Down Expand Up @@ -34,17 +34,31 @@ async function run() {

core.debug(`Changed files: ${changedFiles}`)

let { stdout: eslintOut } = await getExecOutput(
let extensions = core.getInput("extensions").split(",")
core.debug(`Extensions: ${extensions}`)
let changedFilesMatchingExtensions = changedFiles.filter((file) =>
extensions.some((ext) => file.endsWith(ext)),
)
core.debug(
`Changed files matching extensions: ${changedFilesMatchingExtensions}`,
)

// Bail out early if the file list is empty (older ESLint versions will
// complain if the list is empty)
if (changedFilesMatchingExtensions.length === 0) return

let { stdout: eslintOut, exitCode } = await getExecOutput(
"npx eslint --format=json",
changedFiles,
changedFilesMatchingExtensions,
// Eslint will return exit code 1 if it finds linting problems, but that is
// expected and we don't want to stop execution because of it.
{ ignoreReturnCode: true },
)
let eslintJson = JSON.parse(eslintOut)
core.debug(`Eslint exit code: ${exitCode}`)

let promises: Array<Promise<EslintResult>> = eslintJson.map(
(resultObject: ResultObject) => EslintResult.for(resultObject, compareSha),
let promises: Array<Promise<ESLintResult>> = eslintJson.map(
(resultObject: ResultObject) => ESLintResult.for(resultObject, compareSha),
)
let eslintResults = await Promise.all(promises)

Expand Down
2 changes: 1 addition & 1 deletion test/pull_request_event_payload.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "pull_request": { "base": { "sha": "c2eaebd173390cb17efa35fce4d4941ccd5b3b5c" } } }
{ "pull_request": { "base": { "sha": "54de0dbcb922b6544025d1604d46146fcbdbda81" } } }
4 changes: 4 additions & 0 deletions test/snapshots/updates/some_file_that_eslint_should_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class EslintShouldIgnoreThis
def evenThoughItsWeird (*)
end
end
4 changes: 4 additions & 0 deletions test/v6/some_file_that_eslint_should_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class EslintShouldIgnoreThis
def evenThoughItsWeird (*)
end
end
4 changes: 4 additions & 0 deletions test/v7/some_file_that_eslint_should_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class EslintShouldIgnoreThis
def evenThoughItsWeird (*)
end
end
4 changes: 4 additions & 0 deletions test/v8/some_file_that_eslint_should_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class EslintShouldIgnoreThis
def evenThoughItsWeird (*)
end
end
4 changes: 4 additions & 0 deletions test/v9/some_file_that_eslint_should_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class EslintShouldIgnoreThis
def evenThoughItsWeird (*)
end
end

0 comments on commit f880489

Please sign in to comment.