预计4个字符的缩进

时间:2015-10-16 19:58:39

标签: node.js jscs

更新

as @ dev-null(btw thx很多:))建议(参见评论) 正确的方法是

jscs --fix file.js

我的缩进的问题是什么?

.editorconfig

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

{
    "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

'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;

错误

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 ^^) 什么是问题和正确的缩进?

2 个答案:

答案 0 :(得分:1)

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

如果您想要缩进4个空格,请重新输入您的文件:)

例如:

33 |Object.keys(db).forEach((modelName) => {
34 |  if (db[modelName].associate) {

之前如果只有2个空格

答案 1 :(得分:0)

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

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