@ashstack/lint 0.10.4 → 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/rule-types/react.d.ts +8 -2
- package/dist/react/rules/react/prefer-design-system.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 -1
- package/package.json +1 -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}`))};
|
|
@@ -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
|
*
|
|
@@ -178,7 +181,10 @@ declare module "oxlint" {
|
|
|
178
181
|
*
|
|
179
182
|
* @see https://github.com/AlshehriAli0/ashStack/blob/main/packages/lint/rules/stylex.md#ashstackstylexspread-props
|
|
180
183
|
*/
|
|
181
|
-
"@ashstack/stylex/spread-props"?: RuleSetting
|
|
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{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))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{attributeName as
|
|
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",
|