standard: [standard] Parsing error: Unexpected token =

What version of standard? 11.0.1

What operating system, Node.js, and npm version? OSX 6.1.0 10.3.0

What did you expect to happen? standard --fix to fix arrow functions.

What actually happened? Get a parsing error on arrow functions and standard --fix does not fix them.

image

All other rules appear to format ok

standard configs in package.json

  "standard": {
    "parser": "babel-eslint",
    "ignore": [
      "src/utils/epubjs/**/*.js"
    ],
    "globals": [
      "jest",
      "expect",
      "test",
      "describe",
      "it",
      "beforeEach",
      "beforeAll",
      "afterAll",
      "shallow",
      "snapshot",
      "localStorage",
      "FileReader",
      "FormData",
      "location",
      "all",
      "history",
      "mount"
    ]
  }

devDeps

    "babel-eslint": "^8.2.6",
    "babel-jest": "22.4.3",
    "babel-loader": "7.1.4",
    "babel-plugin-react-component-data-attribute": "^0.5.0",
    "babel-plugin-syntax-async-functions": "^6.13.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-async-to-generator": "6.24.1",
    "babel-plugin-transform-class-properties": "6.24.1",
    "babel-plugin-transform-do-expressions": "^6.22.0",
    "babel-plugin-transform-export-extensions": "^6.22.0",
    "babel-plugin-transform-function-bind": "^6.22.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-plugin-transform-regenerator": "^6.26.0",

babelrc

  "presets": [
    ["env"]
  ],
  "plugins": [
    "transform-class-properties",
    "transform-decorators",
    "transform-react-constant-elements",
    "transform-react-inline-elements",
    "transform-object-rest-spread",
    "transform-function-bind",
    "transform-do-expressions",
    "transform-react-jsx",
    "transform-export-extensions",
    "syntax-dynamic-import",
    "syntax-async-functions",
    "transform-regenerator"
  ]
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 29
  • Comments: 33 (5 by maintainers)

Most upvoted comments

I wasn’t running standard via script but with the VS Code plugin. So the issue is at another place. Thanks.

I solved the problem by adding these three lines on my package.json

{
  // ...
  "standard": {
    "parser": "babel-eslint"
  }
}

image

same issue randomly where the first ‘=’ of a file is marked as an invalid token. it’s completely without pattern, and only in about 1/100 files, and doesn’t seem to have any effect. in this example, it’s state… but if i remove that statement, it automatically marks the next = as being the invalid token… doesn’t matter what statement or type of code i place there, if it sees an = sign in absolutely any conceivable code i put there, it marks it invalid.

It appears to be something to do with class level assignments (perhaps tied to React). It happens for me with both:

class Whatever extends Component {
  state = {}
}
class Whatever extends Component {
  myFunc = async (e) => {
  }
}

In any case, it’s the first = /within the class/ – other equal signs either outside of the class or in other functions are fine.

Is there any update? I’m still having this issue.

Seeing the same issue when writing this (including in the online demo):

class MyClass {
  x = () => 'Test'
}

I’m also having this issue with the latest Create React App boilerplate. Usually adding "parser": "babel-eslint" would fix it.

@CodeDraken i have the same issue but using the babel-eslint parser just change the error to image for this code componentDidMount = async() => { const response = await getUserData() localStorage.setItem('user', JSON.stringify(response)) } are there any additional settings you have made for the default to ignore this rule?

No there shouldn’t be anything else required… but like I said I’m also having this issue, I think it’s a conflict with Create-React-App.

😕

@linxuyalun myself and many other future travelers thank you profusely.

time traveler here from 2021! i’m so grateful!

@linxuyalun myself and many other future travelers thank you profusely.

@ThomasGoehringer What do you mean by “doesn’t work”? I cloned the repo you linked to, ran npm install (which installs v12.0.1), and then added a “lint” script to package.json like this:

  "scripts": {
    ...
    "lint": "standard",
    ...
}

And it worked just fine, outputting the following errors:

standard: Use JavaScript Standard Style (https://standardjs.com)
standard: Run `standard --fix` to automatically fix some problems.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/AddExpensePage.js:11:9: Missing space before function parentheses.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/EditExpensePage.js:15:9: Missing space before function parentheses.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/ExpenseForm.js:34:29: Irregular whitespace not allowed.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/ExpenseListFilters.js:2:19: Irregular whitespace not allowed.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/ExpenseListFilters.js:3:27: Irregular whitespace not allowed.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/ExpenseListFilters.js:27:9: Missing space before function parentheses.
  /Users/feross/code/test/react-course-2-expensify-app/src/components/ExpenseListFilters.js:57:15: Value must be omitted for boolean attributes
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/hoc.js:32:7: 'AdminInfo' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/hoc.js:36:27: Value must be omitted for boolean attributes
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/promises.js:7:5: Expected the Promise rejection reason to be an Error.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-101.js:49:7: 'unsubscribe' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:24:7: 'removeExpense' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:30:7: 'editExpense' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:37:7: 'setTextFilter' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:43:7: 'sortByDate' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:53:7: 'setStartDate' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:59:7: 'setEndDate' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:166:7: 'expenseOne' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:167:7: 'expenseTwo' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/playground/redux-expensify.js:182:7: 'demoState' is assigned a value but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/routers/PublicRoute.js:4:8: 'Header' is defined but never used.
  /Users/feross/code/test/react-course-2-expensify-app/src/selectors/expenses.js:20:2: Newline required at end of file but not found.

When upgrading to v13.0.1, it also works just fine.

Perhaps you have an old version of standard which is installed globally that you are running instead of the up-to-date local copy? Can you try running sudo npm rm standard --global to remove the global copy (if one exists)?

Then run add a script to package.json, like I did, and run it with npm run <script-name>

@CodeDraken i have the same issue but using the babel-eslint parser just change the error to image

for this code componentDidMount = async() => { const response = await getUserData() localStorage.setItem('user', JSON.stringify(response)) }

are there any additional settings you have made for the default to ignore this rule?

No there shouldn’t be anything else required… but like I said I’m also having this issue, I think it’s a conflict with Create-React-App.