@@ -288,19 +288,21 @@ describe('JSX guards', () => {
288288 name : 'keeps JSX restrictions: export const Sample = () => <form />;' ,
289289 filename : 'src/components/sample.tsx' ,
290290 code : 'export const Sample = () => <form />;' ,
291- errors : [ / U s e ` F o r m ` f r o m m o s a i c \/ p r i m i t i v e s \/ f o r m / ] ,
291+ errors : [ / ^ U s e ` F o r m ` f r o m s r c \/ p r i m i t i v e s \/ f o r m , d r i v e n b y ` u s e F o r m ` f r o m s r c \/ c o m p o n e n t s \/ f o r m / ] ,
292292 } ,
293293 {
294294 name : "keeps JSX restrictions: export const Sample = ({ Part }: { Part: 'div' }) => <Part className='x' />;" ,
295295 filename : 'src/components/sample.tsx' ,
296296 code : "export const Sample = ({ Part }: { Part: 'div' }) => <Part className='x' />;" ,
297- errors : [ / M o s a i c p a r t s t a k e ` x s t y l e ` / ] ,
297+ errors : [
298+ / ^ M o s a i c p a r t s t a k e ` x s t y l e ` i n s t e a d o f ` c l a s s N a m e ` \/ ` s t y l e ` \. D e f i n e t h e a t o m s w i t h ` s t y l e x \. c r e a t e ` i n t h e s i b l i n g ` \* \. s t y l e s \. t s ` f i l e / ,
299+ ] ,
298300 } ,
299301 {
300302 name : 'rejects native forms in views' ,
301303 filename : 'src/features/reverification/sample.view.tsx' ,
302304 code : 'export function View() { return <form />; }' ,
303- errors : [ / U s e ` F o r m ` f r o m m o s a i c \/ p r i m i t i v e s \/ f o r m / ] ,
305+ errors : [ / ^ U s e ` F o r m ` f r o m s r c \/ p r i m i t i v e s \/ f o r m , d r i v e n b y ` u s e F o r m ` f r o m s r c \/ c o m p o n e n t s \/ f o r m / ] ,
304306 } ,
305307 {
306308 name : 'rejects logical AND in conditional JSX' ,
@@ -312,14 +314,104 @@ describe('JSX guards', () => {
312314 name : `rejects ${ attribute } on member components` ,
313315 filename : 'src/components/sample.tsx' ,
314316 code : `export const Sample = () => <Card.Root ${ attribute } />;` ,
315- errors : [ / M o s a i c p a r t s t a k e ` x s t y l e ` / ] ,
317+ errors : [
318+ / ^ M o s a i c p a r t s t a k e ` x s t y l e ` i n s t e a d o f ` c l a s s N a m e ` \/ ` s t y l e ` \. D e f i n e t h e a t o m s w i t h ` s t y l e x \. c r e a t e ` i n t h e s i b l i n g ` \* \. s t y l e s \. t s ` f i l e / ,
319+ ] ,
316320 } ) ) ,
317321 ...[ 'Part' , 'Card.Root' ] . map ( component => ( {
318322 name : `rejects stylex.props spreads on ${ component } ` ,
319323 filename : 'src/components/sample.tsx' ,
320324 code : `export const Sample = () => <${ component } {...stylex.props(styles.root)} />;` ,
321- errors : [ / M o s a i c p a r t s t a k e t h e a t o m s a s ` x s t y l e ` / ] ,
325+ errors : [
326+ / ^ M o s a i c p a r t s t a k e t h e a t o m s a s ` x s t y l e ` , n o t a ` s t y l e x \. p r o p s \( \. \. \. \) ` s p r e a d \. D e f i n e t h e m w i t h ` s t y l e x \. c r e a t e ` i n t h e s i b l i n g ` \* \. s t y l e s \. t s ` f i l e / ,
327+ ] ,
322328 } ) ) ,
323329 ] . map ( testCase => ( { ...testCase , options } ) ) ,
324330 } ) ;
325331} ) ;
332+
333+ describe ( 'raw element guards in features and blocks' , ( ) => {
334+ const override = config . overrides . find (
335+ override => override . files . includes ( 'src/features/**/*' ) && override . rules [ 'eslint-compat/no-restricted-syntax' ] ,
336+ ) ;
337+ const options = override . rules [ 'eslint-compat/no-restricted-syntax' ] . slice ( 1 ) ;
338+ ruleTester . run ( 'no-restricted-syntax' , syntaxPlugin . rules [ 'no-restricted-syntax' ] , {
339+ valid : [
340+ "export const View = () => <Menu.Item render={<button type='button' onClick={onPick} />} />;" ,
341+ 'export const View = () => <Part render={<svg aria-hidden />} />;' ,
342+ "export const View = () => <input type='hidden' name='id' value={id} />;" ,
343+ "export const View = () => <input readOnly hidden name='identifier' value={identifier} />;" ,
344+ "export const View = () => <input type='password' hidden name='password' />;" ,
345+ 'export const View = () => <Menu.Item render={props => <button {...props} />} />;' ,
346+ 'export const View = () => <Part render={function render(props) { return <svg {...props} />; }} />;' ,
347+ 'export const View = () => <Part render={(props, state) => { return <input {...props} />; }} />;' ,
348+ "export const View = () => <input hidden={true} name='identifier' />;" ,
349+ "export const View = () => <Button type='button' />;" ,
350+ "export const View = () => <Icon name='check' />;" ,
351+ ] . flatMap ( code =>
352+ [ 'src/features/sample/sample.view.tsx' , 'src/blocks/sample/sample.tsx' ] . map ( filename => ( {
353+ code,
354+ filename,
355+ options,
356+ } ) ) ,
357+ ) ,
358+ invalid : [
359+ {
360+ name : 'rejects a raw button' ,
361+ code : "export const View = () => <button type='button' />;" ,
362+ errors : [ / ^ U s e ` B u t t o n ` f r o m s r c \/ c o m p o n e n t s \/ b u t t o n , o r ` S u b m i t B u t t o n ` w h e n t h e c l i c k r u n s a n a s y n c a c t i o n / ] ,
363+ } ,
364+ {
365+ name : 'rejects a raw button nested in a render prop element' ,
366+ code : "export const View = () => <Part render={<div><button type='button' /></div>} />;" ,
367+ errors : [ / ^ U s e ` B u t t o n ` f r o m s r c \/ c o m p o n e n t s \/ b u t t o n / ] ,
368+ } ,
369+ {
370+ name : 'rejects a raw button nested in a render callback element' ,
371+ code : 'export const View = () => <Part render={props => <div {...props}><button type="button" /></div>} />;' ,
372+ errors : [ / ^ U s e ` B u t t o n ` f r o m s r c \/ c o m p o n e n t s \/ b u t t o n / ] ,
373+ } ,
374+ {
375+ name : 'rejects a visible input with hidden={false}' ,
376+ code : "export const View = () => <input hidden={false} name='field' />;" ,
377+ errors : [ / ^ U s e ` I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ i n p u t i n s i d e ` F i e l d ` / ] ,
378+ } ,
379+ {
380+ name : 'rejects a visible password input with hidden={false}' ,
381+ code : "export const View = () => <input type='password' hidden={false} name='field' />;" ,
382+ errors : [ / ^ U s e ` P a s s w o r d I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ p a s s w o r d - i n p u t / ] ,
383+ } ,
384+ {
385+ name : 'rejects a raw svg' ,
386+ code : 'export const View = () => <svg viewBox="0 0 16 16"><path d="M0 0" /></svg>;' ,
387+ errors : [ / ^ U s e a n i c o n f r o m s r c \/ i c o n s t h r o u g h ` I c o n ` .* s t o p a n d a s k t h e u s e r / ] ,
388+ } ,
389+ ...[
390+ [ "type='password'" , / ^ U s e ` P a s s w o r d I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ p a s s w o r d - i n p u t i n s i d e ` F i e l d ` / ] ,
391+ [ "type='tel'" , / ^ U s e ` P h o n e I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ p h o n e - i n p u t i n s i d e ` F i e l d ` / ] ,
392+ [ "type='checkbox'" , / ^ U s e ` C h e c k b o x ` f r o m s r c \/ c o m p o n e n t s \/ c h e c k b o x , o r ` S w i t c h ` / ] ,
393+ [ "type='radio'" , / ^ U s e ` R a d i o ` f r o m s r c \/ c o m p o n e n t s \/ r a d i o / ] ,
394+ [ "type='file'" , / ^ U s e ` F i l e U p l o a d ` f r o m s r c \/ p r i m i t i v e s \/ f i l e - u p l o a d , o r ` A v a t a r U p l o a d ` / ] ,
395+ [ "type='email'" , / ^ U s e ` I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ i n p u t i n s i d e ` F i e l d ` / ] ,
396+ [ "type='text'" , / ^ U s e ` I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ i n p u t i n s i d e ` F i e l d ` / ] ,
397+ [ '' , / ^ U s e ` I n p u t ` f r o m s r c \/ c o m p o n e n t s \/ i n p u t i n s i d e ` F i e l d ` / ] ,
398+ ] . map ( ( [ type , message ] ) => ( {
399+ name : `rejects a visible input: <input ${ type } />` ,
400+ code : `export const View = () => <input ${ type } name='field' />;` ,
401+ errors : [ message ] ,
402+ } ) ) ,
403+ {
404+ name : 'keeps the shared JSX guards' ,
405+ code : 'export const View = () => <form />;' ,
406+ errors : [ / ^ U s e ` F o r m ` f r o m s r c \/ p r i m i t i v e s \/ f o r m , d r i v e n b y ` u s e F o r m ` f r o m s r c \/ c o m p o n e n t s \/ f o r m / ] ,
407+ } ,
408+ ] . flatMap ( testCase =>
409+ [ 'src/features/sample/sample.view.tsx' , 'src/blocks/sample/sample.tsx' ] . map ( filename => ( {
410+ ...testCase ,
411+ name : `${ testCase . name } in ${ filename } ` ,
412+ filename,
413+ options,
414+ } ) ) ,
415+ ) ,
416+ } ) ;
417+ } ) ;
0 commit comments