jsx-closing-tag-location.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @fileoverview Validate closing tag location in JSX
  3. * @author Ross Solomon
  4. */
  5. 'use strict';
  6. // ------------------------------------------------------------------------------
  7. // Requirements
  8. // ------------------------------------------------------------------------------
  9. const rule = require('../../../lib/rules/jsx-closing-tag-location');
  10. const RuleTester = require('eslint').RuleTester;
  11. const parserOptions = {
  12. sourceType: 'module',
  13. ecmaFeatures: {
  14. jsx: true
  15. }
  16. };
  17. const MESSAGE_MATCH_INDENTATION = [{message: 'Expected closing tag to match indentation of opening.'}];
  18. const MESSAGE_OWN_LINE = [{message: 'Closing tag of a multiline JSX expression must be on its own line.'}];
  19. // ------------------------------------------------------------------------------
  20. // Tests
  21. // ------------------------------------------------------------------------------
  22. const ruleTester = new RuleTester({parserOptions});
  23. ruleTester.run('jsx-closing-tag-location', rule, {
  24. valid: [{
  25. code: `
  26. <App>
  27. foo
  28. </App>
  29. `
  30. }, {
  31. code: `
  32. <App>foo</App>
  33. `
  34. }],
  35. invalid: [{
  36. code: `
  37. <App>
  38. foo
  39. </App>
  40. `,
  41. output: `
  42. <App>
  43. foo
  44. </App>
  45. `,
  46. errors: MESSAGE_MATCH_INDENTATION
  47. }, {
  48. code: `
  49. <App>
  50. foo</App>
  51. `,
  52. output: `
  53. <App>
  54. foo
  55. </App>
  56. `,
  57. errors: MESSAGE_OWN_LINE
  58. }]
  59. });