Skip to content

Commit 80d966c

Browse files
committed
refactor: setup prettier
1 parent 1641e09 commit 80d966c

15 files changed

Lines changed: 377 additions & 114 deletions

File tree

eslint.config.mjs

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,75 @@
1-
import { fixupConfigRules } from '@eslint/compat';
2-
import { FlatCompat } from '@eslint/eslintrc';
3-
import js from '@eslint/js';
4-
import prettier from 'eslint-plugin-prettier';
5-
import { defineConfig } from 'eslint/config';
6-
import path from 'node:path';
7-
import { fileURLToPath } from 'node:url';
1+
import { resolve } from "node:path";
82

9-
const __filename = fileURLToPath(import.meta.url);
10-
const __dirname = path.dirname(__filename);
11-
const compat = new FlatCompat({
12-
baseDirectory: __dirname,
13-
recommendedConfig: js.configs.recommended,
14-
allConfig: js.configs.all,
15-
});
3+
import eslint from "@eslint/js";
4+
import prettier from "eslint-plugin-prettier/recommended";
5+
import { globalIgnores } from "eslint/config";
6+
import tseslint from "typescript-eslint";
167

17-
export default defineConfig([
8+
export default tseslint.config(
9+
eslint.configs.recommended,
10+
tseslint.configs.strictTypeChecked,
11+
tseslint.configs.stylisticTypeChecked,
12+
prettier,
13+
{
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true,
17+
tsconfigRootDir: resolve("../"),
18+
},
19+
},
20+
},
21+
globalIgnores([
22+
"**/dist/*",
23+
".yarn/*",
24+
"**/eslint.config.[cm]js",
25+
"**/prettier.config.[cm]js",
26+
"**/babel.config.js",
27+
"**/metro.config.js",
28+
]),
1829
{
19-
extends: fixupConfigRules(compat.extends('@react-native', 'prettier')),
20-
plugins: { prettier },
2130
rules: {
22-
'react/react-in-jsx-scope': 'off',
23-
'prettier/prettier': 'error',
31+
"prefer-const": [
32+
"error",
33+
{
34+
destructuring: "all",
35+
},
36+
],
37+
"no-unused-vars": "off",
38+
"@typescript-eslint/no-unsafe-assignment": "off",
39+
"@typescript-eslint/no-explicit-any": "off",
40+
"@typescript-eslint/no-unsafe-call": "off",
41+
"@typescript-eslint/no-unsafe-return": "off",
42+
"@typescript-eslint/no-unsafe-member-access": "off",
43+
"@typescript-eslint/no-unsafe-member-access": "off",
44+
"@typescript-eslint/no-unsafe-argument": "off",
45+
"@typescript-eslint/no-unused-vars": [
46+
"warn",
47+
{
48+
args: "after-used",
49+
ignoreRestSiblings: true,
50+
argsIgnorePattern: "^_",
51+
},
52+
],
53+
"@typescript-eslint/restrict-template-expressions": [
54+
"error",
55+
{
56+
allow: [{ name: ["Error", "URL", "URLSearchParams"], from: "lib" }],
57+
allowAny: true,
58+
allowBoolean: true,
59+
allowNullish: true,
60+
allowNumber: true,
61+
allowRegExp: true,
62+
},
63+
],
2464
},
2565
},
66+
// Test file specific rules
67+
// These rules are causing false positives with @react-native/testing-library
2668
{
27-
ignores: ['node_modules/', 'lib/'],
69+
files: ["**/__tests__/**/*", "**/*.test.*", "**/*.spec.*"],
70+
rules: {
71+
"@typescript-eslint/no-unsafe-assignment": "off",
72+
"@typescript-eslint/no-unsafe-member-access": "off",
73+
},
2874
},
29-
]);
75+
);

example/src/App.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { View, StyleSheet } from 'react-native';
2-
import { multiply, StyleRegistry } from 'react-native-css-nitro';
3-
import { Text } from 'react-native-css-nitro/components/Text';
1+
import { StyleSheet, View } from "react-native";
42

5-
StyleRegistry.set('text-red-500', { s: [], d: [{ color: 'red' }] });
3+
import { multiply, StyleRegistry } from "react-native-css-nitro";
4+
import { Text } from "react-native-css-nitro/components/Text";
5+
6+
StyleRegistry.set("text-red-500", { s: [], d: [{ color: "red" }] });
67

78
export default function App() {
89
return (
910
<View style={styles.container}>
1011
<Text
1112
className="text-red-500"
1213
onPress={() => {
13-
console.log('Pressed!');
14-
StyleRegistry.set('text-red-500', {
14+
console.log("Pressed!");
15+
StyleRegistry.set("text-red-500", {
1516
s: [],
16-
d: [{ color: 'blue', fontSize: 40 }],
17+
d: [{ color: "blue", fontSize: 40 }],
1718
});
1819
}}
1920
>
@@ -26,7 +27,7 @@ export default function App() {
2627
const styles = StyleSheet.create({
2728
container: {
2829
flex: 1,
29-
alignItems: 'center',
30-
justifyContent: 'center',
30+
alignItems: "center",
31+
justifyContent: "center",
3132
},
3233
});

package.json

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@
7373
"@eslint/eslintrc": "^3.3.1",
7474
"@eslint/js": "^9.35.0",
7575
"@evilmartians/lefthook": "^1.12.3",
76+
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
7677
"@react-native/babel-preset": "0.81.1",
7778
"@react-native/eslint-config": "^0.81.1",
79+
"@react-native/typescript-config": "^0.82.0",
7880
"@release-it/conventional-changelog": "^10.0.1",
7981
"@types/jest": "^29.5.14",
8082
"@types/react": "^19.1.0",
@@ -84,6 +86,7 @@
8486
"eslint-config-prettier": "^10.1.8",
8587
"eslint-plugin-prettier": "^5.5.4",
8688
"jest": "^29.7.0",
89+
"lightningcss": "^1.30.2",
8790
"nitrogen": "^0.29.1",
8891
"prettier": "^3.6.2",
8992
"react": "19.1.0",
@@ -92,7 +95,8 @@
9295
"react-native-nitro-modules": "^0.29.1",
9396
"release-it": "^19.0.4",
9497
"turbo": "^2.5.6",
95-
"typescript": "^5.9.2"
98+
"typescript": "^5.9.2",
99+
"typescript-eslint": "^8.46.1"
96100
},
97101
"peerDependencies": {
98102
"react": "*",
@@ -134,13 +138,6 @@
134138
}
135139
}
136140
},
137-
"prettier": {
138-
"quoteProps": "consistent",
139-
"singleQuote": true,
140-
"tabWidth": 2,
141-
"trailingComma": "es5",
142-
"useTabs": false
143-
},
144141
"react-native-builder-bob": {
145142
"source": "src",
146143
"output": "lib",
@@ -170,9 +167,5 @@
170167
"languages": "kotlin-swift",
171168
"type": "nitro-module",
172169
"version": "0.54.3"
173-
},
174-
"dependencies": {
175-
"@react-native/typescript-config": "^0.82.0",
176-
"lightningcss": "^1.30.2"
177170
}
178171
}

prettier.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @see https://prettier.io/docs/en/configuration.html
3+
* @type {import("prettier").Config}
4+
*/
5+
const config = {
6+
plugins: ["@ianvs/prettier-plugin-sort-imports"],
7+
importOrderParserPlugins: ["typescript", "jsx"],
8+
importOrder: [
9+
"^react$|^react-native$",
10+
"",
11+
"<BUILTIN_MODULES>",
12+
"",
13+
"<THIRD_PARTY_MODULES>",
14+
"",
15+
"^[.]",
16+
],
17+
};
18+
19+
export default config;

src/components/Text/Text.native.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import { Text as RNText, type TextProps } from 'react-native';
2-
import { copyComponentProperties, getDeepKeys } from '../../utils';
3-
import { useStyled } from '../../native/useStyled';
4-
import { useId } from 'react';
5-
import { useRef } from '../../native/useRef';
6-
import { StyleRegistry } from '../../specs/StyleRegistry';
1+
import { useId } from "react";
2+
import { Text as RNText, type TextProps } from "react-native";
3+
4+
import { useRef } from "../../native/useRef";
5+
import { useStyled } from "../../native/useStyled";
6+
import { StyleRegistry } from "../../specs/StyleRegistry";
7+
import { copyComponentProperties, getDeepKeys } from "../../utils";
78

89
export const Text = copyComponentProperties(RNText, (props: TextProps) => {
910
const componentId = useId();
1011

1112
const style = useStyled(
1213
componentId,
1314
(props as Record<string, string>).className,
14-
props
15+
props,
1516
);
1617

1718
const ref = useRef(componentId, (props as Record<string, any>).ref);
1819

1920
if (props.style) {
2021
StyleRegistry.updateComponentInlineStyleKeys(
2122
componentId,
22-
getDeepKeys(props.style)
23+
getDeepKeys(props.style),
2324
);
2425
}
2526

src/components/Text/Text.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { Text as RNText, type TextProps } from 'react-native';
2-
import { copyComponentProperties } from '../../utils';
3-
import { useStyled } from '../../web/useStyled';
1+
import { Text as RNText, type TextProps } from "react-native";
2+
3+
import { copyComponentProperties } from "../../utils";
4+
import { useStyled } from "../../web/useStyled";
45

56
export const Text = copyComponentProperties(
67
RNText,
78
({ className, style, ...props }: TextProps) => {
89
const nextStyle = useStyled(className, style);
910
return <RNText {...props} style={nextStyle} />;
10-
}
11+
},
1112
);

src/components/Text/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Text } from './Text';
2-
export * from './Text';
1+
import { Text } from "./Text";
2+
3+
export * from "./Text";
34

45
export default Text;

src/components/View/View.native.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import { View as RNView, type ViewProps } from 'react-native';
2-
import { copyComponentProperties, getDeepKeys } from '../../utils';
3-
import { useStyled } from '../../native/useStyled';
4-
import { useId } from 'react';
5-
import { useRef } from '../../native/useRef';
6-
import { StyleRegistry } from '../../specs/StyleRegistry';
1+
import { useId } from "react";
2+
import { View as RNView, type ViewProps } from "react-native";
3+
4+
import { useRef } from "../../native/useRef";
5+
import { useStyled } from "../../native/useStyled";
6+
import { StyleRegistry } from "../../specs/StyleRegistry";
7+
import { copyComponentProperties, getDeepKeys } from "../../utils";
78

89
export const View = copyComponentProperties(RNView, (props: ViewProps) => {
910
const componentId = useId();
1011

1112
const style = useStyled(
1213
componentId,
1314
(props as Record<string, string>).className,
14-
props
15+
props,
1516
);
1617

1718
const ref = useRef(componentId, (props as Record<string, any>).ref);
1819

1920
if (props.style) {
2021
StyleRegistry.updateComponentInlineStyleKeys(
2122
componentId,
22-
getDeepKeys(props.style)
23+
getDeepKeys(props.style),
2324
);
2425
}
2526

src/components/View/View.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { View as RNView, type ViewProps } from 'react-native';
2-
import { copyComponentProperties } from '../../utils';
3-
import { useStyled } from '../../web/useStyled';
1+
import { View as RNView, type ViewProps } from "react-native";
2+
3+
import { copyComponentProperties } from "../../utils";
4+
import { useStyled } from "../../web/useStyled";
45

56
export const View = copyComponentProperties(
67
RNView,
78
({ className, style, ...props }: ViewProps) => {
89
const nextStyle = useStyled(className, style);
910
return <RNView {...props} style={nextStyle} />;
10-
}
11+
},
1112
);

src/components/View/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { View } from './View';
2-
export * from './View';
1+
import { View } from "./View";
2+
3+
export * from "./View";
34

45
export default View;

0 commit comments

Comments
 (0)