Skip to content

Comments should not be stripped from 'import' statements and language pragmas #39

Open
@thoughtpolice

Description

@thoughtpolice
Member

Consider:

module Foo where
import Data.Monoid -- from base
import Data.List   -- from base

And then:

$ stylish-haskell /tmp/Foo.hs
module Foo where
import           Data.List
import           Data.Monoid
$

The comments shouldn't be stripped from the end, ideally. At the very least this is inconsistent with the default behavior which will preserve comments in most other positions.

Activity

AnneTheAgile

AnneTheAgile commented on Apr 7, 2014

@AnneTheAgile

This seems like possibly a nice small thing I could help contribute, especially since I am often wont to add remarks about imports :).

I'd like to start with a test on my branch. Would it be right for a test to be added to each section in the imports test file? Or would I only need to add one test? (Maybe I'm asking the wrong question, possibly it depends on the implementation, which I haven't investigated yet.)

I love that you have Travis CI and tests all set up !

Notes to self;
1.I found the right place to add one or more tests, stylish-haskell/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
https://github.com/jaspervdj/stylish-haskell/blob/105a1845152876bb7c49acda190e995c64659d01/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
2.That code is really clean and easy to read.
2a.WISH Haskell had the Ruby RSpec DSL style of test namings.
3.The types of possible import configuration values are the following , taken from the config;
Import cleanup
imports: # There are different ways we can align names and lists.
# - global: Align the import names and import list throughout the entire # file.
# - file: Like global, but don't add padding when there are no qualified # imports in the file. #
# - group: Only align the imports per group (a group is formed by adjacent # import lines).
# - none: Do not perform any alignment. #
# Default: global.
align: global ## Used by SnapFramework
4.I found this project via the NYC Haskell Hackathon via my neighbor's commit,
snapframework/io-streams#24
//AnneTheAgile

jaspervdj

jaspervdj commented on Apr 7, 2014

@jaspervdj
Member

I think only one test should do in this case. I'd add the test for the global configuration, since that is most commonly used (as far as I'm aware off). Thanks for tackling this, and let me know if you have any questions!

AnneTheAgile

AnneTheAgile commented on Apr 8, 2014

@AnneTheAgile

thank you @jaspervdj ! I will give it a go.

AnneTheAgile

AnneTheAgile commented on Apr 22, 2014

@AnneTheAgile

I ginned up a test to add to the end, I think this will work but I haven't tested it yet.
Now -- #39 Allow comments after import statements.

case08 :: Assertion
case08 = expected @=? testStep (step 80 Global) input'
  where
    input' = unlines
        [ "module Herp where"
        , ""
        , "ipmort Data.Monoid -- from base"
        ]

    expected = unlines
        [ "module Herp where"
        , ""
        , "ipmort Data.Monoid -- from base"
        ]
AnneTheAgile

AnneTheAgile commented on Apr 22, 2014

@AnneTheAgile

Hmm, so I'm not sure where the comments are stripped out? It seems like Imports.hs relies on no-comments in a couple of places, eg counting longest import. So then maybe the comments are not parsed out in that file but rather before it gets there? Any easy hints for me? thank you!

p.s. Evie at our Haskell Cats might be able to help me out as well if there is no obvious hint to be given. http://www.meetup.com/Haskell_For_Cats/

AnneTheAgile

AnneTheAgile commented on Apr 23, 2014

@AnneTheAgile

Ticket #7 Treatment of long imports may help. They sought to parse;

import Happstack.Server              (Happstack, Response, badRequest, guessContentTypeM, lookPairs,
 mimeTypes, neverExpires, ok, setHeaderM, toResponse)
langston-barrett

langston-barrett commented on Jan 20, 2017

@langston-barrett
Contributor

Note that this also happens on LANGUAGE pragmas.

{-# LANGUAGE ScopedTypeVariables #-} -- test

becomes

{-# LANGUAGE ScopedTypeVariables #-}
andrewufrank

andrewufrank commented on Mar 8, 2017

@andrewufrank

i observed the same "disappearing" comments on language pragmas and import. please fix soon - is required to document! (and putting them on separate lines makes things less stylish
thank you for a useful tool!

changed the title [-]Comments should not be stripped from the end of 'import' statements.[/-] [+]Comments should not be stripped from 'import' statements[/+] on Apr 15, 2017
neongreen

neongreen commented on Apr 15, 2017

@neongreen

It also happens with comments in the middle of import statements, e.g. #151:

{-# OPTIONS_GHC -F -pgmF htfpp #-}
module Main where

import Test.Framework
import Test.Framework.BlackBoxTest
import {-@ HTF_TESTS @-} MyPkg.A
import {-@ HTF_TESTS @-} MyPkg.B

main = htfMain htf_importedTests
changed the title [-]Comments should not be stripped from 'import' statements[/-] [+]Comments should not be stripped from 'import' statements and language pragmas[/+] on Apr 15, 2017
andrewufrank

andrewufrank commented on May 23, 2017

@andrewufrank

any fix in sight ? - it makes it impossible to use stylish haskell with HTF testing (and HTF testing is in many projects crucial). i am sorry that i had to de-install stylish...

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thoughtpolice@AnneTheAgile@jaspervdj@eflister@andrewufrank

        Issue actions

          Comments should not be stripped from 'import' statements and language pragmas · Issue #39 · haskell/stylish-haskell