Skip to content

Commit

Permalink
Add eslint to precious config and remove lint-js task (#682)
Browse files Browse the repository at this point in the history
This also updates our `eslint` version to 8.57.0, which is the most recent version that works with our YAML config file for `eslint`. Updating our config for the 9.x version didn't seem trivial.
  • Loading branch information
autarch authored Aug 8, 2024
1 parent 685fd93 commit 0fe8aa0
Show file tree
Hide file tree
Showing 20 changed files with 1,311 additions and 121 deletions.
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 [email protected]
//
// 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 [email protected]
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

0 comments on commit 0fe8aa0

Please sign in to comment.