From 160590658bb7e317218dc82e3f4f7684d8290caa Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 6 Jan 2024 19:25:17 -0700 Subject: [PATCH 1/2] Add prettier --- .dir-locals.el | 4 ++++ App.tsx | 12 +++++------- flake.nix | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 .dir-locals.el diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..b8fcab5 --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,4 @@ +((nil + . + ((lsp-pylsp-server-command . ("poetry" "run" "pylsp")) + (apheleia-inhibit . nil)))) diff --git a/App.tsx b/App.tsx index f0d664d..2d7e939 100644 --- a/App.tsx +++ b/App.tsx @@ -1,14 +1,12 @@ import React from "react"; import { SafeAreaView, Text } from "react-native"; - const App: React.FC = () => { - return ( - - Hello, World! - - ); + return ( + + Hello, World! + + ); }; - export default App; diff --git a/flake.nix b/flake.nix index 923b8e7..ccc5dc2 100644 --- a/flake.nix +++ b/flake.nix @@ -53,7 +53,7 @@ in with pkgs; { defaultPackage = appBuild; devShell = mkShell { - buildInputs = [ nodejs yarn watchman gradle_7 alejandra ]; + buildInputs = [ nodejs yarn watchman gradle_7 alejandra nodePackages.prettier ]; ANDROID_SDK_BIN = android-sdk; shellHook = '' export JAVA_HOME=${pkgs.jdk17.home} From ed8371e08a1024dc425d57576af009c317634282 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 6 Jan 2024 19:32:00 -0700 Subject: [PATCH 2/2] Make eslint compatible with prettier --- .eslintrc.js | 106 ++++++++++++++++++++++----------------------------- package.json | 8 ++-- yarn.lock | 5 +++ 3 files changed, 55 insertions(+), 64 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 00ce72a..c278541 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,69 +1,53 @@ module.exports = { - "settings": { - "react": { - "version": "detect", - }, + settings: { + react: { + version: "detect", }, - "env": { - "browser": true, - "es2021": true, - "node": true, + }, + env: { + browser: true, + es2021: true, + node: true, + }, + extends: ["plugin:react/recommended", "prettier"], + overrides: [ + { + env: { + node: true, + }, + files: [".eslintrc.{js,cjs}"], + parserOptions: { + sourceType: "script", + }, }, - "extends": "plugin:react/recommended", - "overrides": [ - { - "env": { - "node": true, - }, - "files": [ - ".eslintrc.{js,cjs}", - ], - "parserOptions": { - "sourceType": "script", - }, - }, - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module", - }, - "plugins": [ - "@typescript-eslint", - "react", - "react-hooks", - "react-native", - ], - "rules": { - // Enforce tab width of 4 spaces - "indent": ["error", 4, { "SwitchCase": 1 }], + ], + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaVersion: "latest", + sourceType: "module", + }, + plugins: ["@typescript-eslint", "react", "react-hooks", "react-native"], + rules: { + // Best Practices + eqeqeq: ["error", "always"], // Enforce '===' instead of '==' + curly: "error", // Require curly braces for all control statements + "no-unused-vars": "warn", // Warn about variables that are declared but not used - // Best Practices - "eqeqeq": ["error", "always"], // Enforce '===' instead of '==' - "curly": "error", // Require curly braces for all control statements - "no-unused-vars": "warn", // Warn about variables that are declared but not used + // React Specific + "react/jsx-filename-extension": [1, { extensions: [".tsx"] }], // Allow jsx syntax in .tsx files + "react/react-in-jsx-scope": "off", // Not necessary with React 17+ + "react/prop-types": "off", // Not needed with TypeScript - // Stylistic Issues - "quotes": ["error", "double"], // Enforce double quotes - "semi": ["error", "always"], // Enforce semicolons at the end of statements - "no-multi-spaces": "error", // Disallow multiple spaces that are not used for indentation - "comma-dangle": ["error", "always-multiline"], // Require trailing commas for multiline + // React-Native Specific + "react-native/no-unused-styles": "warn", // Warn about unused styles + "react-native/split-platform-components": "warn", // Encourage splitting of React Native components into platform-specific files - // React Specific - "react/jsx-filename-extension": [1, { "extensions": [".tsx"] }], // Allow jsx syntax in .tsx files - "react/react-in-jsx-scope": "off", // Not necessary with React 17+ - "react/prop-types": "off", // Not needed with TypeScript + // TypeScript Specific + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], // Warn about variables that are declared but not used - // React-Native Specific - "react-native/no-unused-styles": "warn", // Warn about unused styles - "react-native/split-platform-components": "warn", // Encourage splitting of React Native components into platform-specific files - - // TypeScript Specific - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], // Warn about variables that are declared but not used - - // Hooks Specific - "react-hooks/rules-of-hooks": "error", // Checks rules of Hooks - "react-hooks/exhaustive-deps": "warn", // Checks effect dependencies - }, + // Hooks Specific + "react-hooks/rules-of-hooks": "error", // Checks rules of Hooks + "react-hooks/exhaustive-deps": "warn", // Checks effect dependencies + }, }; diff --git a/package.json b/package.json index ad36a16..babd0f4 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "jest": { "preset": "jest-expo", "transformIgnorePatterns": [ - "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)" - ]}, + "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)" + ] + }, "dependencies": { "@types/react": "~18.2.14", "@typescript-eslint/eslint-plugin": "^6.17.0", @@ -37,7 +38,8 @@ }, "devDependencies": { "@babel/core": "^7.20.0", - "@types/jest": "^29.5.11" + "@types/jest": "^29.5.11", + "eslint-config-prettier": "^9.1.0" }, "private": true } diff --git a/yarn.lock b/yarn.lock index 63d7904..f07eb1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3966,6 +3966,11 @@ escodegen@^2.0.0: optionalDependencies: source-map "~0.6.1" +eslint-config-prettier@^9.1.0: + version "9.1.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" + integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== + eslint-plugin-react-hooks@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"