From 33aed47254ee67c3c920a33267af06ea5a1a56b4 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Sat, 14 Dec 2024 13:27:43 -0500 Subject: [PATCH] integrate prettier with eslint --- .prettierrc | 2 +- lib/src/translateProvider.spec.tsx | 4 +- lib/src/utils.spec.ts | 16 ++--- package-lock.json | 103 +++++++++++++++++++++++++++++ package.json | 17 +++-- 5 files changed, 126 insertions(+), 16 deletions(-) diff --git a/.prettierrc b/.prettierrc index cb7ae7c..1b55d7d 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { "singleQuote": true, "tabWidth": 2, - "trailingComma": "none" + "trailingComma": "es5" } diff --git a/lib/src/translateProvider.spec.tsx b/lib/src/translateProvider.spec.tsx index 7013c53..cd4ce04 100644 --- a/lib/src/translateProvider.spec.tsx +++ b/lib/src/translateProvider.spec.tsx @@ -26,7 +26,9 @@ describe('TranslateProvider', () => { global.fetch = jest.fn().mockImplementation(() => { return Promise.resolve({ ok: true, - json: () => { /* */ }, + json: () => { + /* */ + }, }); }); }); diff --git a/lib/src/utils.spec.ts b/lib/src/utils.spec.ts index c297424..d3045cf 100644 --- a/lib/src/utils.spec.ts +++ b/lib/src/utils.spec.ts @@ -29,7 +29,7 @@ describe('Utils', () => { const template = 'Good luck, {param1} {param2}!'; const params = { param1: 'Mr.', - param2: 'Gorsky' + param2: 'Gorsky', }; const value = format(template, params); @@ -61,9 +61,9 @@ describe('Utils', () => { const data = { en: { messages: { - 404: 'Error, not found.' - } - } + 404: 'Error, not found.', + }, + }, }; const value = getValue(data, 'en', 'messages.404'); @@ -73,8 +73,8 @@ describe('Utils', () => { test('returns original key if nested value not found', () => { const data = { en: { - messages: {} - } + messages: {}, + }, }; const value = getValue(data, 'en', 'messages.500'); @@ -84,8 +84,8 @@ describe('Utils', () => { test('supports tol-level values with dots', () => { const data = { en: { - 'messages.errors.500': 'Aw, snap!' - } + 'messages.errors.500': 'Aw, snap!', + }, }; const value = getValue(data, 'en', 'messages.errors.500'); diff --git a/package-lock.json b/package-lock.json index 58b6849..361074f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,8 @@ "@typescript-eslint/parser": "^5.54.0", "eslint": "^8.35.0", "eslint-config-preact": "^1.3.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "if-env": "^1.0.4", "jest": "^29.7.0", "jest-preset-preact": "^4.1.1", @@ -2853,6 +2855,19 @@ "node": ">=10" } }, + "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/@polka/url": { "version": "1.0.0-next.21", "dev": true, @@ -9254,6 +9269,19 @@ "eslint": "6.x || 7.x || 8.x" } }, + "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-compat": { "version": "4.2.0", "dev": true, @@ -9373,6 +9401,37 @@ } } }, + "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", "dev": true, @@ -10194,6 +10253,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.11", "dev": true, @@ -17216,6 +17282,19 @@ "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-bytes": { "version": "4.0.2", "dev": true, @@ -19818,6 +19897,30 @@ "dev": true, "license": "MIT" }, + "node_modules/synckit": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", + "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", + "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/synckit/node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "dev": true, + "license": "0BSD" + }, "node_modules/tapable": { "version": "1.1.3", "dev": true, diff --git a/package.json b/package.json index 92b2eec..627b42c 100644 --- a/package.json +++ b/package.json @@ -18,25 +18,28 @@ "build": "preact build", "serve": "preact build && preact serve", "dev": "preact watch", - "lint": "npm run format:check && eslint lib", + "lint": "eslint lib", "build.lib": "rollup -c && npm run copy:modules && cp -r README.md dist", "build.lib.dev": "rollup -c -w", "copy:modules": "rm -rf node_modules/@denysvuika && mkdir -p node_modules/@denysvuika/preact-translate && cp -r dist/* node_modules/@denysvuika/preact-translate", "size": "size-limit", "test": "jest --coverage", - "test:watch": "jest --watchAll", - "format:check": "prettier --check \"./**/*.{ts,js,css,scss,html}\"", - "format:fix": "prettier --write \"./**/*.{ts,js,css,scss,html}\"" + "test:watch": "jest --watchAll" }, "eslintConfig": { "parser": "@typescript-eslint/parser", "extends": [ "preact", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" ], "ignorePatterns": [ "build/" - ] + ], + "plugins": ["prettier"], + "rules": { + "prettier/prettier": "error" + } }, "devDependencies": { "@size-limit/preset-small-lib": "^4.12.0", @@ -48,6 +51,8 @@ "@typescript-eslint/parser": "^5.54.0", "eslint": "^8.35.0", "eslint-config-preact": "^1.3.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "if-env": "^1.0.4", "jest": "^29.7.0", "jest-preset-preact": "^4.1.1",