From c0b7a7914e2034765995bc7ac6d70d8849f8c3c1 Mon Sep 17 00:00:00 2001 From: Jesse Katsumata Date: Tue, 26 Nov 2024 22:58:23 +0900 Subject: [PATCH] feat: migrate to biome --- .eslintignore | 4 - .eslintrc.js | 4 - .flowconfig | 81 -- .prettierrc.js | 6 - __tests__/mock.test.js | 28 +- biome.json | 30 + example/App.tsx | 295 ++--- example/app.json | 45 +- example/babel.config.js | 2 +- example/index.js | 6 +- example/tsconfig.json | 2 +- jest/clipboard-mock.js | 28 +- metro.config.js | 41 +- package.json | 188 ++- react-native.config.js | 80 +- src/Clipboard.ts | 398 +++---- src/Clipboard.web.ts | 61 +- src/NativeClipboardModule.ts | 344 +++--- src/index.ts | 4 +- src/useClipboard.ts | 32 +- tsconfig.json | 32 +- yarn.lock | 2074 +++------------------------------- 22 files changed, 976 insertions(+), 2809 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.js delete mode 100644 .flowconfig delete mode 100644 .prettierrc.js create mode 100644 biome.json diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index de29e17b..00000000 --- a/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -typings -node_modules -example/android-bundle.js -example/ios-bundle.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 187894b6..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - root: true, - extends: '@react-native', -}; diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index 6aa8762f..00000000 --- a/.flowconfig +++ /dev/null @@ -1,81 +0,0 @@ -[ignore] -; We fork some components by platform -.*/*[.]android.js - -; Ignore "BUCK" generated dirs -/\.buckd/ - -; Ignore polyfills -node_modules/react-native/Libraries/polyfills/.* - -; These should not be required directly -; require from fbjs/lib instead: require('fbjs/lib/warning') -node_modules/warning/.* - -; Flow doesn't support platforms -.*/Libraries/Utilities/LoadingView.js - -; Ignore example folder -.*/example/.* - - -[untyped] -.*/node_modules/@react-native-community/cli/.*/.* - -[include] - -[libs] -node_modules/react-native/Libraries/react-native/react-native-interface.js -node_modules/react-native/flow/ - -[options] -emoji=true - -esproposal.optional_chaining=enable -esproposal.nullish_coalescing=enable - -module.file_ext=.js -module.file_ext=.json -module.file_ext=.ios.js - -munge_underscores=true - -module.name_mapper='^react-native$' -> '/node_modules/react-native/Libraries/react-native/react-native-implementation' -module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' -module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' - -suppress_type=$FlowIssue -suppress_type=$FlowFixMe -suppress_type=$FlowFixMeProps -suppress_type=$FlowFixMeState - -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ -suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError - -server.max_workers=4 - -[lints] -sketchy-null-number=warn -sketchy-null-mixed=warn -sketchy-number=warn -untyped-type-import=warn -nonstrict-import=warn -deprecated-type=warn -unsafe-getters-setters=warn -inexact-spread=warn -unnecessary-invariant=warn -signature-verification-failure=warn -deprecated-utility=error - -[strict] -deprecated-type -nonstrict-import -sketchy-null -unclear-type -unsafe-getters-setters -untyped-import -untyped-type-import - -[version] -^0.105.0 diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 6e29914c..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - bracketSpacing: false, - jsxBracketSameLine: true, - singleQuote: true, - trailingComma: 'all', -}; \ No newline at end of file diff --git a/__tests__/mock.test.js b/__tests__/mock.test.js index ced42a3e..f7885d46 100644 --- a/__tests__/mock.test.js +++ b/__tests__/mock.test.js @@ -1,19 +1,19 @@ -const mockClipboard = require('../jest/clipboard-mock'); +const mockClipboard = require("../jest/clipboard-mock"); -jest.mock('../dist/index.js', () => mockClipboard); +jest.mock("../dist/index.js", () => mockClipboard); -describe('mockClipboard', () => { - const {getString, useClipboard} = require('../dist/index.js'); +describe("mockClipboard", () => { + const { getString, useClipboard } = require("../dist/index.js"); - it('can get mock string', async () => { - const result = await getString(); - const expected = 'mockString'; - expect(result).toBe(expected); - }); + it("can get mock string", async () => { + const result = await getString(); + const expected = "mockString"; + expect(result).toBe(expected); + }); - it('can get useClipboardHook', async () => { - const [result] = useClipboard(); - const expected = 'mockString'; - expect(result).toBe(expected); - }); + it("can get useClipboardHook", async () => { + const [result] = useClipboard(); + const expected = "mockString"; + expect(result).toBe(expected); + }); }); diff --git a/biome.json b/biome.json new file mode 100644 index 00000000..7734e11e --- /dev/null +++ b/biome.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": false, + "ignore": ["dist", "example/ios", "example/android"] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab" + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + } +} diff --git a/example/App.tsx b/example/App.tsx index 2efc608e..d537ec8e 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -1,171 +1,172 @@ -import React, {useEffect, useState} from 'react'; +import type React from "react"; +import { useCallback, useEffect, useState } from "react"; import { - StyleSheet, - Text, - View, - Button, - TextInput, - Alert, - SafeAreaView, - Platform, - Image, -} from 'react-native'; -import Clipboard, {useClipboard} from '../src'; + StyleSheet, + Text, + View, + Button, + TextInput, + Alert, + SafeAreaView, + Platform, + Image, +} from "react-native"; +import Clipboard, { useClipboard } from "../src"; // Small icon of a plus for demo purposes const TEST_IMAGE = - 'iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=='; + "iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg=="; const changeListener = () => { - console.warn('Clipboard changed!'); + console.warn("Clipboard changed!"); }; const App: React.FC = () => { - const [text, setText] = useState(''); - const [isURL, setIsURL] = useState(false); - const [data, setString] = useClipboard(); - const [image, setImage] = useState(null); - const [imageString, setImageString] = useState(''); + const [text, setText] = useState(""); + const [isURL, setIsURL] = useState(false); + const [data, setString] = useClipboard(); + const [image, setImage] = useState(null); + const [imageString, setImageString] = useState(""); - const checkStringType = async () => { - const checkClipboard = await Clipboard.hasURL(); - setIsURL(checkClipboard); - }; + const checkStringType = useCallback(async () => { + const checkClipboard = await Clipboard.hasURL(); + setIsURL(checkClipboard); + }, []); - const pasteImageAndroid = async () => { - const base64 = await Clipboard.getImage(); - setImageString(base64); - }; + const pasteImageAndroid = async () => { + const base64 = await Clipboard.getImage(); + setImageString(base64); + }; - useEffect(() => { - checkStringType(); - }, [data]); + useEffect(() => { + checkStringType(); + }, [checkStringType]); - useEffect(() => { - if (Platform.OS === 'ios' || Platform.OS === 'android') { - const listener = Clipboard.addListener(changeListener); + useEffect(() => { + if (Platform.OS === "ios" || Platform.OS === "android") { + const listener = Clipboard.addListener(changeListener); - return () => { - listener.remove(); - }; - } - }, []); + return () => { + listener.remove(); + }; + } + }, []); - const writeToClipboard = async () => { - setString(text); - Alert.alert(`Copied to clipboard: ${text}`); - }; + const writeToClipboard = async () => { + setString(text); + Alert.alert(`Copied to clipboard: ${text}`); + }; - const writeImageToClipboard = async () => { - Clipboard.setImage(TEST_IMAGE); - Alert.alert(`Copied Image to clipboard`); - }; + const writeImageToClipboard = async () => { + Clipboard.setImage(TEST_IMAGE); + Alert.alert("Copied Image to clipboard"); + }; - const getImage = async () => { - if (await Clipboard.hasImage()) { - const image = await Clipboard.getImagePNG(); - setImage(image); - } else { - console.warn('No image in clipboard'); - } - }; + const getImage = async () => { + if (await Clipboard.hasImage()) { + const image = await Clipboard.getImagePNG(); + setImage(image); + } else { + console.warn("No image in clipboard"); + } + }; - return ( - - Clipboard Module - - Clipboard Contents: - {data} - Content is URL: - {JSON.stringify(isURL)} - Content is IMAGE: - {image && } - - setText(input)} - value={text} - placeholder="Type here..." - /> -