Skip to content

Instantly share code, notes, and snippets.

@lyleunderwood
Created December 16, 2020 22:14
Show Gist options
  • Save lyleunderwood/9ecc2408a3fb8fc8955934af3c92a477 to your computer and use it in GitHub Desktop.
Save lyleunderwood/9ecc2408a3fb8fc8955934af3c92a477 to your computer and use it in GitHub Desktop.
const unsealedObjectError = () => 'Flow interprets empty objects literals as unsealed objects,' +
' see https://git.io/fj64j';
module.exports = {
'no-unsealed-objects': {
meta: {
docs: {
description: 'no unsealed objects',
category: 'Possible Errors',
recommended: false,
},
schema: [],
fixable: 'code',
},
create: (context) => {
// ignore fixture data
const filename = context.getFilename();
if (filename.match(/fixtures/)) return { ...null };
return {
ObjectExpression: (node) => {
if (node.properties.length === 0) {
context.report({
node,
message: unsealedObjectError(),
fix: fixer => fixer.replaceText(node, '{ ...null }'),
});
}
},
};
},
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment