Skip to content

Commit

Permalink
silence new warnings within node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Nov 19, 2023
1 parent 83e8c7f commit 5271f82
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15224,9 +15224,13 @@ func (v *binaryExprVisitor) visitRightAndFinish(p *parser) js_ast.Expr {
leftIsNullOrUndefined = "always"
leftIsReturned = "never"
}
kind := logger.Warning
if p.suppressWarningsAboutWeirdCode {
kind = logger.Debug
}
rOp := p.source.RangeOfOperatorBefore(e.Right.Loc, "??")
rLeft := logger.Range{Loc: e.Left.Loc, Len: p.source.LocBeforeWhitespace(rOp.Loc).Start - e.Left.Loc.Start}
p.log.AddIDWithNotes(logger.MsgID_JS_SuspiciousNullishCoalescing, logger.Warning, &p.tracker, rOp,
p.log.AddIDWithNotes(logger.MsgID_JS_SuspiciousNullishCoalescing, kind, &p.tracker, rOp,
fmt.Sprintf("The \"??\" operator here will always return the %s operand", which), []logger.MsgData{
p.tracker.MsgData(rLeft, fmt.Sprintf(
"The left operand of the \"??\" operator here will %s be null or undefined, so it will %s be returned. This usually indicates a bug in your code:",
Expand Down Expand Up @@ -15256,19 +15260,23 @@ func (v *binaryExprVisitor) visitRightAndFinish(p *parser) js_ast.Expr {
if boolean, sideEffects, ok := js_ast.ToBooleanWithSideEffects(e.Left.Data); ok {
// Warn about potential bugs
if e == p.suspiciousLogicalOperatorInsideArrow {
// "return foo => 1 || foo <= 0"
var which string
if boolean {
which = "left"
} else {
which = "right"
}
if arrowLoc := p.source.RangeOfOperatorBefore(v.loc, "=>"); arrowLoc.Loc.Start+2 == p.source.LocBeforeWhitespace(v.loc).Start {
// "return foo => 1 || foo <= 0"
var which string
if boolean {
which = "left"
} else {
which = "right"
}
kind := logger.Warning
if p.suppressWarningsAboutWeirdCode {
kind = logger.Debug
}
note := p.tracker.MsgData(arrowLoc,
"The \"=>\" symbol creates an arrow function expression in JavaScript. Did you mean to use the greater-than-or-equal-to operator \">=\" here instead?")
note.Location.Suggestion = ">="
rOp := p.source.RangeOfOperatorBefore(e.Right.Loc, "||")
p.log.AddIDWithNotes(logger.MsgID_JS_SuspiciousLogicalOperator, logger.Warning, &p.tracker, rOp,
p.log.AddIDWithNotes(logger.MsgID_JS_SuspiciousLogicalOperator, kind, &p.tracker, rOp,
fmt.Sprintf("The \"||\" operator here will always return the %s operand", which), []logger.MsgData{note})
}
}
Expand Down Expand Up @@ -15299,19 +15307,23 @@ func (v *binaryExprVisitor) visitRightAndFinish(p *parser) js_ast.Expr {
if boolean, sideEffects, ok := js_ast.ToBooleanWithSideEffects(e.Left.Data); ok {
// Warn about potential bugs
if e == p.suspiciousLogicalOperatorInsideArrow {
// "return foo => 0 && foo <= 1"
var which string
if !boolean {
which = "left"
} else {
which = "right"
}
if arrowLoc := p.source.RangeOfOperatorBefore(v.loc, "=>"); arrowLoc.Loc.Start+2 == p.source.LocBeforeWhitespace(v.loc).Start {
// "return foo => 0 && foo <= 1"
var which string
if !boolean {
which = "left"
} else {
which = "right"
}
kind := logger.Warning
if p.suppressWarningsAboutWeirdCode {
kind = logger.Debug
}
note := p.tracker.MsgData(arrowLoc,
"The \"=>\" symbol creates an arrow function expression in JavaScript. Did you mean to use the greater-than-or-equal-to operator \">=\" here instead?")
note.Location.Suggestion = ">="
rOp := p.source.RangeOfOperatorBefore(e.Right.Loc, "&&")
p.log.AddIDWithNotes(logger.MsgID_JS_SuspiciousLogicalOperator, logger.Warning, &p.tracker, rOp,
p.log.AddIDWithNotes(logger.MsgID_JS_SuspiciousLogicalOperator, kind, &p.tracker, rOp,
fmt.Sprintf("The \"&&\" operator here will always return the %s operand", which), []logger.MsgData{note})
}
}
Expand Down

0 comments on commit 5271f82

Please sign in to comment.