question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected token )

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.19.1
  • Node Version: 9.11.1
  • npm Version: 5.6.0

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

Please show your full configuration:

Configuration
// Use this file as a starting point for your project's .eslintrc.
// Copy this file, and add rule overrides as needed.
{
  "extends": [
    "airbnb", "plugin:vue/essential",
  ],
  "env": {
    "jquery": true,
    "browser": true
  },
  "globals": {
    "App": true,
    "$": true
  },
  "rules": {
    "max-len": [2, 140, 2],
    "no-param-reassign": "warn",
    "no-underscore-dangle": "off",
    "prefer-destructuring": [
      "error",
      {
        "array": false,
        "object": false
      }
    ]
  }
}

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 Vue from 'vue';

export default {
  getChat(token, cb, cbError) {
    const url = Routes.api_v1_chat_path(token);
    Vue.http.get(url).then(response => cb(response.body), () => cbError());
  },

  getChats(cb, cbError) {
    const url = Routes.api_v1_chats_path();
    Vue.http.get(url).then(response => cb(response.body), () => cbError());
  },

  endChat(token, cb, cbError) {
    const url = Routes.api_v1_chat_path(token);
    Vue.http.delete(url).then(response => cb(response.body), () => cbError());
  },

  chatCable: null,
  chatsCable: null,

  disconnectIfNecessary() {
    if (this.chatCable) this.chatCable.unsubscribe();
    this.chatCable = null;
  },

  initChatCable(store, token) {
    this.disconnectIfNecessary();
    if (!token) {
      return;
    }
    this.disconnectIfNecessary();
    this.chatCable = App.cable.subscriptions.create(
      {
        channel: 'ChatChannel',
        chatToken: token,
      },
      {
        connected() {
          this.subscribe();
        },

        disconnected() {
          console.log('WebSocket disconnected.');
        },

        received(data) {
          const message = JSON.parse(data.message);
          const prompt = JSON.parse(data.prompt);
          const chat = JSON.parse(data.chat);

          store.commit('receiveMessage', {
            token,
            chat,
            message,
            prompt,
          });
        },

        sendMessage(message) {
          this.perform('send_message', { message });
        },

        sendResponse(response) {
          this.perform('send_response', { response });
        },

        subscribe() {
          // return this.perform('subscribe');
        },
      },
    );  // THIS IS LINE 72
  },

  disconnectChatsCable() {
    if (this.chatsCable) this.chatsCable.unsubscribe();
    this.chatsCable = null;
  },

  initChatsCable(store) {
    this.chatsCable = App.cable.subscriptions.create(
      {
        channel: 'ChatsChannel',
      },
      {
        connected() {
          this.subscribe();
        },

        disconnected() {
        },

        received(data) {
          const chat = JSON.parse(data.chat);
          store.commit('updateChat', { chat });
        },

        subscribe() {},
      },
    );
  },
};
eslint app/javascript/packs/rather_chat/api/chats.js 

What did you expect to happen?

This is a perfectly valid file.

What actually happened? Please include the actual, raw output from ESLint.

72:5 error Parsing error: Unexpected token )

✖ 1 problem (1 error, 0 warnings)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, May 17, 2018

Hi @gamut, thanks for posting the file.

There’s a dangling comma after the last function argument on line 71. Dangling commas for function arguments is only valid in ES2017 or later. I’m not sure if the airbnb config might be using ES2017, but your config file definitely does not specify an ecmaVersion explicitly so it might be using ES5 by default. In any case, if you are willing to parse your code using ES2017 spec, you should add to your config:

{
    "parserOptions": {
        "ecmaVersion": 2017
    }
}
0reactions
mostlydevcommented, Jun 26, 2018

Thank you. Appreciate the response.

On Thu, May 17, 2018 at 6:29 PM Kevin Partington notifications@github.com wrote:

Hi @gamut https://github.com/gamut, thanks for posting the file.

There’s a dangling comma after the last function argument on line 71. Dangling commas for function arguments is only valid in ES2017 or later. I’m not sure if the airbnb config might be using ES2017, but your config file definitely does not specify an ecmaVersion explicitly so it might be using ES5 by default. In any case, if you are willing to parse your code using ES2017 spec, you should add to your config:

{ “parserOptions”: { “ecmaVersion”: 2017 } }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/10369#issuecomment-390034086, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEGD3v-zpi3y9LLuCGLgzVadyRKmi7oks5tzfnigaJpZM4UD0v8 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
syntax error: unexpected token - javascript - Stack Overflow
The error SyntaxError: Unexpected token < likely means the API endpoint didn't return JSON in its document body, such as due to a...
Read more >
Have a JavaScript Unexpected Token Error? Check Your Syntax
The JavaScript's parser expects tokens and symbols in a particular order, with relevant values or variables in between. Often, an Unexpected ...
Read more >
JavaScript Error Handling: Unexpected Token - GeeksforGeeks
Not follow them throws an error.An unexpected token occurs if JavaScript code has a missing or extra character { like, ) + –...
Read more >
SyntaxError: Unexpected token in JavaScript | bobbyhadz
The "Uncaught SyntaxError: Unexpected token" occurs for multiple reasons: · The error is also caused if you're making an HTTP request to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found