|
| 1 | +/** |
| 2 | + * @fileoverview Limit maximum of props on a single line in JSX |
| 3 | + * @author Yannick Croissant |
| 4 | + */ |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +// ------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +var eslint = require('eslint').linter; |
| 12 | +var ESLintTester = require('eslint').ESLintTester; |
| 13 | + |
| 14 | +// ------------------------------------------------------------------------------ |
| 15 | +// Tests |
| 16 | +// ------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +var eslintTester = new ESLintTester(eslint); |
| 19 | +eslintTester.addRuleTest('lib/rules/jsx-max-props-per-line', { |
| 20 | + valid: [{ |
| 21 | + code: '<App foo />', |
| 22 | + ecmaFeatures: {jsx: true} |
| 23 | + }, { |
| 24 | + code: '<App foo bar />', |
| 25 | + options: [{maximum: 2}], |
| 26 | + ecmaFeatures: {jsx: true} |
| 27 | + }, { |
| 28 | + code: '<App {...this.props} bar />', |
| 29 | + options: [{maximum: 2}], |
| 30 | + ecmaFeatures: {jsx: true} |
| 31 | + }, { |
| 32 | + code: [ |
| 33 | + '<App', |
| 34 | + ' foo', |
| 35 | + ' bar', |
| 36 | + '/>' |
| 37 | + ].join('\n'), |
| 38 | + ecmaFeatures: {jsx: true} |
| 39 | + }, { |
| 40 | + code: [ |
| 41 | + '<App', |
| 42 | + ' foo bar', |
| 43 | + ' baz', |
| 44 | + '/>' |
| 45 | + ].join('\n'), |
| 46 | + options: [{maximum: 2}], |
| 47 | + ecmaFeatures: {jsx: true} |
| 48 | + }], |
| 49 | + |
| 50 | + invalid: [{ |
| 51 | + code: '<App foo bar baz />;', |
| 52 | + errors: [{message: 'Prop `bar` must be placed on a new line'}], |
| 53 | + ecmaFeatures: {jsx: true} |
| 54 | + }, { |
| 55 | + code: '<App foo bar baz />;', |
| 56 | + options: [{maximum: 2}], |
| 57 | + errors: [{message: 'Prop `baz` must be placed on a new line'}], |
| 58 | + ecmaFeatures: {jsx: true} |
| 59 | + }, { |
| 60 | + code: '<App {...this.props} bar />;', |
| 61 | + errors: [{message: 'Prop `bar` must be placed on a new line'}], |
| 62 | + ecmaFeatures: {jsx: true} |
| 63 | + }, { |
| 64 | + code: '<App bar {...this.props} />;', |
| 65 | + errors: [{message: 'Prop `this.props` must be placed on a new line'}], |
| 66 | + ecmaFeatures: {jsx: true} |
| 67 | + }, { |
| 68 | + code: [ |
| 69 | + '<App', |
| 70 | + ' foo bar', |
| 71 | + ' baz', |
| 72 | + '/>' |
| 73 | + ].join('\n'), |
| 74 | + errors: [{message: 'Prop `bar` must be placed on a new line'}], |
| 75 | + ecmaFeatures: {jsx: true} |
| 76 | + }, { |
| 77 | + code: [ |
| 78 | + '<App', |
| 79 | + ' foo {...this.props}', |
| 80 | + ' baz', |
| 81 | + '/>' |
| 82 | + ].join('\n'), |
| 83 | + errors: [{message: 'Prop `this.props` must be placed on a new line'}], |
| 84 | + ecmaFeatures: {jsx: true} |
| 85 | + }] |
| 86 | +}); |
0 commit comments