@starci/eslint-canon-fe 3.0.0 → 3.0.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/class-names.mjs CHANGED
@@ -11,7 +11,8 @@ const isCn = (node) => node?.type === "Identifier" && node.name === "cn"
11
11
 
12
12
  const importedClassNames = (context) => {
13
13
  const imports = new Set()
14
- for (const statement of context.getSourceCode().ast.body) {
14
+ const sourceCode = context.sourceCode || context.getSourceCode()
15
+ for (const statement of sourceCode.ast.body) {
15
16
  if (statement.type !== "ImportDeclaration" || statement.source.value !== "./classNames") continue
16
17
  for (const specifier of statement.specifiers) imports.add(specifier.local.name)
17
18
  }
@@ -58,7 +59,10 @@ const usesImportedClassName = (node, imported) => {
58
59
  if (!node) return false
59
60
  if (node.type === "Identifier") return imported.has(node.name) || node.name === "undefined"
60
61
  if (isEmptyClassName(node)) return true
61
- if (node.type === "CallExpression") return node.callee.type === "Identifier" && imported.has(node.callee.name)
62
+ if (node.type === "CallExpression") {
63
+ if (node.callee.type === "Identifier") return imported.has(node.callee.name)
64
+ return node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && imported.has(node.callee.object.name)
65
+ }
62
66
  if (node.type === "MemberExpression") return node.object.type === "Identifier" && imported.has(node.object.name)
63
67
  if (node.type === "ConditionalExpression") return usesImportedClassName(node.consequent, imported) && usesImportedClassName(node.alternate, imported)
64
68
  if (node.type === "LogicalExpression") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-canon-fe",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "The StarCi front-end lint canon: every rule its laws publish, gathered as one flat-config plugin.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -9,6 +9,7 @@ const normalize = (filename) => String(filename || "").replace(/\\/g, "/")
9
9
  const componentFile = (filename) => /\/src\/components\//.test(normalize(filename))
10
10
  const leafFile = (filename) => /\/src\/components\/leaves\//.test(normalize(filename))
11
11
  const mechanicsFile = (filename) => /\/src\/components\/(branches|overlays)\//.test(normalize(filename))
12
+ const classNamesFile = (filename) => /\/src\/components\/.*\/classNames\.tsx?$/.test(normalize(filename))
12
13
 
13
14
  /** Keep direct Heroicons imports in the Icon leaf. */
14
15
  export const noVendorIconOutsideIconLeaf = {
@@ -19,12 +20,12 @@ export const noVendorIconOutsideIconLeaf = {
19
20
  },
20
21
  }
21
22
 
22
- /** Keep HeroUI mechanics inside leaves and named mechanics branches. */
23
+ /** Keep HeroUI mechanics inside leaves, named mechanics branches, and styling-owner modules. */
23
24
  export const vendorPrimitiveHasNamedOwner = {
24
- meta: { type: "problem", docs: { description: "HeroUI primitives have a named leaf or mechanics owner." }, schema: [], messages: { owner: "Import HeroUI primitives from a named leaf or mechanics branch." } },
25
+ meta: { type: "problem", docs: { description: "HeroUI primitives have a named component or styling owner." }, schema: [], messages: { owner: "Import HeroUI primitives from a named leaf, mechanics branch, or colocated classNames module." } },
25
26
  create(context) {
26
27
  const file = context.filename || context.getFilename()
27
- if (!componentFile(file) || leafFile(file) || mechanicsFile(file)) return {}
28
+ if (!componentFile(file) || leafFile(file) || mechanicsFile(file) || classNamesFile(file)) return {}
28
29
  return { ImportDeclaration(node) { if (String(node.source.value) === "@heroui/react") context.report({ node, messageId: "owner" }) } }
29
30
  },
30
31
  }