@lunit/eslint-config
v3.0.0
Published
Lunit ESLint Config
Keywords
Readme
@lunit/eslint-config
A TypeScript ESLint ruleset designed for Lunit projects based on @rushstack/eslint-config.
This ESLint configuration is only available for TypeScript projects.
Installation
npm install --save-dev @lunit/eslint-configUsage
Getting Started
@lunit/eslint-config v3.x is configured using the ESLint Flat Config approach.
Compatibility
- ESLint 9.27.0 through ESLint 10.x
- Prettier 3 or newer
- TypeScript 5.x, or TypeScript 6.0.x with the override below
ESLint 8.x is not supported. It reached end of life on October 5, 2024: https://eslint.org/blog/2024/09/eslint-v8-eol-version-support/
For projects with React installed in the current working directory, the default config supplies the
installed React version to eslint-plugin-react. This avoids its incompatible version-detection
path on ESLint 10. If React cannot be resolved, the config retains the previous 'detect' behavior.
In a monorepo, the process working directory may differ from the package that owns React. Use the config factory to provide either the React version or the package directory explicitly:
import { createLunitEslintConfig } from '@lunit/eslint-config';
export default defineConfig([
createLunitEslintConfig({ reactResolveFrom: import.meta.dirname }),
// Alternatively: createLunitEslintConfig({ reactVersion: '19.2.0' }),
]);const { createLunitEslintConfig } = require('@lunit/eslint-config');
module.exports = defineConfig([
createLunitEslintConfig({ reactResolveFrom: __dirname }),
]);ESLint 10 runtime compatibility is covered by this package's integration tests. However, the latest
@rushstack/eslint-config and some of its plugins do not yet include ESLint 10 in their peer ranges,
so package managers may report peer dependency warnings until upstream support is published.
@rushstack/[email protected] pins an older TypeScript-ESLint release. TypeScript 6 consumers
must align that transitive toolchain in the application root because dependency-level overrides
are not inherited by package consumers.
pnpm
# pnpm-workspace.yaml
overrides:
'@typescript-eslint/eslint-plugin': 8.68.0
'@typescript-eslint/parser': 8.68.0
'@typescript-eslint/typescript-estree': 8.68.0
'@typescript-eslint/utils': 8.68.0npm
{
"overrides": {
"@typescript-eslint/eslint-plugin": "8.68.0",
"@typescript-eslint/parser": "8.68.0",
"@typescript-eslint/typescript-estree": "8.68.0",
"@typescript-eslint/utils": "8.68.0"
}
}This supports TypeScript 6.0.x; TypeScript 6.1 and newer remain outside the parser's supported range.
For information regarding ESLint Flat Config, please refer to the relevant ESLint Blog post.
- https://eslint.org/blog/2022/08/new-config-system-part-2/
To use it, add @lunit/eslint-config to your eslint.config.js file as follows. If you are using TypeScript ESLint rules, please remove them. This is already being used in Rushstack ESLint, causing conflict issues.
ESM
// eslint.config.js
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import { defineConfig, globalIgnores } from "eslint/config";
import lunitEslintConfig from '@lunit/eslint-config';
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
reactHooks.configs.flat["recommended-latest"],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
lunitEslintConfig,
]);CommonJS
// eslint.config.cjs
const js = require("@eslint/js");
const globals = require("globals");
const reactHooks = require("eslint-plugin-react-hooks");
const reactRefresh = require("eslint-plugin-react-refresh");
const { defineConfig, globalIgnores } = require("eslint/config");
const lunitEslintConfig = require('@lunit/eslint-config');
module.exports = defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
reactHooks.configs.flat["recommended-latest"],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
// You can add the ESLint Config rules as follows.
lunitEslintConfig,
]);If you created the app using vite, please refer to the information below.
If the tsconfig.json file is separate and the actual rules are applied in tsconfig.app.json,
please configure it as follows.
rushstack eslint config internally follows the rules set in tsconfig, so you must link the corresponding JSON file.
ESM
// eslint.config.js
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import { defineConfig, globalIgnores } from "eslint/config";
import lunitEslintConfig from '@lunit/eslint-config';
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
reactHooks.configs.flat["recommended-latest"],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
{
...lunitEslintConfig,
// You must integrate the tsconfig.app.json file applied to the actual ts and tsx files as shown below.
languageOptions: {
parserOptions: {
project: ["./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
},
}
]);CommonJS
// eslint.config.cjs
const js = require("@eslint/js");
const globals = require("globals");
const reactHooks = require("eslint-plugin-react-hooks");
const reactRefresh = require("eslint-plugin-react-refresh");
const { defineConfig, globalIgnores } = require("eslint/config");
const lunitEslintConfig = require('@lunit/eslint-config');
module.exports = defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
reactHooks.configs.flat["recommended-latest"],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
{
...lunitEslintConfig,
// You must integrate the tsconfig.app.json file applied to the actual ts and tsx files as shown below.
languageOptions: {
parserOptions: {
project: ["./tsconfig.app.json"],
tsconfigRootDir: __dirname,
},
},
}
]);Advanced
Override rushstack eslint rule
If you wish to modify the Rushstack ESLint rule, please refer to the code below.
ESM
// eslint.config.js
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import { defineConfig, globalIgnores } from "eslint/config";
import lunitEslintConfig from '@lunit/eslint-config';
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
reactHooks.configs.flat["recommended-latest"],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
{
// Using Spread Operator lunit Eslint Config
...lunitEslintConfig,
rules: {
// Using Spread Operator lunit Eslint Config Rules
...lunitEslintConfig.rules,
// And apply the target rule
'@rushstack/no-new-null': 'error',
},
}
]);CommonJS
// eslint.config.cjs
const js = require("@eslint/js");
const globals = require("globals");
const reactHooks = require("eslint-plugin-react-hooks");
const reactRefresh = require("eslint-plugin-react-refresh");
const { defineConfig, globalIgnores } = require("eslint/config");
const lunitEslintConfig = require('@lunit/eslint-config');
module.exports = defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
reactHooks.configs.flat["recommended-latest"],
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
{
// Using Spread Operator lunit Eslint Config
...lunitEslintConfig,
rules: {
// Using Spread Operator lunit Eslint Config Rules
...lunitEslintConfig.rules,
// And apply the target rule
'@rushstack/no-new-null': 'error',
},
}
]);Migrate 1.x to 2.x
Since migration to the ESLint flat config is required, please refer to the official ESLint documentation guide below.
- https://eslint.org/docs/latest/use/configure/migration-guide
