@ashstack/lint 0.10.3 → 0.11.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/dist/lib/design-system.js +1 -0
- package/dist/lib/registry.js +1 -1
- package/dist/lib/rule-types/react.d.ts +11 -5
- package/dist/react/rules/react/prefer-design-system.js +1 -1
- package/dist/react/rules/stylex/index.js +1 -1
- package/dist/react/rules/stylex/inline-props.js +1 -1
- package/dist/react/rules/stylex/peer.js +1 -0
- package/dist/react/rules/stylex/spread-props.js +1 -0
- package/package.json +1 -1
- package/dist/react/rules/stylex/use-sx-prop.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAbsolute as i}from"node:path";export const DESIGN_SYSTEM_DIR="src/components/ui",DESIGN_SYSTEM_ALIAS="@/components/ui";const o=/^[@~#][^/]*\//;export const DESIGN_SYSTEM_SCHEMA={type:"object",properties:{dir:{type:"string",minLength:1,default:DESIGN_SYSTEM_DIR,description:"Folder holding the design system, whose files own the peer contract."},alias:{type:"string",minLength:1,default:DESIGN_SYSTEM_ALIAS,description:"Import prefix that names the design system."}},additionalProperties:!1},designSystemFolders=(e,s=[])=>[e.dir??DESIGN_SYSTEM_DIR,e.alias??DESIGN_SYSTEM_ALIAS,...s].map((t)=>t.replace(o,"")).filter((t)=>t.length>0),isInsideDesignSystem=(e,s)=>{if(e===void 0)return!1;const t=e.replaceAll("\\","/");return s.some((n)=>t.includes(i(n)?n:`/${n}`))};
|
package/dist/lib/registry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(t)=>new URL(t,import.meta.url).href;export const coreRegistry=[{meta:{name:"@ashstack/core"},url:e("../core/rules/core/index.js"),rules:{"no-comments":{},"no-naming-convention":{},"no-packed-condition":{},"max-lines":{},"max-complexity":{}}},{meta:{name:"@ashstack/zod"},url:e("../core/rules/zod/index.js"),option:"zod",packages:["zod"],rules:{"prefer-enum":{}}}],reactRegistry=[{meta:{name:"@ashstack/react"},url:e("../react/rules/react/index.js"),rules:{"no-unlabeled-icon-button":{},"no-svg-without-title":{},"hoist-intl":{},"prefer-design-system":{defaultOff:!0},"components-tsx-only":{defaultOff:!0}}},{meta:{name:"@ashstack/query"},url:e("../react/rules/query/index.js"),option:"query",packages:["@tanstack/react-query"],rules:{"no-inline-keys":{},"no-deprecated-filters":{},"require-destructured-hooks":{},"no-fetch-in-query-fn":{},"next-page-param-undefined":{}}},{meta:{name:"@ashstack/zustand"},url:e("../react/rules/zustand/index.js"),option:"zustand",packages:["zustand"],rules:{"require-selector":{}}},{meta:{name:"@ashstack/i18n"},url:e("../react/rules/i18n/index.js"),option:"i18n",packages:["i18next","react-i18next","@lingui/core","react-intl","use-intl","next-intl","expo-localization"],rules:{"no-bare-text":{},"no-bare-attrs":{},"no-bare-toast":{}}},{meta:{name:"@ashstack/stylex"},url:e("../react/rules/stylex/index.js"),option:"stylex",packages:["@stylexjs/stylex"],rules:{"inline-props":{},"no-conflicting-props":{},"no-duplicate-styles":{},"require-tokens":{},"
|
|
1
|
+
const e=(t)=>new URL(t,import.meta.url).href;export const coreRegistry=[{meta:{name:"@ashstack/core"},url:e("../core/rules/core/index.js"),rules:{"no-comments":{},"no-naming-convention":{},"no-packed-condition":{},"max-lines":{},"max-complexity":{}}},{meta:{name:"@ashstack/zod"},url:e("../core/rules/zod/index.js"),option:"zod",packages:["zod"],rules:{"prefer-enum":{}}}],reactRegistry=[{meta:{name:"@ashstack/react"},url:e("../react/rules/react/index.js"),rules:{"no-unlabeled-icon-button":{},"no-svg-without-title":{},"hoist-intl":{},"prefer-design-system":{defaultOff:!0},"components-tsx-only":{defaultOff:!0}}},{meta:{name:"@ashstack/query"},url:e("../react/rules/query/index.js"),option:"query",packages:["@tanstack/react-query"],rules:{"no-inline-keys":{},"no-deprecated-filters":{},"require-destructured-hooks":{},"no-fetch-in-query-fn":{},"next-page-param-undefined":{}}},{meta:{name:"@ashstack/zustand"},url:e("../react/rules/zustand/index.js"),option:"zustand",packages:["zustand"],rules:{"require-selector":{}}},{meta:{name:"@ashstack/i18n"},url:e("../react/rules/i18n/index.js"),option:"i18n",packages:["i18next","react-i18next","@lingui/core","react-intl","use-intl","next-intl","expo-localization"],rules:{"no-bare-text":{},"no-bare-attrs":{},"no-bare-toast":{}}},{meta:{name:"@ashstack/stylex"},url:e("../react/rules/stylex/index.js"),option:"stylex",packages:["@stylexjs/stylex"],rules:{"inline-props":{},"no-conflicting-props":{},"no-duplicate-styles":{},"require-tokens":{},"spread-props":{}}},{meta:{name:"@ashstack/tailwind"},url:e("../react/rules/tailwind/index.js"),option:"tailwind",packages:["tailwindcss"],rules:{"prefer-cn":{},"use-logical-classes":{}}},{meta:{name:"@ashstack/tanstack-router"},url:e("../react/rules/tanstack-router/index.js"),option:"tanstackRouter",packages:["@tanstack/react-router"],rules:{"require-selector":{},"no-search-casts":{}}}],reactNativeRegistry=[{meta:{name:"@ashstack/react-native"},url:e("../react-native/rules/react-native/index.js"),restrictedImports:{paths:[{name:"react",importNames:["forwardRef"],message:"Accept `ref` as a regular prop and delete the `forwardRef` wrapper — React 19 passes `ref` like any other prop."},{name:"react",importNames:["useContext"],message:"Call `use(Context)` instead of `useContext(Context)`; React 19 replaces the hook with it."}],patterns:[{group:["expo-linear-gradient","react-native-linear-gradient"],message:"Apply the gradient through the `experimental_backgroundImage` style property instead of a gradient component."}]},rules:{"no-keyboard-will-events":{},"no-scroll-position-state":{},"no-conditional-style-array":{},"no-leaked-render":{},"no-rn-image-network-source":{},"no-redundant-view-nesting":{},"no-rn-namespace-import":{},"no-unlabeled-icon-pressable":{},"hoist-stateless-function":{},"no-manual-memo":{},"no-dynamic-import":{}}},{meta:{name:"@ashstack/unistyles"},url:e("../react-native/rules/unistyles/index.js"),option:"unistyles",packages:["react-native-unistyles"],restrictedImports:{paths:[{name:"react-native",importNames:["StyleSheet"],message:"Import `StyleSheet` from `react-native-unistyles` instead of `react-native`."},{name:"react-native",importNames:["useWindowDimensions","Dimensions"],message:"Read screen size from `rt.screen` inside `StyleSheet.create`, or `UnistylesRuntime.screen` outside it, instead of the `Dimensions` APIs."},{name:"react-native",importNames:["SafeAreaView"],message:'Set `contentInsetAdjustmentBehavior="automatic"` on the scroll view, or apply `rt.insets` from `react-native-unistyles`, instead of `SafeAreaView`.'},{name:"react-native-safe-area-context",importNames:["useSafeAreaInsets","useSafeAreaFrame","SafeAreaView"],message:"Read safe-area values from `rt.insets`, or `UnistylesRuntime.insets` outside a stylesheet, in `react-native-unistyles`."}]},rules:{"animated-theme":{},"content-container":{},"in-sheet":{},insets:{},"no-hardcoded-color":{},"no-hardcoded-spacing":{},"no-margin":{},"no-paramless-dynamic-function":{},"no-style-spread":{},"no-unused-styles":{},"rtl-style-call":{},"theme-screen-component":{},"theme-style-attr":{}}},{meta:{name:"@ashstack/legend-list"},url:e("../react-native/rules/legend-list/index.js"),option:"legendList",packages:["@legendapp/list"],restrictedImports:{paths:[{name:"react-native",importNames:["FlatList","SectionList","VirtualizedList"],message:"Render this list with `LegendList` from `@legendapp/list/react-native`; a `ScrollView` plus `map` is fine for fewer than 20 static items."},{name:"@shopify/flash-list",message:"Import `LegendList` from `@legendapp/list/react-native` — Legend List replaced FlashList in this stack."}],patterns:[{group:["@legendapp/list"],message:"Import from the platform entrypoint `@legendapp/list/react-native`, not the package root."}]},rules:{"required-props":{},"no-index-key-extractor":{},"no-remount-key":{},"no-inline-render-item-props":{},"no-mixed-children":{},"no-flex-in-content-container":{},"typed-items-need-item-type":{},"no-scrollview-map":{},"no-unsupported-props":{}}},{meta:{name:"@ashstack/legend-state"},url:e("../react-native/rules/legend-state/index.js"),option:"legendState",packages:["@legendapp/state"],restrictedImports:{paths:[{name:"@legendapp/state/react",importNames:["use$","useSelector"],message:"Use `useValue` from `@legendapp/state/react`; `use$` and `useSelector` are deprecated."}]},rules:{"no-assignment":{},naming:{},"no-nested-observable":{},"no-react-mirror":{},"no-untracked-get-in-jsx":{},"no-peek-in-selector":{},"no-object-selector":{},"no-observable-in-component":{}}},{meta:{name:"@ashstack/reanimated"},url:e("../react-native/rules/reanimated/index.js"),option:"reanimated",packages:["react-native-reanimated"],restrictedImports:{paths:[{name:"react-native",importNames:["Animated"],message:"Use `react-native-reanimated` instead of React Native's `Animated` API."},{name:"react-native-reanimated",importNames:["runOnJS","runOnUI"],message:"Use `scheduleOnRN` and `scheduleOnUI` from `react-native-worklets`; `runOnJS` and `runOnUI` are deprecated."},{name:"react-native-worklets",importNames:["runOnJS","runOnUI"],message:"Use `scheduleOnRN` and `scheduleOnUI` from `react-native-worklets`; `runOnJS` and `runOnUI` are deprecated."}]},rules:{"animated-reaction-safety":{},"animated-style-needs-animated-component":{},"animated-updater-purity":{},"gpu-properties-only":{},"hoist-layout-animation-builder":{},"interpolate-needs-clamp":{},"no-shared-value-dot-value":{},"no-react-state-from-continuous-worklet":{},"prefer-lazy-shared-value-initializer":{},"schedule-on-rn-scope":{},"shared-value-usage":{}}},{meta:{name:"@ashstack/turbo-image"},url:e("../react-native/rules/turbo-image/index.js"),option:"turboImage",packages:["react-native-turbo-image"],rules:{"require-resize":{},"require-cache-policy":{}}},{meta:{name:"@ashstack/skia"},url:e("../react-native/rules/skia/index.js"),option:"skia",packages:["@shopify/react-native-skia"],restrictedImports:{paths:[{name:"@shopify/react-native-skia",importNames:["usePathValue","usePathInterpolation"],message:"Keep one stable `SkPath` buffer and mutate it inside `useDerivedValue`, with consumers reading the driving shared value."}]},rules:{"canvas-opaque":{}}},{meta:{name:"@ashstack/keyboard"},url:e("../react-native/rules/keyboard/index.js"),option:"keyboard",packages:["react-native-keyboard-controller"],restrictedImports:{paths:[{name:"react-native",importNames:["KeyboardAvoidingView"],message:"Import `KeyboardAvoidingView` from `react-native-keyboard-controller` — same props, tracked per frame. For a scrolling form, its `KeyboardAwareScrollView`."}]},rules:{}}];
|
|
@@ -2,7 +2,7 @@ import type { AllowWarnDeny } from "oxlint";
|
|
|
2
2
|
/** A severity, or a severity followed by as many of the rule's options as you want to set. */
|
|
3
3
|
type RuleSetting<Options extends unknown[] = []> = AllowWarnDeny | [AllowWarnDeny, ...Partial<Options>];
|
|
4
4
|
/** Every rule id `react()` adds on top of the entry below it. */
|
|
5
|
-
export type ReactRuleId = "@ashstack/react/no-unlabeled-icon-button" | "@ashstack/react/no-svg-without-title" | "@ashstack/react/hoist-intl" | "@ashstack/react/prefer-design-system" | "@ashstack/react/components-tsx-only" | "@ashstack/query/no-inline-keys" | "@ashstack/query/no-deprecated-filters" | "@ashstack/query/require-destructured-hooks" | "@ashstack/query/no-fetch-in-query-fn" | "@ashstack/query/next-page-param-undefined" | "@ashstack/zustand/require-selector" | "@ashstack/i18n/no-bare-text" | "@ashstack/i18n/no-bare-attrs" | "@ashstack/i18n/no-bare-toast" | "@ashstack/stylex/inline-props" | "@ashstack/stylex/no-conflicting-props" | "@ashstack/stylex/no-duplicate-styles" | "@ashstack/stylex/require-tokens" | "@ashstack/stylex/
|
|
5
|
+
export type ReactRuleId = "@ashstack/react/no-unlabeled-icon-button" | "@ashstack/react/no-svg-without-title" | "@ashstack/react/hoist-intl" | "@ashstack/react/prefer-design-system" | "@ashstack/react/components-tsx-only" | "@ashstack/query/no-inline-keys" | "@ashstack/query/no-deprecated-filters" | "@ashstack/query/require-destructured-hooks" | "@ashstack/query/no-fetch-in-query-fn" | "@ashstack/query/next-page-param-undefined" | "@ashstack/zustand/require-selector" | "@ashstack/i18n/no-bare-text" | "@ashstack/i18n/no-bare-attrs" | "@ashstack/i18n/no-bare-toast" | "@ashstack/stylex/inline-props" | "@ashstack/stylex/no-conflicting-props" | "@ashstack/stylex/no-duplicate-styles" | "@ashstack/stylex/require-tokens" | "@ashstack/stylex/spread-props" | "@ashstack/tailwind/prefer-cn" | "@ashstack/tailwind/use-logical-classes" | "@ashstack/tanstack-router/require-selector" | "@ashstack/tanstack-router/no-search-casts" | "@ashstack/effects/no-derived-state" | "@ashstack/effects/no-chain-state-updates" | "@ashstack/effects/no-event-handler" | "@ashstack/effects/no-adjust-state-on-prop-change" | "@ashstack/effects/no-reset-all-state-on-prop-change" | "@ashstack/effects/no-pass-live-state-to-parent" | "@ashstack/effects/no-pass-data-to-parent" | "@ashstack/effects/no-external-store-subscription" | "@ashstack/effects/no-initialize-state";
|
|
6
6
|
declare module "oxlint" {
|
|
7
7
|
interface DummyRuleMap {
|
|
8
8
|
/**
|
|
@@ -140,7 +140,10 @@ declare module "oxlint" {
|
|
|
140
140
|
*
|
|
141
141
|
* @see https://github.com/AlshehriAli0/ashStack/blob/main/packages/lint/rules/stylex.md#ashstackstylexinline-props
|
|
142
142
|
*/
|
|
143
|
-
"@ashstack/stylex/inline-props"?: RuleSetting
|
|
143
|
+
"@ashstack/stylex/inline-props"?: RuleSetting<[{
|
|
144
|
+
dir?: string;
|
|
145
|
+
alias?: string;
|
|
146
|
+
}]>;
|
|
144
147
|
/**
|
|
145
148
|
* Report className overrides and inline CSS that overlaps StyleX declarations.
|
|
146
149
|
*
|
|
@@ -172,13 +175,16 @@ declare module "oxlint" {
|
|
|
172
175
|
}
|
|
173
176
|
]>;
|
|
174
177
|
/**
|
|
175
|
-
*
|
|
178
|
+
* Spread complete `stylex.props(...)` results to style custom components.
|
|
176
179
|
*
|
|
177
180
|
* **Default: on**, when `@stylexjs/stylex` is a dependency.
|
|
178
181
|
*
|
|
179
|
-
* @see https://github.com/AlshehriAli0/ashStack/blob/main/packages/lint/rules/stylex.md#
|
|
182
|
+
* @see https://github.com/AlshehriAli0/ashStack/blob/main/packages/lint/rules/stylex.md#ashstackstylexspread-props
|
|
180
183
|
*/
|
|
181
|
-
"@ashstack/stylex/
|
|
184
|
+
"@ashstack/stylex/spread-props"?: RuleSetting<[{
|
|
185
|
+
dir?: string;
|
|
186
|
+
alias?: string;
|
|
187
|
+
}]>;
|
|
182
188
|
/**
|
|
183
189
|
* Require a dynamic class value to go through `cn(...)` before it reaches a `class`, `className` or `*ClassName` prop. Reports both where the value reaches the prop and where a variable named after classes is declared.
|
|
184
190
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readdirSync as
|
|
1
|
+
import{readdirSync as y}from"node:fs";import{isAbsolute as u,join as g}from"node:path";import{optionsOf as h}from"../../../lib/ast.js";import{DESIGN_SYSTEM_ALIAS as f,DESIGN_SYSTEM_DIR as d,designSystemFolders as b,isInsideDesignSystem as S}from"../../../lib/design-system.js";const w=/\.(?:ios|android|native|web)$/,A={Pressable:["TouchableOpacity","TouchableHighlight","TouchableWithoutFeedback","TouchableNativeFeedback"]},m={anyOf:[{type:"string"},{type:"array",items:{type:"string"}}]},E={anyOf:[...m.anyOf,{type:"object",properties:{replaces:m,from:{type:"string"},path:{type:"string"},reason:{type:"string"}},required:["replaces"],additionalProperties:!1}]},I=(e)=>e.split("-").filter(Boolean).map((t)=>t.charAt(0).toUpperCase()+t.slice(1)).join(""),x=(e)=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),p=(e,t,o,n)=>{const s=e.get(t)??new Map;s.set(o,n);e.set(t,s)},O=(e,t,o)=>{let n;try{n=y(u(t)?t:g(process.cwd(),t))}catch{return}for(const s of n){if(!s.endsWith(".tsx"))continue;const r=s.slice(0,-4).replace(w,"");if(r==="index")continue;const a=I(r),i=`${o}/${r}`;p(e,"react-native",a,{name:a,from:i});for(const c of A[a]??[])p(e,"react-native",c,{name:a,from:i})}},T=(e,t,o)=>{for(const[n,s]of Object.entries(o)){const r=typeof s==="string"||Array.isArray(s)?{replaces:s}:s,a={name:n,from:r.path??`${t}/${x(n)}`,reason:r.reason};for(const i of[r.replaces].flat())p(e,r.from??"react-native",i,a)}},v=(e,t,o)=>{const n=[];for(const s of Object.values(o)){if(typeof s==="string"||Array.isArray(s)||s.path===void 0)continue;n.push(s.path)}return b({dir:e,alias:t},n)},l=new Map,M=(e)=>{const t=e.dir??d,o=e.alias??f,n=e.use??{},s=JSON.stringify([t,o,e.use]);let r=l.get(s);if(r===void 0){const a=new Map;O(a,t,o);T(a,o,n);r={banned:a,wrappers:v(t,o,n)};l.set(s,r)}return{banned:r.banned,exempt:[...r.wrappers,...e.exempt??[]]}};export const preferDesignSystem={meta:{type:"problem",docs:{description:"Disallow importing a raw primitive your design system already wraps. Wrappers come from scanning the design-system directory and from the `use` map. Files inside the design system are skipped."},schema:[{type:"object",properties:{dir:{type:"string",minLength:1,default:d,description:"Directory scanned for wrapper components. Every `.tsx` file in it becomes a wrapper."},alias:{type:"string",minLength:1,default:f,description:"Import prefix the diagnostic points at, and a second folder counted as the design system."},use:{type:"object",additionalProperties:E,default:{},description:"Wrappers the scan cannot find, keyed by component name.",examples:[{Button:"Pressable",Text:["Text","RNText"],Sheet:{replaces:"Modal",from:"react-native",path:"@/ui/sheet",reason:"It owns insets."}}]},exempt:{type:"array",items:{type:"string"},default:[],description:"Extra path fragments to skip, added to the design system's own folders."}},additionalProperties:!1}],defaultOff:!0},createOnce(e){let t=new Map;return{before(){const o=h(e,{}),n=M(o);t=n.banned;if(t.size===0)return!1;return!S(e.filename,n.exempt)},ImportDeclaration(o){const n=o.source.value,s=t.get(n);if(s===void 0)return;for(const r of o.specifiers){if(r.type!=="ImportSpecifier")continue;const{imported:a}=r;if(a.type!=="Identifier")continue;const i=s.get(a.name);if(i===void 0)continue;const c=i.reason?` ${i.reason}`:"";e.report({node:r,message:`Import \`${i.name}\` from "${i.from}" instead of \`${a.name}\` from ${n}.${c}`})}}}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineModule as e}from"../../../lib/module.js";import{inlineProps as o}from"./inline-props.js";import{noConflictingProps as r}from"./no-conflicting-props.js";import{noDuplicateStyles as t}from"./no-duplicate-styles.js";import{requireTokens as s}from"./require-tokens.js";import{
|
|
1
|
+
import{defineModule as e}from"../../../lib/module.js";import{inlineProps as o}from"./inline-props.js";import{noConflictingProps as r}from"./no-conflicting-props.js";import{noDuplicateStyles as t}from"./no-duplicate-styles.js";import{requireTokens as s}from"./require-tokens.js";import{spreadProps as p}from"./spread-props.js";export default e({meta:{name:"@ashstack/stylex"},url:import.meta.url,packages:["@stylexjs/stylex"],option:"stylex",docsWhen:"auto-enabled by `react()` when `@stylexjs/stylex` is a dependency",rules:{"inline-props":o,"no-conflicting-props":r,"no-duplicate-styles":t,"require-tokens":s,"spread-props":p}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{problem as
|
|
1
|
+
import{optionsOf as o,problem as i}from"../../../lib/ast.js";import{DESIGN_SYSTEM_SCHEMA as a,designSystemFolders as p,isInsideDesignSystem as l}from"../../../lib/design-system.js";import{collectImports as m,isStylexCall as S}from"./imports.js";const n="Spread `stylex.props(...)` in JSX or return its full result; do not store it.";export const inlineProps=i(n,{meta:{schema:[a]},createOnce(r){const t={namespaces:new Set,named:new Set};let s=[];return{before(){t.namespaces.clear();t.named.clear();s=p(o(r,{}));return r.sourceCode.text.includes("stylex")},Program(e){m(e.body,"props",t)},CallExpression(e){if(!S(r,e,"props",t))return;if(["JSXSpreadAttribute","ReturnStatement","ArrowFunctionExpression"].includes(e.parent.type))return;if(l(r.filename,s)&&e.parent.type==="VariableDeclarator")return;r.report({node:e,message:n})}}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isStylexCall as a}from"./imports.js";export const initializerOf=(r,e)=>{if(e.type!=="Identifier")return null;let t=r.sourceCode.getScope(e);while(t){const i=t.set.get(e.name);if(i){const s=i.defs.find((n)=>n.node.type==="VariableDeclarator")?.node;return s?.type==="VariableDeclarator"?s.init??null:null}t=t.upper}return null};const p=(r)=>{let e=r;while(e.type==="MemberExpression"){if(e.computed)return null;e=e.object}return e.type==="Identifier"?e:null},u=(r,e,t)=>{if(e.type!=="MemberExpression"||e.computed||e.property.type!=="Identifier")return!1;if(e.property.name!=="className"&&e.property.name!=="style")return!1;const i=p(e);if(i===null)return!1;const s=initializerOf(r,i);return s!==null&&a(r,s,"props",t)},l=(r,e,t)=>{if(e.type==="MemberExpression")return u(r,e,t);if(e.type==="CallExpression")return e.arguments.some((i)=>l(r,i.type==="SpreadElement"?i.argument:i,t));if(e.type==="ArrayExpression")return e.elements.some((i)=>i!==null&&l(r,i.type==="SpreadElement"?i.argument:i,t));if(e.type==="ConditionalExpression")return l(r,e.consequent,t)||l(r,e.alternate,t);if(e.type==="LogicalExpression")return l(r,e.left,t)||l(r,e.right,t);if(e.type==="TSAsExpression"||e.type==="TSSatisfiesExpression"||e.type==="TSNonNullExpression")return l(r,e.expression,t);return!1};export const mergesStoredProps=(r,e,t)=>{if(e.type!=="CallExpression")return!1;const i=e.arguments.map((s)=>s.type==="SpreadElement"?s.argument:s);return i.some((s)=>l(r,s,t))&&i.some((s)=>!l(r,s,t))};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{attributeName as b,optionsOf as P,problem as J,tagPath as O}from"../../../lib/ast.js";import{DESIGN_SYSTEM_SCHEMA as B,designSystemFolders as d,isInsideDesignSystem as g}from"../../../lib/design-system.js";import{collectImports as c,isImportedBinding as I,isStylexCall as S}from"./imports.js";import{initializerOf as h,mergesStoredProps as j}from"./peer.js";export const spreadProps=J("Spread complete `stylex.props(...)` results to style custom components.",{meta:{hasSuggestions:!0,schema:[B]},createOnce(s){const u={namespaces:new Set,named:new Set},l={namespaces:new Set,named:new Set},m={namespaces:new Set,named:new Set},y=new Set;let f=[];const E=(e)=>{if(e.type==="TSTypeReference"){const t=e.typeName;if(t.type==="Identifier")return u.named.has(t.name)&&I(s,t);return t.type==="TSQualifiedName"&&t.left.type==="Identifier"&&u.namespaces.has(t.left.name)&&(t.right.name==="StyleXStyles"||t.right.name==="StyleXStylesWithout")&&I(s,t.left)}if(e.type==="TSUnionType"||e.type==="TSIntersectionType")return e.types.some(E);if(e.type==="TSParenthesizedType")return E(e.typeAnnotation);return!1},n=(e,t=!1)=>{if(e.type==="Identifier"){const r=h(s,e);if(r===null||y.has(r))return!1;y.add(r);return n(r,t)}if(e.type==="MemberExpression"){const r=h(s,e.object);if(r!==null&&S(s,r,"create",m))return!0;return n(e.object,t)}if(e.type==="CallExpression")return S(s,e,"props",l)||n(e.callee,t)||t&&e.arguments.some((r)=>n(r,!0));return x(e,t)},x=(e,t)=>{if(e.type==="ArrayExpression")return e.elements.some((r)=>r!==null&&n(r,t));if(e.type==="ObjectExpression")return e.properties.some((r)=>r.type==="Property"&&n(r.value,t));if(e.type==="ConditionalExpression")return n(e.consequent,t)||n(e.alternate,t);if(e.type==="LogicalExpression")return n(e.left,t)||n(e.right,t);if(e.type==="BinaryExpression")return n(e.left,t)||n(e.right,t);if(e.type==="TemplateLiteral")return e.expressions.some((r)=>n(r,t));if(e.type==="SpreadElement")return n(e.argument,t);if(e.type==="ChainExpression")return n(e.expression,t);if(e.type==="TSAsExpression"||e.type==="TSSatisfiesExpression"||e.type==="TSNonNullExpression")return n(e.expression,t);return!1},o=(e)=>{if(e.type==="ArrayExpression")return e.elements.every((r)=>r===null||o(r));if(e.type==="LogicalExpression"&&e.operator==="&&")return o(e.right);if(e.type==="ConditionalExpression")return o(e.consequent)&&o(e.alternate);if(e.type==="Literal")return e.value===null||e.value===!1;if(e.type==="CallExpression")return o(e.callee);if(e.type!=="MemberExpression")return!1;const t=h(s,e.object);return t!==null&&S(s,t,"create",m)},T=(e,t)=>{let r=s.sourceCode.getScope(e);while(r){const a=r.set.get(t);if(a)return a.defs.some((p)=>{if(p.type!=="ImportBinding")return!1;const i=p.node;return i.parent?.type==="ImportDeclaration"&&i.parent.importKind!=="type"&&(i.type!=="ImportSpecifier"||i.importKind!=="type")});r=r.upper}return!1},X=(e)=>{if(e.type!=="JSXOpeningElement")return!1;const[t=""]=O(e.name).split(".");let r=s.sourceCode.getScope(e.name);while(r){const a=r.set.get(t);if(a)return a.defs.some((p)=>p.type==="ImportBinding"&&p.node.parent?.type==="ImportDeclaration"&&g(p.node.parent.source.value,f));r=r.upper}return!1},z=(e)=>{for(const t of l.namespaces)if(T(e,t))return`${t}.props`;for(const t of l.named)if(T(e,t))return t;return null},v=(e,t,r,a)=>{if(/^[a-z][a-zA-Z0-9]*Sx$/.test(a)||e.type!=="JSXOpeningElement")return null;if(e.attributes.some((i)=>i!==t&&(i.type==="JSXSpreadAttribute"||["className","style"].includes(b(i)))))return null;if(r.type==="MemberExpression"&&!r.computed&&r.property.type==="Identifier"){const{object:i,property:N}=r;if(i.type==="CallExpression"&&["className","style"].includes(N.name)&&S(s,i,"props",l))return s.sourceCode.getText(i)}const p=z(t);return p&&o(r)?`${p}(${s.sourceCode.getText(r)})`:null},w=(e,t)=>{if(t.type!=="JSXAttribute")return;y.clear();const r=b(t);if(t.value?.type!=="JSXExpressionContainer")return;const a=t.value.expression;if(!n(a,r==="className"))return;if(r==="sx"&&X(e))return;if(g(s.filename,f)&&j(s,a,l))return;const p=v(e,t,a,r);s.report({node:t,message:`Spread \`stylex.props(...)\` on this component instead of passing a StyleX style as \`${r}\`.`,suggest:p===null?void 0:[{desc:"Spread complete StyleX props",fix:(i)=>i.replaceText(t,`{...${p}}`)}]})};return{before(){u.namespaces.clear();u.named.clear();l.namespaces.clear();l.named.clear();m.namespaces.clear();m.named.clear();y.clear();f=d(P(s,{}));return s.sourceCode.text.includes("stylex")},Program(e){c(e.body,"StyleXStyles",u);c(e.body,"StyleXStylesWithout",u);c(e.body,"props",l);c(e.body,"create",m)},TSPropertySignature(e){if(u.named.size===0&&u.namespaces.size===0)return;if(e.computed||!e.typeAnnotation||!E(e.typeAnnotation.typeAnnotation))return;if(g(s.filename,f)&&e.key.type==="Identifier"&&e.key.name==="sx")return;s.report({node:e.key,message:"Spread `stylex.props(...)` at the call site instead of defining a StyleX style prop."})},JSXOpeningElement(e){if(e.name.type==="JSXIdentifier"&&!/^[A-Z]/.test(e.name.name))return;if(!m.namespaces.size&&!m.named.size&&!l.namespaces.size&&!l.named.size)return;for(const t of e.attributes)w(e,t)}}}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ashstack/lint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "ashStack shared oxlint configuration and custom rules. Entries: core, react, react-native, with per-library rule groups auto-detected from your dependencies. Consume from oxlint.config.mts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{attributeName as x,problem as h}from"../../../lib/ast.js";import{collectImports as l,isImportedBinding as m,isStylexCall as o}from"./imports.js";const f=/^[a-z][a-zA-Z0-9]*Sx$/,S=(i,n)=>{if(n.type!=="Identifier")return null;let a=i.sourceCode.getScope(n);while(a){const p=a.set.get(n.name);if(p){const y=p.defs.find((u)=>u.node.type==="VariableDeclarator")?.node;return y?.type==="VariableDeclarator"?y.init??null:null}a=a.upper}return null};export const useSxProp=h("Name StyleX override props `sx` or `<slot>Sx` and pass styles through them.",{createOnce(i){const n={namespaces:new Set,named:new Set},a={namespaces:new Set,named:new Set},p={namespaces:new Set,named:new Set},y=new Set,u=(e)=>{if(e.type==="TSTypeReference"){const t=e.typeName;if(t.type==="Identifier")return n.named.has(t.name)&&m(i,t);return t.type==="TSQualifiedName"&&t.left.type==="Identifier"&&n.namespaces.has(t.left.name)&&(t.right.name==="StyleXStyles"||t.right.name==="StyleXStylesWithout")&&m(i,t.left)}if(e.type==="TSUnionType"||e.type==="TSIntersectionType")return e.types.some(u);if(e.type==="TSParenthesizedType")return u(e.typeAnnotation);return!1},r=(e,t=!1)=>{if(e.type==="Identifier"){const s=S(i,e);if(s===null||y.has(s))return!1;y.add(s);return r(s,t)}if(e.type==="MemberExpression"){const s=S(i,e.object);if(s!==null&&o(i,s,"create",p))return!0;return r(e.object,t)}if(e.type==="CallExpression")return o(i,e,"props",a)||r(e.callee,t)||t&&e.arguments.some((s)=>r(s,!0));return c(e,t)},c=(e,t)=>{if(e.type==="ArrayExpression")return e.elements.some((s)=>s!==null&&r(s,t));if(e.type==="ObjectExpression")return e.properties.some((s)=>s.type==="Property"&&r(s.value,t));if(e.type==="ConditionalExpression")return r(e.consequent,t)||r(e.alternate,t);if(e.type==="LogicalExpression")return r(e.left,t)||r(e.right,t);if(e.type==="BinaryExpression")return r(e.left,t)||r(e.right,t);if(e.type==="TemplateLiteral")return e.expressions.some((s)=>r(s,t));if(e.type==="SpreadElement")return r(e.argument,t);if(e.type==="ChainExpression")return r(e.expression,t);if(e.type==="TSAsExpression"||e.type==="TSSatisfiesExpression"||e.type==="TSNonNullExpression")return r(e.expression,t);return!1};return{before(){n.namespaces.clear();n.named.clear();a.namespaces.clear();a.named.clear();p.namespaces.clear();p.named.clear();y.clear();return i.sourceCode.text.includes("stylex")},Program(e){l(e.body,"StyleXStyles",n);l(e.body,"StyleXStylesWithout",n);l(e.body,"props",a);l(e.body,"create",p)},TSPropertySignature(e){if(n.named.size===0&&n.namespaces.size===0)return;if(e.computed||!e.typeAnnotation||!u(e.typeAnnotation.typeAnnotation))return;let t=null;if(e.key.type==="Identifier")t=e.key.name;if(e.key.type==="Literal"&&typeof e.key.value==="string")t=e.key.value;if(t===null||t==="sx"||f.test(t))return;const s=t.startsWith("style")?"sx":`${t.replace(/Style$/,"")}Sx`;i.report({node:e.key,message:`Rename \`${t}\` to \`${s}\` for a StyleX override prop.`})},JSXOpeningElement(e){if(e.name.type==="JSXIdentifier"&&!/^[A-Z]/.test(e.name.name))return;if(!p.namespaces.size&&!p.named.size&&!a.namespaces.size&&!a.named.size)return;for(const t of e.attributes){y.clear();if(t.type==="JSXSpreadAttribute"){if(r(t.argument))i.report({node:t,message:"Pass StyleX styles as `sx` to this component."});continue}const s=x(t);if(s==="sx"||f.test(s)||t.value?.type!=="JSXExpressionContainer")continue;if(r(t.value.expression,s==="className"))i.report({node:t,message:`Pass this StyleX style as \`sx\` or a named \`<slot>Sx\` prop, not \`${s}\`.`})}}}}});
|