Skip to content

feat: add ESLint rule to enforce named ILogger conventions#17687

Open
ankitsharma101 wants to merge 2 commits into
eclipse-theia:masterfrom
ankitsharma101:feature/eslint-logger-rule
Open

feat: add ESLint rule to enforce named ILogger conventions#17687
ankitsharma101 wants to merge 2 commits into
eclipse-theia:masterfrom
ankitsharma101:feature/eslint-logger-rule

Conversation

@ankitsharma101

Copy link
Copy Markdown
Contributor

What it does

Resolves #17468.

This PR introduces a new custom ESLint rule (named-logger-check.js) to the private-eslint-plugin to enforce the new logger coding guidelines. Specifically, the rule ensures that:

  1. console.* statements are not used inside @injectable() classes.
  2. Injected ILogger instances are accompanied by an @named(...) decorator.
  3. The string passed to @named follows the required naming convention: [optional-purpose]package-name:class-name#optional-suffix.
  4. Files residing in electron-main are explicitly excluded from this check, as the DI container is not fully available during early bootstrap.

How to test

  1. Automated Tests: Run the Mocha test suite in dev-packages/private-eslint-plugin to verify the AST logic and regex patterns.
  2. Manual Verification: Add a temporary console.log("test") inside any @injectable class in the frontend (e.g., packages/core/src/browser/application-shell.ts). Run yarn lint packages/core and observe the custom ESLint error Use injected ILogger instead of console statements in @injectable classes.

Follow-ups

Aligning the rest of the codebase to pass this new rule. (Note: Existing violations are currently being addressed in PR #17541).

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

@ankitsharma101 ankitsharma101 force-pushed the feature/eslint-logger-rule branch from 347d1fa to a985fdc Compare June 20, 2026 13:21
@ndoschek ndoschek mentioned this pull request Jun 22, 2026
29 tasks

@sdirix sdirix 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.

Looks pretty good already! However we can only activate this if the rest of the codebase is migrated in a separate PR or within this PR as otherwise we have a lot of lint errors.

"runtime-import-check": require('./rules/runtime-import-check'),
"shared-dependencies": require('./rules/shared-dependencies')
"shared-dependencies": require('./rules/shared-dependencies'),
"named-logger-check": require('./rules/named-logger-check')

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.

Registering the rule here only exposes it under @theia/named-logger-check, it doesn't activate it. The rule isn't added to configs/errors.eslintrc.json (or any other config), so npm run lint never runs it and the "How to test" steps in the PR description won't produce an error.

@@ -0,0 +1,90 @@
/** @type {import('eslint').Rule.RuleModule} */

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.

Missing the EPL license header and // @ts-check. Every other rule file has both, e.g. annotation-check.js. annotation-check.js also uses proper @typedef imports instead of the inline /** @type {any} */ casts here, worth following the same pattern.

@@ -0,0 +1,70 @@
const { RuleTester } = require('eslint');

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.

Missing the EPL license header here too.

meta: {
type: 'problem',
docs: {
description: 'Enforce ILogger usage and naming conventions in @injectable classes',

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.

New rule isn't documented in the plugin README, which lists every other rule. Please add a named-logger-check entry.

@github-project-automation github-project-automation Bot moved this from Waiting on reviewers to Waiting on author in PR Backlog Jun 23, 2026
@ankitsharma101

Copy link
Copy Markdown
Contributor Author

Hi Stefan, thanks for the review! I've updated the rule with the requested license headers, added // @ts-check with proper JSDoc typedefs to satisfy type checking, and added documentation to the README. The rule remains disabled in errors.eslintrc.json as discussed to avoid build breaks during the migration. Ready for another look!

@ankitsharma101 ankitsharma101 requested a review from sdirix June 29, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on author

Development

Successfully merging this pull request may close these issues.

Add ESLint rule for named Loggers

2 participants