mirror of
				https://github.com/lingble/twenty.git
				synced 2025-10-31 04:37:56 +00:00 
			
		
		
		
	 bb7d94a455
			
		
	
	bb7d94a455
	
	
	
		
			
			### Description Create ESLint rule to discourage usage of navigate() and prefer Link ### Refs #5468 ### Demo   Fixes #5468 --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { TSESLint } from '@typescript-eslint/utils';
 | |
| 
 | |
| import { rule, RULE_NAME } from './no-navigate-prefer-link';
 | |
| 
 | |
| const ruleTester = new TSESLint.RuleTester({
 | |
|   parser: require.resolve('@typescript-eslint/parser'),
 | |
| });
 | |
| 
 | |
| ruleTester.run(RULE_NAME, rule, {
 | |
|   valid: [
 | |
|     {
 | |
|       code: 'if(someVar) { navigate("/"); }',
 | |
|     },
 | |
|     {
 | |
|       code: '<Link to="/"><Button>Click me</Button></Link>',
 | |
|       parserOptions: {
 | |
|         ecmaFeatures: {
 | |
|           jsx: true,
 | |
|         },
 | |
|       },
 | |
|     },
 | |
|     {
 | |
|       code: '<Button onClick={() =>{ navigate("/"); doSomething(); }} />',
 | |
|       parserOptions: {
 | |
|         ecmaFeatures: {
 | |
|           jsx: true,
 | |
|         },
 | |
|       },
 | |
|     },
 | |
|   ],
 | |
|   invalid: [
 | |
|     {
 | |
|       code: '<Button onClick={() => navigate("/")} />',
 | |
|       errors: [
 | |
|         {
 | |
|           messageId: 'preferLink',
 | |
|         },
 | |
|       ],
 | |
|       parserOptions: {
 | |
|         ecmaFeatures: {
 | |
|           jsx: true,
 | |
|         },
 | |
|       },
 | |
|     },
 | |
|     {
 | |
|       code: '<Button onClick={() => { navigate("/");} } />',
 | |
|       errors: [
 | |
|         {
 | |
|           messageId: 'preferLink',
 | |
|         },
 | |
|       ],
 | |
|       parserOptions: {
 | |
|         ecmaFeatures: {
 | |
|           jsx: true,
 | |
|         },
 | |
|       },
 | |
|     },
 | |
|   ],
 | |
| });
 |