npm package: @springernature/eslint-config
Description: Springernature shareable config for ESLint
Author: Springer Nature
Latest version: 8.0.0

# Springer Nature ESLint Configuration

[![MIT licensed][badge-license]][info-license]
![NPM Version](https://img.shields.io/npm/v/%40springernature%2Feslint-config)

[Shareable ESLint config](https://eslint.org/) used at Springer Nature for enforcing consistent code style across JavaScript files.

ESLint statically analyzes your code to quickly find problems. It is built into most text editors and you can run ESLint as part of your continuous integration pipeline.

> [!IMPORTANT]  
> As of version `7.0.0` of this configuration all code format rules have been removed, and you should be using this in conjunction with our [prettier configuration](https://github.com/springernature/frontend-tooling/tree/main/linting/prettier).

## Requirements

This package requires:

- [Node version 24 or greater](https://nodejs.org/en/download/releases)
- `eslint@^9.39.3`
- `@eslint/js@^9.39.3`
- `eslint-plugin-import-x@^4.16.1`
- `eslint-plugin-no-use-extend-native@^0.7.2`
- `eslint-plugin-promise@^7.2.1`
- `eslint-plugin-unicorn@^63.0.0`
- `globals@^16.3.0`
- _`eslint-plugin-jest@^29.15.0` (jest config only)_
- _`eslint-plugin-n@^17.24.0` (node config only)_
- _`eslint-plugin-security@^4.0.0` (node config only)_

## Installation

Our default export contains all of our **ESLint rules**.

`eslint` is defined in `peerDependencies`, which means that you will need to add these to your own project's `devDependencies`.

Install our config and all it's required dependencies to your `devDependencies` with the following command:

```
npm install -D eslint@^9.39.3 @eslint/js@^9.39.3 eslint-plugin-import-x@^4.16.1 eslint-plugin-no-use-extend-native@^0.7.2 eslint-plugin-promise@^7.2.1 eslint-plugin-unicorn@^63.0.0 globals@^16.3.0 @springernature/eslint-config
```

If configuring for **jest**, you can add the additional dependency to your `devDependencies` with the following command:

```
npm install -D eslint-plugin-jest@^29.15.0
```

If configuring for **node**, you can add the additional dependencies to your `devDependencies` with the following command:


```
npm install -D eslint-plugin-n@^17.24.0 eslint-plugin-security@^4.0.0
```

## Usage

You then need to setup the configuration so it can be used in your project.

1. Create an `eslint.config.js` file in the root of your project.
2. Configure the `core` configuration as in the example below. All implementations must use this as a minimum.
3. Configure one or more of the additional configurations as per your requirements.

### Core Configuration

```javascript
import {coreConfig} from '@springernature/eslint-config';
import {defineConfig} from "eslint/config";

export default defineConfig([
  {
    files: ["**/*.js"],
    extends: [coreConfig],
    rules: {
      // custom rules
    },
  },
]);
```
### Additional Configurations

* [`browser`](./configs/browser.js) - For browser environments
* [`node`](./configs/node.js) - Add if your project contains [Node.js](https://nodejs.org/en/)
* [`jest`](./configs/jest.js) - Add if your project uses [Jest](https://facebook.github.io/jest/)

Import the configuration(s) your need for your project, and then add the configuration map(s) to the exported array.

```javascript
import {coreConfig, nodeConfig, browserConfig, jestConfig} from '@springernature/eslint-config';
import {defineConfig} from "eslint/config";
import globals from 'globals';

export default defineConfig([
  {
    files: ["**/*.js"],
    languageOptions: {
      globals: {...globals.node, ...globals.browser}
    },
    extends: [coreConfig],
    rules: {
      // custom rules
    },
  },
  {
    files: ["server/**/*.js", "cli/**/*.js"],
    extends: [nodeConfig],
    rules: {
      // custom rules
    },
  },
  {
    files: ["lib/frontend/**/*.js"],
    extends: [browserConfig],
    rules: {
      // custom rules
    },
  },
  {
    files: ["**/*(spec|test).js"],
    extends: [jestConfig]
  }
]);
```

#### Different versions of Jest

The behaviour of some rules (specifically no-deprecated-functions) change depending on the version of Jest being used.

By default, this plugin will attempt to locate Jest using require.resolve, meaning it will start looking in the closest `node_modules` folder to the file being linted and work its way up.

Since we cache the automatically determined version, if you're linting sub-folders that have different versions of Jest, you may find that the wrong version of Jest is considered when linting. You can work around this by providing the Jest version explicitly in nested ESLint configs:

```json
{
  "settings": {
    "jest": {
      "version": 30
    }
  }
}
```

To avoid hard-coding a number, you can also fetch it from the installed version of Jest in your `eslint.config.js` file:

```js
module.exports = {
  settings: {
    jest: {
      version: require('jest/package.json').version,
    },
  },
};
```

### Linting your project

There are several ways that ESLint can be used, however, it is recommended to run it from within your [code editor](https://eslint.org/docs/latest/use/integrations).

Visual code, for example, has an [eslint-vscode plugin](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).

If you don't already use ESLint, it is likely that you will want to run it against your whole project, and then use the editor to maintain it's usage as you make code changes.

To do this, you can run:

```shell
npx eslint 
```

This will format all matching files according to the ESLint configuration. This could result in a large number of stylistic changes to the code, mostly from changing quote style, adding spaces around braces, etc. If you want to start using ESLint more incrementally, you can instruct it to ignore code.

### Ignore code

Often you will want to ignore certain files or folders from being formatted. For example, compiled code or test coverage folders.

You can do this by adding an `ignores` property in your `eslint.config.js` file.

```javascript
// eslint.config.js
export default [
  {
    ignores: [".config/*"]
  }
];
```

## Contributing

This package is used by many active Springer Nature projects. We always welcome issues and pull requests, but we may not always be able to merge your suggestions.

If we decide that we can't merge your PR or act on your issue, it's nothing personal! We love to see new contributors, and we strive to provide a welcoming and inclusive environment.

## License

The eslint-config-springernature repository is licensed under the [MIT License][info-license].    
All packages within this repository are licensed under the [MIT License][info-license].    
Copyright &copy; 2025, Springer Nature

[info-license]: /LICENSE
[badge-license]: https://img.shields.io/badge/license-MIT-blue.svg