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

Add eslint to precious config and remove lint-js task #682

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
47 changes: 42 additions & 5 deletions buildscript/sa.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ const (
goimportsVersion = "v0.22.0"
goimportsPkg = "golang.org/x/tools/cmd/goimports@" + goimportsVersion

// For JS tools like eslint and prettier, these versions need to match the ones in the
// `package.json` file. To update to a new version, run a command like this:
//
// npm install --save-dev --save-exact prettier@3.3.1
//
// Then update the version in this file as well.

// This is the latest version to support a YAML config file. Updating to
// the new config file syntax did not seem trivial.
eslintVersion = "8.57.0"
golangCILintVersion = "1.59.1"
golinesVersion = "0.12.2"
gosecVersion = "2.20.0"
Expand Down Expand Up @@ -46,7 +56,7 @@ func SAInstallDevTools(ctx *task.Context) error {
if err := installPrecious(ctx); err != nil {
return err
}
return installPrettier(ctx)
return installJSTools(ctx)
}

// Install goimports.
Expand Down Expand Up @@ -251,28 +261,55 @@ func installBinaryTool(
)
}

func installPrettier(ctx *task.Context) error {
// We have to install all the JS tools at once. If we run `npm install <tool>` multiple times, each
// execution wipes the entire `node_modules` directory, so we only end up with one tool (the last
// one) installed.
func installJSTools(ctx *task.Context) error {
eslint, err := eslintPath()
if err != nil {
return err
}

exists, err := executableExistsWithVersion(ctx, eslint, eslintVersion)
if err != nil {
return err
}
if !exists {
return runNPMInstall(ctx)
}

prettier, err := prettierPath()
if err != nil {
return err
}

exists, err := executableExistsWithVersion(ctx, prettier, prettierVersion)
exists, err = executableExistsWithVersion(ctx, prettier, prettierVersion)
if err != nil {
return err
}
if exists {
return nil
}

return runNPMInstall(ctx)
}

func runNPMInstall(ctx *task.Context) error {
return sh.Run(
ctx,
"npm", "install",
"--no-save",
fmt.Sprintf("prettier@%s", prettierVersion),
)
}

func eslintPath() (string, error) {
root, err := repoRoot()
if err != nil {
return "", err
}

return filepath.Join(root, "node_modules", ".bin", "eslint"), nil
}

func prettierPath() (string, error) {
root, err := repoRoot()
if err != nil {
Expand Down
16 changes: 0 additions & 16 deletions common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1624,21 +1624,6 @@ tasks:
set -e
./dev-bin/precious lint --all

- name: lint-js
commands:
- func: "fetch source"
- command: shell.exec
type: test
params:
working_dir: src/github.com/mongodb/mongo-tools
script: |
set -x
set -v
set -e
PATH="/opt/nodejs/node-v16.17.0-linux-x64/bin:$PATH"
npm install eslint@3.2
node node_modules/eslint/bin/eslint.js test/qa-tests/jstests/**/*.js

- name: qa-tests-5.0
tags: ["5.0"]
commands:
Expand Down Expand Up @@ -1898,7 +1883,6 @@ buildvariants:
_platform: rhel80
tasks:
- name: lint
- name: lint-js
- name: mod-tidy
- name: evergreen-validate
- name: vet
Expand Down
Loading