kibana/packages/kbn-eslint-config
Jeramy Soucy 2627f48d95
Harden console functions (#171367)
## Summary

This PR overrides console functions only in production, in order to
sanitize input parameters for any potential calls made to the global
console from Kibana's dependencies.

This initial implementation overrides the `debug`, `error`, `info`,
`log`, `trace`, and `warn` functions, and only sanitizes string inputs.
Future updates may expand this to handle other types, or strings nested
in objects.

The unmodified console methods are now exposed internally in Kibana as
`unsafeConsole`. Where needed for formatting (log appenders, core
logger), calls to the global console have been replaced by
`unsafeConsole`. This PR also adds a new es linting rule to disallow
calls to `unsafeConsole` unless `eslint-disable-next-line
@kbn/eslint/no_unsafe_console` is used.

### Testing
Not sure how we could test this. The overrides are only enabled when
running in a true production environment (e.g. docker) by checking
`process.env.NODE_ENV`.

I was able to manually test by adding additional console output denoting
when the console functions were being overriden or not.

Closes https://github.com/elastic/kibana-team/issues/664
Closes #176340

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2024-02-09 09:13:52 -05:00
..
.eslintrc.js Harden console functions (#171367) 2024-02-09 09:13:52 -05:00
.gitignore chore(NA): rename @elastic/eslint-config-kibana as @kbn/eslint-config (#132278) 2022-05-16 13:02:02 -07:00
javascript.js Remove eslint-plugin-prefer-object-spread dependency (#162439) 2023-07-25 10:04:44 +02:00
jest.js chore(NA): rename @elastic/eslint-config-kibana as @kbn/eslint-config (#132278) 2022-05-16 13:02:02 -07:00
kibana.jsonc Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
package.json [packages] migrate all plugins to packages (#148130) 2023-02-08 21:06:50 -06:00
react.js Upgrade ESLint React plugins (#162464) 2023-07-28 10:43:53 +02:00
README.mdx Initialize ops documentation section (#132262) 2022-05-17 15:22:38 -05:00
restricted_globals.js chore(NA): rename @elastic/eslint-config-kibana as @kbn/eslint-config (#132278) 2022-05-16 13:02:02 -07:00
typescript.js Remove eslint-plugin-prefer-object-spread dependency (#162439) 2023-07-25 10:04:44 +02:00

---
id: kibDevDocsOpsEslintConfig
slug: /kibana-dev-docs/ops/eslint-config
title: "@kbn/eslint-config"
description: A package holding the main eslint configs on Kibana
date: 2022-05-16
tags: ['kibana', 'dev', 'contributor', 'operations', 'eslint', 'custom', 'config']
---

This package is used to group and provide the eslint configurations used by the Kibana team.
It defines default plugins, env, parserOptions and rules for javascript, typescript, and react code bases. 
Optionally it can also be used with jest as explained below.

## Usage

To use this eslint config, it needs to be referenced in the `.eslintrc` file:

```javascript
module.exports = {
  extends: [
    '@kbn/eslint-config'
  ]
}
```

## Optional jest eslint config

If [jest test runner](https://facebook.github.io/jest/) is used, 
the `@kbn/eslint-config/jest` config can be extended as well to use 
`eslint-plugin-jest` and add settings specific to it:

```javascript
module.exports = {
  extends: [
    '@kbn/eslint-config',
    '@kbn/eslint-config/jest'
  ]
}
```