standard icon indicating copy to clipboard operation
standard copied to clipboard

[standard] Parsing error: Unexpected token =

Open gunningham opened this issue 8 years ago • 33 comments

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

gunningham avatar Jul 17 '18 11:07 gunningham

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[bot] avatar Oct 15 '18 12:10 stale[bot]

??

brody2consult avatar Oct 15 '18 12:10 brody2consult

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

CodeDraken avatar Nov 12 '18 20:11 CodeDraken

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

GustavoDinizMonteiro avatar Nov 15 '18 14:11 GustavoDinizMonteiro

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

CodeDraken avatar Nov 15 '18 21:11 CodeDraken

@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 avatar Nov 17 '18 13:11 GustavoDinizMonteiro

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.

kaigouthro avatar Jan 06 '19 17:01 kaigouthro

Yep, seeing same behavior.

okdistribute avatar Jan 10 '19 17:01 okdistribute

Encountering the same issue!

0x7061 avatar Jan 12 '19 14:01 0x7061

same issue with @kaigouthro

jisi724 avatar Jan 18 '19 17:01 jisi724

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

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

ghost avatar Feb 12 '19 16:02 ghost

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

TonyJDavies avatar Feb 25 '19 11:02 TonyJDavies

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

pjoriginal avatar Apr 17 '19 17:04 pjoriginal

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

Junting-Liu avatar Apr 21 '19 10:04 Junting-Liu

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

ThomasGoehringer avatar Jun 06 '19 11:06 ThomasGoehringer

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.

srevenant avatar Jun 19 '19 23:06 srevenant

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

LinusU avatar Jun 20 '19 07:06 LinusU

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

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

srevenant avatar Jun 22 '19 20:06 srevenant

Yes, me too.

ThomasGoehringer avatar Jul 04 '19 10:07 ThomasGoehringer

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

oliverfunk avatar Jul 04 '19 15:07 oliverfunk