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

[standard] Parsing error: Unexpected token = #1165

Closed
gunningham opened this issue Jul 17, 2018 · 33 comments
Closed

[standard] Parsing error: Unexpected token = #1165

gunningham opened this issue Jul 17, 2018 · 33 comments

Comments

@gunningham
Copy link

gunningham commented Jul 17, 2018

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"
  ]
}
@stale
Copy link

stale bot commented Oct 15, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Oct 15, 2018
@brodybits
Copy link
Contributor

brodybits commented Oct 15, 2018 via email

@stale stale bot removed the stale label Oct 15, 2018
@CodeDraken
Copy link

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

@GustavoDinizMonteiro
Copy link

@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?

@CodeDraken
Copy link

@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.

@GustavoDinizMonteiro
Copy link

@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.

:/

@kaigouthro
Copy link

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.

@okdistribute
Copy link

Yep, seeing same behavior.

@codepushr
Copy link

Encountering the same issue!

@jisi724
Copy link

jisi724 commented Jan 18, 2019

same issue with @kaigouthro

@donald-cme
Copy link

donald-cme commented Feb 12, 2019

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

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

@TonyJDavies
Copy link

Seeing the same issue as well. Oddly when I run the standard --verbose --fix command directly from the command line, instead of via npm run fix (which is configured to do exactly the same) the errors do not occur, and the subsequent running of npm run fix succeeds. I've checked to see whether any content within the project directory has changed, and I can see nothing at all different!!

@pjoriginal
Copy link

Same for me.
standard --verbose --fix still produces the error in my case

@Junting-Liu
Copy link

Junting-Liu commented Apr 21, 2019

when i replace standard(11.0.1) with standardx(3.0.1), i encountered the same issue.

@ThomasGoehringer
Copy link

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

@srevenant
Copy link

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.

@LinusU
Copy link
Member

LinusU commented Jun 20, 2019

@ThomasGoehringer, @srevenant are you using babel-eslint as the parser?

@srevenant
Copy link

@ThomasGoehringer, @srevenant are you using babel-eslint as the parser?

Yes. If there is guidance for something else, I'm game to try.

@ThomasGoehringer
Copy link

Yes, me too.

@oliverfunk
Copy link

Also getting this issue. I don't want to have to use babel-eslint as the parser to make this lint'ing false positive go away...

@feross
Copy link
Member

feross commented Jul 6, 2019

Hi everyone!

A couple things to try:

  1. Please try out the prerelease version of standard 13 by running npm install standard@next and then run standard however you normally do. See if that fixes your issue.

  2. Please share the output of running npm ls eslint as well as npm ls eslint-config-standard.

  3. Lastly, the most helpful thing would be if someone could share a minimal GitHub repository that I can clone to see the issue in action.

Thanks!

@ThomasGoehringer
Copy link

Prerelease version doesn't work either.

Here's the output of npm ls ...:

└─┬ standard@12.0.1
  └── eslint@5.4.0 
└─┬ standard@12.0.1
  └── eslint-config-standard@12.0.0 

And here's a link to a repo where I'm having this problem: https://github.com/ThomasGoehringer/react-course-2-expensify-app
Have a look on src/components/AddExpensePage.js for example.

@srevenant
Copy link

srevenant commented Jul 11, 2019

Running standard as I would, but on version 13, received a TB the first time, but the second time it ran without error. However, it didn't actually work even though it ran without error.

The TB:


Error: Failed to load plugin 'node' declared in '--config » eslint-config-standard': Cannot find module 'eslint-plugin-node'
Require stack:
- /Users/brandon/share/git/protos/perform/perform-frontend/src/__placeholder__.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.resolve (internal/modules/cjs/helpers.js:21:19)
    at Object.resolve (/Users/brandon/share/git/protos/perform/perform-frontend/node_modules/standard/node_modules/eslint/lib/shared/relative-module-resolver.js:44:50)
    at ConfigArrayFactory._loadPlugin (/Users/brandon/share/git/protos/perform/perform-frontend/node_modules/standard/node_modules/eslint/lib/cli-engine/config-array-factory.js:841:39)
    at /Users/brandon/share/git/protos/perform/perform-frontend/node_modules/standard/node_modules/eslint/lib/cli-engine/config-array-factory.js:730:33
    at Array.reduce (<anonymous>)
    at ConfigArrayFactory._loadPlugins (/Users/brandon/share/git/protos/perform/perform-frontend/node_modules/standard/node_modules/eslint/lib/cli-engine/config-array-factory.js:726:22)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/Users/brandon/share/git/protos/perform/perform-frontend/node_modules/standard/node_modules/eslint/lib/cli-engine/config-array-factory.js:552:32)
    at _normalizeObjectConfigDataBody.next (<anonymous>)
    at ConfigArrayFactory._normalizeObjectConfigData (/Users/brandon/share/git/protos/perform/perform-frontend/node_modules/standard/node_modules/eslint/lib/cli-engine/config-array-factory.js:491:20)

If you think this is a bug in `standard`, open an issue: https://github.com/standard/standard/issues

$ npm ls eslint

├─┬ react-scripts@3.0.1
│ └── eslint@5.16.0
└─┬ standard@13.0.0
  └── eslint@6.0.1

@feross
Copy link
Member

feross commented Jul 12, 2019

@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>

@feross
Copy link
Member

feross commented Jul 12, 2019

@srevenant I believe that your issue is a duplicate of #1329

@no-response
Copy link

no-response bot commented Jul 13, 2019

This issue has been automatically closed because there was no response to a request for more information from the issue opener. Please leave a comment or open a new issue if you have additional information related to this issue.

@no-response no-response bot closed this as completed Jul 13, 2019
@ThomasGoehringer
Copy link

ThomasGoehringer commented Jul 13, 2019

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

@linxuyalun
Copy link

linxuyalun commented Sep 17, 2019

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"
  }
}

@brandonaaskov
Copy link

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

@stevenpollack
Copy link

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"
  }
}

@linxuyalun -- this fixed my issue. THANK YOU SO VERY MUCH!

@thomasvanholder
Copy link

@frostyandy2k
Copy link

I got it running worked after spending some time trying out different options. Hope this helps anyone else getting stuck.

.eslintrc.json (in root project folder):

{
    "env": {
        "browser": true,
        "es2021": true,
        "jest/globals": true
    },
    "extends": [
        "standard",
        "plugin:jest/all"
    ],
    "parser": "@babel/eslint-parser",
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "rules": {
        "jest/no-hooks": [
            "error",
            {
                "allow": [
                    "afterEach",
                    "beforeEach"
                ]
            }
        ]
    },
    "plugins": [
        "jest"
    ]
}

Empty .babelrc (in root project folder):

{}

.package.json (in root project folder):

{
  "scripts": {
    "test": "jest",
    "lint": "npx eslint --format=table .",
    "lintfix": "npx eslint --fix ."
  },
  "devDependencies": {
    "@babel/core": "^7.15.0",
    "@babel/eslint-parser": "^7.15.0",
    "aws-sdk-mock": "^5.2.1",
    "eslint": "^7.32.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.24.0",
    "eslint-plugin-jest": "^24.4.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^5.1.0",
    "jest": "^27.0.6"
  }
}

VS Code settings.xml (editor configuration: enables auto fix on save + babel parser):

    "eslint.alwaysShowStatus": true,
    "eslint.format.enable": true,
    "eslint.lintTask.enable": true,
    "eslint.options": {
        "parser": "@babel/eslint-parser"
    },
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    },
    "eslint.validate": [
        "javascript"
    ]

@JoseBS
Copy link

JoseBS commented Nov 8, 2021

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

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests