更改atom-typescript中的制表符空间

时间:2017-10-16 18:39:10

标签: javascript indentation atom-editor

当我们格式化代码时,Atom-typescript会将标签空间从2更改为4。

我更改了formatting.js文件并将其设置为2但仍然面临同样的问题..

如何更改atom-typescript中的标签空间?

下面是formatting.js的内容

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Maintainance:
 * When a new option is added add it to:
 * - the FormatCodeOptions interface
 * - the defaultFormatCodeOptions function
 * - the makeFormatCodeOptions function
 */
const os_1 = require("os");
function defaultFormatCodeOptions() {
    return {
        baseIndentSize: 2,
        indentSize: 2,
        tabSize: 2,
        newLineCharacter: os_1.EOL,
        convertTabsToSpaces: true,
        indentStyle: "Smart",
        insertSpaceAfterCommaDelimiter: true,
        insertSpaceAfterSemicolonInForStatements: true,
        insertSpaceBeforeAndAfterBinaryOperators: true,
        insertSpaceAfterKeywordsInControlFlowStatements: true,
        insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
        insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
        insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
        insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
        insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
        placeOpenBraceOnNewLineForFunctions: false,
        placeOpenBraceOnNewLineForControlBlocks: false,
    };
}
exports.defaultFormatCodeOptions = defaultFormatCodeOptions;
//# sourceMappingURL=formatting.js.map

1 个答案:

答案 0 :(得分:0)

根据@baruch的建议,这里是参考:github.com/TypeStrong/atom-typescript/issues/1236

我发布了对我有用的内容。

要将atom-typescript的缩进更改为2:

  1. 转到您的项目目录。
  2. 打开或创建tsconfig.json
  3. 添加以下代码

    "formatCodeOptions": {
        "baseIndentSize": 0,
        "indentSize": 2,
        "tabSize": 2,
        "newLineCharacter": "\n",
        "convertTabsToSpaces": true,
        "indentStyle": "Smart",
        "insertSpaceAfterCommaDelimiter": true,
        "insertSpaceAfterSemicolonInForStatements": false,
        "insertSpaceBeforeAndAfterBinaryOperators": true,
        "insertSpaceAfterConstructor": false,
        "insertSpaceAfterKeywordsInControlFlowStatements": true,
        "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
        "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
        "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
        "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
        "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
        "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
        "insertSpaceBeforeFunctionParenthesis": false,
        "placeOpenBraceOnNewLineForFunctions": false,
        "placeOpenBraceOnNewLineForControlBlocks": false
    }
    
  4. 这对我有用!