Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable existing hints if linting is disabled #1275

Merged
merged 2 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/sema/check_casting_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (checker *Checker) VisitCastingExpression(expression *ast.CastingExpression
Range: ast.NewRangeFromPositioned(leftHandExpression),
},
)
} else if IsSubType(leftHandType, rightHandType) {
} else if checker.lintEnabled && IsSubType(leftHandType, rightHandType) {

switch expression.Operation {
case ast.OperationFailableCast:
Expand Down
19 changes: 10 additions & 9 deletions runtime/sema/check_force_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ func (checker *Checker) VisitForceExpression(expression *ast.ForceExpression) as

optionalType, ok := valueType.(*OptionalType)
if !ok {

// A non-optional type is forced. Suggest removing it

checker.hint(
&RemovalHint{
Description: "unnecessary force operator",
Range: ast.Range{
StartPos: expression.EndPos,
EndPos: expression.EndPos,
if checker.lintEnabled {
checker.hint(
&RemovalHint{
Description: "unnecessary force operator",
Range: ast.Range{
StartPos: expression.EndPos,
EndPos: expression.EndPos,
},
},
},
)
)
}

return valueType
}
Expand Down
10 changes: 6 additions & 4 deletions runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3126,14 +3126,16 @@ func numberFunctionArgumentExpressionsChecker(targetType Type) ArgumentExpressio
switch argument := argument.(type) {
case *ast.IntegerExpression:
if CheckIntegerLiteral(argument, targetType, checker.report) {

suggestIntegerLiteralConversionReplacement(checker, argument, targetType, invocationRange)
if checker.lintEnabled {
suggestIntegerLiteralConversionReplacement(checker, argument, targetType, invocationRange)
}
}

case *ast.FixedPointExpression:
if CheckFixedPointLiteral(argument, targetType, checker.report) {

suggestFixedPointLiteralConversionReplacement(checker, targetType, argument, invocationRange)
if checker.lintEnabled {
suggestFixedPointLiteralConversionReplacement(checker, targetType, argument, invocationRange)
}
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions runtime/tests/checker/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Fix64(1)
`)

Expand All @@ -58,7 +58,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = UFix64(1)
`)

Expand All @@ -78,7 +78,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Fix64(-1)
`)

Expand All @@ -100,7 +100,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = UFix64(1.2)
`)

Expand All @@ -120,7 +120,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Fix64(-1.2)
`)

Expand All @@ -144,7 +144,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = UInt8(1)
`)

Expand All @@ -164,7 +164,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Int8(1)
`)

Expand All @@ -184,7 +184,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Int8(-1)
`)

Expand All @@ -204,7 +204,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Int(1)
`)

Expand All @@ -224,7 +224,7 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) {

t.Parallel()

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x = Int(-1)
`)

Expand Down
7 changes: 6 additions & 1 deletion runtime/tests/checker/dynamic_casting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ func TestCheckDynamicCastingCapability(t *testing.T) {

func TestCheckAlwaysSucceedingDynamicCast(t *testing.T) {

t.Parallel()

const types = `
struct interface I {}

Expand All @@ -1305,6 +1307,8 @@ func TestCheckAlwaysSucceedingDynamicCast(t *testing.T) {

test := func(t *testing.T, operation ast.Operation, hintType sema.Hint) {

t.Parallel()

usage := fmt.Sprintf(
`
let s1 = S1()
Expand All @@ -1314,7 +1318,8 @@ func TestCheckAlwaysSucceedingDynamicCast(t *testing.T) {
`,
operation.Symbol(),
)
checker, err := ParseAndCheck(t, types+usage)

checker, err := ParseAndCheckWithLinting(t, types+usage)

errs := ExpectCheckerErrors(t, err, 1)

Expand Down
2 changes: 1 addition & 1 deletion runtime/tests/checker/force_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCheckForce(t *testing.T) {

t.Run("non-optional", func(t *testing.T) {

checker, err := ParseAndCheck(t, `
checker, err := ParseAndCheckWithLinting(t, `
let x: Int = 1
let y = x!
`)
Expand Down
12 changes: 12 additions & 0 deletions runtime/tests/checker/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func ParseAndCheckWithPanic(t *testing.T, code string) (*sema.Checker, error) {
},
)
}

func ParseAndCheckWithAny(t *testing.T, code string) (*sema.Checker, error) {
return ParseAndCheckWithOptions(t,
code,
Expand All @@ -57,3 +58,14 @@ func ParseAndCheckWithAny(t *testing.T, code string) (*sema.Checker, error) {
},
)
}

func ParseAndCheckWithLinting(t *testing.T, code string) (*sema.Checker, error) {
return ParseAndCheckWithOptions(t,
code,
ParseAndCheckOptions{
Options: []sema.Option{
sema.WithLintingEnabled(true),
},
},
)
}