Skip to content

Commit 395d488

Browse files
fernandatoledoasdolo
authored andcommitted
Merge pull request #46 from rootstrap/fix/sonar_issues
Fix/sonar issues
2 parents a7228f8 + f8caa9c commit 395d488

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+251
-151
lines changed

.eslintrc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ module.exports = {
1919
ignore: ['/android', '/ios'],
2020
},
2121
],
22+
curly: [2, 'all'],
23+
'prefer-const': [
24+
'error',
25+
{
26+
destructuring: 'any',
27+
},
28+
],
2229
},
2330
overrides: [
2431
// Configuration for TypeScript files
@@ -39,6 +46,8 @@ module.exports = {
3946
project: './tsconfig.json',
4047
},
4148
rules: {
49+
'react/react-in-jsx-scope': 'off',
50+
'react/jsx-uses-react': 'off',
4251
'prettier/prettier': [
4352
'error',
4453
{
@@ -72,6 +81,19 @@ module.exports = {
7281
caughtErrorsIgnorePattern: '^_',
7382
},
7483
],
84+
'no-restricted-imports': [
85+
'error',
86+
{
87+
paths: [
88+
{
89+
name: 'react',
90+
importNames: ['default'],
91+
message: 'No need to import React',
92+
},
93+
],
94+
},
95+
],
96+
curly: [2, 'all'],
7597
},
7698
},
7799
// Configuration for translations files (i18next)
@@ -106,6 +128,7 @@ module.exports = {
106128
endOfLine: 'auto',
107129
},
108130
],
131+
curly: [2, 'all'],
109132
},
110133
},
111134
{

.vscode/project.code-snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Component": {
2626
"prefix": "comp",
2727
"body": [
28-
"import * as React from 'react';",
28+
"import React from 'react';",
2929
"",
3030
"import { Text, View } from '@/ui';",
3131
"",

docs/src/content/docs/ui-and-theme/Forms.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Let's say you want to create a form that allows the user to log in to the applic
3636
The right way to validate a form is to create a schema validation. You can use any library you want but we recommend using zod as you can easily infer the types from the schema. Here is how you can create a schema validation for the login form:
3737

3838
```tsx
39-
import * as z from 'zod';
39+
import z from 'zod';
4040

4141
const schema = z.object({
4242
email: z.string().email(),
@@ -53,9 +53,8 @@ Here is how you can create your login screen:
5353

5454
```tsx
5555
import { zodResolver } from '@hookform/resolvers/zod';
56-
import React from 'react';
5756
import { useForm } from 'react-hook-form';
58-
import * as z from 'zod';
57+
import z from 'zod';
5958

6059
import { useAuth } from '@/core';
6160
import { Button, ControlledInput, View } from '@/ui';

docs/src/content/docs/ui-and-theme/components.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ We also provide an `EmptyList` component that you can use to display a message w
5656
**Use Case**
5757

5858
```tsx
59-
import * as React from 'react';
59+
import React from 'react';
6060
import { List, EmptyList, Text } from '@/ui';
6161

6262
const MyComponent = () => {
@@ -85,7 +85,7 @@ The `cssInterop` function from `nativewind` is used to apply styling and, in thi
8585
**Use Case**
8686

8787
```tsx
88-
import * as React from 'react';
88+
import React from 'react';
8989
import { Image } from '@/ui';
9090

9191
const MyComponent = () => {
@@ -119,7 +119,7 @@ You can also use the `t` snippet to create a simple Text with a default `classNa
119119
**Use Case**
120120

121121
```tsx
122-
import * as React from 'react';
122+
import React from 'react';
123123
import { Text, View } from 'react-native';
124124

125125
const MyComponent = () => {
@@ -183,7 +183,7 @@ Read more about Handling Forms [here](../forms/).
183183
**Use Case**
184184

185185
```tsx
186-
import * as React from 'react';
186+
import React from 'react';
187187
import { Input, View } from '@/ui';
188188

189189
const MyComponent = () => {
@@ -214,7 +214,7 @@ Based on your needs, you can use the `Modal` if you don't have a fixed height fo
214214
**Use Case**
215215

216216
```tsx
217-
import * as React from 'react';
217+
import React from 'react';
218218
import { Modal, useModal, View, Button, Text } from '@/ui';
219219

220220
const MyComponent = () => {
@@ -256,7 +256,7 @@ Feel free to update the component implementation to fit your need and as you kee
256256
**Use Case**
257257

258258
```tsx
259-
import * as React from 'react';
259+
import React from 'react';
260260

261261
import type { Option } from '@/ui';
262262
import { SelectInput, View } from '@/ui';

src/api/common/api-provider.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useReactQueryDevTools } from '@dev-plugins/react-query';
22
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3-
import * as React from 'react';
4-
53
export const queryClient = new QueryClient();
64

75
export function APIProvider({ children }: { children: React.ReactNode }) {

src/api/common/utils.spec.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toCamelCase, toSnakeCase } from './utils';
1+
import { getUrlParameters, toCamelCase, toSnakeCase } from './utils';
22

33
describe('utils', () => {
44
describe('toCamelCase', () => {
@@ -57,3 +57,32 @@ describe('utils', () => {
5757
});
5858
});
5959
});
60+
61+
describe('getUrlParameters', () => {
62+
it('should return null for a null URL', () => {
63+
const result = getUrlParameters(null);
64+
expect(result).toBeNull();
65+
});
66+
67+
it('should return an empty object for a URL with no parameters', () => {
68+
const result = getUrlParameters('https://example.com');
69+
expect(result).toEqual({});
70+
});
71+
72+
it('should return an object with a single key-value pair for a URL with one parameter', () => {
73+
const result = getUrlParameters('https://example.com?name=John');
74+
expect(result).toEqual({ name: 'John' });
75+
});
76+
77+
it('should return an object with multiple key-value pairs for a URL with multiple parameters', () => {
78+
const result = getUrlParameters('https://example.com?name=John&age=30');
79+
expect(result).toEqual({ name: 'John', age: '30' });
80+
});
81+
82+
it('should handle special characters in the URL parameters', () => {
83+
const result = getUrlParameters(
84+
'https://example.com?name=John%20Doe&city=New%20York'
85+
);
86+
expect(result).toEqual({ name: 'John Doe', city: 'New York' });
87+
});
88+
});

src/api/common/utils.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ export function getUrlParameters(
2828
if (url === null) {
2929
return null;
3030
}
31-
let regex = /[?&]([^=#]+)=([^&#]*)/g,
32-
params = {},
33-
match;
34-
while ((match = regex.exec(url))) {
35-
if (match[1] !== null) {
36-
//@ts-ignore
37-
params[match[1]] = match[2];
38-
}
39-
}
31+
const urlObj = new URL(url);
32+
const params: { [key: string]: string } = {};
33+
urlObj.searchParams.forEach((value, key) => {
34+
params[key] = value;
35+
});
4036
return params;
4137
}
4238

src/app/(app)/_layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable react/no-unstable-nested-components */
22
import { Link, Redirect, SplashScreen, Tabs } from 'expo-router';
3-
import React, { useCallback, useEffect } from 'react';
3+
import { useCallback, useEffect } from 'react';
44

55
import { useAuth, useIsFirstTime } from '@/core';
66
import { Pressable, Text } from '@/ui';

src/app/(app)/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FlashList } from '@shopify/flash-list';
2-
import React from 'react';
2+
import { useCallback } from 'react';
33

44
import type { Post } from '@/api';
55
import { usePosts } from '@/api';
@@ -8,7 +8,7 @@ import { EmptyList, FocusAwareStatusBar, Text, View } from '@/ui';
88

99
export default function Feed() {
1010
const { data, isPending, isError } = usePosts();
11-
const renderItem = React.useCallback(
11+
const renderItem = useCallback(
1212
({ item }: { item: Post }) => <Card {...item} />,
1313
[]
1414
);

src/app/(app)/settings.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable react/react-in-jsx-scope */
21
import { Env } from '@env';
32
import { useColorScheme } from 'nativewind';
43

0 commit comments

Comments
 (0)