alm
Version:
The best IDE for TypeScript
36 lines (35 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* loads and parses `editorconfig` into the TypeScript `EditorOptions`
*/
var editorconfig = require("editorconfig");
var os = require("os");
function getEditorOptions(filePath) {
/** Note: any thing not defined comes back as `undefined` (which is good) */
var config = editorconfig.parseSync(filePath);
// console.log(filePath, config); // DEBUG
/**
* Convert editorconfig to EditorOptions
*/
// CR sounds like a dumb option. I am treating it as same as os.EOL
var end_of_line = config.end_of_line || 'os';
var newLineCharacter = end_of_line && config.end_of_line === 'lf' ? '\n'
: end_of_line && config.end_of_line === 'crlf' ? '\r\n'
: os.EOL;
var indent_style = config.indent_style || 'space';
var convertTabsToSpaces = indent_style === 'space' ? true : false;
// TODO: consolidate tabSize (its indentSize or tabWidth)
// Similar to https://github.com/editorconfig/editorconfig-vscode/blob/73d1e7c00de20db83fd47b1d0ab3b0ffc5696ae0/src/Utils.ts#L14-L26
var tabSize = config.indent_size || config.tab_width || 2;
var trimTrailingWhitespace = config.trim_trailing_whitespace || false;
var insertFinalNewline = config.insert_final_newline == undefined ? false : config.insert_final_newline;
return {
tabSize: tabSize,
newLineCharacter: newLineCharacter,
convertTabsToSpaces: convertTabsToSpaces,
trimTrailingWhitespace: trimTrailingWhitespace,
insertFinalNewline: insertFinalNewline,
};
}
exports.getEditorOptions = getEditorOptions;