-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(@stylexjs/eslint-plugin): Accept { from: string, as: string } syntax in validImports option for RSD #569
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,13 @@ import getPropertyPriorityAndType from './utils/getPropertyPriorityAndType'; | |
/*:: import { Rule } from 'eslint'; */ | ||
|
||
type Schema = { | ||
validImports: Array<string>, | ||
validImports: Array< | ||
| string | ||
| { | ||
from: string, | ||
as: string, | ||
}, | ||
>, | ||
minKeys: number, | ||
allowLineSeparatedGroups: boolean, | ||
}; | ||
|
@@ -64,7 +70,18 @@ const stylexSortKeys = { | |
properties: { | ||
validImports: { | ||
type: 'array', | ||
items: { type: 'string' }, | ||
items: { | ||
oneOf: [ | ||
{ type: 'string' }, | ||
{ | ||
type: 'object', | ||
properties: { | ||
from: { type: 'string' }, | ||
as: { type: 'string' }, | ||
}, | ||
}, | ||
], | ||
}, | ||
default: ['stylex', '@stylexjs/stylex'], | ||
}, | ||
minKeys: { | ||
|
@@ -128,32 +145,47 @@ const stylexSortKeys = { | |
return; | ||
} | ||
|
||
if (!importsToLookFor.includes(node.source.value)) { | ||
return; | ||
} | ||
|
||
node.specifiers.forEach((specifier) => { | ||
if ( | ||
specifier.type === 'ImportDefaultSpecifier' || | ||
specifier.type === 'ImportNamespaceSpecifier' | ||
) { | ||
styleXDefaultImports.add(specifier.local.name); | ||
const foundImportSource = importsToLookFor.find((importSource) => { | ||
if (typeof importSource === 'string') { | ||
return importSource === node.source.value; | ||
} | ||
return importSource.from === node.source.value; | ||
}); | ||
|
||
if ( | ||
specifier.type === 'ImportSpecifier' && | ||
specifier.imported.name === 'create' | ||
) { | ||
styleXCreateImports.add(specifier.local.name); | ||
} | ||
if (typeof foundImportSource === 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then, if |
||
node.specifiers.forEach((specifier) => { | ||
if ( | ||
specifier.type === 'ImportDefaultSpecifier' || | ||
specifier.type === 'ImportNamespaceSpecifier' | ||
) { | ||
styleXDefaultImports.add(specifier.local.name); | ||
} | ||
|
||
if ( | ||
specifier.type === 'ImportSpecifier' && | ||
specifier.imported.name === 'keyframes' | ||
) { | ||
styleXKeyframesImports.add(specifier.local.name); | ||
} | ||
}); | ||
if ( | ||
specifier.type === 'ImportSpecifier' && | ||
specifier.imported.name === 'create' | ||
) { | ||
styleXCreateImports.add(specifier.local.name); | ||
} | ||
|
||
if ( | ||
specifier.type === 'ImportSpecifier' && | ||
specifier.imported.name === 'keyframes' | ||
) { | ||
styleXKeyframesImports.add(specifier.local.name); | ||
} | ||
}); | ||
} | ||
|
||
if (typeof foundImportSource === 'object') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If using the new
|
||
node.specifiers.forEach((specifier) => { | ||
if (specifier.type === 'ImportSpecifier') { | ||
if (specifier.imported.name === foundImportSource.as) { | ||
styleXDefaultImports.add(specifier.local.name); | ||
} | ||
} | ||
}); | ||
} | ||
}, | ||
CallExpression( | ||
node: $ReadOnly<{ ...CallExpression, ...Rule.NodeParentExtension }>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foundImportSource
will be either a string or the object containing "as" and "from".