From c57b2068e82e60a4a6dba427da5c4dee9f702cc5 Mon Sep 17 00:00:00 2001 From: Bartosz Dokurno Date: Sat, 21 Sep 2024 12:25:58 +0200 Subject: [PATCH] Migrate style linting to Prettier (#37) --- .eslintrc.js | 55 +++-- package-lock.json | 218 ++++++++++++++++-- package.json | 6 +- src/GifPickerReact.tsx | 15 +- src/components/Button.tsx | 6 +- src/components/ErrorBoundary.tsx | 4 +- src/components/PickerMain.tsx | 9 +- src/components/body/Body.tsx | 42 ++-- src/components/body/Category.tsx | 19 +- src/components/body/CategoryList.tsx | 23 +- src/components/body/FeaturedCategory.tsx | 8 +- src/components/body/GifList.tsx | 27 ++- src/components/body/GifListPlaceholder.tsx | 22 +- src/components/body/ResultImage.tsx | 13 +- src/components/body/SearchResult.tsx | 13 +- src/components/body/TrendingCategory.tsx | 18 +- src/components/body/TrendingResult.tsx | 13 +- src/components/header/ClearButton.tsx | 7 +- src/components/header/Header.tsx | 10 +- src/components/header/Search.tsx | 8 +- src/components/header/Title.tsx | 13 +- .../placeholders/CategoryPlaceholder.tsx | 6 +- src/components/placeholders/Placeholder.tsx | 7 +- .../placeholders/ResultPlaceholder.tsx | 9 +- src/context/PickerContext.ts | 4 +- src/hooks/usePickerContext.ts | 14 +- src/hooks/useSettings.ts | 19 +- src/index.tsx | 6 +- src/managers/TenorManager.ts | 89 ++++--- src/stories/GifPicker.stories.tsx | 55 +++-- src/types/exposedTypes.ts | 38 +-- 31 files changed, 529 insertions(+), 267 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9a293a4..461c497 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,45 +1,44 @@ module.exports = { env: { - 'browser': true, - 'jest': true + browser: true, + jest: true, }, - extends: [ 'eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended', 'plugin:storybook/recommended' ], + extends: [ + 'eslint:recommended', + 'plugin:react/recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:storybook/recommended', + 'plugin:prettier/recommended', + ], overrides: [], settings: { react: { - version: 'detect' - } + version: 'detect', + }, }, - ignorePatterns: [ '*.html' ], + ignorePatterns: ['*.html'], parser: '@typescript-eslint/parser', parserOptions: { - 'ecmaVersion': '13', - 'sourceType': 'module' + ecmaVersion: '13', + sourceType: 'module', }, - plugins: [ 'react', '@typescript-eslint' ], + plugins: ['react', '@typescript-eslint', 'prettier'], rules: { - 'brace-style': [ 'error', 'stroustrup', { - 'allowSingleLine': true - } ], - 'quotes': [ 'error', 'single' ], - 'no-trailing-spaces': [ 'error' ], - 'eol-last': [ 'error', 'always' ], - 'curly': [ 'error', 'multi-line', 'consistent' ], - 'indent': [ 'error', 'tab', { - 'SwitchCase': 1, - 'ignoredNodes': [ 'TemplateLiteral *' ] - } ], - 'semi': [ 'error', 'always' ], - 'no-multiple-empty-lines': [ 'error', { - 'max': 1 - } ], - 'comma-dangle': [ 'error', 'never' ], '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-this-alias': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-empty-interface': 'off', - 'array-bracket-spacing': [ 'error', 'always' ], - '@typescript-eslint/no-use-before-define': 'off' - } + '@typescript-eslint/no-use-before-define': 'off', + 'prettier/prettier': [ + 'error', + { + endOfLine: 'auto', + useTabs: true, + singleQuote: true, + printWidth: 100, + singleAttributePerLine: true, + }, + ], + }, }; diff --git a/package-lock.json b/package-lock.json index e998527..997283d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,11 +26,14 @@ "autoprefixer": "^10.4.20", "cssnano": "^7.0.6", "eslint": "^8.43.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react": "^7.32.2", "eslint-plugin-storybook": "^0.6.12", "postcss": "^8.4.47", "postcss-inline-svg": "^6.0.0", "postcss-svgo": "^7.0.1", + "prettier": "3.3.3", "react": "18.3.1", "react-dom": "18.3.1", "storybook": "7.0.23", @@ -3317,6 +3320,19 @@ "node": ">=14" } }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@pmmmwh/react-refresh-webpack-plugin": { "version": "0.5.10", "resolved": "https://registry.npmjs.org/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz", @@ -4305,6 +4321,22 @@ "node": ">= 6" } }, + "node_modules/@storybook/cli/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/@storybook/cli/node_modules/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", @@ -4750,6 +4782,22 @@ "node": ">=6.9.0" } }, + "node_modules/@storybook/codemod/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/@storybook/components": { "version": "7.0.23", "resolved": "https://registry.npmjs.org/@storybook/components/-/components-7.0.23.tgz", @@ -9056,6 +9104,50 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", + "dev": true, + "license": "MIT", + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.9.1" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": "*", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-plugin-react": { "version": "7.32.2", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz", @@ -9559,6 +9651,13 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", @@ -13734,20 +13833,34 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, + "license": "MIT", "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty-error": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz", @@ -15559,6 +15672,23 @@ "integrity": "sha512-AsS729u2RHUfEra9xJrE39peJcc2stq2+poBXX8bcM08Y6g9j/i/PUzwNQqkaJde7Ntg1TO7bSREbR5sdosQ+g==", "dev": true }, + "node_modules/synckit": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.1.tgz", + "integrity": "sha512-7gr8p9TQP6RAHusBOSLs46F4564ZrjV8xFmw5zCmgmhGUcw2hxsShhJ6CEiHQMgPDwAQ1fWHPM0ypc4RMAig4A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", @@ -15957,9 +16087,9 @@ "license": "Apache-2.0" }, "node_modules/tslib": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", - "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", "dev": true, "license": "0BSD" }, @@ -19520,6 +19650,12 @@ "dev": true, "optional": true }, + "@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true + }, "@pmmmwh/react-refresh-webpack-plugin": { "version": "0.5.10", "resolved": "https://registry.npmjs.org/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz", @@ -20121,6 +20257,12 @@ "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", "dev": true }, + "prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true + }, "semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", @@ -20464,6 +20606,12 @@ "@babel/helper-validator-identifier": "^7.19.1", "to-fast-properties": "^2.0.0" } + }, + "prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true } } }, @@ -23852,6 +24000,23 @@ } } }, + "eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "requires": {} + }, + "eslint-plugin-prettier": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.9.1" + } + }, "eslint-plugin-react": { "version": "7.32.2", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz", @@ -24141,6 +24306,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, "fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", @@ -27071,11 +27242,20 @@ "dev": true }, "prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-error": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz", @@ -28426,6 +28606,16 @@ "integrity": "sha512-AsS729u2RHUfEra9xJrE39peJcc2stq2+poBXX8bcM08Y6g9j/i/PUzwNQqkaJde7Ntg1TO7bSREbR5sdosQ+g==", "dev": true }, + "synckit": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.1.tgz", + "integrity": "sha512-7gr8p9TQP6RAHusBOSLs46F4564ZrjV8xFmw5zCmgmhGUcw2hxsShhJ6CEiHQMgPDwAQ1fWHPM0ypc4RMAig4A==", + "dev": true, + "requires": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + } + }, "tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", @@ -28730,9 +28920,9 @@ "dev": true }, "tslib": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz", - "integrity": "sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", "dev": true }, "tsup": { diff --git a/package.json b/package.json index 96ada0f..a582a77 100644 --- a/package.json +++ b/package.json @@ -56,11 +56,14 @@ "autoprefixer": "^10.4.20", "cssnano": "^7.0.6", "eslint": "^8.43.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react": "^7.32.2", "eslint-plugin-storybook": "^0.6.12", "postcss": "^8.4.47", "postcss-inline-svg": "^6.0.0", "postcss-svgo": "^7.0.1", + "prettier": "3.3.3", "react": "18.3.1", "react-dom": "18.3.1", "storybook": "7.0.23", @@ -71,6 +74,5 @@ "peerDependencies": { "react": ">=17", "react-dom": ">=17" - }, - "dependencies": {} + } } diff --git a/src/GifPickerReact.tsx b/src/GifPickerReact.tsx index fd85348..ebeabe8 100644 --- a/src/GifPickerReact.tsx +++ b/src/GifPickerReact.tsx @@ -29,10 +29,17 @@ export interface GifPickerReactProps { function GifPickerReact(props: GifPickerReactProps): JSX.Element { const settings = useSettings(props); const pickerContext = usePickerContext(settings.initialSearchTerm); - const tenorManager: TenorManager = useMemo(() => ( - new TenorManager(settings.tenorApiKey, settings.clientKey, - settings.country, settings.locale, settings.contentFilter) - ), [ ]); + const tenorManager: TenorManager = useMemo( + () => + new TenorManager( + settings.tenorApiKey, + settings.clientKey, + settings.country, + settings.locale, + settings.contentFilter, + ), + [], + ); return ( diff --git a/src/components/Button.tsx b/src/components/Button.tsx index f6ce154..e8ef148 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,6 +1,10 @@ import * as React from 'react'; -interface PropsProps extends React.DetailedHTMLProps, HTMLButtonElement> {} +interface PropsProps + extends React.DetailedHTMLProps< + React.ButtonHTMLAttributes, + HTMLButtonElement + > {} function Button(props: PropsProps): JSX.Element { return ( diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index 51de0f1..aa2c958 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; export interface ErrorBoundaryProps { - children: React.ReactNode; + children: React.ReactNode; } export interface ErrorBoundaryState { - hasError: boolean; + hasError: boolean; } export default class ErrorBoundary extends React.Component { diff --git a/src/components/PickerMain.tsx b/src/components/PickerMain.tsx index 77ffbbd..fed61b6 100644 --- a/src/components/PickerMain.tsx +++ b/src/components/PickerMain.tsx @@ -3,7 +3,7 @@ import SettingsContext from '../context/SettingsContext'; import { Theme } from '../types/exposedTypes'; export interface PickerMainProps { - children: React.ReactNode; + children: React.ReactNode; } function PickerMain({ children }: PickerMainProps): JSX.Element { @@ -11,11 +11,14 @@ function PickerMain({ children }: PickerMainProps): JSX.Element { const style: React.CSSProperties = { height: settings.height, - width: settings.width + width: settings.width, }; return ( -