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

Bug report: Always errors for use strict #228

Closed
mondwan opened this issue Dec 31, 2015 · 23 comments
Closed

Bug report: Always errors for use strict #228

mondwan opened this issue Dec 31, 2015 · 23 comments

Comments

@mondwan
Copy link

mondwan commented Dec 31, 2015

Versions

$ cat package.json
  "devDependencies": {
       "eslint": "~1.10.3",
       "babel-eslint": "~5.0.0-beta6",
        "eslint-plugin-react": "~3.13.1"
  }

.eslintrc

$ cat .eslintrc 
{
  "parser": "babel-eslint",
  "env": {
    "browser": true,
    "node": true,
    "amd": true
  },
  "settings": {
      "ecmascript": 6,
      "jsx": true
  },
  "plugins": [
      "react"
  ],
  "rules": {
    "strict": [2, "global"],
  }
}

a.js

"use strict";

console.log('a.js');

Reproduce error

$ node_modules/.bin/eslint -c .eslintrc a.js 

/home/mondwan/Documents/test/babel_eslint_test/a.js
  3:1  error  Use the global form of "use strict"  strict

✖ 1 problem (1 error, 0 warnings)

Note

  • I have tried "use strict", "use strict"; 'use strict' and 'use strict';. None of them work.
  • I have tried Babel-eslint v4.1.6. No such bug occur
@jmm
Copy link
Member

jmm commented Jan 4, 2016

Thanks for the report! I think this is due to the introduction of the Directive* node types in Babel v6. There are probably 2 solutions: persuade eslint to modify the rule to check for those node types first, or here rework them to the regular AST structure / types that the eslint rule is expecting. BTW, this can be trimmed down to a more minimal reproduction.

@jmm
Copy link
Member

jmm commented Jan 4, 2016

I double checked with eslint on their gitter and per nzakas they only want to support ESTree.

@satya164
Copy link

satya164 commented Jan 5, 2016

I'm also facing this.

@hzoo
Copy link
Member

hzoo commented Jan 5, 2016

We can definitely change directive to estree b/c that's what we've had to do for everything else anyway. If you are using modules you shouldn't need use strict since they are all in strict mode right?

@satya164
Copy link

satya164 commented Jan 5, 2016

@hzoo Yeah. My code is a mix of these things right now as I'm running in my tests with Babel and other files with plain Node. I should change to use modules anyways and setup the server to run with babel :D

@jmm
Copy link
Member

jmm commented Jan 5, 2016

@hzoo I was wondering what is this line for?:

ast.directives = ast.program.directives;

@hzoo
Copy link
Member

hzoo commented Jan 5, 2016

I think I was just trying to copy whatever was needed from the babylon AST to estree since it uses File instead of Program but looking at what you posted I wouldn't need to add that line since estree doesn't use that anyway.

@jmm
Copy link
Member

jmm commented Jan 5, 2016

@hzoo 👍

@hzoo
Copy link
Member

hzoo commented Jan 7, 2016

Ok still have to convert Directive to an ExpressionStatement that has a Literal - It's getting pretty annoying to do this manually. Maybe we can use some more babel utilities to make it easier.

@mondwan
Copy link
Author

mondwan commented Jan 7, 2016

Sorry, I am not sure I can follow the discussion.

Any hints for Directive* node, AST tree, ESTree? And how should I fix this problem? By configuration ?

@hzoo
Copy link
Member

hzoo commented Jan 7, 2016

The AST is different so we have to convert it in https://github.com/babel/acorn-to-esprima/blob/master/src/toAST.js. Not much you can do other than using a different version or not using the rule.

@mondwan
Copy link
Author

mondwan commented Jan 7, 2016

Yes. I am using a different version currently. But how to not using the rule?

And I am not sure the meaning of AST and esproma? I guess this is some kind of parsing mechanism? Do you have any links for showing the concept of them?

Thanks very much.

@hzoo
Copy link
Member

hzoo commented Jan 7, 2016

Oh I just meant turning off the rule "strict": [2, "global"], (although you probably don't want that).

AST: https://en.wikipedia.org/wiki/Abstract_syntax_tree
esprima: http://esprima.org/, https://github.com/jquery/esprima - esprima/babylon/acorn are javascript parsers. Check out http://astexplorer.net/, https://www.youtube.com/watch?v=rKuNbEwoQfQ

You'll just have to wait for a fix.

@mondwan
Copy link
Author

mondwan commented Jan 7, 2016

Thanks. I will check them out later on.

@jmm
Copy link
Member

jmm commented Jan 7, 2016

@hzoo

Ok still have to convert Directive to an ExpressionStatement that has a Literal - It's getting pretty annoying to do this manually. Maybe we can use some more babel utilities to make it easier.

It is a bit annoying, but it shouldn't be too bad. Want me to take a crack at it? (I sort of already did it before just to test things out.)

@jmm
Copy link
Member

jmm commented Jan 22, 2016

WIP fix for this: babel/acorn-to-esprima@master...jmm:directives. I believe acorn-to-esprima is the correct home for this, right?

@hzoo
Copy link
Member

hzoo commented Jan 22, 2016

Yeah. Also, all that code needs cleanup - would be nice to be able to use more babel methods instead of stuff like

@d6u
Copy link

d6u commented Jan 29, 2016

FYI, strict: [2, 'function'] behaves like what strict: [2, 'global'] intended to do.

@jmm
Copy link
Member

jmm commented Jan 30, 2016

@hzoo Thanks.

would be nice to be able to use more babel methods instead of stuff like

Hmm, I probably don't actually know the Babel method for that as of yet.

Submitted #241 for this.

@d6u I'm not sure what you mean.

@jmm
Copy link
Member

jmm commented Jan 30, 2016

Huh, so putting "Fixes {{someuser}}/{{somerepo}}#123" in a PR in a different repo closes the referenced issue when merged? Maybe just if they're under the same org?

@hzoo
Copy link
Member

hzoo commented Jan 30, 2016

Yeah since you have colloborator access to the org

@jmm
Copy link
Member

jmm commented Jan 30, 2016

Oh ok, I'll have to be more careful with that. But since you merged and published babel/acorn-to-esprima#5 it is fixed now ✨.

@hzoo
Copy link
Member

hzoo commented Jan 30, 2016

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

No branches or pull requests

5 participants