预期4个字符的缩进

UPDATE

作为@ dev-null(btw thx很多:))build议(见评论)正确的方法是

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

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

如果你想有一个4个空格的缩进,重新加载你的文件:)

例如:

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

之前如果只有2个空格

如果你想有2个空格的缩进,你应该改变"validateIndentation": 4,改为"validateIndentation": 2,

我build议你使用预设( http://jscs.info/overview