close

prefer-global/console

Unreleased

Configuration

rslint.config.ts
import { defineConfig, nodePlugin } from '@rslint/core';

export default defineConfig([
  nodePlugin.configs.recommended,
  {
    rules: {
      'node/prefer-global/console': 'error',
    },
  },
]);

Enforce consistent use of the global console variable or the console module.

Options

  • "always" (default): use the global console variable.
  • "never": load console from a module instead of using the global variable.
import { globals } from '@rslint/core';

export default [{
  plugins: ['node'],
  languageOptions: { globals: globals.node },
  rules: {
    'node/prefer-global/console': ['error', 'always'],
  },
}];

With "always", these module references are incorrect:

const console = require('console');
import importedConsole from 'node:console';
const logger = process.getBuiltinModule('console');

Use the global variable instead:

console.log('hello');

With "never", using the global variable is incorrect:

console.log('hello');

Load the module instead:

const console = require('node:console');
console.log('hello');

The rule recognizes CommonJS loads, process.getBuiltinModule(), static imports and re-exports, including the node: prefix. Local bindings that shadow globals are respected. The rule provides no automatic fixes or suggestions.

Original documentation