Конфиг файла для редактора VSCODE?

Кто может поделиться настройками (файлом) для редактора VScode для форматированния кода (Windows 10)?

Сейчас задалбывет, что после форматированния VScode переносит строки импорта и кода, который должен помещаться в строку.
  • Вопрос задан
  • 92 просмотра
Решения вопроса 1
shotlandec1980
@shotlandec1980
1. Beautify для форматирования javascript, JSON, CSS, Sass, и HTML.
Расширение читает настройки из файла .jsbeautifyrc, в корне вашего проекта:
{
	"end_with_newline": true,
	"eol": "\r\n",
	"indent_char": " ",
	"indent_size": 4,
	"indent_with_tabs": false,
	"preserve_newlines": false,
	"html": {
		"brace_style": "collapse",
		"break_chained_methods": false,
		"end_with_newline": true,
		"eval_code": false,
		"indent_body_inner_html": true,
		"indent_char": " ",
		"indent_handlebars": true,
		"indent_head_inner_html": true,
		"indent_inner_html": false,
		"indent_level": 0,
		"indent_scripts": "separate",
		"indent_with_tabs": false,
		"jslint_happy": false,
		"keep_array_indentation": false,
		"keep_function_indentation": false,
		"max_preserve_newlines": 10,
		"preserve_newlines": false,
		"space_after_anon_function": false,
		"space_before_conditional": true,
		"unescape_strings": false,
		"unformatted": [],
		"wrap_attributes": "auto",
		"wrap_attributes_indent_size": 0,
		"wrap_line_length": 0,
		"allowed_file_extensions": [
			"htm",
			"html",
			"xhtml",
			"shtml",
			"xml",
			"svg",
			"dust",
			"njk",
			"liquid",
			"markdown",
			"md"
		],
		"extra_liners": [
			"head",
			"body",
			"/html"
		],
		"inline": [
			"a",
			"abbr",
			"area",
			"audio",
			"b",
			"bdi",
			"bdo",
			"br",
			"button",
			"canvas",
			"cite",
			"code",
			"data",
			"datalist",
			"del",
			"dfn",
			"em",
			"embed",
			"i",
			"iframe",
			"img",
			"input",
			"ins",
			"kbd",
			"keygen",
			"label",
			"map",
			"mark",
			"math",
			"meter",
			"noscript",
			"object",
			"output",
			"progress",
			"q",
			"ruby",
			"s",
			"samp",
			"select",
			"small",
			"span",
			"strong",
			"sub",
			"sup",
			"svg",
			"template",
			"textarea",
			"time",
			"u",
			"var",
			"video",
			"wbr",
			"text",
			"acronym",
			"address",
			"big",
			"dt",
			"ins",
			"strike",
			"tt"
		],
		"content_unformatted": [
			"pre",
			"textarea"
		],
		"void_elements": [
			"area",
			"base",
			"br",
			"col",
			"embed",
			"hr",
			"img",
			"input",
			"keygen",
			"link",
			"menuitem",
			"meta",
			"param",
			"source",
			"track",
			"wbr",
			"!doctype",
			"?xml",
			"?php",
			"?=",
			"basefont",
			"isindex"
		],
		"js": {
			"indent_size": 4
		},
		"css": {
			"indent_size": 4
		}
	},
	"css": {
		"end_with_newline": true,
		"indent_char": " ",
		"indent_size": 4,
		"max_preserve_newlines": 10,
		"newline_between_rules": true,
		"preserve_newlines": false,
		"selector_separator": " ",
		"selector_separator_newline": true,
		"space_around_combinator": false,
		"allowed_file_extensions": [
			"css",
			"scss",
			"sass",
			"less"
		]
	},
	"js": {
		"brace_style": "collapse,preserve-inline",
		"break_chained_methods": false,
		"comma_first": false,
		"e4x": false,
		"end_with_newline": true,
		"indent_char": " ",
		"indent_level": 0,
		"indent_size": 4,
		"indent_with_tabs": false,
		"jslint_happy": false,
		"keep_array_indentation": true,
		"keep_function_indentation": true,
		"max_preserve_newlines": 4,
		"operator_position": "before-newline",
		"preserve_newlines": true,
		"space_after_anon_function": false,
		"space_after_named_function": false,
		"space_before_conditional": true,
		"space_in_empty_paren": false,
		"space_in_paren": false,
		"unescape_strings": false,
		"wrap_line_length": 220,
		"allowed_file_extensions": [
			"js",
			"json",
			"jshintrc",
			"jsbeautifyrc"
		]
	}
}

В настройке редактора %APPDATA%\Code\User\settings.json, указываем, какие типы файлов, расширения или конкретные имена файлов должны быть форматированы, пример:
{
  "beautify.language": {
    "js": {
      "type": ["javascript", "json"],
      "filename": [".jshintrc", ".jsbeautifyrc"]
      // "ext": ["js", "json"]
      // ^^ to set extensions to be beautified using the javascript beautifier
    },
    "css": ["css", "scss"],
    "html": ["htm", "html"]
    // ^^ providing just an array sets the VS Code file type
  }
}

Мои настройки:
"beautify.language": {
        "js": {
            "type": [
                "javascript",
                "json",
                "jsonc",
                "js"
            ],
            "filename": [
                ".jshintrc",
                ".jsbeautifyrc"
            ],
            "ext": [
                "js",
                "json"
            ]
        },
        "css": [
            "css",
            "scss",
            "less"
        ],
        "html": [
            "htm",
            "html",
            "php",
            "swig",
            "twig",
            "pug",
            "hbs",
            "njk",
            "nunjucks",
            "handlebars",
            "md",
            "liquid",
            "markdown"
        ],
        "njk": [
            "html",
            "njk",
            "nunjucks"
        ]
    },

2. Или Prettier, .prettierrc.json:
{
    "printWidth": 80,
    "tabWidth": 4,
    "useTabs": true,
    "semi": true,
    "singleQuote": true,
    "quoteProps": "as-needed",
    "jsxSingleQuote": true,
    "trailingComma": "es5",
    "bracketSpacing": true,
    "jsxBracketSameLine": true,
    "arrowParens": "always",
    "proseWrap": "always",
    "htmlWhitespaceSensitivity": "css",
    "vueIndentScriptAndStyle": true,
    "endOfLine": "crlf",
    "requirePragma": true,
    "insertPragma": true,
    "overrides": [
        {
            "files": "*.js",
            "options": {
                "printWidth": 220,
                "tabWidth": 4,
                "useTabs": false,
                "requirePragma": false,
                "insertPragma": false
            }
        },
        {
            "files": "*.json",
            "options": {
                "tabWidth": 4,
                "useTabs": false
            }
        },
        {
            "files": "*.php",
            "options": {
                "printWidth": 120,
                "tabWidth": 4,
                "useTabs": false,
                "singleQuote": true,
                "trailingCommaPHP": "all",
                "braceStyle": "1tbs",
                "requirePragma": false,
                "insertPragma": false
            }
        }
    ]
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы