From 9db2814ffdc014f00607aa82aed56b979a4f47d2 Mon Sep 17 00:00:00 2001 From: nielm Date: Wed, 13 Mar 2024 09:23:31 +0100 Subject: [PATCH] feat: Add prettier auto-formatter Add the prettier auto-formatter and integrate with eslint --- .eslintignore | 6 +++ .eslintrc.js | 10 ++-- .prettierignore | 7 +++ .prettierrc.js | 62 +++++++++++++++++++++++++ jsconfig.json | 2 +- package-lock.json | 116 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 7 ++- src/package.json | 2 +- 8 files changed, 200 insertions(+), 12 deletions(-) create mode 100644 .eslintignore create mode 100644 .prettierignore create mode 100644 .prettierrc.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..1fb48e00 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +.next +next-env.d.ts +node_modules +yarn.lock +package-lock.json +public diff --git a/.eslintrc.js b/.eslintrc.js index dd12ab4a..06051e6e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,15 +20,13 @@ module.exports = { 'commonjs': true, 'es2021': true, }, - 'extends': 'google', + 'extends': ['google', 'plugin:prettier/recommended'], 'overrides': [ { 'env': { 'node': true, }, - 'files': [ - '.eslintrc.{js,cjs}', - ], + 'files': ['.eslintrc.{js,cjs}'], 'parserOptions': { 'sourceType': 'script', }, @@ -37,7 +35,5 @@ module.exports = { 'parserOptions': { 'ecmaVersion': 'latest', }, - 'rules': { - }, + 'rules': {}, }; - diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..f64f8afe --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +.next +next-env.d.ts +node_modules +yarn.lock +package-lock.json +public +*.md diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..4844b5b0 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,62 @@ +const shared = { + printWidth: 80, + tabWidth: 2, + useTabs: false, + semi: true, + singleQuote: true, + quoteProps: 'preserve', + bracketSpacing: false, + trailingComma: 'all', + arrowParens: 'always', + embeddedLanguageFormatting: 'off', + bracketSameLine: true, + singleAttributePerLine: false, + jsxSingleQuote: false, + htmlWhitespaceSensitivity: 'strict', +}; + +module.exports = { + overrides: [ + { + /** TSX/TS/JS-specific configuration. */ + files: '*.tsx', + options: shared, + }, + { + files: '*.ts', + options: shared, + }, + { + files: '*.js', + options: shared, + }, + { + /** Sass-specific configuration. */ + files: '*.scss', + options: { + singleQuote: true, + }, + }, + { + files: '*.html', + options: { + printWidth: 100, + }, + }, + { + files: '*.acx.html', + options: { + parser: 'angular', + singleQuote: true, + }, + }, + { + files: '*.ng.html', + options: { + parser: 'angular', + singleQuote: true, + printWidth: 100, + }, + }, + ], +}; diff --git a/jsconfig.json b/jsconfig.json index 29bf5a23..f0c64dab 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -4,7 +4,7 @@ "target": "ES6", "checkJs": true, "allowJs": true, - "noEmit": true, + "noEmit": true }, "include": ["src/**/*"], "exclude": ["src/**/node_modules"] diff --git a/package-lock.json b/package-lock.json index c58b8186..99fcb9a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,12 +12,15 @@ "@types/mocha": "^10.0.6", "eslint": "^8.57.0", "eslint-config-google": "^0.14.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.1.3", "markdownlint-cli": "^0.39.0", + "prettier": "^3.2.5", "typescript": "^5.4.2" }, "engines": { - "node": "^18.22.0 || >=20.5.0", - "npm": "^10.0.0" + "node": ">=18.0.0 || >=20.0.0", + "npm": ">=10.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -207,6 +210,18 @@ "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, + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@types/mocha": { "version": "10.0.6", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", @@ -521,6 +536,48 @@ "eslint": ">=5.16.0" } }, + "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, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", + "integrity": "sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.8.6" + }, + "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-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", @@ -614,6 +671,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "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 + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -1280,6 +1343,33 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "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, + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -1537,12 +1627,34 @@ "node": ">=8" } }, + "node_modules/synckit": { + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", + "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", + "dev": true, + "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/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index d984235f..749460ef 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "scripts": { "eslint": "eslint .", "eslint-fix": "eslint --fix .", + "check-format": "prettier --check .", + "format": "prettier --write .", "typecheck": "tsc --project jsconfig.json --maxNodeModuleJsDepth 0 --noEmit", "mdlint": "markdownlint '**/*.md' --config .mdl.json --ignore '**/node_modules/**' --ignore 'code-of-conduct.md' --ignore 'CHANGELOG.md'", "install-all": "find . -name package.json -a ! -path '*/node_modules/*' -execdir pwd \\; -execdir npm install --save \\;" @@ -16,11 +18,14 @@ "@types/mocha": "^10.0.6", "eslint": "^8.57.0", "eslint-config-google": "^0.14.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.1.3", "markdownlint-cli": "^0.39.0", + "prettier": "^3.2.5", "typescript": "^5.4.2" }, "engines": { "node": ">=18.0.0 || >=20.0.0", - "npm": ">=10.0.0" + "npm": ">=10.0.0" } } diff --git a/src/package.json b/src/package.json index 06009b08..4c7172fa 100644 --- a/src/package.json +++ b/src/package.json @@ -15,6 +15,6 @@ }, "engines": { "node": ">=18.0.0 || >=20.0.0", - "npm": ">=10.0.0" + "npm": ">=10.0.0" } }