ESLint 9 with the new flat config format is now the default for new adapters. You have two migration options:
The official @iobroker/eslint-config package provides a standardized, maintained ESLint configuration that includes Prettier integration. This is the recommended approach for most adapters as it ensures consistency across the ioBroker ecosystem and reduces maintenance overhead.
- Centrally maintained configuration
- Automatic updates with best practices
- Prettier integration included
- Consistent code style across ioBroker adapters
- Less configuration to maintain
Remove old ESLint-related dependencies and add the official config:
"devDependencies": {
- "eslint": "^8.x.x",
- "@typescript-eslint/eslint-plugin": "^7.x.x",
- "@typescript-eslint/parser": "^7.x.x",
- "eslint-config-prettier": "^x.x.x",
- "eslint-plugin-prettier": "^x.x.x",
+ "@iobroker/eslint-config": "^2.2.0",
// ... other dependencies
}Replace your .eslintrc.js or .eslintrc.json with eslint.config.mjs:
For TypeScript adapters:
// iobroker eslint configuration
import iobrokerEslintConfig from '@iobroker/eslint-config/iobroker.config.mjs';
export default [
...iobrokerEslintConfig,
{
ignores: [
'.dev-server/',
'.vscode/',
'*.test.js',
'test/**/*.js',
'*.config.mjs',
'build',
'dist',
'admin/build/',
'admin/words.js',
'admin/admin.d.ts',
'**/adapter-config.d.ts',
]
}
];For JavaScript adapters:
// iobroker eslint configuration
import iobrokerEslintConfig from '@iobroker/eslint-config/iobroker.config.mjs';
export default [
...iobrokerEslintConfig,
{
ignores: [
'.dev-server/',
'.vscode/',
'*.test.js',
'test/**/*.js',
'*.config.mjs',
'admin/words.js',
]
}
];If using Prettier, create prettier.config.mjs:
// iobroker prettier configuration file
import prettierConfig from '@iobroker/eslint-config/prettier.config.mjs';
export default {
...prettierConfig,
// Adjust these to match your preferences:
useTabs: true, // or false for spaces
singleQuote: false, // or true for single quotes
};Update your package.json lint script:
"scripts": {
- "lint": "eslint .",
+ "lint": "eslint -c eslint.config.mjs .",
// ... other scripts
}Remove these files if they exist:
.eslintrc.jsor.eslintrc.json.eslintignore(ignores are now ineslint.config.mjs).prettierrc.js(replaced byprettier.config.mjs)
Add Prettier extension to .vscode/extensions.json for TypeScript projects:
"recommendations": [
"dbaeumer.vscode-eslint",
+ "esbenp.prettier-vscode",
// ... other extensions
]If you prefer to maintain your own ESLint configuration, you can upgrade to ESLint 9 while keeping full control over your rules.
- Full control over all ESLint rules
- Custom rule configurations
- Flexibility for project-specific needs
Upgrade ESLint and related packages to version 9:
"devDependencies": {
- "eslint": "^8.x.x",
+ "eslint": "^9.15.0",
+ "@eslint/js": "^9.15.0",
- "@typescript-eslint/eslint-plugin": "^7.x.x",
- "@typescript-eslint/parser": "^7.x.x",
+ "@typescript-eslint/eslint-plugin": "^8.15.0",
+ "@typescript-eslint/parser": "^8.15.0",
// ... other dependencies
}Create eslint.config.mjs to replace .eslintrc.js:
For TypeScript adapters:
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import globals from 'globals';
export default [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.node,
...globals.mocha,
},
parserOptions: {
projectService: true,
},
},
rules: {
'prefer-template': 'error',
'no-unused-vars': 'off',
},
},
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tseslint.parser,
},
plugins: {
'@typescript-eslint': tseslint.plugin,
},
rules: {
...tseslint.configs.recommended.rules,
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
},
{
ignores: [
'.dev-server/',
'.vscode/',
'*.test.js',
'test/**/*.js',
'*.config.mjs',
'build',
'dist',
'admin/build/',
'admin/words.js',
'admin/admin.d.ts',
'**/adapter-config.d.ts',
],
},
];For JavaScript adapters:
import js from '@eslint/js';
import globals from 'globals';
export default [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
...globals.node,
...globals.mocha,
},
},
rules: {
'prefer-template': 'error',
'no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
},
{
ignores: [
'.dev-server/',
'.vscode/',
'*.test.js',
'test/**/*.js',
'*.config.mjs',
'admin/words.js',
],
},
];If you're using globals in your config:
npm install --save-dev globalsUpdate your package.json lint script:
"scripts": {
- "lint": "eslint .",
+ "lint": "eslint -c eslint.config.mjs .",
// ... other scripts
}Remove these files:
.eslintrc.jsor.eslintrc.json.eslintignore(ignores are now ineslint.config.mjs)
If your adapter includes VIS widgets, add special configuration for them:
export default [
// ... your existing config
{
files: ['widgets/**/*.js'],
languageOptions: {
ecmaVersion: 5,
sourceType: 'script',
globals: {
...globals.browser,
$: 'readonly',
jQuery: 'readonly',
vis: 'readonly',
},
},
rules: {
'no-var': 'off',
'prefer-const': 'off',
'prefer-template': 'off',
},
},
];After updating your package.json:
npm installnpm run lintFix any issues reported. Many can be auto-fixed:
npm run lint -- --fixEnsure everything still works:
npm test
npm run build # for TypeScript adapters- Flat config format: Uses JavaScript modules instead of JSON/commonjs
- No
.eslintignore: Ignores are now part of the config file - Different plugin loading: Plugins are imported and used differently
- Improved performance: Faster execution with the new architecture