ota-meshi/jsonc-eslint-parser

Expected to be an expression, but got empty.

work933k opened this issue · 3 comments

In our NX-workspace we get an error on the following package.json file (/root/dummy/tools/workspace-plugin/package.json):

{
  "name": "@dummy-nx/workspace-plugin",
  "version": "0.0.1",
  "type": "commonjs",
  "generators": "./generators.json"
}

This is part of the debug log:

 eslint:linter With ConfigArray: /root/dummy/tools/workspace-plugin/package.json +0ms
  eslint:linter Apply the processor: 'json/.json' +3ms
  eslint:linter A code block was found: '(unnamed)' +8ms
  eslint:linter Parsing: /root/dummy/tools/workspace-plugin/package.json +2ms
  eslint:linter Parsing error: Expected to be an expression, but got empty.
  eslint:linter SyntaxError: Expected to be an expression, but got empty.
    at ExtendParser.raise (/root/dummy/node_modules/jsonc-eslint-parser/lib/parser/extend-parser.js:74:25)
    at ExtendParser.unexpected (/root/dummy/node_modules/jsonc-eslint-parser/lib/parser/extend-parser.js:94:26)
    at ExtendParser.pp$5.parseExprAtomDefault (/root/dummy/node_modules/acorn/dist/acorn.js:2929:10)
    at ExtendParser.pp$5.parseExprAtom (/root/dummy/node_modules/acorn/dist/acorn.js:2924:19)
    at ExtendParser.pp$5.parseExprSubscripts (/root/dummy/node_modules/acorn/dist/acorn.js:2708:21)
    at ExtendParser.pp$5.parseMaybeUnary (/root/dummy/node_modules/acorn/dist/acorn.js:2674:19)
    at ExtendParser.pp$5.parseExprOps (/root/dummy/node_modules/acorn/dist/acorn.js:2601:21)
    at ExtendParser.pp$5.parseMaybeConditional (/root/dummy/node_modules/acorn/dist/acorn.js:2584:21)
    at ExtendParser.pp$5.parseMaybeAssign (/root/dummy/node_modules/acorn/dist/acorn.js:2551:21)
    at ExtendParser.pp$5.parseExpression (/root/dummy/node_modules/acorn/dist/acorn.js:2514:21) +16ms
  eslint:linter Generating fixed text for /root/dummy/tools/workspace-plugin/package.json (pass 1) +2ms
  eslint:source-code-fixer Applying fixes +0ms
  eslint:source-code-fixer No fixes to apply +0ms
  eslint:file-enumerator Complete iterating files: ["package.json"] +3s
  eslint:cli-engine Linting complete in: 3001ms +33ms
  eslint:cli Fix mode enabled - applying fixes +3s

/root/dummy/tools/workspace-plugin/package.json
  1:2  error  Parsing error: Expected to be an expression, but got empty

We get this error on v2.3.0 and also v2.4.0. Why is this error given?

I can't reproduce the error. Please share a minimal repository to reproduce.

I'll try to provide a minimal repository to reproduce. In the mean-time maybe this screenshot-snippet helps?
image

I noticed the text "CSS contributions to package.json", which i find weird.

When i started stripping my workspace, the error disappeared when i removed a json-plugin ("eslint-plugin-json": "3.1.0",) which i had configured in the root eslintrc-file. So probably that plugin causes the issue.

This is what i had configured in the root eslintrc-file:

{
  "root": true,
  "ignorePatterns": ["**/*"],
  "extends": ["plugin:jasmine/recommended", "plugin:storybook/recommended", "prettier"],
  "plugins": ["@nx", "json", "sonarjs", "jsdoc", "jasmine", "yaml", "deprecation"],
  "settings": {
    "json/sort-package-json": true,
    "json/json-with-comments-files": []
  },
...

I re-aligned with NX and remove the above json-configuration, and added:

 {
      "files": "*.json",
      "parser": "jsonc-eslint-parser",
      "rules": {}
}

This resolved the issue. So this issue can be marked as resolved as it was caused by a conflict with the json-plugin i was using.

Thank you for your help!