Skip to content

CSS adds comma after @import url #2773

Closed
Closed

Description

@torarnek

Prettier Version: 1.6.1 / master

@import url("responsive/gt768.css") screen and (min-width: 768px);

Expected behavior:

@import url("responsive/gt768.css") screen and (min-width: 768px);

Actual behavior:

@import url("responsive/gt768.css"), screen and (min-width: 768px);

Please see @import doc

Activity

  1. added
    lang:css/scss/less
    on Sep 8, 2017
  2. gimenete commented on Sep 8, 2017

    @gimenete

    I have the same issue. Quick way to test it:

    require('prettier').format('@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css) screen;', {parser: 'postcss'})

    Outputs:

    @import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css),
      screen;
  3. lydell commented on Sep 8, 2017

    @lydell
    Member

    Wow, I didn't even know that people used the media-query thing of @imports for real! Or @imports at all, for that matter. One workaround (which should also be more performant) is to use <link> tags instead. You can also use a /* prettier-ignore */ comment: playground

  4. gimenete commented on Sep 12, 2017

    @gimenete

    I think the problem is here: https://github.com/prettier/prettier/blob/master/src/printer-postcss.js#L103

    The structure of an @import statement is: @import <url> <media-query>?. For an import with media-query the node has this structure:

    {
      after: '',
      before: '',
      type: 'media-query-list',
      value: 'url(foo.css) screen',
      sourceIndex: 0,
      nodes:
       [ Node {
           after: ' ',
           before: '',
           type: 'media-url',
           value: 'url(foo.css)',
           sourceIndex: 0 },
         Node {
           after: '',
           before: ' ',
           type: 'media-query',
           value: 'screen',
           sourceIndex: 13,
           nodes: [Array] } ] }
    

    So, the first node is a media-url node type and the second node is a media-query, so I think if n.name === "import" the concat() should be called in a different way: first concat the media-url and then concat the media-query.

  5. added
    locked-due-to-inactivity
    on Jul 6, 2018
  6. locked as resolved and limited conversation to collaborators on Jul 6, 2018
  7. added theissue type on Mar 3, 2025
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

    lang:css/scss/lesslocked-due-to-inactivity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions