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

Support Async Functions in eslint #2

Open
rafadorado opened this issue Dec 22, 2017 · 5 comments
Open

Support Async Functions in eslint #2

rafadorado opened this issue Dec 22, 2017 · 5 comments

Comments

@rafadorado
Copy link

Eslint parser does not support async functions, eslint/eslint#8366

Basically we need to add to the .eslintrc

"parserOptions": {
        "ecmaVersion": 2017
},
@iroy2000
Copy link

iroy2000 commented Dec 6, 2018

I try to use the same config

  "parserOptions": {
    "ecmaVersion": 2017,
    "ecmaFeatures": {
      // Enabled object spread
      "experimentalObjectRestSpread": true,
      "jsx": true
    }
  },

But the same error still coming out.

And what I end up is creating a class to wrap the asycn functions, which works fine

class API {
  static async getStuff(apiPayload) {
    const response = await apiAsyncGetStuff(apiPayload)

    // ... do something
  }
}

@yukhnevych
Copy link

You can fix it using the latest version of ESLint and set parser options like this:

{
  "parserOptions": {
      "ecmaVersion": 8
  }
}

@JMTK
Copy link

JMTK commented Feb 19, 2019

Still having some troubles with this one...

ESLint file is: (I am on 5.14.1)

module.exports = {
      "env": {
          "node": true,
          "es7": true
      },
      "parserOptions": {
          "ecmaVersion": 8
      },
      "rules": {
          "linebreak-style": [
              "error",
              "unix"
          ],
          "semi": [
              "error",
              "always"
          ]
      }
  };

I've verified changing the ecmaVersion DOES affect the parsing, if I set it to ES5 then I get a lot of issues with let and arrow syntax. I have no other .eslint files. I've tried ecmaVersion: 2018 as well as ecmaVersion: 2017.

This is an excerpt from a file that has no errors until we get to a line that has an async/await WITH an arrow function
image
image

botReply: (message, text, embed) => {
    return new Promise(async (resolve, reject) => {
	let prefs = null;
	if (!text) {
		  text = '';
	  }
	  let split = false;
	  if (text.length >= Config.MaxMessageLength) {
		  split = true;
	  }
	  if (!util.isPM(message)) {
		  prefs = util.ServerPrefs[message.guild.id];
	  }
	  else {
		  prefs = Config.Defaults.PMPrefs;
	  }
	  let translate = 'en';
	  if (prefs && prefs.Language && prefs.Language !== translate) {
		  translate = prefs.Language;
	  }
	  try {
		  if (typeof embed === 'object' && translate !== 'en') {
			embed.title = await util.translate('en', translate, embed.title);
			embed.description = await util.translate('en', translate, embed.description);
//function continues on

Compiles fine in NodeJS 10.x and I've been using it since Node 8.

EDIT: Quick correction, es7 was not a valid environment variable so I've changed it to es6. It did not fix any issues but it did fix a couple of my rules like "no-unused-vars" to start working correctly.

@JMTK
Copy link

JMTK commented Feb 19, 2019

For comparison, I tried just doing the command line but this seems to be a vim issue maybe?

image

image

Not sure where the disconnect is. I'm using w0rp/ale right now.

@jramcast
Copy link
Owner

Hi, I updated the package with support for es2018. Let me know if that solves your problem.

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

No branches or pull requests

5 participants