首页 > 解决方案 > ", expected" in opening and closing brackets, ESLint and JavaScript

问题描述

I have been working on this issue for about three hours and I can't find what I've done wrong or how to fix it. I've scoured stack and haven't found anything, and I'm not sure if this is syntax or if I have done something horribly wrong in my programming unrelated to syntax (logic errors, etc.). I am new to both JS and stackoverflow, so I apologize if my formatting, way of asking this question, or question in general are incorrect.

import Vue from 'vue'
import Vuex from 'vuex'
import sourceData from '@/data'
import {countObjectProperties} from '@/utils'

Vue.use(Vuex)

const makeAppendChildToParentMutation = ({parent, child}) =>
    (state, {childId, parentId}) => {
      const resource = state[parent][parentId]
        if (!resource[child]) {
          Vue.set(resource, child, {})
        }
      Vue.set(resource[child], childId, childId)
    }
export default new Vuex.Store({

  state: {
    ...sourceData,
    authId: 'VXjpr2WHa8Ux4Bnggym8QFLdv5C3'
  },

  getters: {
    authUser (state) {
      return state.users[state.authId]
    },

      userThreadsCount: state => id => countObjectProperties(state.users[id].threads),
      userPostsCount: state => id => countObjectProperties(state.users[id].posts)
    },
  actions: {
    createPost ({commit, state}, post) {
      const postId = 'greatPost' + Math.random()
      post['.key'] = postId
      post.userId = state.authId
      post.publishedAt = Math.floor(Date.now() / 1000)
      commit('setPost', {
                  postId: id,
                  post: {
                    ...post,
                      text,
                      edited: {
                        at: Math.floor(Date.now() / 1000),
                          by: state.authId
                      }
                  }
              })
      commit('appendPostToThread', {threadId: post.threadId, postId})
      commit('appendPostToUser', {userId: post.userId, postId})
      return Promise.resolve(state.posts[postId])
    },
    createThread ({state, commit, dispatch}, {text, title, forumId}) {
      return new Promise((resolve, reject) => {
        const threadId = 'greatThread' + Math.random()
          const userId = state.authId
          const publishedAt = Math.floor(Date.now() / 1000)
      const thread = {'.key': threadId, title, forumId, publishedAt, userId}
      commit('setThread', {threadId, thread})
      commit('appendThreadToForum', {forumId, threadId})
      commit('appendThreadToUser', {userId, threadId})
      dispatch('createPost', {text, threadId})
        .then(post => {
          commit('setThread', {threadId, thread: {...thread, firstPostId: post['.key']}})
        })
      resolve(state.threads[threadId])
    },
        updateThread ({state, commit, dispatch}, {title, text, id}) {
              return new Promise((resolve, reject) => {
                    const thread = state.threads[id]
                    const newThread = {...thread, title}
                    commit('setThread', {thread: newThread, threadId: id})

There is also an error here^(update thread line) expecting a comma right after the closing parentheses and before the open bracket

                dispatch('updatePost', {id: thread.firstPostId, text})
                          .then(() => {
                              resolve(newThread)
                            })
                  })
        }
      updatePost ({state, commit}, {id, text}); {
              return new Promise((resolve, reject) => {
                    const post = state.posts[id]
                    commit('setPost', {postId: id, post: {...post, text}})
                    resolve(post)
                  })
              }
      updateUser ({commit}, user);{
      commit('setUser', {userId: user['.key'], user})
    }},
  setThread (state, {thread, threadId}) {
    Vue.set(state.threads, threadId, thread)
  },

  mutations: {
    setPost (state, {post, postId}) {
      Vue.set(state.posts, postId, post)
    },
    setUser (state, {user, userId}) {
      Vue.set(state.users, userId, user)
    },
    AppendPostToThread (state, {postId, threadId}) {
      const thread = state.threads[threadId]
      if (!thread.posts) {
        Vue.set(thread, 'posts', {})
      }
      Vue.set(thread.posts, postId, postId)
    },
    appendPostToUser (state, {postId, userId}) {
      const user = state.users[userId]
      if (!user.posts) {
        Vue.set(user, 'posts', {})
      }
      Vue.set(user.posts, postId, postId)
    },
    appendThreadToForum (state, {forumId, threadId}) {
      const forum = state.forums[forumId]
      if (!forum.threads) {
        Vue.set(forum, 'threads', {})
      }
      Vue.set(forum.threads, threadId, threadId)
    },

    appendThreadToUser (state, {userId, threadId}) {
      const user = state.users[userId]
      if (!user.threads) {
        Vue.set(user, 'threads', {})
      }
      Vue.set(user.threads, threadId, threadId)
    }
    }
})

The issue is with the last parentheses above^ it says that there is a comma expected.

标签: javascriptsyntax-erroreslint

解决方案


在操作之前,您缺少吸气剂的右括号。


推荐阅读