Skip to content

Commit

Permalink
Add missing option (#55)
Browse files Browse the repository at this point in the history
* Add missing option

* Add test for invalid use of Readonly

* Add test for explicit useExperimentalTypeScriptSyntax: false
  • Loading branch information
short-dsb committed Mar 2, 2024
1 parent df0d78c commit 6ca6930
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/requireReadonlyReactProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const isReadOnlyType = (node, options) => (
const create = (context) => {
const useImplicitExactTypes = _.get(context, ['options', 0, 'useImplicitExactTypes'], false);
const useExperimentalTypeScriptSyntax = _.get(context, ['options', 0, 'useExperimentalTypeScriptSyntax'], false);
const options = { useImplicitExactTypes };
const options = { useImplicitExactTypes, useExperimentalTypeScriptSyntax };

const readOnlyTypes = [];
const foundTypes = [];
Expand Down
52 changes: 52 additions & 0 deletions tests/rules/assertions/requireReadonlyReactProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ export default {
},
],
},
{
code: 'type Props = Readonly<{ }>; class Foo extends React.Component<Props> { }',
errors: [
{
message: 'Props must be $ReadOnly',
},
],
options: [
{
useExperimentalTypeScriptSyntax: false,
},
],
},
{
code: 'type Props = Readonly<{ }>; class Foo extends React.Component<Props> { }',
errors: [
{
message: 'Props must be $ReadOnly',
},
],
},
{
code: 'type OtherProps = { foo: string }; class Foo extends React.Component<OtherProps> { }',
errors: [
Expand Down Expand Up @@ -149,6 +170,37 @@ export default {
},
],
},
{
// vvvvv
code: 'type Props = Readonly<{ }>; function Foo(props: Props) { return <p /> }',
errors: [
{
column: 49,
endColumn: 54,
endLine: 1,
line: 1,
message: 'Props must be $ReadOnly',
},
],
options: [
{
useExperimentalTypeScriptSyntax: false,
},
],
},
{
// vvvvv
code: 'type Props = Readonly<{ }>; function Foo(props: Props) { return <p /> }',
errors: [
{
column: 49,
endColumn: 54,
endLine: 1,
line: 1,
message: 'Props must be $ReadOnly',
},
],
},
{
code: 'type Props = { }; function Foo(props: Props) { return foo ? <p /> : <span /> }',
errors: [
Expand Down

0 comments on commit 6ca6930

Please sign in to comment.