Skip to content

Commit 6ca6930

Browse files
authored
Add missing option (#55)
* Add missing option * Add test for invalid use of Readonly * Add test for explicit useExperimentalTypeScriptSyntax: false
1 parent df0d78c commit 6ca6930

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/rules/requireReadonlyReactProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const isReadOnlyType = (node, options) => (
8282
const create = (context) => {
8383
const useImplicitExactTypes = _.get(context, ['options', 0, 'useImplicitExactTypes'], false);
8484
const useExperimentalTypeScriptSyntax = _.get(context, ['options', 0, 'useExperimentalTypeScriptSyntax'], false);
85-
const options = { useImplicitExactTypes };
85+
const options = { useImplicitExactTypes, useExperimentalTypeScriptSyntax };
8686

8787
const readOnlyTypes = [];
8888
const foundTypes = [];

tests/rules/assertions/requireReadonlyReactProps.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ export default {
2323
},
2424
],
2525
},
26+
{
27+
code: 'type Props = Readonly<{ }>; class Foo extends React.Component<Props> { }',
28+
errors: [
29+
{
30+
message: 'Props must be $ReadOnly',
31+
},
32+
],
33+
options: [
34+
{
35+
useExperimentalTypeScriptSyntax: false,
36+
},
37+
],
38+
},
39+
{
40+
code: 'type Props = Readonly<{ }>; class Foo extends React.Component<Props> { }',
41+
errors: [
42+
{
43+
message: 'Props must be $ReadOnly',
44+
},
45+
],
46+
},
2647
{
2748
code: 'type OtherProps = { foo: string }; class Foo extends React.Component<OtherProps> { }',
2849
errors: [
@@ -149,6 +170,37 @@ export default {
149170
},
150171
],
151172
},
173+
{
174+
// vvvvv
175+
code: 'type Props = Readonly<{ }>; function Foo(props: Props) { return <p /> }',
176+
errors: [
177+
{
178+
column: 49,
179+
endColumn: 54,
180+
endLine: 1,
181+
line: 1,
182+
message: 'Props must be $ReadOnly',
183+
},
184+
],
185+
options: [
186+
{
187+
useExperimentalTypeScriptSyntax: false,
188+
},
189+
],
190+
},
191+
{
192+
// vvvvv
193+
code: 'type Props = Readonly<{ }>; function Foo(props: Props) { return <p /> }',
194+
errors: [
195+
{
196+
column: 49,
197+
endColumn: 54,
198+
endLine: 1,
199+
line: 1,
200+
message: 'Props must be $ReadOnly',
201+
},
202+
],
203+
},
152204
{
153205
code: 'type Props = { }; function Foo(props: Props) { return foo ? <p /> : <span /> }',
154206
errors: [

0 commit comments

Comments
 (0)