Skip to content
Permalink
Browse files
Fix/require exact type nested (#442)
* fix: require-exact-type for interfaces

* fix: require-exact-type for interfaces, add more tests
  • Loading branch information
Marcosld committed Mar 28, 2020
1 parent 0fa8d62 commit 58d8f91eb2a0018c200bb4dd90b7594daaf30a9d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
@@ -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 [
@@ -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

@@ -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: [

@@ -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

{
@@ -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.