Formator-Prettier

Introduction

This plugin is used to format less, sass, vue, stylus, ts, yaml code.

This plugin needs to be downloaded from HBuilderX Plugin Market.

Configuration

Click the menu [Tools] -> [Settings] -> [Plugin Configuration] -> prettier -> prettier.config.js to open the configuration file.

Formator-Prettier - 图1

Format options

The formatting options configuration file is prettier.config.js, and the corresponding options are described as follows:

  • printWidth: Specify the line length that the printer will wrap on.
  • semi: Print semicolons at the ends of statements. options: true|false.
  • tabWidth: Specify the number of spaces per indentation-level.
  • useTabs: Indent lines with tabs instead of spaces.
  • singleQuote:Use single quotes instead of double quotes.
  • trailingComma: Print trailing commas wherever possible in multi-line comma-separated syntactic structures. (A single-line array, for example, never gets trailing commas.)
  • bracketSpacing: Print spaces between brackets in object literals. options: true|false.

Detailed configuration instructions can refer to prettier options

How to support new languages?

  1. Modify the package.json configuration and add the file suffix of the new language to be supported
    1. "contributes": {
    2. "formator": {
    3. "name": "Prettier",
    4. "class": "prettier_service.js",
    5. "filetypes": [
    6. "less",
    7. "sass",
    8. "scss",
    9. "vue",
    10. "ux",
    11. "ts",
    12. "foo"//File extension name
    13. ]
    14. }
    15. }
  2. Modify prettier.config.js to configure the newly added language to the corresponding formatting processor.
    1. parsers: {
    2. ".jsx": "flow",
    3. ".scss": "scss",
    4. ".ts": "typescript",
    5. ".less": "css",
    6. ".vue": "vue",
    7. ".ux": "vue",
    8. ".yml": "yaml",
    9. ".foo":"flow"//Format program corresponding to file suffix
    10. }

Example

Formator-Prettier - 图2