Skip to content

Commit 0fe8aa0

Browse files
authored
Add eslint to precious config and remove lint-js task (#682)
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.
1 parent 685fd93 commit 0fe8aa0

20 files changed

+1311
-121
lines changed

Diff for: buildscript/sa.go

+42-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ const (
1919
goimportsVersion = "v0.22.0"
2020
goimportsPkg = "golang.org/x/tools/cmd/goimports@" + goimportsVersion
2121

22+
// For JS tools like eslint and prettier, these versions need to match the ones in the
23+
// `package.json` file. To update to a new version, run a command like this:
24+
//
25+
// npm install --save-dev --save-exact [email protected]
26+
//
27+
// Then update the version in this file as well.
28+
29+
// This is the latest version to support a YAML config file. Updating to
30+
// the new config file syntax did not seem trivial.
31+
eslintVersion = "8.57.0"
2232
golangCILintVersion = "1.59.1"
2333
golinesVersion = "0.12.2"
2434
gosecVersion = "2.20.0"
@@ -46,7 +56,7 @@ func SAInstallDevTools(ctx *task.Context) error {
4656
if err := installPrecious(ctx); err != nil {
4757
return err
4858
}
49-
return installPrettier(ctx)
59+
return installJSTools(ctx)
5060
}
5161

5262
// Install goimports.
@@ -251,28 +261,55 @@ func installBinaryTool(
251261
)
252262
}
253263

254-
func installPrettier(ctx *task.Context) error {
264+
// We have to install all the JS tools at once. If we run `npm install <tool>` multiple times, each
265+
// execution wipes the entire `node_modules` directory, so we only end up with one tool (the last
266+
// one) installed.
267+
func installJSTools(ctx *task.Context) error {
268+
eslint, err := eslintPath()
269+
if err != nil {
270+
return err
271+
}
272+
273+
exists, err := executableExistsWithVersion(ctx, eslint, eslintVersion)
274+
if err != nil {
275+
return err
276+
}
277+
if !exists {
278+
return runNPMInstall(ctx)
279+
}
280+
255281
prettier, err := prettierPath()
256282
if err != nil {
257283
return err
258284
}
259285

260-
exists, err := executableExistsWithVersion(ctx, prettier, prettierVersion)
286+
exists, err = executableExistsWithVersion(ctx, prettier, prettierVersion)
261287
if err != nil {
262288
return err
263289
}
264290
if exists {
265291
return nil
266292
}
267293

294+
return runNPMInstall(ctx)
295+
}
296+
297+
func runNPMInstall(ctx *task.Context) error {
268298
return sh.Run(
269299
ctx,
270300
"npm", "install",
271-
"--no-save",
272-
fmt.Sprintf("prettier@%s", prettierVersion),
273301
)
274302
}
275303

304+
func eslintPath() (string, error) {
305+
root, err := repoRoot()
306+
if err != nil {
307+
return "", err
308+
}
309+
310+
return filepath.Join(root, "node_modules", ".bin", "eslint"), nil
311+
}
312+
276313
func prettierPath() (string, error) {
277314
root, err := repoRoot()
278315
if err != nil {

Diff for: common.yml

-16
Original file line numberDiff line numberDiff line change
@@ -1624,21 +1624,6 @@ tasks:
16241624
set -e
16251625
./dev-bin/precious lint --all
16261626
1627-
- name: lint-js
1628-
commands:
1629-
- func: "fetch source"
1630-
- command: shell.exec
1631-
type: test
1632-
params:
1633-
working_dir: src/github.com/mongodb/mongo-tools
1634-
script: |
1635-
set -x
1636-
set -v
1637-
set -e
1638-
PATH="/opt/nodejs/node-v16.17.0-linux-x64/bin:$PATH"
1639-
npm install [email protected]
1640-
node node_modules/eslint/bin/eslint.js test/qa-tests/jstests/**/*.js
1641-
16421627
- name: qa-tests-5.0
16431628
tags: ["5.0"]
16441629
commands:
@@ -1898,7 +1883,6 @@ buildvariants:
18981883
_platform: rhel80
18991884
tasks:
19001885
- name: lint
1901-
- name: lint-js
19021886
- name: mod-tidy
19031887
- name: evergreen-validate
19041888
- name: vet

0 commit comments

Comments
 (0)