Cheminfo ESLint TypeScript Configuration
This package provides a shared ESLint configuration specifically tailored for TypeScript projects within the Cheminfo ecosystem. It aims to enforce consistent coding styles and best practices across various repositories. Currently at version 22.0.0, the configuration is actively maintained with a relatively frequent release cadence, often aligning with updates to its base JavaScript configuration (`eslint-config-cheminfo`), ESLint itself, and various ESLint plugins. A key differentiator is its strict adherence to the ESLint Flat Config format, moving away from legacy configurations and embracing modern ESLint practices. It builds upon a robust base JS config and integrates plugins for JSDoc, Unicorn, and Vitest, offering a comprehensive and opinionated linting solution for TypeScript development.
Common errors
-
Error: Failed to load config "cheminfo-typescript" to extend from. Referenced from: ...
cause ESLint cannot find the configuration package because it's either not installed or the import path is incorrect.fixEnsure `eslint-config-cheminfo-typescript` is installed (`npm i -D eslint-config-cheminfo-typescript`) and the import path in `eslint.config.mjs` is `import cheminfo from 'eslint-config-cheminfo-typescript';`. -
ESLint: Cannot read properties of undefined (reading 'eslint') TypeError: Cannot read properties of undefined (reading 'eslint')
cause This error often occurs when `eslint-plugin-typescript` (or related plugins) cannot find the TypeScript parser or `tsconfig.json`.fixVerify `typescript` is installed and that your `eslint.config.mjs` includes `languageOptions: { parserOptions: { project: './tsconfig.json' } }` correctly configured for your project. -
ESLint: Cannot read config file: ...eslint.config.mjs
cause ESLint is unable to parse or find the configuration file, possibly due to incorrect file extension, syntax errors, or module type issues.fixEnsure your config file is named `eslint.config.mjs` (or `.js` with `"type": "module"` in `package.json`), contains valid JavaScript/ESM syntax, and is accessible to ESLint. -
ESLint: Rule 'no-redeclare' was removed and replaced by 'no-redeclare' in @typescript-eslint/eslint-plugin.
cause A common conflict or deprecation when using TypeScript ESLint plugins, where the base ESLint rule is replaced by a type-aware version.fixThis specific rule was fixed in v21.0.1. If on an older version, update the package. Otherwise, ensure no custom rules conflict by re-enabling `@typescript-eslint/no-redeclare` if needed, or remove the rule entirely if it's implicitly handled.
Warnings
- breaking All configurations now strictly require the ESLint Flat Config format. Traditional `.eslintrc.*` files are no longer supported.
- breaking The package frequently updates its peer dependency for `eslint`. Ensure your `eslint` version meets the minimum requirement specified in `peerDependencies` to avoid compatibility issues.
- breaking Major versions often introduce breaking changes by updating the base JavaScript config, underlying ESLint plugins, or ESLint itself, leading to new rules or changes in existing ones.
- gotcha The configuration relies on `typescript` being installed and correctly configured in your project's `tsconfig.json` for type-aware linting rules to function.
- breaking Version 22.0.0 specifically updates the base config to v18, which may introduce new linting rules or modify existing rule severities inherited from the JavaScript base configuration.
Install
-
npm install eslint-config-cheminfo-typescript -
yarn add eslint-config-cheminfo-typescript -
pnpm add eslint-config-cheminfo-typescript
Imports
- cheminfo
const cheminfo = require('eslint-config-cheminfo-typescript');import cheminfo from 'eslint-config-cheminfo-typescript';
- cheminfo.base
import { base } from 'eslint-config-cheminfo-typescript';import cheminfoBase from 'eslint-config-cheminfo-typescript/base';
- defineConfig
import defineConfig from 'eslint/config';
import { defineConfig } from 'eslint/config';
Quickstart
import { defineConfig } from 'eslint/config';
import cheminfo from 'eslint-config-cheminfo-typescript';
export default defineConfig(
// Apply the base Cheminfo TypeScript config
cheminfo,
{
// Example: Override or add project-specific rules
rules: {
'no-console': 'warn',
'prefer-const': 'error'
},
// Example: Target specific files
files: ['src/**/*.ts', 'test/**/*.ts'],
// Example: Configure parser options for specific environments
languageOptions: {
parserOptions: {
project: './tsconfig.json'
}
}
}
);