预期缩进 4 个字符

Expected indentation of 4 characters

更新

作为@dev-null(顺便说一句,很多:))建议(见评论) 正确的方法是

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个空格,你应该把"validateIndentation": 4,改成"validateIndentation": 2,

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

您的 index.js 文件中缩进了 2 个空格。

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

例如:

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

if之前只有2个空格