-
Notifications
You must be signed in to change notification settings - Fork 205
Add typeApplications option for restricted functions
#1667
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
Open
terror
wants to merge
1
commit into
ndmitchell:master
Choose a base branch
from
terror:forbid-from-integral
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| - functions: | ||
| - {name: fromIntegral, typeApplications: required} | ||
| - {name: Just, typeApplications: required} | ||
| - {name: id, typeApplications: forbidden} | ||
| - {name: Left, typeApplications: forbidden} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,7 +343,19 @@ parseRestrict restrictType v = do | |
| Just def -> do | ||
| b <- parseBool def | ||
| allowFields v ["default"] | ||
| pure $ Restrict restrictType b [] mempty mempty mempty mempty [] NoRestrictIdents Nothing | ||
| pure Restrict | ||
| { restrictType = restrictType | ||
| , restrictDefault = b | ||
| , restrictName = [] | ||
| , restrictAs = mempty | ||
| , restrictAsRequired = mempty | ||
| , restrictImportStyle = mempty | ||
| , restrictQualifiedStyle = mempty | ||
| , restrictTypeApp = Nothing | ||
| , restrictWithin = [] | ||
| , restrictIdents = NoRestrictIdents | ||
| , restrictMessage = Nothing | ||
| } | ||
| Nothing -> do | ||
| restrictName <- parseFieldOpt "name" v >>= maybe (pure []) parseArrayString | ||
| restrictWithin <- parseFieldOpt "within" v >>= maybe (pure [("","")]) (parseArray >=> concatMapM parseWithin) | ||
|
|
@@ -361,6 +373,10 @@ parseRestrict restrictType v = do | |
| , ("post" , QualifiedStylePost) | ||
| , ("unrestricted", QualifiedStyleUnrestricted) | ||
| ] | ||
| restrictTypeApp <- parseFieldOpt "typeApplications" v >>= maybeParseEnum | ||
| [ ("required" , TypeAppRequired) | ||
| , ("forbidden", TypeAppForbidden) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm questioning the need for a |
||
| ] | ||
|
|
||
|
|
||
| restrictBadIdents <- parseFieldOpt "badidents" v | ||
|
|
@@ -375,9 +391,10 @@ parseRestrict restrictType v = do | |
| restrictMessage <- parseFieldOpt "message" v >>= maybeParse parseString | ||
| allowFields v $ | ||
| ["name", "within", "message"] ++ | ||
| if restrictType == RestrictModule | ||
| then ["as", "asRequired", "importStyle", "qualifiedStyle", "badidents", "only"] | ||
| else [] | ||
| case restrictType of | ||
| RestrictModule -> ["as", "asRequired", "importStyle", "qualifiedStyle", "badidents", "only"] | ||
| RestrictFunction -> ["typeApplications"] | ||
| _ -> [] | ||
| pure Restrict{restrictDefault=True,..} | ||
|
|
||
| parseWithin :: Val -> Parser [(String, String)] -- (module, decl) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --------------------------------------------------------------------- | ||
| RUN tests/typeAppsRequired.hs --hint=data/type_applications.yaml --only="Use visible type application" | ||
| FILE tests/typeAppsRequired.hs | ||
| {-# LANGUAGE TypeApplications #-} | ||
| module TypeAppsRequired where | ||
|
|
||
| a = fromIntegral (1 :: Int) | ||
| b = fromIntegral @Int @Integer (1 :: Int) | ||
| OUTPUT | ||
| tests/typeAppsRequired.hs:4:5-16: Warning: Use visible type application | ||
| Found: | ||
| fromIntegral | ||
| Note: may break the code | ||
|
|
||
| 1 hint | ||
|
|
||
| --------------------------------------------------------------------- | ||
| RUN tests/typeAppsRequiredPattern.hs --hint=data/type_applications.yaml --only="Use visible type application" | ||
| FILE tests/typeAppsRequiredPattern.hs | ||
| {-# LANGUAGE TypeApplications #-} | ||
| module TypeAppsRequiredPattern where | ||
|
|
||
| f (Just x) = x | ||
| g (Just @Int x) = x | ||
| OUTPUT | ||
| tests/typeAppsRequiredPattern.hs:4:4-7: Warning: Use visible type application | ||
| Found: | ||
| Just | ||
| Note: may break the code | ||
|
|
||
| 1 hint | ||
|
|
||
| --------------------------------------------------------------------- | ||
| RUN tests/typeAppsForbiddenPattern.hs --hint=data/type_applications.yaml --only="Avoid visible type application" | ||
| FILE tests/typeAppsForbiddenPattern.hs | ||
| {-# LANGUAGE TypeApplications #-} | ||
| module TypeAppsForbiddenPattern where | ||
|
|
||
| f (Left @Int x) = x | ||
| g (Left x) = x | ||
| OUTPUT | ||
| tests/typeAppsForbiddenPattern.hs:4:4-7: Warning: Avoid visible type application | ||
| Found: | ||
| Left | ||
| Note: may break the code | ||
|
|
||
| 1 hint | ||
|
|
||
| --------------------------------------------------------------------- | ||
| RUN tests/typeAppsForbidden.hs --hint=data/type_applications.yaml --only="Avoid visible type application" | ||
| FILE tests/typeAppsForbidden.hs | ||
| {-# LANGUAGE TypeApplications #-} | ||
| module TypeAppsForbidden where | ||
|
|
||
| a x = id @Int x | ||
| b x = id x | ||
| OUTPUT | ||
| tests/typeAppsForbidden.hs:4:7-8: Warning: Avoid visible type application | ||
| Found: | ||
| id | ||
| Note: may break the code | ||
|
|
||
| 1 hint | ||
|
|
||
| --------------------------------------------------------------------- |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from adding
restrictTypeApp, this is strictly a style refactor to make it more apparent as to what's going on. If this doesn't align with how we proceed elsewhere I'm happy to revert!