ota-meshi / eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
https://ota-meshi.github.io/eslint-plugin-jsonc/
MIT License
181 stars 17 forks source link

Keep getting "Parsing error: Expected to be an expression, but got empty" #273

Closed sidferreira closed 5 months ago

sidferreira commented 7 months ago

I just tried a very small simple case, and I keep receiving this error.

Config eslint-config.js

module.exports = {
  extends: ['plugin:jsonc/recommended-with-jsonc'],
  // rules: {},
};

The target eslint-to-test.json

{
  "b": "bbb",
  "a": "aaa"
}

cli:

npx eslint -c eslint-config.js eslint-to-test.json

/.../eslint-to-test.json
  1:2  error  Parsing error: Expected to be an expression, but got empty

✖ 1 problem (1 error, 0 warnings)

What am I missing?!

JounQin commented 7 months ago

A reproduction is required. You must be misconfig the parser accidentally.

sidferreira commented 5 months ago

@JounQin after extra time, the problem is eslint-i18n-json that changes all JSON files into a big comment string...

JounQin commented 5 months ago

🤣 @sidferreira I think you should report there to ask them to use the correct eslint parser jsonc-eslint-parser without any hacking.

sidferreira commented 5 months ago

I'm trying to do it my self. Do you3have a guide?

JounQin commented 5 months ago

Well, all you should post is letting them to know there is already a correct parser, so preprocess hacking is not required any more. But they will need to adapt the new JSON* nodes, see also https://github.com/ota-meshi/jsonc-eslint-parser/blob/master/docs/AST.md.

And don't forget to link this issue of course.

What means that plugin is not compatible with this one.

sidferreira commented 5 months ago

@JounQin yeah, but I don't think they will be fast. I'll try to just create a custom solution and move on.

Your plugin does almost all the rules we want anyways

sidferreira commented 5 months ago

So... I'm trying to make a rule, but having a hard time:

const esCompatUtils = require('eslint-compat-utils');
// import {parse: icuMessageFormatParser} from '@formatjs/icu-messageformat-parser'

module.exports = {
  meta: {
    type: 'problem',
    docs: {
      description: 'Check JSON files for I18N messages',
    },
    fixable: 'code',
    schema: [], // no options
  },
  create: function (context) {
    // console.log(`>>>>`, esCompatUtils.getSourceCode(context).);

    return {};
  },
};

but when I try to run the test:

    {
      code: `
      {
          "translationKeyA": "translation value a",
          "translationKeyB": "translation value b",
          "translationKeyC": "translation value escaped curly brackets '{}'",
          "translationKeyD": "translation value with backslash \u005C"
      }
      `,
      options: [],
      filename: 'file.json',
    },

it throws

AssertionError [ERR_ASSERTION]: A fatal parsing error occurred: Parsing error: Unexpected token :
    at runRuleForItem (.../eslint/lib/rule-tester/rule-tester.js:843:13)
    at testValidTemplate (.../eslint/lib/rule-tester/rule-tester.js:896:28)
    at RuleTester.<anonymous> (.../eslint/lib/rule-tester/rule-tester.js:1181:33)
    at RuleTester.itDefaultHandler (.../eslint/lib/rule-tester/rule-tester.js:453:23)
    at .../eslint/lib/rule-tester/rule-tester.js:1178:71
    at Array.forEach (<anonymous>)
    at RuleTester.<anonymous> (.../eslint/lib/rule-tester/rule-tester.js:1177:32)
    at RuleTester.describeDefaultHandler (.../eslint/lib/rule-tester/rule-tester.js:470:19)
    at RuleTester.<anonymous> (.../eslint/lib/rule-tester/rule-tester.js:1176:34)
    at RuleTester.describeDefaultHandler (.../eslint/lib/rule-tester/rule-tester.js:470:19) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

My goal is to have a rule matching against import {parse: icuMessageFormatParser} from '@formatjs/icu-messageformat-parser'