/
jsx-pascal-case.js
114 lines (106 loc) · 2.93 KB
/
jsx-pascal-case.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* @fileoverview Tests for jsx-pascal-case
* @author Jake Marsh
*/
'use strict';
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const RuleTester = require('eslint').RuleTester;
const rule = require('../../../lib/rules/jsx-pascal-case');
const parsers = require('../../helpers/parsers');
const parserOptions = {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
};
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const ruleTester = new RuleTester({parserOptions});
ruleTester.run('jsx-pascal-case', rule, {
valid: [{
// The rule must not warn on components that start with a lowercase
// because they are interpreted as HTML elements by React
code: '<testcomponent />'
}, {
code: '<testComponent />'
}, {
code: '<test_component />'
}, {
code: '<TestComponent />'
}, {
code: '<CSSTransitionGroup />'
}, {
code: '<BetterThanCSS />'
}, {
code: '<TestComponent><div /></TestComponent>'
}, {
code: '<Test1Component />'
}, {
code: '<TestComponent1 />'
}, {
code: '<T3StComp0Nent />'
}, {
code: '<Éurströmming />'
}, {
code: '<Año />'
}, {
code: '<Søknad />'
}, {
code: '<T />'
}, {
code: '<T />',
parser: parsers.BABEL_ESLINT
}, {
code: '<YMCA />',
options: [{allowAllCaps: true}]
}, {
code: '<TEST_COMPONENT />',
options: [{allowAllCaps: true}]
}, {
code: '<Modal.Header />'
}, {
code: '<qualification.T3StComp0Nent />'
}, {
code: '<Modal:Header />'
}, {
code: '<IGNORED />',
options: [{ignore: ['IGNORED']}]
}, {
code: '<$ />'
}, {
code: '<_ />'
}, {
code: '<H1>Hello!</H1>'
}, {
code: '<Typography.P />'
}],
invalid: [{
code: '<Test_component />',
errors: [{message: 'Imported JSX component Test_component must be in PascalCase'}]
}, {
code: '<TEST_COMPONENT />',
errors: [{message: 'Imported JSX component TEST_COMPONENT must be in PascalCase'}]
}, {
code: '<YMCA />',
errors: [{message: 'Imported JSX component YMCA must be in PascalCase'}]
}, {
code: '<_TEST_COMPONENT />',
options: [{allowAllCaps: true}],
errors: [{message: 'Imported JSX component _TEST_COMPONENT must be in PascalCase or SCREAMING_SNAKE_CASE'}]
}, {
code: '<TEST_COMPONENT_ />',
options: [{allowAllCaps: true}],
errors: [{message: 'Imported JSX component TEST_COMPONENT_ must be in PascalCase or SCREAMING_SNAKE_CASE'}]
}, {
code: '<__ />',
options: [{allowAllCaps: true}],
errors: [{message: 'Imported JSX component __ must be in PascalCase or SCREAMING_SNAKE_CASE'}]
}, {
code: '<$a />',
errors: [{message: 'Imported JSX component $a must be in PascalCase'}]
}]
});