Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

[rule: spaced-comment] shebang errors if followed by import #163

Closed
olalonde opened this issue Aug 12, 2015 · 7 comments
Closed

[rule: spaced-comment] shebang errors if followed by import #163

olalonde opened this issue Aug 12, 2015 · 7 comments

Comments

@olalonde
Copy link

So I found out that:

#!/usr/bin/env node

import { BlockWorker } from '../Workers';
import config from '../config';
// ...

gives a spaced-comment error, while this does not:

#!/usr/bin/env node

import config from '../config';
import { BlockWorker } from '../Workers';
// ...

See eslint/eslint#3296

@hzoo
Copy link
Member

hzoo commented Aug 13, 2015

Ok looks like the issue is because although eslint tries to remove all shebang comments in https://github.com/eslint/eslint/blob/c694db4740d3f8e3d9f908a4e7321c398e924225/lib/eslint.js#L804-L810, babel-eslint has another leadingComments on spawn

screen shot 2015-08-13 at 9 54 44 am

not sure why it's different since it's the same comment attachment?

  it("shebang comment with spaceed-comment", function () {
    verifyAndAssertMessages(
      [
        "#!/usr/bin/env node",
        "",
        "import { BlockWorker } from '../Workers';",
        "import config from '../config';"
      ].join("\n"),
      { "spaced-comment": 1 },
      [ ]
    )
  });

@millette
Copy link

millette commented Apr 22, 2016

As a workaround for now, I start my cli files with this instead:

#!/usr/bin/env node
var _eslint_workaround = true // eslint-disable-line no-unused-vars

Third line can be anything it seems.

Works with the latest standard code style.

This works too:

#!/usr/bin/env node
// see https://github.com/babel/babel-eslint/issues/163
var _eslint_workaround = true // eslint-disable-line no-unused-vars

@danez
Copy link
Member

danez commented Apr 25, 2016

There is a PR with the fix for babylon now. Problem was that babylon is cloning the key-Identifier to the value-Identifier if destructuring with shorthands is used in objects. Espree/Acorn is not doing any cloning and therefore also not cloning the comment.

@danez danez removed the v5 label Apr 25, 2016
@dasilvacontin
Copy link

Thanks for working on the fix @danez! Looking forward to remove my personal workaround from the code:

#!/usr/bin/env node
// @flow
2 + 2 === 5 // https://git.io/vwmJK
import fs from 'fs'

@millette
Copy link

millette commented May 7, 2016

Well this is strange. I'm using

  "devDependencies": {
    "ava": "^0.14.0",
    "babel-eslint": "^6.0.4",
    "coveralls": "^2.11.9",
    "nyc": "^6.4.3",
    "standard": "^7.0.1"
  }

And it worked for a day or so without the workaround.

After another install, something (not sure what) upgraded babel-types from 6.8.0 to 6.8.1 and it's failing again.

@danez
Copy link
Member

danez commented Jun 26, 2016

Sorry that it took so long to fix this. As of babylon 6.8.2 this is now fixed.

@danez danez closed this as completed Jun 26, 2016
@dasilvacontin
Copy link

Thanks @danez!

dasilvacontin added a commit to dasilvacontin/js-boilerplate that referenced this issue Aug 17, 2016
nicolo-ribaudo pushed a commit to babel/babel that referenced this issue Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants