@nkzw/eslint-plugin-fbtee 0.1.0 → 0.1.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.
package/lib/index.cjs CHANGED
@@ -29,7 +29,7 @@ module.exports = __toCommonJS(src_exports);
29
29
  // package.json
30
30
  var package_default = {
31
31
  name: "@nkzw/eslint-plugin-fbtee",
32
- version: "0.1.0",
32
+ version: "0.1.2",
33
33
  description: "",
34
34
  keywords: [],
35
35
  repository: {
@@ -129,7 +129,7 @@ var no_empty_strings_default = createRule({
129
129
  create(context) {
130
130
  return {
131
131
  CallExpression(node) {
132
- if (node.callee.type === "Identifier" && !(node.callee.name === "fbt" || node.callee.name === "fbs")) {
132
+ if (node.callee.type !== "Identifier" || !(node.callee.name === "fbt" || node.callee.name === "fbs")) {
133
133
  return;
134
134
  }
135
135
  const [text] = node.arguments;
@@ -182,7 +182,9 @@ function validateChildren(node, nodesToReport) {
182
182
  }
183
183
  }
184
184
  if (child.type === "JSXExpressionContainer" && child.expression.type !== "JSXEmptyExpression") {
185
- if (isEmptyString(child.expression)) {
185
+ if (isEmptyString(child.expression) && (node.children.length === 1 || node.children.every(
186
+ (otherChild) => child === otherChild || otherChild.type === "JSXText" && otherChild.value.trim() === ""
187
+ ))) {
186
188
  nodesToReport.add(child.expression);
187
189
  } else {
188
190
  hasTextContent = true;
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@nkzw/eslint-plugin-fbtee",
4
- version: "0.1.0",
4
+ version: "0.1.2",
5
5
  description: "",
6
6
  keywords: [],
7
7
  repository: {
@@ -101,7 +101,7 @@ var no_empty_strings_default = createRule({
101
101
  create(context) {
102
102
  return {
103
103
  CallExpression(node) {
104
- if (node.callee.type === "Identifier" && !(node.callee.name === "fbt" || node.callee.name === "fbs")) {
104
+ if (node.callee.type !== "Identifier" || !(node.callee.name === "fbt" || node.callee.name === "fbs")) {
105
105
  return;
106
106
  }
107
107
  const [text] = node.arguments;
@@ -154,7 +154,9 @@ function validateChildren(node, nodesToReport) {
154
154
  }
155
155
  }
156
156
  if (child.type === "JSXExpressionContainer" && child.expression.type !== "JSXEmptyExpression") {
157
- if (isEmptyString(child.expression)) {
157
+ if (isEmptyString(child.expression) && (node.children.length === 1 || node.children.every(
158
+ (otherChild) => child === otherChild || otherChild.type === "JSXText" && otherChild.value.trim() === ""
159
+ ))) {
158
160
  nodesToReport.add(child.expression);
159
161
  } else {
160
162
  hasTextContent = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkzw/eslint-plugin-fbtee",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -206,5 +206,17 @@ ruleTester.run('no-empty-strings', rule, {
206
206
  </fbt>;
207
207
  `,
208
208
  },
209
+ {
210
+ code: `
211
+ <fbt desc="Greeting">
212
+ Apple{' '}Banana
213
+ </fbt>;
214
+ `,
215
+ },
216
+ {
217
+ code: `
218
+ name.replaceAll(' ', '-');
219
+ `,
220
+ },
209
221
  ],
210
222
  });
@@ -6,7 +6,7 @@ export default createRule<[], 'emptyString' | 'jsxEmptyString'>({
6
6
  return {
7
7
  CallExpression(node) {
8
8
  if (
9
- node.callee.type === 'Identifier' &&
9
+ node.callee.type !== 'Identifier' ||
10
10
  !(node.callee.name === 'fbt' || node.callee.name === 'fbs')
11
11
  ) {
12
12
  return;
@@ -78,7 +78,15 @@ function validateChildren(
78
78
  child.type === 'JSXExpressionContainer' &&
79
79
  child.expression.type !== 'JSXEmptyExpression'
80
80
  ) {
81
- if (isEmptyString(child.expression)) {
81
+ if (
82
+ isEmptyString(child.expression) &&
83
+ (node.children.length === 1 ||
84
+ node.children.every(
85
+ (otherChild) =>
86
+ child === otherChild ||
87
+ (otherChild.type === 'JSXText' && otherChild.value.trim() === ''),
88
+ ))
89
+ ) {
82
90
  nodesToReport.add(child.expression);
83
91
  } else {
84
92
  hasTextContent = true;