sindresorhus / read-package-up

Read the closest package.json file
MIT License
258 stars 18 forks source link

"package" is a reserved keyword linting error in v6.x.x #11

Closed Aghassi closed 5 years ago

Aghassi commented 5 years ago

Using airbnb + prettier for ESlinting, I can't destructure the way I use to when reading a package. I now get this linting error:

Parsing error: The keyword 'package' is reserved

Before I could do

const { pkg } = require('read-pkg-up').sync();

But as of v6 I can't do the following without the above error

const { package } = require('read-pkg-up').sync();

Can pkg be left for backwards compatibility? Or is there a better recommended way of importing? I guess I can this?

const { package: pkg } = require('read-pkg-up').sync();

Not sure why the property needed to be renamed, but just wanted to call out this issue in case others run into it.

sindresorhus commented 5 years ago

Ouch. I didn't think of destructuring when making that change... The reason I made that change is that I'm trying to use more readable variable names (no acronyms).

How about making it:

const {packageJson} = require('read-pkg-up').sync();

?

Aghassi commented 5 years ago

@sindresorhus that's fine with me :).

sindresorhus commented 5 years ago

https://github.com/sindresorhus/read-pkg-up/releases/tag/v7.0.0