Skip to content

Commit

Permalink
feat: add --fix support to require-indexer-name (#426)
Browse files Browse the repository at this point in the history
* Add fix to require-indexer-name

* update require-indexer-name docs
  • Loading branch information
goodmind authored and gajus committed Aug 9, 2019
1 parent 83b48d5 commit 72a8a55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .README/rules/require-indexer-name.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/rules/requireIndexerName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down

0 comments on commit 72a8a55

Please sign in to comment.