[no-magic-numbers] - false error report on array destructuring declaration
See original GitHub issueTell us about your environment
Node version: v12.12.0 npm version: v6.9.0 Local ESLint version: v6.8.0 (Currently used) Global ESLint version: Not found
What parser (default, Babel-ESLint, etc.) are you using? typescript 3.8 Please show your full configuration:
Configuration
env:
es2020: true
browser: true
extends:
- "eslint:recommended"
- "plugin:@typescript-eslint/recommended"
- "plugin:@typescript-eslint/eslint-recommended"
- "plugin:functional/all"
- "plugin:jest/recommended"
- "plugin:react/recommended"
- "plugin:no-unsanitized/DOM"
- "prettier"
- "prettier/@typescript-eslint"
parser: "@typescript-eslint/parser"
parserOptions:
# project: "./tsconfig.json"
sourceType: module
plugins:
- "@typescript-eslint/eslint-plugin"
- functional
- jest
- no-unsanitized
- promise
- react
- react-hooks
overrides:
- files:
- "*.test.js"
- "*.spec.js"
globals:
globalThis: "writable"
# devprint: "readonly"
rules:
"@typescript-eslint/camelcase": off
"@typescript-eslint/class-name-casing":
- off
"@typescript-eslint/explicit-function-return-type":
- error
- allowExpressions: true
"@typescript-eslint/interface-name-prefix":
- warn
"@typescript-eslint/no-empty-interface":
- error
- "allowSingleExtends": true
"@typescript-eslint/no-use-before-define": off
arrow-body-style: "off"
arrow-parens: warn
camelcase: off
comma-dangle: "off"
complexity:
- warn
- 3
func-style: warn
functional/functional-parameters:
- error
- enforceParameterCount: false
functional/immutable-data:
- error
- ignorePattern:
- globalThis
functional/prefer-readonly-type: off
functional/no-conditional-statement: off
functional/no-expression-statement:
- off
- ignorePattern:
- console
- devprint
- globalThis
- render
functional/no-return-void: off
id-length:
- warn
- {min: 3, exceptions: [_, fn, id, is, BG]}
id-match:
- error
- "^[a-zA-Z_0-9]*$"
- properties: true
indent: off
lines-around-comment:
- warn
- ignorePattern: /prettier-ignore/
max-len:
- warn
- code: 90
comments: 120
tabWidth: 2
# "^\\} from" part is for multi-line imports
ignorePattern: "Spec|import|^\\} from"
ignoreUrls: true
max-lines:
- warn
- max: 50
skipBlankLines: true
max-params:
- warn
- 6
max-statements:
- warn
- 10
multiline-ternary: "off"
new-cap: off
no-console: warn
no-inline-comments: "off"
no-magic-numbers:
- error
- ignore:
- 0
- 1
- -1
no-multi-spaces: "off"
no-param-reassign:
- error
- props: true
no-nested-ternary: "off"
no-return-await: warn
no-shadow:
- error
- builtinGlobals: true
allow:
- "name"
- "status"
no-warning-comments: off
no-undef: error
no-underscore-dangle:
- error
- "allow": ["_id", "_text"]
no-unneeded-ternary: "off"
no-unused-vars: warn
no-use-before-define: "off"
no-useless-catch: warn
object-curly-newline: "off"
one-var: off
operator-linebreak:
- warn
- before
- overrides:
+: ignore
=: ignore
padding-line-between-statements: "off"
prefer-destructuring: warn
radix: "off"
react/no-string-refs:
- error
- noTemplateLiterals: true
react-hooks/rules-of-hooks: error
react-hooks/exhaustive-deps: warn
react/display-name: "off"
react/prop-types: "off"
semi: warn
settings: {}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
const [widht, height] = [10, 20];
I use Webstorm's built-in eslint reporting service
What did you expect to happen? No errors reported
What actually happened? Please include the actual, raw output from ESLint. No magic number: 10. (no-magic-numbers)
Are you willing to submit a pull request to fix this bug? noooo…
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:12 (8 by maintainers)
Top Results From Across the Web
no-magic-numbers - ESLint - Pluggable JavaScript Linter
A boolean to specify if numbers used in the context of array indexes (e.g., data[2] ) are considered okay. false by default. This...
Read more >Reduce smelling code and detect JavaScript issues with ESLint
Problem statement: Smelling Code Have you ever had to fix an error in someone else's code - but you had to reformat the...
Read more >ESLint with TypeScript and Firebase - no-undef error
I use eslint in my project with typescript-eslint to be able to lint TypeScript code. I have an issue with an import provided...
Read more >no-unsafe-assignment | typescript-eslint
This rule disallows assigning any to a variable, and assigning any[] to an array destructuring. This rule also compares generic type argument types...
Read more >declaration or statement expected. this '=' follows a block of ...
Today, you'll get an error on the = like. Declaration or statement expected. Destructuring assignments are super confusing on their own because object ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reporting!
In my opinion, It makes sense to treat it as a bug because all numbers are named.
Something like this might be correct:
We could find the assignment target for the number, and if it’s a
MemberExpression
then allow/disallow based ondetectObjects
.If it’s an
Identifier
, then allow only if the assignment is initializing variable (VariableDeclarator
, which must be in aconst
declaration if"enforceConst": true
).Perhaps we could do this for object patterns as well, maybe even support nested destructuring.
There is also proposal #12611 to optionally allow default assignments.