This product is not supported for your selected Datadog site. ().
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다. 현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.
Metadata
ID:javascript-best-practices/no-dupe-keys
Language: JavaScript
Severity: Error
Category: Error Prone
Description
Object literals should not have duplicate keys. If you define an object with duplicate keys, the last one will overwrite any preceding ones.
Non-Compliant Code Examples
varx={a:b,['a']:b};varx={y:1,y:2};varx={'':1,'':2};varx={'':1,[``]:2};varfoo={0x1:1,1:2};// should be captured by no-octal
// var x = { 012: 1, 10: 2 };
varx={0b1:1,1:2};varx={0o1:1,1:2};varx={1n:1,1:2};varx={1_0:1,10:2};varx={"z":1,z:2};varfoo={bar:1,bar:1,bar(){}}varx={a:1,get['a'](){}};varx={a:1,seta(value){}};varx={a:1,b:{a:2},getb(){}};varx=({'/(?<zero>0)/':1,[/(?<zero>0)/]:2})// while we can't evaluate the value of the template string we will assume that
// two keys with the exact same template string will evaluate to the same key
constobj={props:{[`${classes.foo}${classes.bar}`]:():boolean=>{returnnull;},[`${classes.foo}${classes.bar}`]:():boolean=>{returnnull;},}}
Compliant Code Examples
varfoo={__proto__:1,two:2};varx={foo:1,bar:2};varx={'':1,bar:2};varx={'':1,' ':2};varx={'':1,[null]:2};varx={'':1,[a]:2};varx={[a]:1,[a]:2};+{geta(){},seta(b){}};varx={a:b,[a]:b};varx={a:b,...c}varx={geta(){},seta(value){}};varx={a:1,b:{a:2}};varx=({null:1,[/(?<zero>0)/]:2})var{a,a}=obj// should be captured by no-octal
// var x = { 012: 1, 12: 2 };
varx={1_0:1,1:2};// template literals should be valid as long as they are not exactly the same
constobj={props:{[`${classes.foo}${classes.bar}`]:():boolean=>{returnnull;},[`${classes.baz}${classes.bla}`]:():boolean=>{returnnull;},}}
원활한 통합. Datadog Code Security를 경험해 보세요
Datadog Code Security
이 규칙을 사용해 Datadog Code Security로 코드를 분석하세요
규칙 사용 방법
1
2
rulesets:- javascript-best-practices # Rules to enforce JavaScript best practices.
리포지토리 루트에 위의 내용을 포함하는 static-analysis.datadog.yml을 만듭니다
무료 IDE 플러그인을 사용하거나 CI 파이프라인에 Code Security 검사를 추가합니다