@pandacss/eslint-plugin 0.1.7 → 0.1.9

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/dist/index.js CHANGED
@@ -7957,7 +7957,7 @@ init_cjs_shims();
7957
7957
 
7958
7958
  // package.json
7959
7959
  var name = "@pandacss/eslint-plugin";
7960
- var version = "0.1.7";
7960
+ var version = "0.1.9";
7961
7961
 
7962
7962
  // src/configs/all.ts
7963
7963
  init_cjs_shims();
@@ -8078,12 +8078,16 @@ var isPandaIsh = (name2, context) => {
8078
8078
  return syncAction("matchFile", getSyncOpts(context), name2, imports);
8079
8079
  };
8080
8080
  var findDeclaration = (name2, context) => {
8081
- const scope = (0, import_scope_manager.analyze)(context.sourceCode.ast, {
8082
- sourceType: "module"
8083
- });
8084
- const decl = scope.variables.find((v) => v.name === name2)?.defs.find((d) => isIdentifier(d.name) && d.name.name === name2)?.node;
8085
- if (isVariableDeclarator(decl))
8086
- return decl;
8081
+ try {
8082
+ const scope = (0, import_scope_manager.analyze)(context.sourceCode.ast, {
8083
+ sourceType: "module"
8084
+ });
8085
+ const decl = scope.variables.find((v) => v.name === name2)?.defs.find((d) => isIdentifier(d.name) && d.name.name === name2)?.node;
8086
+ if (isVariableDeclarator(decl))
8087
+ return decl;
8088
+ } catch (error) {
8089
+ return;
8090
+ }
8087
8091
  };
8088
8092
  var isLocalStyledFactory = (node, context) => {
8089
8093
  if (!isJSXIdentifier(node.name))
@@ -8754,23 +8758,50 @@ var rule8 = createRule({
8754
8758
  Property(node) {
8755
8759
  if (!isObjectExpression(node.value) || isIdentifier(node.key))
8756
8760
  return;
8757
- if (!isInPandaFunction(node, context) && !isInJSXProp(node, context))
8761
+ const caller = isInPandaFunction(node, context);
8762
+ if (!caller && !isInJSXProp(node, context))
8758
8763
  return;
8759
8764
  if (isStyledProperty(node, context))
8760
8765
  return;
8761
- const invalidLiteral = isLiteral(node.key) && typeof node.key.value === "string" && !node.key.value.includes("&");
8762
- const invalidTemplateLiteral = isTemplateLiteral(node.key) && !node.key.quasis[0].value.raw.includes("&");
8763
- if (invalidLiteral || invalidTemplateLiteral) {
8764
- context.report({
8765
- node: node.key,
8766
- messageId: "nesting"
8767
- });
8768
- }
8766
+ const invalidNesting = isInvalidNesting(node, context, caller);
8767
+ if (!invalidNesting)
8768
+ return;
8769
+ context.report({
8770
+ node: node.key,
8771
+ messageId: "nesting"
8772
+ });
8769
8773
  }
8770
8774
  };
8771
8775
  }
8772
8776
  });
8773
8777
  var no_invalid_nesting_default = rule8;
8778
+ function isInvalidNesting(node, context, caller) {
8779
+ const recipe = getImports(context).find((imp) => ["cva", "sva"].includes(imp.name) && imp.alias === caller);
8780
+ if (!recipe)
8781
+ return checkNode(node);
8782
+ let currentNode = node;
8783
+ let length = 0;
8784
+ let styleObjectParent = null;
8785
+ while (currentNode) {
8786
+ if (currentNode.key && ["base", "variants"].includes(currentNode.key.name)) {
8787
+ styleObjectParent = currentNode.key.name;
8788
+ }
8789
+ currentNode = currentNode.parent;
8790
+ if (!styleObjectParent)
8791
+ length++;
8792
+ }
8793
+ const requiredLength = caller === "cva" ? 2 : 4;
8794
+ const extraLength = styleObjectParent === "base" ? 0 : 4;
8795
+ if (length >= requiredLength + extraLength) {
8796
+ return checkNode(node);
8797
+ }
8798
+ return false;
8799
+ }
8800
+ function checkNode(node) {
8801
+ const invalidLiteral = isLiteral(node.key) && typeof node.key.value === "string" && !node.key.value.includes("&");
8802
+ const invalidTemplateLiteral = isTemplateLiteral(node.key) && !node.key.quasis[0].value.raw.includes("&");
8803
+ return invalidLiteral || invalidTemplateLiteral;
8804
+ }
8774
8805
 
8775
8806
  // src/rules/no-invalid-token-paths.ts
8776
8807
  init_cjs_shims();
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ var name, version;
10
10
  var init_package = __esm({
11
11
  "package.json"() {
12
12
  name = "@pandacss/eslint-plugin";
13
- version = "0.1.7";
13
+ version = "0.1.9";
14
14
  }
15
15
  });
16
16
 
@@ -8054,12 +8054,16 @@ var init_helpers = __esm({
8054
8054
  return syncAction("matchFile", getSyncOpts(context), name2, imports);
8055
8055
  };
8056
8056
  findDeclaration = (name2, context) => {
8057
- const scope = (0, import_scope_manager.analyze)(context.sourceCode.ast, {
8058
- sourceType: "module"
8059
- });
8060
- const decl = scope.variables.find((v) => v.name === name2)?.defs.find((d) => isIdentifier(d.name) && d.name.name === name2)?.node;
8061
- if (isVariableDeclarator(decl))
8062
- return decl;
8057
+ try {
8058
+ const scope = (0, import_scope_manager.analyze)(context.sourceCode.ast, {
8059
+ sourceType: "module"
8060
+ });
8061
+ const decl = scope.variables.find((v) => v.name === name2)?.defs.find((d) => isIdentifier(d.name) && d.name.name === name2)?.node;
8062
+ if (isVariableDeclarator(decl))
8063
+ return decl;
8064
+ } catch (error) {
8065
+ return;
8066
+ }
8063
8067
  };
8064
8068
  isLocalStyledFactory = (node, context) => {
8065
8069
  if (!isJSXIdentifier(node.name))
@@ -8775,6 +8779,33 @@ var init_no_important = __esm({
8775
8779
  });
8776
8780
 
8777
8781
  // src/rules/no-invalid-nesting.ts
8782
+ function isInvalidNesting(node, context, caller) {
8783
+ const recipe = getImports(context).find((imp) => ["cva", "sva"].includes(imp.name) && imp.alias === caller);
8784
+ if (!recipe)
8785
+ return checkNode(node);
8786
+ let currentNode = node;
8787
+ let length = 0;
8788
+ let styleObjectParent = null;
8789
+ while (currentNode) {
8790
+ if (currentNode.key && ["base", "variants"].includes(currentNode.key.name)) {
8791
+ styleObjectParent = currentNode.key.name;
8792
+ }
8793
+ currentNode = currentNode.parent;
8794
+ if (!styleObjectParent)
8795
+ length++;
8796
+ }
8797
+ const requiredLength = caller === "cva" ? 2 : 4;
8798
+ const extraLength = styleObjectParent === "base" ? 0 : 4;
8799
+ if (length >= requiredLength + extraLength) {
8800
+ return checkNode(node);
8801
+ }
8802
+ return false;
8803
+ }
8804
+ function checkNode(node) {
8805
+ const invalidLiteral = isLiteral(node.key) && typeof node.key.value === "string" && !node.key.value.includes("&");
8806
+ const invalidTemplateLiteral = isTemplateLiteral(node.key) && !node.key.quasis[0].value.raw.includes("&");
8807
+ return invalidLiteral || invalidTemplateLiteral;
8808
+ }
8778
8809
  var RULE_NAME8, rule8, no_invalid_nesting_default;
8779
8810
  var init_no_invalid_nesting = __esm({
8780
8811
  "src/rules/no-invalid-nesting.ts"() {
@@ -8802,18 +8833,18 @@ var init_no_invalid_nesting = __esm({
8802
8833
  Property(node) {
8803
8834
  if (!isObjectExpression(node.value) || isIdentifier(node.key))
8804
8835
  return;
8805
- if (!isInPandaFunction(node, context) && !isInJSXProp(node, context))
8836
+ const caller = isInPandaFunction(node, context);
8837
+ if (!caller && !isInJSXProp(node, context))
8806
8838
  return;
8807
8839
  if (isStyledProperty(node, context))
8808
8840
  return;
8809
- const invalidLiteral = isLiteral(node.key) && typeof node.key.value === "string" && !node.key.value.includes("&");
8810
- const invalidTemplateLiteral = isTemplateLiteral(node.key) && !node.key.quasis[0].value.raw.includes("&");
8811
- if (invalidLiteral || invalidTemplateLiteral) {
8812
- context.report({
8813
- node: node.key,
8814
- messageId: "nesting"
8815
- });
8816
- }
8841
+ const invalidNesting = isInvalidNesting(node, context, caller);
8842
+ if (!invalidNesting)
8843
+ return;
8844
+ context.report({
8845
+ node: node.key,
8846
+ messageId: "nesting"
8847
+ });
8817
8848
  }
8818
8849
  };
8819
8850
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pandacss/eslint-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Eslint plugin for Panda CSS",
5
5
  "author": "Abraham Aremu <anubra266@gmail.com>",
6
6
  "main": "dist/index.js",