Skip to content

Prettier 3.2.3 incorrectly formats .estlintrc.json #15946

@fstaffa

Description

@fstaffa

After updating to prettier 3.2.3, it formats .eslintrc.json with trailing commas, here is an example:

{
	"parser": "@typescript-eslint/parser",
	"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
	"plugins": ["no-only-tests"],
	"parserOptions": {
		"ecmaVersion": 2018,
		"sourceType": "module", <--
	},
	"ignorePatterns": ["node_modules/", "build"],
	"rules": {
		"no-console": ["off"],
		"@typescript-eslint/consistent-type-assertions": [
			"error",
			{
				"assertionStyle": "angle-bracket", <--
			}, <--
		],
		"@typescript-eslint/no-explicit-any": "off",
		"@typescript-eslint/no-var-requires": "off",
		"@typescript-eslint/explicit-function-return-type": "off",
		"@typescript-eslint/no-use-before-define": "off",
		"@typescript-eslint/no-empty-function": "off",
		"prefer-const": "off",
		"no-only-tests/no-only-tests": ["error"], <--
	}, <--
}

When running eslint 8.56.0, it throw an error
Cannot read config file: [foldername]/.eslintrc.json Error: Unexpected token } in JSON at position 210

I assume this is related to #15881 , and that it incorrectly identifies which files are json and which jsonc. While eslint config specifies it allows comments, I am not sure it implies it also accepts trailing commas https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-formats

[Edit]: Here are minimal replication steps:

  1. checkout https://github.com/fstaffa/prettier-eslintrc-issue
  2. run npm ci
  3. run npm run eslint (works as exptected)
  4. run npm run prettier (changes .eslintrc.json)
  5. run npm run eslint (fails with error similar to what was reported above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions