Fail the test if the rule provides fixes but doesn't say it is fixable

This commit is contained in:
Jeroen Engels 2022-10-17 23:56:38 +02:00
parent ebfb30a071
commit f164cecdf2
2 changed files with 17 additions and 4 deletions

View File

@ -1483,7 +1483,7 @@ checkDetailsAreCorrect error_ (ExpectedError expectedError) =
checkFixesAreCorrect : RuleCanProvideFixes -> CodeInspector -> ReviewError -> ExpectedError -> Expectation
checkFixesAreCorrect ruleCanProvideFixes codeInspector ((Error.ReviewError err) as error_) ((ExpectedError expectedError_) as expectedError) =
checkFixesAreCorrect (RuleCanProvideFixes ruleCanProvideFixes) codeInspector ((Error.ReviewError err) as error_) ((ExpectedError expectedError_) as expectedError) =
case ( expectedError_.fixedSource, err.fixes ) of
( Nothing, Nothing ) ->
Expect.pass
@ -1500,7 +1500,11 @@ checkFixesAreCorrect ruleCanProvideFixes codeInspector ((Error.ReviewError err)
case Fix.fix err.target fixes codeInspector.source of
Fix.Successful fixedSource ->
if fixedSource == expectedFixedSource then
Expect.pass
if ruleCanProvideFixes then
Expect.pass
else
Expect.fail FailureMessage.ruleNotMarkedAsFixableError
else if removeWhitespace fixedSource == removeWhitespace expectedFixedSource then
Expect.fail <| FailureMessage.fixedCodeWhitespaceMismatch fixedSource expectedFixedSource error_

View File

@ -3,7 +3,7 @@ module Review.Test.FailureMessage exposing
, parsingFailure, globalErrorInTest, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
, underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
, needToUsedExpectErrorsForModules, missingSources, duplicateModuleName, unknownModulesInExpectedErrors
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
, missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges, ruleNotMarkedAsFixableError
, didNotExpectGlobalErrors, expectedMoreGlobalErrors, fixedCodeWhitespaceMismatch, messageMismatchForConfigurationError
, messageMismatchForGlobalError, missingConfigurationError, tooManyGlobalErrors
, unexpectedConfigurationError, unexpectedConfigurationErrorDetails, unexpectedGlobalErrorDetails
@ -19,7 +19,7 @@ module Review.Test.FailureMessage exposing
@docs parsingFailure, globalErrorInTest, messageMismatch, emptyDetails, unexpectedDetails, wrongLocation, didNotExpectErrors
@docs underMismatch, expectedMoreErrors, tooManyErrors, locationNotFound, underMayNotBeEmpty, locationIsAmbiguousInSourceCode
@docs needToUsedExpectErrorsForModules, missingSources, duplicateModuleName, unknownModulesInExpectedErrors
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges
@docs missingFixes, unexpectedFixes, fixedCodeMismatch, unchangedSourceAfterFix, invalidSourceAfterFix, hasCollisionsInFixRanges, ruleNotMarkedAsFixableError
@docs didNotExpectGlobalErrors, expectedMoreGlobalErrors, fixedCodeWhitespaceMismatch, messageMismatchForConfigurationError
@docs messageMismatchForGlobalError, missingConfigurationError, tooManyGlobalErrors
@docs unexpectedConfigurationError, unexpectedConfigurationErrorDetails, unexpectedGlobalErrorDetails
@ -619,6 +619,15 @@ Hint: Maybe you duplicated a fix, or you targeted the wrong node for one
of your fixes.""")
ruleNotMarkedAsFixableError : String
ruleNotMarkedAsFixableError =
failureMessage "RULE WAS NOT MARKED AS FIXABLE"
"""I expected that the rule would use either
`Rule.providesFixesForModuleRule` or `providesFixesForProjectRule` to
indicate that it may provide fixes. This is valuable for improving the
performance of running `elm-review` in fix mode."""
unexpectedConfigurationError : { message : String, details : List String } -> String
unexpectedConfigurationError error =
failureMessage "UNEXPECTED CONFIGURATION ERROR"