prefer-array-index-of.js 886 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const simpleArraySearchRule = require('./shared/simple-array-search-rule.js');
  3. const indexOfOverFindIndexRule = simpleArraySearchRule({
  4. method: 'findIndex',
  5. replacement: 'indexOf',
  6. });
  7. const lastIndexOfOverFindLastIndexRule = simpleArraySearchRule({
  8. method: 'findLastIndex',
  9. replacement: 'lastIndexOf',
  10. });
  11. /** @type {import('eslint').Rule.RuleModule} */
  12. module.exports = {
  13. create: context => ({
  14. ...indexOfOverFindIndexRule.createListeners(context),
  15. ...lastIndexOfOverFindLastIndexRule.createListeners(context),
  16. }),
  17. meta: {
  18. type: 'suggestion',
  19. docs: {
  20. description: 'Prefer `Array#{indexOf,lastIndexOf}()` over `Array#{findIndex,findLastIndex}()` when looking for the index of an item.',
  21. },
  22. fixable: 'code',
  23. hasSuggestions: true,
  24. messages: {
  25. ...indexOfOverFindIndexRule.messages,
  26. ...lastIndexOfOverFindLastIndexRule.messages,
  27. },
  28. },
  29. };