Dropstone Docs

Formatters

Dropstone verwendet sprachspezifische Formatters.

Dropstone kann Dateien nach dem Schreiben oder Bearbeiten mit sprachspezifischen Formatters formatieren. Formatters sind standardmäßig deaktiviert; aktivieren Sie sie in Ihrer Konfiguration, bevor Dropstone sie ausführt.


Built-in

Dropstone wird mit mehreren integrierten Formatters für beliebte Sprachen und Frameworks geliefert. Nachfolgend finden Sie eine Liste der Formatters, unterstützten Dateierweiterungen und erforderlichen Befehle oder Konfigurationsoptionen.

FormatterExtensionsRequirements
air.Rair command available
biome.js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml, und mehrbiome.json(c) config file
cargofmt.rscargo fmt command available
clang-format.c, .cpp, .h, .hpp, .ino, und mehr.clang-format config file
cljfmt.clj, .cljs, .cljc, .edncljfmt command available
dart.dartdart command available
dfmt.ddfmt command available
gleam.gleamgleam command available
gofmt.gogofmt command available
htmlbeautifier.erb, .html.erbhtmlbeautifier command available
ktlint.kt, .ktsktlint command available
mix.ex, .exs, .eex, .heex, .leex, .neex, .sfacemix command available
nixfmt.nixnixfmt command available
ocamlformat.ml, .mliocamlformat command available und .ocamlformat config file
ormolu.hsormolu command available
pint.phplaravel/pint dependency in composer.json
prettier.js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml, und mehrprettier dependency in package.json
rubocop.rb, .rake, .gemspec, .rurubocop command available
ruff.py, .pyiruff command available with config
rustfmt.rsrustfmt command available
shfmt.sh, .bashshfmt command available
standardrb.rb, .rake, .gemspec, .rustandardrb command available
terraform.tf, .tfvarsterraform command available
uv.py, .pyiuv command available
zig.zig, .zonzig command available

Wenn Formatters aktiviert sind, verwendet Dropstone prettier für übereinstimmende Dateien, wenn Ihr Projekt prettier in package.json hat.


Funktionsweise

Wenn Dropstone eine Datei schreibt oder bearbeitet und Formatters aktiviert sind, führt es folgende Schritte aus:

  1. Überprüft die Dateierweiterung gegen alle aktivierten Formatters.
  2. Führt den entsprechenden Formatter-Befehl auf der Datei aus.
  3. Wendet die Formatierungsänderungen an.

Dieser Prozess läuft im Hintergrund für aktivierte Formatters ab.


Konfigurieren

Sie können Formatters über den formatter-Abschnitt in Ihrer Dropstone-Konfiguration aktivieren und anpassen.

Um alle integrierten Formatters zu aktivieren, setzen Sie formatter auf true.

{
  "$schema": "https://dropstone.io/schema/config.json",
  "formatter": true
}

Verwenden Sie ein Objekt, um integrierte Formatters aktiviert zu halten und gleichzeitig Overrides oder benutzerdefinierte Formatters zu konfigurieren.

{
  "$schema": "https://dropstone.io/schema/config.json",
  "formatter": {}
}

Jede Formatter-Konfiguration unterstützt Folgendes:

PropertyTypeDescription
disabledbooleanSetzen Sie dies auf true, um den Formatter zu deaktivieren
commandstring[]Der auszuführende Befehl zum Formatieren. Erforderlich für benutzerdefinierte Formatters; optional für integrierte.
environmentobjectUmgebungsvariablen, die beim Ausführen des Formatters gesetzt werden
extensionsstring[]Dateierweiterungen, die dieser Formatter verarbeiten soll

Schauen wir uns einige Beispiele an.


Formatters deaktivieren

Wenn formatter weggelassen wird, sind alle Formatters deaktiviert. Um alle Formatters zu deaktivieren, nachdem eine andere Konfiguration sie aktiviert hat, setzen Sie formatter auf false:

{
  "$schema": "https://dropstone.io/schema/config.json",
  "formatter": false
}

Um einen bestimmten Formatter zu deaktivieren, setzen Sie disabled auf true:

{
  "$schema": "https://dropstone.io/schema/config.json",
  "formatter": {
    "prettier": {
      "disabled": true
    }
  }
}

Benutzerdefinierte Formatters

Sie können integrierte Formatters mit Optionen wie environment oder extensions konfigurieren. Um einen benutzerdefinierten Formatter hinzuzufügen, geben Sie einen command und extensions an:

{
  "$schema": "https://dropstone.io/schema/config.json",
  "formatter": {
    "prettier": {
      "command": ["npx", "prettier", "--write", "$FILE"],
      "environment": {
        "NODE_ENV": "development"
      },
      "extensions": [".js", ".ts", ".jsx", ".tsx"]
    },
    "custom-markdown-formatter": {
      "command": ["deno", "fmt", "$FILE"],
      "extensions": [".md"]
    }
  }
}

Der $FILE-Platzhalter im Befehl wird durch den Pfad zur zu formatierenden Datei ersetzt.

Strg+I