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

how to use eslint-disable in json files #336

Closed
manojkiraneda opened this issue Apr 30, 2024 · 2 comments
Closed

how to use eslint-disable in json files #336

manojkiraneda opened this issue Apr 30, 2024 · 2 comments

Comments

@manojkiraneda
Copy link

hi there, I am new to javascript language & eslint as well, just trying to explore how i could leverage eslint along with eslint-plugin-jsonc in my project(c++ project with lot of JSON files with comments) CI infrastructure to lint and catch JSON errors.

here is my config file in CI:

import eslintPluginJsonc from 'eslint-plugin-jsonc';
export default [
  ...eslintPluginJsonc.configs['flat/recommended-with-jsonc'],
];

when i try to test my repository:

manojeda@manojeda-vm:$ eslint -c eslint.config.mjs  .

/home/manojeda/Documents/Code/pldm-workspace/test/pldm/host-bmc/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json
  2:12  error  Parsing error: Unexpected token ':'

✖ 1 problems (1 errors, 0 warnings)

The json file which was marked as error - was intentionally written as a malformed JSON for unit testing purposes, so i figured that we have two ways to ignore the file.

  1. using eslint-disable constructs.
  2. using ignore in the flat configs.

I don't prefer option 2 , since my CI runs on multiple repositories and each of them can have malformed JSON's checked in at various places & i don't like developers of the repositories to add their ignore patterns in the config file(global one for all repositories).

So, i am left with option 1 , but when i try using the eslint-diable construct in the JSON file as mentioned in the readme , it does not seem to have any effect on the result, what am i missing here ?

manojeda@manojeda-vm:pldm$ cat /home/manojeda/Documents/Code/pldm-workspace/test/pldm/host-bmc/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json
/* eslint-disable */
"effecters": [
    {
        "dbus_info": {
            "object_path": "/xyz/openbmc_project/control/host0/boot",
            "interface": "xyz.openbmc_project.Control.Boot.Mode",
            "property_values": [
                "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"
                ]
        }
        ]
manojeda@manojeda-vm:$ cat eslint.config.mjs
import eslintPluginJsonc from 'eslint-plugin-jsonc';
export default [
  ...eslintPluginJsonc.configs['flat/recommended-with-jsonc'],
];

manojeda@manojeda-vm:$ eslint -c eslint.config.mjs  .

/home/manojeda/Documents/Code/pldm-workspace/test/pldm/host-bmc/test/host_effecter_jsons/malformed/dbus_to_host_effecter.json
  2:12  error  Parsing error: Unexpected token ':'

✖ 1 problems (1 errors, 0 warnings)
@ota-meshi
Copy link
Owner

Hi @manojkiraneda

  1. using eslint-disable constructs.
  2. using ignore in the flat configs.

eslint-disable is not available because it only works with JSON files that can be parsed. This is a limitation of ESLint.
Please select option 2.

@manojkiraneda
Copy link
Author

sure, thanks for your suggestion @ota-meshi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants