]> git.lizzy.rs Git - rust.git/commitdiff
prettier config
authorAndrei Listochkin <andrei.listochkin@ferrous-systems.com>
Wed, 11 May 2022 17:19:45 +0000 (18:19 +0100)
committerAndrei Listochkin <andrei.listochkin@ferrous-systems.com>
Tue, 17 May 2022 17:12:49 +0000 (18:12 +0100)
[Prettier][1] is an up-to date code formatter for JavaScript ecosystem.

For settings we rely on [EditorConfig][2] for things like tab style and
size (with added bonus that the code editor with an EditorConfig plugin
does some automated code formatting on file save for you). Unfortunately,
Prettier's Glob handling isn't great:
 1. `*.{ts,js,json}` has no effect
 2. Similarly, in a list of globs `*.ts,*.js,*.json` only the first glob
has an effect, the rest are ignored.
That's why the file looks the way it does.

The only other setting we change is line width. [Lukas][3] suggested we
use 100 instead of 80, because that's what Rustfmt is using.

[1]: https://prettier.io
[2]: https://editorconfig.org
[3]: https://github.com/Veykril

.editorconfig [new file with mode: 0644]
editors/code/.eslintrc.js
editors/code/.prettierignore [new file with mode: 0644]
editors/code/.prettierrc.js [new file with mode: 0644]
editors/code/package-lock.json
editors/code/package.json

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..314f79d
--- /dev/null
@@ -0,0 +1,19 @@
+# https://EditorConfig.org
+root = true
+
+[*]
+charset = utf-8
+trim_trailing_whitespace = true
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+
+[*.{rs,toml}]
+indent_size = 4
+
+[*.ts]
+indent_size = 4
+[*.js]
+indent_size = 4
+[*.json]
+indent_size = 4
index 631d956da2be5c8a3827a2d6947f66cecd2661d3..518c5d0755736698f0cd24c067e2f01e35161ed6 100644 (file)
@@ -3,6 +3,7 @@ module.exports = {
         "es6": true,
         "node": true
     },
+    "extends": ["prettier"],
     "parser": "@typescript-eslint/parser",
     "parserOptions": {
         "project": "tsconfig.eslint.json",
diff --git a/editors/code/.prettierignore b/editors/code/.prettierignore
new file mode 100644 (file)
index 0000000..13baf68
--- /dev/null
@@ -0,0 +1,3 @@
+node_modules
+.vscode-test
+out
diff --git a/editors/code/.prettierrc.js b/editors/code/.prettierrc.js
new file mode 100644 (file)
index 0000000..cafb12f
--- /dev/null
@@ -0,0 +1,5 @@
+module.exports = {
+    // use 100 because it's Rustfmt's default
+    // https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#max_width
+    printWidth: 100,
+};
index 74cda037d8bcf9ae64c279539243c0596da64573..d766f9f1c9ef1d80ed39504642bd53cfde142e08 100644 (file)
@@ -22,6 +22,8 @@
                 "cross-env": "^7.0.3",
                 "esbuild": "^0.14.27",
                 "eslint": "^8.11.0",
+                "eslint-config-prettier": "^8.5.0",
+                "prettier": "^2.6.2",
                 "tslib": "^2.3.0",
                 "typescript": "^4.6.3",
                 "typescript-formatter": "^7.2.2",
                 "url": "https://opencollective.com/eslint"
             }
         },
+        "node_modules/eslint-config-prettier": {
+            "version": "8.5.0",
+            "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz",
+            "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==",
+            "dev": true,
+            "bin": {
+                "eslint-config-prettier": "bin/cli.js"
+            },
+            "peerDependencies": {
+                "eslint": ">=7.0.0"
+            }
+        },
         "node_modules/eslint-scope": {
             "version": "5.1.1",
             "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
                 "node": ">= 0.8.0"
             }
         },
+        "node_modules/prettier": {
+            "version": "2.6.2",
+            "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz",
+            "integrity": "sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==",
+            "dev": true,
+            "bin": {
+                "prettier": "bin-prettier.js"
+            },
+            "engines": {
+                "node": ">=10.13.0"
+            },
+            "funding": {
+                "url": "https://github.com/prettier/prettier?sponsor=1"
+            }
+        },
         "node_modules/process-nextick-args": {
             "version": "2.0.1",
             "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
                 }
             }
         },
+        "eslint-config-prettier": {
+            "version": "8.5.0",
+            "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz",
+            "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==",
+            "dev": true,
+            "requires": {}
+        },
         "eslint-scope": {
             "version": "5.1.1",
             "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
             "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
             "dev": true
         },
+        "prettier": {
+            "version": "2.6.2",
+            "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz",
+            "integrity": "sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==",
+            "dev": true
+        },
         "process-nextick-args": {
             "version": "2.0.1",
             "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
index 04006d74345bc608b3f745d873aceba4cbb94987..e2888a088dc5b1f3f00e5ffa2eb7191447f3fce9 100644 (file)
@@ -48,6 +48,8 @@
         "cross-env": "^7.0.3",
         "esbuild": "^0.14.27",
         "eslint": "^8.11.0",
+        "eslint-config-prettier": "^8.5.0",
+        "prettier": "^2.6.2",
         "tslib": "^2.3.0",
         "typescript": "^4.6.3",
         "typescript-formatter": "^7.2.2",