diff --git a/.README/rules/require-indexer-name.md b/.README/rules/require-indexer-name.md index 220713c2..c09e5347 100644 --- a/.README/rules/require-indexer-name.md +++ b/.README/rules/require-indexer-name.md @@ -1,5 +1,7 @@ ### `require-indexer-name` +_The `--fix` option on the command line automatically fixes problems reported by this rule._ + This rule validates Flow object indexer name. #### Options diff --git a/src/rules/requireIndexerName.js b/src/rules/requireIndexerName.js index 8a872866..43ee1f02 100644 --- a/src/rules/requireIndexerName.js +++ b/src/rules/requireIndexerName.js @@ -14,8 +14,12 @@ const create = (context) => { return { ObjectTypeIndexer (node) { const id = getParameterName(node, context); + const rawKeyType = context.getSourceCode().getText(node.key); if (id === null) { context.report({ + fix (fixer) { + return fixer.replaceText(node.key, 'key: ' + rawKeyType); + }, message: 'All indexers must be declared with key name.', node, });