eslint-plugin-mobx

raw JSON →
0.0.14 verified Mon Apr 27 auth: no javascript

ESLint plugin providing MobX-specific linting rules for enforcing correct usage of makeObservable, makeAutoObservable, decorators, and observer in React components. Current stable version: 0.0.14. Supports ESLint 3–10 including flat config (ESLint 9+) and TypeScript via @typescript-eslint/parser. Key differentiator: catches common MobX footguns like missing makeObservable calls, non-exhaustive annotations, and missing observer wrappers, with autofix capabilities.

error ESLint: Cannot read config file: .../eslint.config.js: Unexpected token 'export'
cause Using flat config syntax with ESM in CommonJS project (package.json missing "type": "module").
fix
Add "type": "module" to package.json or rename file to .mjs.
error Error: Failed to load plugin 'mobx' declared in 'extends': Cannot find module 'eslint-plugin-mobx'
cause eslint-plugin-mobx not installed or not in node_modules.
fix
Run npm install --save-dev eslint-plugin-mobx.
error Parsing error: The keyword 'import' is reserved
cause Using ESM import statements in a CommonJS file (.eslintrc.js without type:module).
fix
Use require() for legacy config or switch to flat config with .mjs extension.
error Definition for rule 'mobx/exhaustive-make-observable' was not found
cause Plugin not specified in plugins array in legacy config.
fix
Add 'mobx' to plugins: ['mobx'] in .eslintrc.js.
breaking Flat config support requires ESLint >=9 and ESM module system; legacy .eslintrc config is not compatible.
fix Use eslint.config.js with import syntax instead of .eslintrc.js with require.
gotcha The exhaustive-make-observable rule does not support fields introduced by constructor (this.foo = 5) and may miss annotations.
fix Manually annotate such fields in makeObservable or use makeAutoObservable.
deprecated Legacy config (plugin:mobx/recommended via extends) is deprecated in favor of flat config (pluginMobx.flatConfigs.recommended) for ESLint >=9.
fix Migrate to eslint.config.js with flat config syntax.
gotcha The missing-observer rule may produce false positives for non-component functions with capitalized names (e.g., helper functions).
fix Use overrides to limit rule to .jsx/.tsx files or adjust naming conventions.
gotcha Autofix for exhaustive-make-observable defaults to adding field:true; migrating projects may accidentally override existing behavior.
fix Run autofix with --rule='mobx/exhaustive-make-observable: [2, { autofixAnnotation: false }]' to annotate with false.
npm install eslint-plugin-mobx
yarn add eslint-plugin-mobx
pnpm add eslint-plugin-mobx

Shows both legacy (.eslintrc) and flat config (eslint.config.js) setups with recommended rules.

// Install: npm install --save-dev eslint @typescript-eslint/parser eslint-plugin-mobx

// .eslintrc.js (legacy)
module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: ['mobx'],
  extends: 'plugin:mobx/recommended',
  rules: {
    'mobx/exhaustive-make-observable': 'warn',
    'mobx/missing-make-observable': 'error',
    'mobx/missing-observer': 'warn'
  }
};

// eslint.config.js (flat config, ESLint >=9)
import pluginMobx from 'eslint-plugin-mobx';
export default [
  pluginMobx.flatConfigs.recommended,
  {
    files: ['**/*.jsx'],
    rules: {
      'mobx/missing-observer': 'warn'
    }
  }
];