ESLint plugin that disallows destructuring arrays as objects.
Note This plugin utilizes the awesome power of TypeScript's type checking.
These rules are slower to run and and you will need to specify a path to yourtsconfig.json
file in the"project"
property of"parserOptions"
.
For more information see: https://typescript-eslint.io/getting-started/typed-linting
Assuming you already have ESLint installed, run:
# npm
npm install --save-dev @arabasta/eslint-plugin-no-destructuring-arrays-as-objects
# yarn
yarn add --dev @arabasta/eslint-plugin-no-destructuring-arrays-as-objects
# pnpm
pnpm add --save-dev @arabasta/eslint-plugin-no-destructuring-arrays-as-objects
Flat config (eslint.config.js)
// ...
import noDestructuringArraysAsObjects from '@arabasta/eslint-plugin-no-destructuring-arrays-as-objects';
export default [
// ...
{
...noDestructuringArraysAsObjects.configs.recommended,
languageOptions: {
parserOptions: {
project: './tsconfig.json',
},
},
},
];
Legacy config (.eslintrc)
{
"extends": [
// ...
"plugin:@arabasta/no-destructuring-arrays-as-objects/recommended-legacy"
],
// ...
"parserOptions": {
"project": "tsconfig.json"
}
}
✅ Set in the recommended
configuration
Rule | Description | ✅ |
---|---|---|
no-destructuring-arrays-as-objects | Disallow destructuring arrays as objects | ✅ |
Examples of incorrect code for this rule:
const foo = [];
const { length } = foo;
Examples of correct code for this rule:
const foo = { bar: true };
const { bar } = foo;
MIT