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

Types, generics throw parsing errors #1131

Closed
pglhall opened this issue May 15, 2018 · 3 comments

Comments

@pglhall
Copy link

commented May 15, 2018

Using standard 11.0.1, Node.js 9.11.1, yarn 1.6.0, macOS 10.13.4.

I'm trying to use a React Native component directly from React Native 0.55.3's boilerplate, and a very similar one of my own. I didn't expect it to pass Standard, but I was surprised that it caused parsing errors.

Here's the relevant code from the boilerplate and the code I wrote myself:

type Props = {}
export default class App extends Component<Props> {
export default class MyLoginButton extends Component<{}> {

That generates the following parsing errors:

standard: Use JavaScript Standard Style (https://standardjs.com)
standard: Run `standard --fix` to automatically fix some problems.
  /Users/peter/Projects/project/App.js:24:6: Parsing error: Unexpected token Props
  /Users/peter/Projects/project/src/components/LoginButton.js:11:53: Parsing error: Unexpected token <

Obviously, it's not recognising either the type declaration or the generic. I think I don't mind if these are forbidden by Standard (as long as there's a sensible alternative), but the parsing errors are preventing me from using Standard across the project.

I noticed that React Native installed a bunch of babel/eslint plugins on project creation. Should I be hooking these into Standard in any way? Would it help?

Thanks :)

@feross

This comment has been minimized.

Copy link
Member

commented May 15, 2018

@pglhall The type keyword is not part of the JavaScript language. It looks like you're using TypeScript – is that correct?

To use TypeScript with standard please follow the setup instructions in the readme here: https://standardjs.com/#typescript

Let me know if that fixes things for you.

@pglhall

This comment has been minimized.

Copy link
Author

commented May 15, 2018

It turns out to be Flow. I did a bit of digging through the node_modules directory to see what React Native installed out of the box, and there are several Babel modules for parsing and removing Flow syntax.

I've added eslint-plugin-flowtype and configured Standard to use it, and it now parses. A bit irritated that RN likes to add this unnecessary stuff, but I'd rather keep my code in line with the syntax of their current sample code than remove it.

Thanks for your help :)

@no-response no-response bot removed the need more info label May 15, 2018

@feross

This comment has been minimized.

Copy link
Member

commented May 15, 2018

Perfect.

@feross feross closed this May 15, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Aug 13, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.