eslint-plugin-jsonc icon indicating copy to clipboard operation
eslint-plugin-jsonc copied to clipboard

sort-keys: Misplaced comments in tsconfig.json

Open LangLangBart opened this issue 1 year ago • 1 comments

description

  • sort-keys misplaces the comments in a tsconfig.json

reproduction

  • create a package.json
{
  "dependencies": {
    "eslint": "^8.49.0",
    "eslint-plugin-jsonc": "^2.9.0"
  },
  "eslintConfig": {
    "plugins": [
      "eslint-plugin-jsonc"
    ],
    "parser": "jsonc-eslint-parser",
    "rules": {
      "jsonc/sort-keys": [
        "error",
        {
          "pathPattern": "^compilerOptions$",
          "order": [
            "target",
            "strict"
          ]
        }
      ]
    }
  }
}
  • create a tsconfig.json
{
  "compilerOptions": {
    "strict": true, /* Enable all strict type-checking options. */
    "target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
  }
}
  • after applying the rule the tsconfig.json transforms into:
{
  "compilerOptions": { /* Enable all strict type-checking options. */
    "target": "esnext",
    "strict": true /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
  }
}

reference

  • https://github.com/antfu/eslint-config/issues/248

LangLangBart avatar Sep 20 '23 20:09 LangLangBart

It looks like a bug, but I think we need to think about how we handle comments. If you have an idea, please consider submitting a pull request.

ota-meshi avatar Sep 21 '23 07:09 ota-meshi