diff --git a/src/rules/requireExactType.js b/src/rules/requireExactType.js index 1039bd45..c49975dc 100644 --- a/src/rules/requireExactType.js +++ b/src/rules/requireExactType.js @@ -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 [ diff --git a/tests/rules/assertions/requireExactType.js b/tests/rules/assertions/requireExactType.js index fe4fb511..26ff36a1 100644 --- a/tests/rules/assertions/requireExactType.js +++ b/tests/rules/assertions/requireExactType.js @@ -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 |}; + }`, + }, ], };