Skip to content

Commit e4ecbcf

Browse files
jaesoekjjangljharb
authored andcommitted
[Fix] checked-requires-onchange-or-readonly: correct options that were behaving opposite
1 parent 69de42e commit e4ecbcf

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1212
* [`boolean-prop-naming`]: allow TSIntersectionType ([#3705][] @developer-bandi)
1313
* [`no-unknown-property`]: support `popover`, `popovertarget`, `popovertargetaction` attributes ([#3707][] @ljharb)
1414
* [`no-unknown-property`]: only match `data-*` attributes containing `-` ([#3713][] @silverwind)
15+
* [`checked-requires-onchange-or-readonly`]: correct options that were behaving opposite ([#3715][] @jaesoekjjang)
1516

1617
### Changed
1718
* [`boolean-prop-naming`]: improve error message (@ljharb)
1819

20+
[#3715]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3715
1921
[#3713]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3713
2022
[#3707]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3707
2123
[#3705]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3705

lib/rules/checked-requires-onchange-or-readonly.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const messages = {
1919
const targetPropSet = new Set(['checked', 'onChange', 'readOnly', 'defaultChecked']);
2020

2121
const defaultOptions = {
22-
ignoreMissingProperties: true,
23-
ignoreExclusiveCheckedAttribute: true,
22+
ignoreMissingProperties: false,
23+
ignoreExclusiveCheckedAttribute: false,
2424
};
2525

2626
/**
@@ -93,12 +93,12 @@ module.exports = {
9393
return;
9494
}
9595

96-
if (options.ignoreExclusiveCheckedAttribute && propSet.has('defaultChecked')) {
96+
if (!options.ignoreExclusiveCheckedAttribute && propSet.has('defaultChecked')) {
9797
reportExclusiveCheckedAttribute(node);
9898
}
9999

100100
if (
101-
options.ignoreMissingProperties
101+
!options.ignoreMissingProperties
102102
&& !(propSet.has('onChange') || propSet.has('readOnly'))
103103
) {
104104
reportMissingProperty(node);

tests/lib/rules/checked-requires-onchange-or-readonly.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ ruleTester.run('checked-requires-onchange-or-readonly', rule, {
4040
"React.createElement('input', { checked: foo, onChange: noop, readOnly: true })",
4141
{
4242
code: '<input type="checkbox" checked />',
43-
options: [{ ignoreMissingProperties: false }],
43+
options: [{ ignoreMissingProperties: true }],
4444
},
4545
{
4646
code: '<input type="checkbox" checked={true} />',
47-
options: [{ ignoreMissingProperties: false }],
47+
options: [{ ignoreMissingProperties: true }],
4848
},
4949
{
5050
code: '<input type="checkbox" onChange={noop} checked defaultChecked />',
51-
options: [{ ignoreExclusiveCheckedAttribute: false }],
51+
options: [{ ignoreExclusiveCheckedAttribute: true }],
5252
},
5353
{
5454
code: '<input type="checkbox" onChange={noop} checked={true} defaultChecked />',
55-
options: [{ ignoreExclusiveCheckedAttribute: false }],
55+
options: [{ ignoreExclusiveCheckedAttribute: true }],
56+
},
57+
{
58+
code: '<input type="checkbox" onChange={noop} checked defaultChecked />',
59+
options: [{ ignoreMissingProperties: true, ignoreExclusiveCheckedAttribute: true }],
5660
},
5761
'<span/>',
5862
"React.createElement('span')",
@@ -99,13 +103,21 @@ ruleTester.run('checked-requires-onchange-or-readonly', rule, {
99103
},
100104
{
101105
code: '<input type="checkbox" checked defaultChecked />',
102-
options: [{ ignoreMissingProperties: false }],
106+
options: [{ ignoreMissingProperties: true }],
103107
errors: [{ messageId: 'exclusiveCheckedAttribute' }],
104108
},
105109
{
106110
code: '<input type="checkbox" checked defaultChecked />',
107-
options: [{ ignoreExclusiveCheckedAttribute: false }],
111+
options: [{ ignoreExclusiveCheckedAttribute: true }],
108112
errors: [{ messageId: 'missingProperty' }],
109113
},
114+
{
115+
code: '<input type="checkbox" checked defaultChecked />',
116+
options: [{ ignoreMissingProperties: false, ignoreExclusiveCheckedAttribute: false }],
117+
errors: [
118+
{ messageId: 'exclusiveCheckedAttribute' },
119+
{ messageId: 'missingProperty' },
120+
],
121+
},
110122
]),
111123
});

0 commit comments

Comments
 (0)