eslint-plugin-formatjs 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/index.d.ts +22 -0
  2. package/index.d.ts.map +1 -0
  3. package/index.js +38 -0
  4. package/package.json +3 -3
  5. package/rules/blocklist-elements.d.ts +4 -0
  6. package/rules/blocklist-elements.d.ts.map +1 -0
  7. package/rules/blocklist-elements.js +127 -0
  8. package/rules/enforce-default-message.d.ts +4 -0
  9. package/rules/enforce-default-message.d.ts.map +1 -0
  10. package/rules/enforce-default-message.js +57 -0
  11. package/rules/enforce-description.d.ts +4 -0
  12. package/rules/enforce-description.d.ts.map +1 -0
  13. package/rules/enforce-description.js +54 -0
  14. package/rules/enforce-id.d.ts +4 -0
  15. package/rules/enforce-id.d.ts.map +1 -0
  16. package/rules/enforce-id.js +125 -0
  17. package/rules/enforce-placeholders.d.ts +4 -0
  18. package/rules/enforce-placeholders.d.ts.map +1 -0
  19. package/rules/enforce-placeholders.js +118 -0
  20. package/rules/enforce-plural-rules.d.ts +4 -0
  21. package/rules/enforce-plural-rules.d.ts.map +1 -0
  22. package/rules/enforce-plural-rules.js +104 -0
  23. package/rules/no-camel-case.d.ts +4 -0
  24. package/rules/no-camel-case.d.ts.map +1 -0
  25. package/rules/no-camel-case.js +77 -0
  26. package/rules/no-complex-selectors.d.ts +4 -0
  27. package/rules/no-complex-selectors.d.ts.map +1 -0
  28. package/rules/no-complex-selectors.js +99 -0
  29. package/rules/no-emoji.d.ts +4 -0
  30. package/rules/no-emoji.d.ts.map +1 -0
  31. package/rules/no-emoji.js +47 -0
  32. package/rules/no-id.d.ts +4 -0
  33. package/rules/no-id.d.ts.map +1 -0
  34. package/rules/no-id.js +52 -0
  35. package/rules/no-invalid-icu.d.ts +4 -0
  36. package/rules/no-invalid-icu.d.ts.map +1 -0
  37. package/rules/no-invalid-icu.js +54 -0
  38. package/rules/no-literal-string-in-jsx.d.ts +4 -0
  39. package/rules/no-literal-string-in-jsx.d.ts.map +1 -0
  40. package/rules/no-literal-string-in-jsx.js +166 -0
  41. package/rules/no-multiple-plurals.d.ts +4 -0
  42. package/rules/no-multiple-plurals.d.ts.map +1 -0
  43. package/rules/no-multiple-plurals.js +71 -0
  44. package/rules/no-multiple-whitespaces.d.ts +4 -0
  45. package/rules/no-multiple-whitespaces.d.ts.map +1 -0
  46. package/rules/no-multiple-whitespaces.js +146 -0
  47. package/rules/no-offset.d.ts +4 -0
  48. package/rules/no-offset.d.ts.map +1 -0
  49. package/rules/no-offset.js +70 -0
  50. package/util.d.ts +24 -0
  51. package/util.d.ts.map +1 -0
  52. package/util.js +240 -0
  53. package/BUILD +0 -89
  54. package/CHANGELOG.md +0 -892
  55. package/index.ts +0 -38
  56. package/rules/blocklist-elements.ts +0 -159
  57. package/rules/enforce-default-message.ts +0 -71
  58. package/rules/enforce-description.ts +0 -68
  59. package/rules/enforce-id.ts +0 -171
  60. package/rules/enforce-placeholders.ts +0 -161
  61. package/rules/enforce-plural-rules.ts +0 -134
  62. package/rules/no-camel-case.ts +0 -97
  63. package/rules/no-complex-selectors.ts +0 -125
  64. package/rules/no-emoji.ts +0 -60
  65. package/rules/no-id.ts +0 -63
  66. package/rules/no-invalid-icu.ts +0 -69
  67. package/rules/no-literal-string-in-jsx.ts +0 -213
  68. package/rules/no-multiple-plurals.ts +0 -89
  69. package/rules/no-multiple-whitespaces.ts +0 -194
  70. package/rules/no-offset.ts +0 -88
  71. package/tests/blocklist-elements.test.ts +0 -120
  72. package/tests/enforce-default-message.test.ts +0 -260
  73. package/tests/enforce-description.test.ts +0 -117
  74. package/tests/enforce-id.test.ts +0 -209
  75. package/tests/enforce-placeholders.test.ts +0 -170
  76. package/tests/enforce-plural-rules.test.ts +0 -86
  77. package/tests/fixtures.ts +0 -15
  78. package/tests/no-camel-case.test.ts +0 -31
  79. package/tests/no-complex-selectors.test.ts +0 -125
  80. package/tests/no-id.test.ts +0 -151
  81. package/tests/no-invalid-icu.test.ts +0 -106
  82. package/tests/no-literal-string-in-jsx.test.ts +0 -213
  83. package/tests/no-multiple-plurals.test.ts +0 -42
  84. package/tests/no-multiple-whitespaces.test.ts +0 -100
  85. package/tests/no-offset.test.ts +0 -41
  86. package/tests/util.ts +0 -26
  87. package/tsconfig.json +0 -5
  88. package/util.ts +0 -307
@@ -1,213 +0,0 @@
1
- import noLiteralStringInJsx from '../rules/no-literal-string-in-jsx'
2
- import {ruleTester} from './util'
3
-
4
- ruleTester.run('no-literal-string-in-jsx', noLiteralStringInJsx, {
5
- valid: [
6
- {
7
- code: '<FormattedMessage defaultMessage="Test" />',
8
- },
9
- {
10
- code: '<div aria-label={f("label")} />',
11
- },
12
- {
13
- code: '<img alt={f("alt")} />',
14
- },
15
- {
16
- code: '<div>{f("message")}</div>',
17
- },
18
- // Excluded built-in img alt attribute check
19
- {
20
- code: '<img alt="alt" />',
21
- options: [
22
- {
23
- props: {
24
- exclude: [['img', 'alt']],
25
- },
26
- },
27
- ],
28
- },
29
- // Excluded built-in aria-label check.
30
- {
31
- code: `
32
- <>
33
- <Foo aria-label="test" />
34
- <Bar aria-label="test" />
35
- </>
36
- `,
37
- options: [
38
- {
39
- props: {
40
- exclude: [['*', 'aria-label']],
41
- },
42
- },
43
- ],
44
- },
45
- // Exclusion works on member expression and type parameters
46
- {
47
- code: '<UI.Button<T> aria-label="test" />',
48
- options: [
49
- {
50
- props: {
51
- exclude: [['*', 'aria-label']],
52
- },
53
- },
54
- ],
55
- },
56
- // Exclusion overrides inclusion
57
- {
58
- code: '<UI.Button<T> name="test" />',
59
- options: [
60
- {
61
- props: {
62
- include: [['*', 'name']],
63
- exclude: [['UI.Button', 'name']],
64
- },
65
- },
66
- ],
67
- },
68
- {
69
- code: '<input type="text" placeholder={f("foo")} aria-label={f("bar")} />',
70
- },
71
- {
72
- code: `
73
- <Component
74
- aria-label={intl.formatMessage({defaultMessage: "test"})}
75
- name={intl.formatMessage({defaultMessage: "test"})}
76
- >
77
- <FormattedMessage defaultMessage="test" />
78
- </Component>
79
- `,
80
- options: [
81
- {
82
- props: {
83
- include: [['Component', 'name']],
84
- },
85
- },
86
- ],
87
- },
88
- ],
89
- invalid: [
90
- {
91
- code: '<h1>Test</h1>',
92
- errors: [{message: 'Cannot have untranslated text in JSX'}],
93
- },
94
- {
95
- code: '<img src="/example.png" alt="Example" />',
96
- errors: [{message: 'Cannot have untranslated text in JSX'}],
97
- },
98
- {
99
- code: '<img src="/example.png" alt={"Example"} />',
100
- errors: [{message: 'Cannot have untranslated text in JSX'}],
101
- },
102
- {
103
- code: '<img src="/example.png" alt={"Exa" + `mple`} />',
104
- errors: [
105
- {message: 'Cannot have untranslated text in JSX'},
106
- {message: 'Cannot have untranslated text in JSX'},
107
- ],
108
- },
109
- {
110
- code: '<img src="/example.png" alt={`Example`} />',
111
- errors: [{message: 'Cannot have untranslated text in JSX'}],
112
- },
113
- {
114
- code: '<div title="title" />',
115
- errors: [{message: 'Cannot have untranslated text in JSX'}],
116
- },
117
- {
118
- code: '<div title="title">text</div>',
119
- errors: [
120
- {message: 'Cannot have untranslated text in JSX'},
121
- {message: 'Cannot have untranslated text in JSX'},
122
- ],
123
- },
124
- {
125
- code: '<div aria-label="test">test</div>',
126
- errors: [
127
- {message: 'Cannot have untranslated text in JSX'},
128
- {message: 'Cannot have untranslated text in JSX'},
129
- ],
130
- },
131
- {
132
- code: '<div aria-description="test">test</div>',
133
- errors: [
134
- {message: 'Cannot have untranslated text in JSX'},
135
- {message: 'Cannot have untranslated text in JSX'},
136
- ],
137
- },
138
- {
139
- code: '<div>{"foo"}</div>',
140
- errors: [{message: 'Cannot have untranslated text in JSX'}],
141
- },
142
- {
143
- code: `
144
- <div>
145
- {\`foo\` + x}
146
- bar
147
- {'baz' + 'qux'}
148
- </div>
149
- `,
150
- errors: [
151
- {message: 'Cannot have untranslated text in JSX'},
152
- {message: 'Cannot have untranslated text in JSX'},
153
- {message: 'Cannot have untranslated text in JSX'},
154
- {message: 'Cannot have untranslated text in JSX'},
155
- ],
156
- },
157
- {
158
- code: `
159
- <div>
160
- foo
161
- <div>
162
- bar
163
- </div>
164
- </div>
165
- `,
166
- errors: [
167
- {message: 'Cannot have untranslated text in JSX'},
168
- {message: 'Cannot have untranslated text in JSX'},
169
- ],
170
- },
171
- // Inclusion works
172
- {
173
- code: '<UI.Button<T> name="test" />',
174
- options: [
175
- {
176
- props: {
177
- include: [['UI.Button', 'name']],
178
- },
179
- },
180
- ],
181
- errors: [{message: 'Cannot have untranslated text in JSX'}],
182
- },
183
- {
184
- code: '<UI.Button<T> name="test" />',
185
- options: [
186
- {
187
- props: {
188
- include: [['*', 'name']],
189
- // Exclude should match the entire member expression. So this one is a miss.
190
- exclude: [['Button', 'name']],
191
- },
192
- },
193
- ],
194
- errors: [{message: 'Cannot have untranslated text in JSX'}],
195
- },
196
- // Multiple
197
- {
198
- code: '<UI.Button<T> aria-label={`label`} aria-description="description">Child</UI.Button>',
199
- errors: [
200
- {message: 'Cannot have untranslated text in JSX'},
201
- {message: 'Cannot have untranslated text in JSX'},
202
- {message: 'Cannot have untranslated text in JSX'},
203
- ],
204
- },
205
- {
206
- code: '<input type="text" placeholder="foo" aria-label="bar" />',
207
- errors: [
208
- {message: 'Cannot have untranslated text in JSX'},
209
- {message: 'Cannot have untranslated text in JSX'},
210
- ],
211
- },
212
- ],
213
- })
@@ -1,42 +0,0 @@
1
- import noMultiplePlurals from '../rules/no-multiple-plurals'
2
- import {ruleTester} from './util'
3
- import {dynamicMessage, noMatch, spreadJsx, emptyFnCall} from './fixtures'
4
- ruleTester.run('no-multiple-plurals', noMultiplePlurals, {
5
- valid: [
6
- `import {defineMessage} from 'react-intl'
7
- defineMessage({
8
- defaultMessage: 'a {placeholder}',
9
- description: 'asd'
10
- })`,
11
- dynamicMessage,
12
- noMatch,
13
- spreadJsx,
14
- emptyFnCall,
15
- ],
16
- invalid: [
17
- {
18
- code: `
19
- import {defineMessage} from 'react-intl'
20
- defineMessage({
21
- defaultMessage: '{p1, plural, one{one} other{other}} {p2, plural, one{two} other{other}}'
22
- })`,
23
- errors: [
24
- {
25
- message: 'Cannot specify more than 1 plural rules',
26
- },
27
- ],
28
- },
29
- {
30
- code: `
31
- import {defineMessage} from 'react-intl'
32
- defineMessage({
33
- defaultMessage: '{p1, plural, one{{p2, plural, one{two} other{other}}} other{other}}'
34
- })`,
35
- errors: [
36
- {
37
- message: 'Cannot specify more than 1 plural rules',
38
- },
39
- ],
40
- },
41
- ],
42
- })
@@ -1,100 +0,0 @@
1
- import noMultipleWhitespaces from '../rules/no-multiple-whitespaces'
2
- import {ruleTester} from './util'
3
- import {dynamicMessage, noMatch, spreadJsx, emptyFnCall} from './fixtures'
4
- ruleTester.run('no-multiple-whitespaces', noMultipleWhitespaces, {
5
- valid: [
6
- `import {defineMessage} from 'react-intl'
7
- defineMessage({
8
- defaultMessage: 'a {placeholder}',
9
- description: 'asd'
10
- })`,
11
- dynamicMessage,
12
- noMatch,
13
- spreadJsx,
14
- emptyFnCall,
15
- `
16
- import {defineMessage} from 'react-intl'
17
- defineMessage({
18
- defaultMessage: \`a {
19
- b, select,
20
- c {d}
21
- other {e}
22
- }\`
23
- })
24
- `,
25
- ],
26
- invalid: [
27
- {
28
- code: "import {defineMessage} from 'react-intl';defineMessage({defaultMessage: 'a \
29
- {placeHolder}'})",
30
- errors: [
31
- {
32
- message: 'Multiple consecutive whitespaces are not allowed',
33
- },
34
- ],
35
- output: `import {defineMessage} from 'react-intl';defineMessage({defaultMessage: "a {placeHolder}"})`,
36
- },
37
- {
38
- code: "<FormattedMessage defaultMessage='a thing'/>",
39
- errors: [
40
- {
41
- message: 'Multiple consecutive whitespaces are not allowed',
42
- },
43
- ],
44
- output: `<FormattedMessage defaultMessage="a thing"/>`,
45
- },
46
- {
47
- code: `
48
- import {defineMessage} from 'react-intl'
49
- defineMessage({
50
- defaultMessage: 'a {placeHolder}'
51
- })`,
52
- errors: [
53
- {
54
- message: 'Multiple consecutive whitespaces are not allowed',
55
- },
56
- ],
57
- output: `
58
- import {defineMessage} from 'react-intl'
59
- defineMessage({
60
- defaultMessage: "a {placeHolder}"
61
- })`,
62
- },
63
- {
64
- code: `
65
- import {defineMessage} from 'react-intl'
66
- defineMessage({
67
- defaultMessage: \`hello {a, select,
68
- b {{c, plural, one { d} other { #}}}
69
- other {e}
70
- }\`
71
- })
72
- `,
73
- errors: [
74
- {
75
- message: 'Multiple consecutive whitespaces are not allowed',
76
- },
77
- ],
78
- output: `
79
- import {defineMessage} from 'react-intl'
80
- defineMessage({
81
- defaultMessage: \`hello {a, select,
82
- b {{c, plural, one { d} other { #}}}
83
- other {e}
84
- }\`
85
- })
86
- `,
87
- },
88
- // Backslash escapes in the template literals
89
- {
90
- code: "import {defineMessage} from 'react-intl';defineMessage({defaultMessage: `a\\\\ \\` {placeHolder}`})",
91
- errors: [
92
- {
93
- message: 'Multiple consecutive whitespaces are not allowed',
94
- },
95
- ],
96
- output:
97
- "import {defineMessage} from 'react-intl';defineMessage({defaultMessage: `a\\\\ \\` {placeHolder}`})",
98
- },
99
- ],
100
- })
@@ -1,41 +0,0 @@
1
- import noOffset from '../rules/no-offset'
2
- import {ruleTester} from './util'
3
- import {dynamicMessage, noMatch, spreadJsx, emptyFnCall} from './fixtures'
4
- ruleTester.run('no-offset', noOffset, {
5
- valid: [
6
- `import {defineMessage} from 'react-intl'
7
- defineMessage({
8
- defaultMessage: '{count, plural, one {#} other {# more}}'
9
- })`,
10
- dynamicMessage,
11
- noMatch,
12
- spreadJsx,
13
- emptyFnCall,
14
- ],
15
- invalid: [
16
- {
17
- code: `
18
- import {defineMessage} from 'react-intl'
19
- defineMessage({
20
- defaultMessage: '{count, plural, offset:1 one {#} other {# more}}'
21
- })`,
22
- errors: [
23
- {
24
- message: 'offset are not allowed in plural rules',
25
- },
26
- ],
27
- },
28
- {
29
- code: `
30
- import {defineMessage} from 'react-intl'
31
- defineMessage({
32
- defaultMessage: '{count, plural, offset:1 one {#} other {# more}'
33
- })`,
34
- errors: [
35
- {
36
- message: 'EXPECT_ARGUMENT_CLOSING_BRACE',
37
- },
38
- ],
39
- },
40
- ],
41
- })
package/tests/util.ts DELETED
@@ -1,26 +0,0 @@
1
- import {RuleTester} from 'eslint'
2
-
3
- export const ruleTester = new RuleTester({
4
- parser: require.resolve('@typescript-eslint/parser'),
5
- parserOptions: {
6
- ecmaVersion: 6,
7
- sourceType: 'module',
8
- ecmaFeatures: {
9
- modules: true,
10
- jsx: true,
11
- },
12
- },
13
- })
14
-
15
- export const vueRuleTester = new RuleTester({
16
- parser: require.resolve('vue-eslint-parser'),
17
- parserOptions: {
18
- ecmaVersion: 6,
19
- sourceType: 'module',
20
- ecmaFeatures: {
21
- globalReturn: false,
22
- impliedStrict: false,
23
- jsx: false,
24
- },
25
- },
26
- })
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- // @generated
2
- {
3
- // This is purely for IDE, not for compilation
4
- "extends": "../../tsconfig.json"
5
- }