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

Allow enabling extensions in a settings file #223

Closed
wolftune opened this issue Mar 2, 2016 · 25 comments
Closed

Allow enabling extensions in a settings file #223

wolftune opened this issue Mar 2, 2016 · 25 comments

Comments

@wolftune
Copy link

wolftune commented Mar 2, 2016

I really don't like continually seeing parse errors for things like [whamlet| blocks. I get that hlint can't deal with whamlet. It should ignore it and similar cases instead of reporting the parse error.

@ndmitchell
Copy link
Owner

It's not a parse error for there to be arbitrary stuff in a whamlet block, and HLint is meant to ignore it. Taking the first example at http://www.yesodweb.com/book/basics#basics_hello_world I am able to check that module with no errors. Can you give me an example of a whamlet block that doesn't work?

@wolftune
Copy link
Author

wolftune commented Mar 2, 2016

src/Handler/NewDesign.hs in Snowdrift has a parse error on the h3 line in:

projectNav :: ProjectHandle -> Widget
projectNav handle =
    [whamlet|
        <h3>Subpages
        <ul>
            <li><a href=@{PUpdatesR handle}>Updates
            <li><a href=@{WikiPagesR handle}>Wiki</a> (links to pre-alpha)
            <li><a href=@{ProjectDiscussionR handle}>Discussion</a> (links to pre-alpha)
            <li><a href=@{PTransactionsR handle}>Transactions
    |]

also src/Handler/User/Create.hs on the line with form

        [whamlet|
            <form method=POST>
                ^{form}
                <input type=submit>
        |]

Also src/View/Time.hs:19:9

        toWidget [hamlet|
  >         <span title=#{render time}>
                #{showDiffTime now time}&nbsp;ago
        |]

and other cases

@ndmitchell
Copy link
Owner

The error is because you don't have {-# LANGUAGE QuasiQuotes #-} at the top of your file, and instead use it as a default-extension in your .cabal file. HLint turns on many extensions, but QuasiQuotes is one that has a habit of breaking modules not designed for it, so I explicitly turn it off. You can solve that by adding -XQuasiQuotes on the command line when running HLint, which will tell HLint what you have already told Cabal about default extensions.

@wolftune
Copy link
Author

wolftune commented Mar 3, 2016

Is there a way to add this to an hlint settings file or something? As hlint is integrated with other tools and I also want to minimize the room for manual human command adjustment, it would be much better if there were a way to just set HLint to use this option by default…

Incidentally, would you recommend us setting that language extension per file anyway/instead?

@ndmitchell
Copy link
Owner

I generally use all extensions explicitly per file, but its really up to you - different people have different preferences, which is why HLint tries to turn on all the extensions it think it can do without breaking stuff. It's just unfortunate in your case the one you need does break stuff sometimes.

There's no way to add it to a settings file yet, but I'll leave this bug open to do that.

@ndmitchell ndmitchell changed the title ignore parse errors in template haskell as appropriate Allow enabling extensions in a settings file Mar 15, 2016
@Cypher1
Copy link

Cypher1 commented Jul 22, 2016

Would really like a .hlintrc like pylint has

@decentral1se
Copy link
Contributor

decentral1se commented Sep 19, 2016

@ndmitchell Can you provide some hints as to what a .hlintrc file might look like? I'd like to take a stab at it. Would something like ini be sufficient? Something like:

[EXTENSIONS]
quasiquotes=True

Not sure.

EDIT: Oh, I just saw #160. So, perhaps it should all be centered around the Hlint.hs file. Would it be possible to set extensions there?

@ndmitchell
Copy link
Owner

I would imagine you could put extensions in the Hlint.hs file with:

{-# LANGUAGE QuasiQuotes #-}

Furthermore it seems to make sense to allow arbitrary command line flags in the Hlint.hs, for example:

{-# OPTIONS_HLINT --ignore=foo #-}

@ndmitchell
Copy link
Owner

You can now create a .hlint.yaml file and add - arguments: [-XQuasiQuote]

@decentral1se
Copy link
Contributor

🎉

@ndmitchell
Copy link
Owner

Btw, I've now got the release almost ready to go, so if anyone wants to try it out I'd welcome any feedback before the actual release.

@wolftune
Copy link
Author

does the .hlint.yaml file go universally in ~/ or in a project's directory or either/both…?

@ndmitchell
Copy link
Owner

@wolftune we search the current directory upwards, so a projects directory. I considered in ~/, but in the end decided to replicate the stylish-haskell logic, since I'm trying to be more consistent with other tools.

@wolftune
Copy link
Author

thanks

@AlexeyRaga
Copy link

@ndmitchell should it also work for MultiParamTypeClasses?
It is in my default-extensions, but hlint still wants me to add it to each file.

I tried adding

- arguments: [-XMultiParamTypeClasses]

But it didn't seem to work.

@ndmitchell
Copy link
Owner

@AlexeyRaga That works for me to enable extensions, however, you don't need to enable MultiParamTypeClasses as that's on by default, so it's no great surprise enabling it doesn't have any impact. What error are you seeing or change are you trying to get?

@AlexeyRaga
Copy link

@ndmitchell Oh, sorry, I think the error is actually from stylish-haskell and not from hlint!
Sorry for making noise!

@vyorkin
Copy link

vyorkin commented Mar 22, 2018

hm, it doesn't seem to work when I enable the -XUnicodeSyntax extension.
my example file:

module Model.File where

import qualified Data.Bson as Bson
import Data.Int (Int64)
import Data.Time.Clock (UTCTime)
import GHC.Generics (Generic)

-- | Represents a file stored in Mongo GridFS.
data File = File
  { _id         Bson.ObjectId
  , length      Int64
  , uploadDate  UTCTime
  , fileName    String
  } deriving (Eq, Show, Generic)
 ▲ haskell/2018/spreadsheet-api cat .hlint.yaml
- arguments: [-XUnicodeSyntax]

 ▲ haskell/2018/spreadsheet-api hlint src/Model/File.hs --refactor
refactor: (RealSrcSpan SrcSpanOneLine "src/Model/File.hs" 10 16 17,"parse error on input \8216\8759\8217")
CallStack (from HasCallStack):
  error, called at src/Main.hs:189:22 in main:Main

 △ haskell/2018/spreadsheet-api hlint --version
HLint v2.0.11, (C) Neil Mitchell 2006-2017

@ndmitchell
Copy link
Owner

@vyorkin Does it work if you don't pass --refactor? My guess is that -XUnicodeSyntax isn't required either in the .hlint.yaml or on the command line. And separately refactor can't deal with unicode, perhaps unless you pass some argument. I'm going to raise a separate bug for that.

@ndmitchell
Copy link
Owner

I opened #465 to track the refactor issue separately. I don't think it has anything to do with extensions in a settings file.

@vyorkin
Copy link

vyorkin commented Apr 5, 2018

Without --refactor it just outputs no hints (as it should, I guess).
But if I introduce some issue (like duplicate import)

...
import GHC.Generics (Generic)
import GHC.Generics (Generic)
...

it correctly reports it:

▲ play/haskell/tmp hlint File.hs                                                                                                                                                                                                                                           2m
File.hs:6:1: Warning: Use fewer imports
Found:
  import GHC.Generics (Generic)
  import GHC.Generics (Generic)

Why not:
  import GHC.Generics (Generic)


1 hint

with --refactor as I mentioned previously:

 △ play/haskell/tmp hlint --refactor File.hs
refactor: (RealSrcSpan SrcSpanOneLine "File.hs" 11 16 17,"parse error on input \8216\8759\8217")
CallStack (from HasCallStack):
  error, called at src/Main.hs:189:22 in main:Main

@ndmitchell
Copy link
Owner

Yep, since it doesn't touch refactor unless there are hints to be dealt with. Leaving this to #465

@Martinsos
Copy link
Contributor

Martinsos commented Jul 29, 2020

You can now create a .hlint.yaml file and add - arguments: [-XQuasiQuote]

@ndmitchell This answer was exactly what I was looking for, but there is typo: it should be QuasiQuotes, not QuasiQuote (s is missing!). It took me some time to figure out that was the problem!

@ndmitchell
Copy link
Owner

Thanks for mentioning that @Martinsos - I've raised #1093 to emit a warning - way too easy to make a typo here

@Martinsos
Copy link
Contributor

Thanks for mentioning that @Martinsos - I've raised #1093 to emit a warning - way too easy to make a typo here

Great, that is even better :)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants