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

eslint parser flags import (in import.meta.url) as an error #12518

Closed
bmacnaughton opened this issue Nov 1, 2019 · 7 comments
Closed

eslint parser flags import (in import.meta.url) as an error #12518

bmacnaughton opened this issue Nov 1, 2019 · 7 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon

Comments

@bmacnaughton
Copy link

bmacnaughton commented Nov 1, 2019

Tell us about your environment

vscode information
Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:33:40.634Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0 (vscode is apparently running a different node than the shell)
V8: 6.9.427.31-electron.0
OS: Linux x64 4.15.0-66-generic

eslint is executed via: Dirk Baeumer's vscode eslint extension: https://github.com/Microsoft/vscode-eslint

System configuration:
Node version: v12.11.1
npm version: v6.12.1
Local ESLint version: Not found
Global ESLint version: v6.6.0 (Currently used)

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:

Configuration
env:
  node: true
  es6: true
  mocha: true # NOTE: Not all tests pass eslint.

parserOptions:
  ecmaVersion: 2018

rules:
  # Possible Errors
  # http://eslint.org/docs/rules/#possible-errors
  comma-dangle: [2, "only-multiline"]
  no-control-regex: 2
  no-debugger: 2
  no-console: 2
  no-dupe-args: 2
  no-dupe-keys: 2
  no-duplicate-case: 2
  no-empty-character-class: 2
  no-ex-assign: 2
  no-extra-boolean-cast : 2
  no-extra-parens: [2, "functions"]
  no-extra-semi: 2
  no-func-assign: 2
  no-invalid-regexp: 2
  no-irregular-whitespace: 2
  no-negated-in-lhs: 2
  no-obj-calls: 2
  no-proto: 2
  no-unexpected-multiline: 2
  no-unreachable: 2
  use-isnan: 2
  valid-typeof: 2
  no-var: 2
  object-curly-spacing: [2, "never"]

  # Best Practices
  # http://eslint.org/docs/rules/#best-practices
  no-fallthrough: 2
  no-octal: 2
  no-redeclare: 2
  no-self-assign: 2
  no-unused-labels: 2

  # Strict Mode
  # http://eslint.org/docs/rules/#strict-mode
  strict: [2, "global"]

  # Variables
  # http://eslint.org/docs/rules/#variables
  no-delete-var: 2
  no-undef: 2
  #no-unused-vars: [2, {"args": "after-used"}]
  no-unused-vars: [2, {"args": "none"}]     # don't complain about unused args

  # Node.js and CommonJS
  # http://eslint.org/docs/rules/#nodejs-and-commonjs
  no-mixed-requires: 2
  no-new-require: 2
  no-path-concat: 2
  no-restricted-modules: [2, "sys", "_linklist"]

  # Stylistic Issues
  # http://eslint.org/docs/rules/#stylistic-issues
  comma-spacing: 2
  eol-last: 2
  indent: [2, 2, {SwitchCase: 1}]
  keyword-spacing: 2
  max-len: [2, 100, 2, {ignoreComments: true, ignoreStrings: true, ignoreTemplateLiterals: true}]
  new-parens: 2
  no-mixed-spaces-and-tabs: 2
  no-multiple-empty-lines: [2, {max: 2}]
  no-trailing-spaces: 2
  quotes: [2, "single", "avoid-escape"]
  # semi: 2
  space-before-blocks: [2, "always"]
  space-before-function-paren: [2, "always"]
  # space-in-parens: [2, "never"]
  space-infix-ops: 2
  space-unary-ops: 2

  # ECMAScript 6
  # http://eslint.org/docs/rules/#ecmascript-6
  # arrow-parens: [2, "always"]
  arrow-spacing: [2, {"before": true, "after": true}]
  constructor-super: 2
  no-class-assign: 2
  # no-confusing-arrow: [2, {"allowParens": true}]
  no-const-assign: 2
  no-dupe-class-members: 2
  no-new-symbol: 2
  no-this-before-super: 2
  prefer-const: 2

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import {createRequire} from 'module';
const require = createRequire(import.meta.url);

What did you expect to happen?
no error flagged from referring to import.meta.url

What actually happened? Please include the actual, raw output from ESLint.
(parsing error unexpected token: import)
image

Are you willing to submit a pull request to fix this bug?
if someone points me at the appropriate parsing code i'll give it a try.

@bmacnaughton bmacnaughton added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Nov 1, 2019
@mysticatea
Copy link
Member

Thank you for your report. But this is correct behavior because import.meta is not part of JS yet. You have to use babel-eslint to use the experimental syntax. See also What about experimental features?

@runarberg
Copy link

runarberg commented Feb 5, 2020

import.meta is already in stage 3 and is implemented by all modern browsers except edge as well as node.

It notably replaces __dirname and __filename in native es modules in node. Meaning that if you want to get these values in a module you must use import.meta.

It is indeed annoying that the only reason to pull in babel as a dev dependency is because eslint is unable to parse import.meta.

@runarberg
Copy link

We will make changes to core rules in order to avoid crashes on stage 3 ECMAScript syntax proposals

Does this apply yet, given the above?

@besenwagen
Copy link

besenwagen commented Mar 13, 2020

import.meta is already in stage 3 and is implemented by all modern browsers except edge as well as node.

And deno (the Chromium based Edge has been released on January 15, by the way).

@kaicataldo
Copy link
Member

Let's move this discussion to #13042, since it's an open issue.

@kaicataldo
Copy link
Member

I do want to note that our policy is to update core rules to not crash. Parser errors are not included in this.

@blake-regalia
Copy link

For those who came here by search engine:

Here is the actual issue being tracked for import.meta: #13133

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 1, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon
Projects
None yet
Development

No branches or pull requests

6 participants