Skip to content

Commit 3ece8ed

Browse files
committed
Switch to object option
1 parent c22f7cb commit 3ece8ed

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default [
155155
- `no-duplicate-keys` - warns when there are two keys in an object with the same text.
156156
- `no-empty-keys` - warns when there is a key in an object that is an empty string or contains only whitespace (note: `package-lock.json` uses empty keys intentionally)
157157
- `no-unsafe-values` - warns on values that are unsafe for interchange, such as numbers outside safe range or lone surrogates.
158-
- `no-unnormalized-keys` - warns on keys containing [unnormalized characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize#description).
158+
- `no-unnormalized-keys` - warns on keys containing [unnormalized characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize#description). You can optionally specify the normalization form via `{ form: "form_name" }`, where `form_name` can be any of `"NFC"`, `"NFD"`, `"NFKC"`, or `"NFKD"`.
159159

160160
## Configuration Comments
161161

src/rules/no-unnormalized-keys.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@ export default {
1515
unnormalizedKey: "Unnormalized key '{{key}}' found.",
1616
},
1717

18-
schema: {
19-
type: "array",
20-
minItems: 0,
21-
maxItems: 1,
22-
items: {
23-
enum: ["NFC", "NFD", "NFKC", "NFKD"],
18+
schema: [
19+
{
20+
type: "object",
21+
properties: {
22+
form: {
23+
type: "string",
24+
enum: ["NFC", "NFD", "NFKC", "NFKD"],
25+
},
26+
},
27+
additionalProperties: false,
2428
},
25-
},
29+
],
2630
},
2731

2832
create(context) {
2933
const normalization = context.options.length
30-
? text => text.normalize(context.options[0])
34+
? text => text.normalize(context.options[0].form)
3135
: text => text.normalize();
3236
return {
3337
Member(node) {

tests/rules/no-unnormalized-keys.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ ruleTester.run("no-unnormalized-keys", rule, {
2929
`{"${o}":"NFC"}`,
3030
{
3131
code: `{"${o}":"NFC"}`,
32-
options: ["NFC"],
32+
options: [{ form: "NFC" }],
3333
},
3434
{
3535
code: `{"${o.normalize("NFD")}":"NFD"}`,
36-
options: ["NFD"],
36+
options: [{ form: "NFD" }],
3737
},
3838
{
3939
code: `{"${o.normalize("NFKC")}":"NFKC"}`,
40-
options: ["NFKC"],
40+
options: [{ form: "NFKC" }],
4141
},
4242
{
4343
code: `{"${o.normalize("NFKD")}":"NFKD"}`,
44-
options: ["NFKD"],
44+
options: [{ form: "NFKD" }],
4545
},
4646
],
4747
invalid: [
@@ -74,7 +74,7 @@ ruleTester.run("no-unnormalized-keys", rule, {
7474
},
7575
{
7676
code: `{"${o.normalize("NFKC")}":"NFKC"}`,
77-
options: ["NFKD"],
77+
options: [{ form: "NFKD" }],
7878
errors: [
7979
{
8080
messageId: "unnormalizedKey",

0 commit comments

Comments
 (0)