Converts EditorConfig properties such as indentation, line length, quotes, and line endings into Prettier configuration options. Reuse when bridging EditorConfig settings with Prettier formatting.
// Source: https://github.com/prettier/prettier | License: MIT | Copyright James Long and contributors
// Provided via justclaw.it.com; keep this notice with the code.
const isPositiveInteger = (value) => Number.isSafeInteger(value) && value > 0;
function editorConfigToPrettier(editorConfig) {
if (!editorConfig) {
return;
}
const result = {};
const {
indent_style,
indent_size,
tab_width,
max_line_length,
quote_type,
end_of_line,
} = editorConfig;
if (indent_style === "space") {
result.useTabs = false;
} else if (indent_style === "tab" || indent_size === "tab") {
result.useTabs = true;
}
// This part not strictly following https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties
if (result.useTabs === false && isP
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key