Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:javascript-best-practices/no-import-assign
Language: JavaScript
Severity: Error
Category: Error Prone
Description
Imported modules must be immutable. Assignments to the imported bindings are forbidden.
importmodfrom'mod';mod.prop=0importmodfrom'mod';mod.prop+=0importmodfrom'mod';mod.prop++importmodfrom'mod';deletemod.propimportmodfrom'mod';for(mod.propinfoo);importmodfrom'mod';for(mod.propoffoo);importmodfrom'mod';[mod.prop]=foo;importmodfrom'mod';[...mod.prop]=foo;importmodfrom'mod';({bar:mod.prop}=foo);importmodfrom'mod';({...mod.prop}=foo);import{named}from'mod';named.prop=0import{named}from'mod';named.prop+=0import{named}from'mod';named.prop++import{named}from'mod';deletenamed.propimport{named}from'mod';for(named.propinfoo);import{named}from'mod';for(named.propoffoo);import{named}from'mod';[named.prop]=foo;import{named}from'mod';[...named.prop]=foo;import{named}from'mod';({bar:named.prop}=foo);import{named}from'mod';({...named.prop}=foo);import*asmodfrom'mod';mod.named.prop=0import*asmodfrom'mod';mod.named.prop+=0import*asmodfrom'mod';mod.named.prop++import*asmodfrom'mod';deletemod.named.propimport*asmodfrom'mod';for(mod.named.propinfoo);import*asmodfrom'mod';for(mod.named.propoffoo);import*asmodfrom'mod';[mod.named.prop]=foo;import*asmodfrom'mod';[...mod.named.prop]=foo;import*asmodfrom'mod';({bar:mod.named.prop}=foo);import*asmodfrom'mod';({...mod.named.prop}=foo);import*asmodfrom'mod';obj[mod]=0import*asmodfrom'mod';obj[mod.named]=0import*asmodfrom'mod';for(varfooinmod.named);import*asmodfrom'mod';for(varfooofmod.named);import*asmodfrom'mod';[bar=mod.named]=foo;import*asmodfrom'mod';({bar=mod.named}=foo);import*asmodfrom'mod';({bar:baz=mod.named}=foo);import*asmodfrom'mod';({[mod.named]:bar}=foo);import*asmodfrom'mod';varobj={...mod.named};import*asmodfrom'mod';varobj={foo:mod.named};// scoped import name re-use not covered
// import mod from 'mod'; { let mod = 0; mod = 1 }
// import * as mod from 'mod'; { let mod = 0; mod = 1 }
// import * as mod from 'mod'; { let mod = 0; mod.named = 1 }
import{}from'mod'import'mod'importmodfrom'mod';Object.assign(mod,obj);import{named}from'mod';Object.assign(named,obj);import*asmodfrom'mod';Object.assign(mod.prop,obj);import*asmodfrom'mod';Object.assign(obj,mod,other);import*asmodfrom'mod';Object[assign](mod,obj);import*asmodfrom'mod';Object.getPrototypeOf(mod);import*asmodfrom'mod';Reflect.set(obj,key,mod);// Object redeclare not analyzed
// import * as mod from 'mod'; { var Object; Object.assign(mod, obj); }
// import * as mod from 'mod'; var Object; Object.assign(mod, obj);
import*asmodfrom'mod';Object.seal(mod,obj)import*asmodfrom'mod';Object.preventExtensions(mod)import*asmodfrom'mod';Reflect.preventExtensions(mod)
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- javascript-best-practices # Rules to enforce JavaScript best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines