_common.js 579 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const errors = [ {
  2. } ];
  3. module.exports = (ruleTester, rule) => ruleTester.run('prefer-string-slice', rule, {
  4. valid: [
  5. 'foo.slice()',
  6. 'foo.slice(0)',
  7. 'foo.slice(1, 2)',
  8. 'foo.slice(-3, -2)',
  9. ],
  10. invalid: [
  11. {
  12. code: 'foo.substr()',
  13. output: 'foo.slice()',
  14. errors,
  15. },
  16. {
  17. code: '"foo".substr()',
  18. output: '"foo".slice()',
  19. errors,
  20. },
  21. {
  22. code: 'foo.substr(start)',
  23. errors,
  24. },
  25. {
  26. code: '"foo".substr(1)',
  27. errors,
  28. },
  29. {
  30. code: 'foo.substr(start, length)',
  31. errors,
  32. },
  33. {
  34. code: '"foo".substr(1, 3)',
  35. errors,
  36. },
  37. ],
  38. });