eslint-plugin-formatjs 6.3.0 → 6.4.1

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/package.json CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "eslint-plugin-formatjs",
3
3
  "description": "ESLint plugin for formatjs",
4
- "version": "6.3.0",
4
+ "version": "6.4.1",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
8
8
  "types": "index.d.ts",
9
+ "exports": {
10
+ ".": "./index.js"
11
+ },
9
12
  "dependencies": {
10
13
  "@types/picomatch": "^4.0.0",
11
14
  "@unicode/unicode-17.0.0": "^1.6.16",
12
15
  "magic-string": "^0.30.0",
13
16
  "picomatch": "2 || 3 || 4",
14
- "tslib": "^2.8.1",
15
- "@formatjs/icu-messageformat-parser": "3.5.1",
16
- "@formatjs/ts-transformer": "4.4.0"
17
+ "@formatjs/ts-transformer": "4.4.1",
18
+ "@formatjs/icu-messageformat-parser": "3.5.2"
17
19
  },
18
20
  "peerDependencies": {
19
21
  "eslint": "9 || 10"
@@ -3,5 +3,9 @@ export declare enum Option {
3
3
  literal = "literal",
4
4
  anything = "anything"
5
5
  }
6
+ export type ObjectOption = {
7
+ mode?: Option;
8
+ minLength?: number;
9
+ };
6
10
  export declare const name = "enforce-description";
7
11
  export declare const rule: Rule.RuleModule;
@@ -4,9 +4,27 @@ export let Option = /* @__PURE__ */ function(Option) {
4
4
  Option["anything"] = "anything";
5
5
  return Option;
6
6
  }({});
7
+ function normalizeOptions(raw) {
8
+ if (typeof raw === "string") {
9
+ return {
10
+ mode: raw,
11
+ minLength: undefined
12
+ };
13
+ }
14
+ if (typeof raw === "object" && raw !== null) {
15
+ return {
16
+ mode: raw.mode,
17
+ minLength: raw.minLength
18
+ };
19
+ }
20
+ return {
21
+ mode: undefined,
22
+ minLength: undefined
23
+ };
24
+ }
7
25
  function checkNode(context, node) {
8
26
  const msgs = extractMessages(node, getSettings(context));
9
- const { options: [type] } = context;
27
+ const { mode: type, minLength } = normalizeOptions(context.options[0]);
10
28
  for (const [{ message: { description }, descriptionNode, messageDescriptorNode }] of msgs) {
11
29
  if (!description) {
12
30
  if (type === "literal" && descriptionNode) {
@@ -20,6 +38,15 @@ function checkNode(context, node) {
20
38
  messageId: "enforceDescription"
21
39
  });
22
40
  }
41
+ } else if (typeof minLength === "number" && typeof description === "string" && description.length < minLength) {
42
+ context.report({
43
+ node: descriptionNode ?? messageDescriptorNode,
44
+ messageId: "enforceDescriptionMinLength",
45
+ data: {
46
+ minLength: String(minLength),
47
+ length: String(description.length)
48
+ }
49
+ });
23
50
  }
24
51
  }
25
52
  }
@@ -32,13 +59,28 @@ export const rule = {
32
59
  url: "https://formatjs.github.io/docs/tooling/linter#enforce-description"
33
60
  },
34
61
  fixable: "code",
35
- schema: [{
62
+ schema: [{ oneOf: [{
36
63
  type: "string",
37
64
  enum: Object.keys(Option)
38
- }],
65
+ }, {
66
+ type: "object",
67
+ properties: {
68
+ mode: {
69
+ type: "string",
70
+ enum: Object.keys(Option)
71
+ },
72
+ minLength: {
73
+ type: "integer",
74
+ minimum: 1
75
+ }
76
+ },
77
+ additionalProperties: false,
78
+ minProperties: 1
79
+ }] }],
39
80
  messages: {
40
81
  enforceDescription: "`description` has to be specified in message descriptor",
41
- enforceDescriptionLiteral: "`description` has to be a string literal (not function call or variable)"
82
+ enforceDescriptionLiteral: "`description` has to be a string literal (not function call or variable)",
83
+ enforceDescriptionMinLength: "`description` must be at least {{minLength}} characters long (currently {{length}})"
42
84
  }
43
85
  },
44
86
  create(context) {