Skip to content

Commit

Permalink
Fix/require exact type nested (#442)
Browse files Browse the repository at this point in the history
* fix: require-exact-type for interfaces

* fix: require-exact-type for interfaces, add more tests
  • Loading branch information
Marcosld authored Mar 28, 2020
1 parent 0fa8d62 commit 58d8f91
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/requireExactType.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const create = (context) => {
ObjectTypeAnnotation (node) {
const {exact, indexers} = node;

if (always && !exact && indexers.length === 0) {
if (node.parent.type !== 'InterfaceDeclaration' && always && !exact && indexers.length === 0) {
context.report({
fix: (fixer) => {
return [
Expand Down
72 changes: 72 additions & 0 deletions tests/rules/assertions/requireExactType.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ export default {
options: ['always'],
output: '(foo: Array<{|bar: string|}>) => {};',
},
{
code: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: { name: string };
}`,
errors: [
{
message: 'Object type must be exact.',
},
],
options: ['always'],
output: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: {| name: string |};
}`,
},

// Never

Expand Down Expand Up @@ -93,6 +113,26 @@ export default {
options: ['never'],
output: '(foo: Array<{ bar: string }>) => {};',
},
{
code: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: {| name: string |};
}`,
errors: [
{
message: 'Object type must not be exact.',
},
],
options: ['never'],
output: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: { name: string };
}`,
},
],
valid: [

Expand Down Expand Up @@ -131,6 +171,22 @@ export default {
options: ['always'],
},

{
code: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: {| name: string |};
}`,
options: ['always'],
output: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: {| name: string |};
}`,
},

// Never

{
Expand All @@ -153,5 +209,21 @@ export default {
code: 'type foo = number;',
options: ['never'],
},

{
code: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: {| name: string |};
}`,
options: ['always'],
output: `interface StackFrame {
colno?: number;
lineno?: number;
filename?: string;
function?: {| name: string |};
}`,
},
],
};

0 comments on commit 58d8f91

Please sign in to comment.