eslint-plugin-formatjs 2.21.0 → 3.0.0
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.
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +1 -1
- package/rules/{blacklist-elements.d.ts → blocklist-elements.d.ts} +1 -1
- package/rules/blocklist-elements.d.ts.map +1 -0
- package/rules/{blacklist-elements.js → blocklist-elements.js} +15 -15
- package/rules/enforce-id.js +2 -2
- package/rules/blacklist-elements.d.ts.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const plugin: {
|
|
2
2
|
rules: {
|
|
3
|
-
'
|
|
3
|
+
'blocklist-elements': import("eslint").Rule.RuleModule;
|
|
4
4
|
'enforce-default-message': import("eslint").Rule.RuleModule;
|
|
5
5
|
'enforce-description': import("eslint").Rule.RuleModule;
|
|
6
6
|
'enforce-id': import("eslint").Rule.RuleModule;
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var
|
|
4
|
+
var blocklist_elements_1 = (0, tslib_1.__importDefault)(require("./rules/blocklist-elements"));
|
|
5
5
|
var enforce_default_message_1 = (0, tslib_1.__importDefault)(require("./rules/enforce-default-message"));
|
|
6
6
|
var enforce_description_1 = (0, tslib_1.__importDefault)(require("./rules/enforce-description"));
|
|
7
7
|
var enforce_id_1 = (0, tslib_1.__importDefault)(require("./rules/enforce-id"));
|
|
@@ -16,7 +16,7 @@ var no_multiple_whitespaces_1 = (0, tslib_1.__importDefault)(require("./rules/no
|
|
|
16
16
|
var no_offset_1 = (0, tslib_1.__importDefault)(require("./rules/no-offset"));
|
|
17
17
|
var plugin = {
|
|
18
18
|
rules: {
|
|
19
|
-
'
|
|
19
|
+
'blocklist-elements': blocklist_elements_1.default,
|
|
20
20
|
'enforce-default-message': enforce_default_message_1.default,
|
|
21
21
|
'enforce-description': enforce_description_1.default,
|
|
22
22
|
'enforce-id': enforce_id_1.default,
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocklist-elements.d.ts","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-formatjs/rules/blocklist-elements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAA;AAkH3B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAyChB,CAAA;AAED,eAAe,IAAI,CAAA"}
|
|
@@ -7,7 +7,7 @@ var BlacklistElement = /** @class */ (function (_super) {
|
|
|
7
7
|
(0, tslib_1.__extends)(BlacklistElement, _super);
|
|
8
8
|
function BlacklistElement(type) {
|
|
9
9
|
var _this = _super.call(this) || this;
|
|
10
|
-
_this.message = "".concat(type, " element is
|
|
10
|
+
_this.message = "".concat(type, " element is blocklisted");
|
|
11
11
|
return _this;
|
|
12
12
|
}
|
|
13
13
|
return BlacklistElement;
|
|
@@ -24,36 +24,36 @@ var Element;
|
|
|
24
24
|
Element["plural"] = "plural";
|
|
25
25
|
Element["tag"] = "tag";
|
|
26
26
|
})(Element || (Element = {}));
|
|
27
|
-
function verifyAst(
|
|
27
|
+
function verifyAst(blocklist, ast) {
|
|
28
28
|
for (var _i = 0, ast_1 = ast; _i < ast_1.length; _i++) {
|
|
29
29
|
var el = ast_1[_i];
|
|
30
|
-
if ((0, icu_messageformat_parser_1.isLiteralElement)(el) &&
|
|
30
|
+
if ((0, icu_messageformat_parser_1.isLiteralElement)(el) && blocklist.includes(Element.literal)) {
|
|
31
31
|
throw new BlacklistElement(Element.literal);
|
|
32
32
|
}
|
|
33
|
-
if ((0, icu_messageformat_parser_1.isArgumentElement)(el) &&
|
|
33
|
+
if ((0, icu_messageformat_parser_1.isArgumentElement)(el) && blocklist.includes(Element.argument)) {
|
|
34
34
|
throw new BlacklistElement(Element.argument);
|
|
35
35
|
}
|
|
36
|
-
if ((0, icu_messageformat_parser_1.isNumberElement)(el) &&
|
|
36
|
+
if ((0, icu_messageformat_parser_1.isNumberElement)(el) && blocklist.includes(Element.number)) {
|
|
37
37
|
throw new BlacklistElement(Element.number);
|
|
38
38
|
}
|
|
39
|
-
if ((0, icu_messageformat_parser_1.isDateElement)(el) &&
|
|
39
|
+
if ((0, icu_messageformat_parser_1.isDateElement)(el) && blocklist.includes(Element.date)) {
|
|
40
40
|
throw new BlacklistElement(Element.date);
|
|
41
41
|
}
|
|
42
|
-
if ((0, icu_messageformat_parser_1.isTimeElement)(el) &&
|
|
42
|
+
if ((0, icu_messageformat_parser_1.isTimeElement)(el) && blocklist.includes(Element.time)) {
|
|
43
43
|
throw new BlacklistElement(Element.time);
|
|
44
44
|
}
|
|
45
|
-
if ((0, icu_messageformat_parser_1.isSelectElement)(el) &&
|
|
45
|
+
if ((0, icu_messageformat_parser_1.isSelectElement)(el) && blocklist.includes(Element.select)) {
|
|
46
46
|
throw new BlacklistElement(Element.select);
|
|
47
47
|
}
|
|
48
|
-
if ((0, icu_messageformat_parser_1.isTagElement)(el) &&
|
|
48
|
+
if ((0, icu_messageformat_parser_1.isTagElement)(el) && blocklist.includes(Element.tag)) {
|
|
49
49
|
throw new BlacklistElement(Element.tag);
|
|
50
50
|
}
|
|
51
51
|
if ((0, icu_messageformat_parser_1.isPluralElement)(el)) {
|
|
52
|
-
if (
|
|
52
|
+
if (blocklist.includes(Element.plural)) {
|
|
53
53
|
throw new BlacklistElement(Element.argument);
|
|
54
54
|
}
|
|
55
55
|
if (el.pluralType === 'ordinal' &&
|
|
56
|
-
|
|
56
|
+
blocklist.includes(Element.selectordinal)) {
|
|
57
57
|
throw new BlacklistElement(Element.selectordinal);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -61,7 +61,7 @@ function verifyAst(blacklist, ast) {
|
|
|
61
61
|
var options = el.options;
|
|
62
62
|
for (var _a = 0, _b = Object.keys(options); _a < _b.length; _a++) {
|
|
63
63
|
var selector = _b[_a];
|
|
64
|
-
verifyAst(
|
|
64
|
+
verifyAst(blocklist, options[selector].value);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -71,8 +71,8 @@ function checkNode(context, node) {
|
|
|
71
71
|
if (!msgs.length) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
var
|
|
75
|
-
if (!Array.isArray(
|
|
74
|
+
var blocklist = context.options[0];
|
|
75
|
+
if (!Array.isArray(blocklist) || !blocklist.length) {
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
for (var _i = 0, msgs_1 = msgs; _i < msgs_1.length; _i++) {
|
|
@@ -100,7 +100,7 @@ var rule = {
|
|
|
100
100
|
description: 'Disallow specific elements in ICU message format',
|
|
101
101
|
category: 'Errors',
|
|
102
102
|
recommended: false,
|
|
103
|
-
url: 'https://formatjs.io/docs/tooling/linter#
|
|
103
|
+
url: 'https://formatjs.io/docs/tooling/linter#blocklist-elements',
|
|
104
104
|
},
|
|
105
105
|
fixable: 'code',
|
|
106
106
|
schema: [
|
package/rules/enforce-id.js
CHANGED
|
@@ -41,7 +41,7 @@ function checkNode(context, node, _a) {
|
|
|
41
41
|
if (id !== correctId_1) {
|
|
42
42
|
var message = "\"id\" does not match with hash pattern ".concat(idInterpolationPattern);
|
|
43
43
|
if (idWhitelistRegexps) {
|
|
44
|
-
message += " or
|
|
44
|
+
message += " or allowlisted patterns [\"".concat(idWhitelistRegexps
|
|
45
45
|
.map(function (r) { return r.toString(); })
|
|
46
46
|
.join('", "'), "\"]");
|
|
47
47
|
}
|
|
@@ -93,7 +93,7 @@ exports.default = {
|
|
|
93
93
|
},
|
|
94
94
|
idWhitelist: {
|
|
95
95
|
type: 'array',
|
|
96
|
-
description: "An array of strings with regular expressions. This array allows
|
|
96
|
+
description: "An array of strings with regular expressions. This array allows allowlist custom ids for messages. For example '`\\\\.`' allows any id which has dot; `'^payment_.*'` - allows any custom id which has prefix `payment_`. Be aware that any backslash \\ provided via string must be escaped with an additional backslash.",
|
|
97
97
|
items: {
|
|
98
98
|
type: 'string',
|
|
99
99
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blacklist-elements.d.ts","sourceRoot":"","sources":["../../../../../../packages/eslint-plugin-formatjs/rules/blacklist-elements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAA;AAkH3B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAyChB,CAAA;AAED,eAAe,IAAI,CAAA"}
|