Description
Is there an existing issue for this?
- I have searched the existing issues and my issue is unique
- My issue appears in the command-line and not only in the text editor
Description Overview
When forcing the react/jsx-no-leaked-render
rule to only support coercing (we were attempting to enforce a standard format across an existing repo before re-enabling ternary render options) with the configuration setting of:
"react/jsx-no-leaked-render": ["error", {
"validStrategies": ["coerce"]
}],
the autofixer wasn't simply adding coerced values but was actively removing otherwise valid ternary code and introducing bugs into the codebase.
Obviously the nested ternaries are a problem and should be avoided but they are technically functional, if messy, code.
ESLint auto-fixer shouldn't be making functional changes to the codebase
The command I ran was simply eslint --fix-dry-run
on the codebase with the followingeslint.config.mjs
the relevant part being the rules section.
// eslint.config.mjs
import globals from "globals";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react"
import jsxA11y from "eslint-plugin-jsx-a11y";
import { defineConfig } from "eslint/config";
export default defineConfig([
///// CONFIG /////
{
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: globals.browser
},
settings: {
react: {
version: 'detect'
}
},
},
///// TEST CONFIG /////
{
files: ["src/__test*/**/*"],
languageOptions: {
globals: {
...globals.browser,
...globals.jest,
"module": true
}
}
},
///// RULES /////
tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
pluginReact.configs.flat['jsx-runtime'],
jsxA11y.flatConfigs.recommended,
{
rules: {
// DISABLED RULES
// These two should be re-enabled after tackling typescript type issues.
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-function-type": "off",
// This should be re-enabled after tackling section 508 compliance tickets.
"jsx-a11y/click-events-have-key-events": "off",
"no-unused-vars": "off",
"no-extra-boolean-cast": "off",
"no-case-declarations": "off",
"react/jsx-child-element-spacing": "off",
"react/no-unescaped-entities": "off",
"react/display-name": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/ban-ts-comment": "off",
// ENABLED RULES
"no-fallthrough": "error",
"no-sparse-arrays": "error",
"react/jsx-no-constructed-context-values": "error",
"react/jsx-max-props-per-line": ["error", {
"maximum": { "single": 3, "multi": 1 }
}],
"react/jsx-no-leaked-render": ["error", {
"validStrategies": ["coerce"]
}],
"react/no-unused-prop-types": "error",
"react/self-closing-comp": "error",
"react/no-object-type-as-default-prop": "error",
"react/no-unstable-nested-components": "error",
"react/jsx-closing-tag-location": "error",
"@typescript-eslint/no-unused-vars": ["error", {
"varsIgnorePattern": "^_|^React$",
"argsIgnorePattern": "^_"
}],
}
},
]);
Expected Behavior
ESLint should not be introducing bugs or removing functional code when applying autofixes
eslint-plugin-react version
v7.37.5
eslint version
v9.25.1
node version
v22.14.0