Skip to content

fix(examples): fix lint failures in npm test and lb-eslint CLI resolution - #11840

Open
pranesh-sridhar wants to merge 4 commits into
loopbackio:masterfrom
pranesh-sridhar:fix/examples-lint-eslint-cli-resolution
Open

pranesh-sridhar wants to merge 4 commits into
loopbackio:masterfrom
pranesh-sridhar:fix/examples-lint-eslint-cli-resolution

Conversation

@pranesh-sridhar

@pranesh-sridhar pranesh-sridhar commented Oct 16, 2026 •

Copy link
Copy Markdown

Summary

Ran every project under examples/ through a local npm test (fresh build, then mocha, then posttest lint where defined) on Node v26.10.0. All 24 examples pass their mocha tests. Three examples failed npm test only because of the lint step, and lb-eslint itself was broken in every package. This PR fixes those. (example-rpc-server had a fourth lint failure, but it was fixed upstream by a2d1e2dea while this PR was open, so that change was dropped on rebase.)

Findings and fixes

Area Issue Fix
@loopback/build lb-eslint crashed in every package with ERR_PACKAGE_PATH_NOT_EXPORTED. ESLint 8.57+ does not expose bin/eslint through its exports map, so require.resolve('eslint/bin/eslint') fails. resolveCLI now falls back to resolving <pkg>/package.json and building the absolute path from it (packages/build/bin/utils.js).
example-context mocha/handle-done-callback misreads this: Mocha.Context as a done callback. Use an arrow function and .timeout(5000).
example-express-composition Typed linting cannot parse .eslintrc.js (not in tsconfig.json). Add .eslintignore that ignores .eslintrc.js.
example-validation-app Same .eslintrc.js parse error. Add .eslintrc.js to the existing .eslintignore.

Test results

Example Mocha result
access-control-migration 24 passing
binding-resolution 3 passing
context 1 passing
express-composition 10 passing
file-transfer 6 passing
graphql 16 passing
greeter-extension 4 passing
greeting-app 3 passing
hello-world 1 passing
lb3-application 33 passing
log-extension 19 passing
metrics-prometheus 2 passing
multi-tenancy 9 passing
passport-login 29 passing
references-many 45 passing
rest-crud 13 passing
rpc-server 8 passing
soap-calculator 2 passing, 17 pending (describe.skip in source)
socketio 1 passing
todo-jwt 6 passing
todo-list 74 passing
todo 37 passing
validation-app 13 passing
webpack 4 passing

After the fixes:

  • npm test exits 0 for context, express-composition and validation-app (re-verified after rebasing onto the latest master).
  • Root-level run-eslint over examples and packages/build exits 0.
  • The 21 packages/build tests still pass.

Not changed (intentionally)

Running lb-eslint directly inside other packages (for example todo, webpack, packages/http-server) still reports the this: Mocha.Context and .eslintrc.js errors. The root .eslintrc.js already turns mocha/handle-done-callback off for .ts files, CI lints from the root, and those packages do not run lint in posttest, so npm test is unaffected. Making per-package lint match root lint would be a follow-up change to @loopback/eslint-config.

Checklist

  • DCO signed in all commits
  • npm test passes for every touched example
  • New tests added: not applicable, lint/tooling fixes only
  • Code conforms with the style guide
  • API documentation / docs / CLI templates: not affected

@dhmlau dhmlau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pranesh-sridhar, thanks for the PR. LGTM.

ESLint 8.57+ restricts subpaths through its package exports map, so
require.resolve('eslint/bin/eslint') threw ERR_PACKAGE_PATH_NOT_EXPORTED and
lb-eslint crashed in every package. Fall back to resolving package.json and
building the absolute path from it.

Signed-off-by: pranesh-sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
The 'this: Mocha.Context' parameter is misread by the mocha plugin as a done
callback. Use an arrow function and set the timeout with .timeout() instead.

Signed-off-by: pranesh-sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
Typed linting failed to parse .eslintrc.js because it is not included in
tsconfig.json, which made posttest lint fail.

Signed-off-by: pranesh-sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
Typed linting failed to parse .eslintrc.js because it is not included in
tsconfig.json, which made posttest lint fail.

Signed-off-by: pranesh-sridhar <68075088+pranesh-sridhar@users.noreply.github.com>
@pranesh-sridhar
pranesh-sridhar force-pushed the fix/examples-lint-eslint-cli-resolution branch from 016068e to d035608 Compare October 22, 2026 06:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants