首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >4个字符的期望缩进

4个字符的期望缩进
EN

Stack Overflow用户
提问于 2015-10-16 19:58:39
回答 2查看 8.6K关注 0票数 1

更新

正如@dev-null (btw thx很多:)所建议的(参见注释),正确的方法是

代码语言:javascript
复制
jscs --fix file.js

我的压痕有什么问题?

.editorconfig

代码语言:javascript
复制
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

.jscsrc

代码语言:javascript
复制
{
    "disallowKeywords": ["with"],
    "disallowKeywordsOnNewLine": ["else"],
    "disallowMixedSpacesAndTabs": true,
    "disallowMultipleVarDecl": "exceptUndefined",
    "disallowNewlineBeforeBlockStatements": true,
    "disallowQuotedKeysInObjects": true,
    "disallowSpaceAfterObjectKeys": true,
    "disallowSpaceAfterPrefixUnaryOperators": true,
    "disallowSpacesInFunction": {
        "beforeOpeningRoundBrace": true
    },
    "disallowSpacesInsideParentheses": true,
    "disallowTrailingWhitespace": true,
    "maximumLineLength": 100,
    "requireCamelCaseOrUpperCaseIdentifiers": true,
    "requireCapitalizedComments": true,
    "requireCapitalizedConstructors": true,
    "requireCurlyBraces": true,
    "requireSpaceAfterKeywords": [
        "if",
        "else",
        "for",
        "while",
        "do",
        "switch",
        "case",
        "return",
        "try",
        "catch",
        "typeof"
    ],
    "requireSpaceAfterLineComment": true,
    "requireSpaceAfterBinaryOperators": true,
    "requireSpaceBeforeBinaryOperators": true,
    "requireSpaceBeforeBlockStatements": true,
    "requireSpaceBeforeObjectValues": true,
    "requireSpacesInFunction": {
        "beforeOpeningCurlyBrace": true
    },
    "validateIndentation": 4,
    "validateLineBreaks": "LF",
    "validateQuoteMarks": "'"
}

index.js

代码语言:javascript
复制
'use strict';

/**
 * Module dependencies.
 */
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename  = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/database.json')[env];
const db = {};
const sequelizeFactory = (config) => {
  if (config.use_env_variable) {
    return new Sequelize(process.env[config.use_env_variable]);
  } else {
    return new Sequelize(config.database, config.username,config.password,config);
  }
};

const sequelize = sequelizeFactory(config);

fs
.readdirSync(__dirname)
.filter((file) => {
  return (file.indexOf('.') !== 0) && (file !== basename);
})
.forEach((file) => {
  let model = sequelize['import'](path.join(__dirname, file));
  db[model.name] = model;
});

Object.keys(db).forEach((modelName) => {
  if (db[modelName].associate) {
    db[modelName].associate(db);
  }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

错误

代码语言:javascript
复制
Expected indentation of 4 characters at src/models/index.js :
    12 |const db = {};
    13 |const sequelizeFactory = (config) => {
    14 |  if (config.use_env_variable) {
------------^
    15 |    return new Sequelize(process.env[config.use_env_variable]);
    16 |  } else {

All identifiers must be camelCase or UPPER_CASE at src/models/index.js :
    12 |const db = {};
    13 |const sequelizeFactory = (config) => {
    14 |  if (config.use_env_variable) {
---------------------^
    15 |    return new Sequelize(process.env[config.use_env_variable]);
    16 |  } else {

Expected indentation of 8 characters at src/models/index.js :
    13 |const sequelizeFactory = (config) => {
    14 |  if (config.use_env_variable) {
    15 |    return new Sequelize(process.env[config.use_env_variable]);
----------------^
    16 |  } else {
    17 |    return new Sequelize(config.database, config.username,config.password,config);

All identifiers must be camelCase or UPPER_CASE at src/models/index.js :
    13 |const sequelizeFactory = (config) => {
    14 |  if (config.use_env_variable) {
    15 |    return new Sequelize(process.env[config.use_env_variable]);
----------------------------------------------------^
    16 |  } else {
    17 |    return new Sequelize(config.database, config.username,config.password,config);

Expected indentation of 4 characters at src/models/index.js :
    14 |  if (config.use_env_variable) {
    15 |    return new Sequelize(process.env[config.use_env_variable]);
    16 |  } else {
------------^
    17 |    return new Sequelize(config.database, config.username,config.password,config);
    18 |  }

Expected indentation of 8 characters at src/models/index.js :
    15 |    return new Sequelize(process.env[config.use_env_variable]);
    16 |  } else {
    17 |    return new Sequelize(config.database, config.username,config.password,config);
----------------^
    18 |  }
    19 |};

Expected indentation of 4 characters at src/models/index.js :
    16 |  } else {
    17 |    return new Sequelize(config.database, config.username,config.password,config);
    18 |  }
------------^
    19 |};
    20 |

Expected indentation of 4 characters at src/models/index.js :
    24 |.readdirSync(__dirname)
    25 |.filter((file) => {
    26 |  return (file.indexOf('.') !== 0) && (file !== basename);
------------^
    27 |})
    28 |.forEach((file) => {

Expected indentation of 4 characters at src/models/index.js :
    27 |})
    28 |.forEach((file) => {
    29 |  let model = sequelize['import'](path.join(__dirname, file));
------------^
    30 |  db[model.name] = model;
    31 |});

Expected indentation of 4 characters at src/models/index.js :
    28 |.forEach((file) => {
    29 |  let model = sequelize['import'](path.join(__dirname, file));
    30 |  db[model.name] = model;
------------^
    31 |});
    32 |

Expected indentation of 4 characters at src/models/index.js :
    32 |
    33 |Object.keys(db).forEach((modelName) => {
    34 |  if (db[modelName].associate) {
------------^
    35 |    db[modelName].associate(db);
    36 |  }

Expected indentation of 8 characters at src/models/index.js :
    33 |Object.keys(db).forEach((modelName) => {
    34 |  if (db[modelName].associate) {
    35 |    db[modelName].associate(db);
----------------^
    36 |  }
    37 |});

Expected indentation of 4 characters at src/models/index.js :
    34 |  if (db[modelName].associate) {
    35 |    db[modelName].associate(db);
    36 |  }
------------^
    37 |});
    38 |


13 code style errors found.

因此,抛开关于config.use_env_variable的错误(在本例中,我同意jscsrc ^^),有什么问题和正确的缩进吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-17 11:15:50

index.js文件中有两个空格的缩进。

如果您想要缩进4个空格,请重新修改文件:)

例如:

代码语言:javascript
复制
33 |Object.keys(db).forEach((modelName) => {
34 |  if (db[modelName].associate) {

如果只有两个空格

票数 1
EN

Stack Overflow用户

发布于 2015-10-16 20:51:57

如果要缩进两个空格,则应将"validateIndentation": 4,更改为"validateIndentation": 2,

我建议您使用预置(http://jscs.info/overview)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33178643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档