Skip to content

ESlint Typescript MailOnline config, migrated from tslint-config-mailonline due to tslint deprecation

License

Notifications You must be signed in to change notification settings

MailOnline/eslint-config-ts-mailonline

Repository files navigation

eslint-config-ts-mailonline

NPM version Build status

MailOnline ESLint Typescript configuration for ESLint 9+ (flat config).

Requirements

  • ESLint >= 9.0.0
  • TypeScript >= 5.0.0
  • Node.js >= 18.18.0

Usage

  1. Add eslint-config-ts-mailonline, eslint, typescript, prettier, husky, and pretty-quick as development dependencies:
yarn add --dev eslint-config-ts-mailonline eslint typescript prettier husky pretty-quick
  1. Create a tsconfig.eslint.json file at the root of your project:
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "allowJs": true,
    "noEmit": true
  },
  "include": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts", "**/*.js", "**/*.jsx", "**/*.mjs", "**/*.cjs"],
  "exclude": ["node_modules", "dist", "coverage"]
}

Why is this needed? This configuration uses @typescript-eslint/parser with type-aware linting, which requires TypeScript to know about all files being linted. Many projects exclude test files and config files from their main tsconfig.json to avoid compiling them. The tsconfig.eslint.json ensures all files are included for linting purposes without affecting your build configuration.

tsconfig.eslint.json is now required: You must create a tsconfig.eslint.json file in your project root. This is necessary because the configuration uses @typescript-eslint/parser with project: './tsconfig.eslint.json' for type-aware linting rules.

  1. Create an eslint.config.mjs file at the root of your project using defineConfig (defineConfig is the standard way to define ESLint configurations since ESLint 9):
import { defineConfig } from 'eslint/config';
import { baseConfig, reactConfig } from 'eslint-config-ts-mailonline';

// defineConfig accepts both a config object or an array of config objects
export default defineConfig({
  // extends automatically flattens configuration arrays, so no spread operator needed
  extends: [
    baseConfig,
    reactConfig // optional, only if using React
  ]
  // your custom overrides here:
  // rules: { 'no-console': 'warn' }
});
  1. Create prettier.config.mjs at the root of your project:
export { default } from 'eslint-config-ts-mailonline/prettierConfig';
  1. Add the following script command to your package.json:
{
  "scripts": {
    "lint": "tsc --noEmit && eslint ."
  }
}
  1. Add the following hooks to your husky scripts:

Pre-commit (.husky/pre-commit):

pretty-quick --staged && yarn run lint

Pre-push (.husky/pre-push):

yarn run test

Ignoring files

With ESLint 9 flat config, ignores are defined in your eslint.config.mjs using globalIgnores:

import { defineConfig, globalIgnores } from 'eslint/config';
import { baseConfig } from 'eslint-config-ts-mailonline';

export default defineConfig([
  // These ignores will be merged with the ones in baseConfig global ignores object
  // ending up in: ['**/node_modules/**', '**/coverage/**', '**/dist/**', 'bin/**', 'legacy/**']
  globalIgnores(['bin/**', 'legacy/**']),
  {
    extends: [
      baseConfig
      // other configs...
    ]
  }
]);

Bundled dependencies

This package includes the following ESLint plugins and configurations as direct dependencies. You should remove these from your project's devDependencies if you have them:

  • @typescript-eslint/eslint-plugin
  • @typescript-eslint/parser
  • eslint-config-prettier
  • eslint-import-resolver-typescript
  • eslint-plugin-import
  • eslint-plugin-no-only-tests
  • eslint-plugin-prefer-arrow
  • eslint-plugin-react
  • eslint-plugin-react-hooks
  • eslint-plugin-unicorn

Why? By bundling these dependencies, we:

  1. Guarantee compatibility: The config package ensures all plugins work correctly together
  2. Avoid version conflicts: No risk of peer dependency mismatches or duplicate packages
  3. Simplify adoption: Consumers don't need to manage ESLint plugin versions
  4. Single source of truth: Updates to plugins are handled centrally in this package

Breaking changes

Any changes to this package that might cause code using it to not validate anymore, will be a semver-major change.

Migration from v4.x to v5.x

See Migration Guide for instructions on upgrading from v4.x (ESLint 8) to v5.x (ESLint 9).

About

ESlint Typescript MailOnline config, migrated from tslint-config-mailonline due to tslint deprecation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6