-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
jsx-pascal-case.js
142 lines (134 loc) · 3.82 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* @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: '<__this.TestComponent />'
}, {
code: '<$ />'
}, {
code: '<_ />'
}, {
// The rule must not warn on components with a namespace
// because this pattern is handled by jsx-no-namespace
code: '<svg:path />'
}, {
code: '<ns:testComponent />'
}, {
code: '<Ns:testComponent />'
}, {
code: '<__ns:testComponent />'
}, {
code: '<ns:TestComponent />'
}, {
code: '<Ns:TestComponent />'
}, {
code: '<__ns:TestComponent />'
}, {
code: '<Modal:Header />'
}, {
code: '<layout:Header />'
}, {
code: '<IGNORED />',
options: [{ignore: ['IGNORED']}]
}],
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: '<$a />',
errors: [{message: 'Imported JSX component $a must be in PascalCase'}]
}, {
code: '<foo.bar />',
errors: [{message: 'Imported JSX component bar must be in PascalCase'}]
}, {
code: '<object.testComponent />',
errors: [{message: 'Imported JSX component testComponent must be in PascalCase'}]
}, {
code: '<Module.testComponent />',
errors: [{message: 'Imported JSX component testComponent must be in PascalCase'}]
}, {
code: '<__this.testComponent />',
errors: [{message: 'Imported JSX component testComponent 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'}]
}]
});