{"id":19944,"library":"eslint-plugin-sort-react-dependency-arrays","title":"eslint-plugin-sort-react-dependency-arrays","description":"ESLint plugin to enforce alphanumerically sorted React hook dependency arrays (useEffect, useLayoutEffect, etc.). Version 1.0.0 stable, requires Node >=18.18 or 20+. Differentiators: automatic fix with --fix, no external runtime dependencies beyond ESLint >=7, and focuses solely on sorting rather than comprehensive dependency checks. Lightweight alternative to eslint-plugin-react-hooks for ordering only.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","eslint","eslintplugin","eslint-plugin","react","react-dependency-array","react-dependency-arrays","sort-react-dependency-array","sort-react-dependency-arrays"],"install":[{"cmd":"npm install eslint-plugin-sort-react-dependency-arrays","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-sort-react-dependency-arrays","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-sort-react-dependency-arrays","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; requires ESLint >=7","package":"eslint","optional":false}],"imports":[{"note":"ESM export; the package is ESM-only. CommonJS require still works for Node, but named import is preferred.","wrong":"const rules = require('eslint-plugin-sort-react-dependency-arrays').rules","symbol":"rules","correct":"import { rules } from 'eslint-plugin-sort-react-dependency-arrays'"},{"note":"configs is a named export, not default.","wrong":"import configs from 'eslint-plugin-sort-react-dependency-arrays'","symbol":"configs","correct":"import { configs } from 'eslint-plugin-sort-react-dependency-arrays'"},{"note":"Default export is the plugin object. With CommonJS, require returns the default.","wrong":"const sortReactDepArrPlugin = require('eslint-plugin-sort-react-dependency-arrays')","symbol":"plugin","correct":"import sortReactDepArrPlugin from 'eslint-plugin-sort-react-dependency-arrays'"}],"quickstart":{"code":"// .eslintrc.json\n{\n  \"plugins\": [\"sort-react-dependency-arrays\"],\n  \"rules\": {\n    \"sort-react-dependency-arrays/sort\": \"error\"\n  }\n}\n\n// Example React component\nimport { useEffect } from 'react';\n\nfunction MyComponent({ flag, value }) {\n  useEffect(() => {\n    // ...\n  }, [value, flag]); // <-- sorted correctly (alphabetically)\n\n  useEffect(() => {\n    // ...\n  }, [flag, value]); // <-- will trigger lint error; use --fix to reorder\n}","lang":"typescript","description":"Configures the plugin and shows a sorted vs unsorted dependency array in useEffect."},"warnings":[{"fix":"Combine with eslint-plugin-react-hooks/exhaustive-deps for full coverage.","message":"The rule only sorts arrays, it does not validate missing dependencies.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review autofixed output; the rule assumes alphabetical is always safe.","message":"Autofix may break order if dependencies have side effects or implicit ordering.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node to >=18.18, >=20, or >=22.","message":"Node versions below 18.18.0 are not supported.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade ESLint to v9 (flat config). The plugin still works with v8 but may not receive updates.","message":"ESLint v8 is deprecated; use ESLint v9 if possible.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use for React hooks only; for general array sorting, use other plugins.","message":"Only works with React hooks dependency arrays; does not sort other arrays.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install eslint-plugin-sort-react-dependency-arrays --save-dev`","cause":"Plugin not installed or missing from node_modules.","error":"Error: Failed to load plugin 'sort-react-dependency-arrays' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-sort-react-dependency-arrays'"},{"fix":"Upgrade ESLint to >=7: `npm install eslint@^7 --save-dev`","cause":"Using an older ESLint version (<7) that does not support custom rules properly.","error":"TypeError: ruleMapper is not a function"},{"fix":"Use 'plugins' array with string names, not import statements inside config.","cause":"Using 'import' in .eslintrc.json (which must be valid JSON).","error":"Parsing error: The keyword 'import' is reserved"},{"fix":"Rewrite to use a static array literal for the autofix to work.","cause":"Dependency array is dynamically constructed (e.g., using spread).","error":"Cannot read properties of undefined (reading 'sort')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}