Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with eslint v9 #799

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Custom token to allow commits trigger other workflows.
token: ${{ secrets.BUILD_ACTION_GITHUB_TOKEN }}

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ jobs:
steps:
- name: Check out repository (push)
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check out repository (pull_request_target)
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# ClangFormat

Expand All @@ -44,7 +44,7 @@ jobs:
# Go

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19.4

Expand All @@ -56,7 +56,7 @@ jobs:
# Node.js

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Install your linters here

Expand Down Expand Up @@ -130,12 +130,12 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 12
node-version: 20

# ESLint and Prettier must be in `package.json`
- name: Install Node.js dependencies
Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -211,7 +211,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -253,7 +253,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v1
Expand Down Expand Up @@ -292,7 +292,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install ClangFormat
run: sudo apt-get install -y clang-format
Expand Down Expand Up @@ -325,7 +325,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up .NET
uses: actions/setup-dotnet@v1
Expand Down Expand Up @@ -360,7 +360,7 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v1
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ inputs:
default: "true"

runs:
using: node16
using: node20
main: ./dist/index.js

branding:
Expand Down
36 changes: 25 additions & 11 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 src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function runAction() {
if (core.getInput(linterId) === "true") {
core.startGroup(`Run ${linter.name}`);

const fileExtensions = core.getInput(`${linterId}_extensions`, { required: true });
const fileExtensions = core.getInput(`${linterId}_extensions`);
const args = core.getInput(`${linterId}_args`);
const lintDirRel = core.getInput(`${linterId}_dir`) || ".";
const prefix = core.getInput(`${linterId}_command_prefix`);
Expand Down
34 changes: 24 additions & 10 deletions src/linters/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@ class ESLint {
* @param {string} prefix - Prefix to the lint command
* @returns {{status: number, stdout: string, stderr: string}} - Output of the lint command
*/
static lint(dir, extensions, args = "", fix = false, prefix = "") {
const extensionsArg = extensions.map((ext) => `.${ext}`).join(",");
const fixArg = fix ? "--fix" : "";
static lint(dir, extensions = [], args = "", fix = false, prefix = "") {
const commandPrefix = prefix || getNpmBinCommand(dir);
return run(
`${commandPrefix} eslint --ext ${extensionsArg} ${fixArg} --no-color --format json ${args} "."`,
{
dir,
ignoreErrors: true,
},
);
const { stdout: version } = run(`${commandPrefix} eslint -v`, { dir });
const isV9 = version.startsWith("v9.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to also be required for eslint version 8.x.y as well.

It would be better to parse out the major version ^v(\d+)\.\d+.\d+, and check it it's >= 8.

const extensionsArg =
extensions.length > 0 ? `--ext ${extensions.map((ext) => `.${ext}`).join(",")}` : "";
const fixArg = fix ? "--fix" : "";

const command = [
commandPrefix,
"eslint",
isV9 ? "" : extensionsArg,
fixArg,
"--no-color",
"--format json",
args,
'"."',
]
.filter((s) => s.length > 0)
.join(" ");

return run(command, {
dir,
ignoreErrors: true,
});
}

/**
Expand Down
Loading