Error: Unexpected end of JSON input when using empty package.json
See original GitHub issueThe version of ESLint you are using. 6.6.0
The problem you want to solve.
When I have an empty package.json
file in nested folder, near checked files, eslint gives error:
Error: Unexpected end of JSON input
There were similar issues previously - https://github.com/eslint/eslint/issues/11026#issuecomment-433744443, https://github.com/eslint/eslint/issues/7748 and there was no error in 5.16.0. Since 6.0.0 an error is thrown.
Your take on the correct solution to problem. It would be nice to have an option to disable this error. I tried to ignore this json file, but didn’t succeed.
This is useful for me because I want this file to be invalid on purpose so later I can check it.
Are you willing to submit a pull request to implement this change? Probably not, no free time to dive in atm.
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (12 by maintainers)
Top GitHub Comments
I think we should treat invalid or empty object package.json the same way as we treat lack of configuration files of any other type. The only thing in package.json that counts as an ESLint configuration is an
eslintConfig
key and object. Anything else should not matter to ESLint.I think we should throw if the
eslintConfig
value is invalid for some reason (e.g., it’s an array or string rather than an object). But, if we can’t even see aneslintConfig
key, then there is no configuration for ESLint to look at and we know this for a fact. Throwing on invalid JSON (for package.json) is unnecessarily intrusive, in my opinion.You are right. In that case, you need
/tests/bad-json
in your.eslintignore
, or a valid ESLint configuration file that has a higher priority thanpackage.json
such as/tests/bad-json/.eslintrc.yml
.Because ESLint reads
/tests/bad-json/package.json
when it entered/tests/bad-json
directory in order to check if the config file change how ESLint traverses the subdirectory via RFC20 or RFC22. (so/tests/bad-json/package.json
can have a setting that ignores/unignores/tests/bad-json/*
.)