123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- /**
- * @fileoverview Validate props indentation in JSX
- * @author Yannick Croissant
- */
- 'use strict';
- // ------------------------------------------------------------------------------
- // Requirements
- // ------------------------------------------------------------------------------
- const rule = require('../../../lib/rules/jsx-indent-props');
- const RuleTester = require('eslint').RuleTester;
- const parserOptions = {
- ecmaVersion: 2018,
- sourceType: 'module',
- ecmaFeatures: {
- jsx: true
- }
- };
- // ------------------------------------------------------------------------------
- // Tests
- // ------------------------------------------------------------------------------
- const ruleTester = new RuleTester({parserOptions});
- ruleTester.run('jsx-indent-props', rule, {
- valid: [{
- code: [
- '<App foo',
- '/>'
- ].join('\n')
- }, {
- code: [
- '<App',
- ' foo',
- '/>'
- ].join('\n'),
- options: [2]
- }, {
- code: [
- '<App',
- 'foo',
- '/>'
- ].join('\n'),
- options: [0]
- }, {
- code: [
- ' <App',
- 'foo',
- ' />'
- ].join('\n'),
- options: [-2]
- }, {
- code: [
- '<App',
- '\tfoo',
- '/>'
- ].join('\n'),
- options: ['tab']
- }, {
- code: [
- '<App/>'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- '<App aaa',
- ' b',
- ' cc',
- '/>'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- '<App aaa',
- ' b',
- ' cc',
- '/>'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- 'const test = <App aaa',
- ' b',
- ' cc',
- ' />'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- '<App aaa x',
- ' b y',
- ' cc',
- '/>'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- 'const test = <App aaa x',
- ' b y',
- ' cc',
- ' />'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- '<App aaa',
- ' b',
- '>',
- ' <Child c',
- ' d/>',
- '</App>'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- '<Fragment>',
- ' <App aaa',
- ' b',
- ' cc',
- ' />',
- ' <OtherApp a',
- ' bbb',
- ' c',
- ' />',
- '</Fragment>'
- ].join('\n'),
- options: ['first']
- }, {
- code: [
- '<App',
- ' a',
- ' b',
- '/>'
- ].join('\n'),
- options: ['first']
- }],
- invalid: [{
- code: [
- '<App',
- ' foo',
- '/>'
- ].join('\n'),
- output: [
- '<App',
- ' foo',
- '/>'
- ].join('\n'),
- errors: [{message: 'Expected indentation of 4 space characters but found 2.'}]
- }, {
- code: [
- '<App',
- ' foo',
- '/>'
- ].join('\n'),
- output: [
- '<App',
- ' foo',
- '/>'
- ].join('\n'),
- options: [2],
- errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
- }, {
- code: [
- '<App',
- ' foo',
- '/>'
- ].join('\n'),
- output: [
- '<App',
- '\tfoo',
- '/>'
- ].join('\n'),
- options: ['tab'],
- errors: [{message: 'Expected indentation of 1 tab character but found 0.'}]
- }, {
- code: [
- '<App',
- '\t\t\tfoo',
- '/>'
- ].join('\n'),
- output: [
- '<App',
- '\tfoo',
- '/>'
- ].join('\n'),
- options: ['tab'],
- errors: [{message: 'Expected indentation of 1 tab character but found 3.'}]
- }, {
- code: [
- '<App a',
- ' b',
- '/>'
- ].join('\n'),
- output: [
- '<App a',
- ' b',
- '/>'
- ].join('\n'),
- options: ['first'],
- errors: [{message: 'Expected indentation of 5 space characters but found 2.'}]
- }, {
- code: [
- '<App a',
- ' b',
- '/>'
- ].join('\n'),
- output: [
- '<App a',
- ' b',
- '/>'
- ].join('\n'),
- options: ['first'],
- errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
- }, {
- code: [
- '<App',
- ' a',
- ' b',
- '/>'
- ].join('\n'),
- output: [
- '<App',
- ' a',
- ' b',
- '/>'
- ].join('\n'),
- options: ['first'],
- errors: [{message: 'Expected indentation of 6 space characters but found 3.'}]
- }, {
- code: [
- '<App',
- ' a',
- ' b',
- ' c',
- '/>'
- ].join('\n'),
- output: [
- '<App',
- ' a',
- ' b',
- ' c',
- '/>'
- ].join('\n'),
- options: ['first'],
- errors: [
- {message: 'Expected indentation of 2 space characters but found 1.'},
- {message: 'Expected indentation of 2 space characters but found 3.'}
- ]
- }]
- });
|