不要怂,就是干,撸起袖子干!

Commit 8d4700fb by Felix Becker Committed by GitHub

style(spacing): add spacing rules to .eslintrc (#7921)

Requires a spaces after an if and before the opening brace of blocks
1 parent 18e04a2b
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
"prefer-const": "error", "prefer-const": "error",
"semi": ["error", "always"], "semi": ["error", "always"],
"space-before-function-paren": ["warn", "never"], "space-before-function-paren": ["warn", "never"],
"keyword-spacing": ["warn"], "space-before-blocks": ["error"],
"keyword-spacing": ["error"],
"prefer-arrow-callback": "error", "prefer-arrow-callback": "error",
"arrow-parens": ["error", "as-needed"], "arrow-parens": ["error", "as-needed"],
"comma-style": ["warn", "last"], "comma-style": ["warn", "last"],
......
...@@ -115,10 +115,10 @@ const QueryGenerator = { ...@@ -115,10 +115,10 @@ const QueryGenerator = {
let outputColumns = ''; let outputColumns = '';
tmpTable = 'declare @tmp table (<%= columns %>); '; tmpTable = 'declare @tmp table (<%= columns %>); ';
for (const modelKey in modelAttributes){ for (const modelKey in modelAttributes) {
const attribute = modelAttributes[modelKey]; const attribute = modelAttributes[modelKey];
if (!(attribute.type instanceof DataTypes.VIRTUAL)){ if (!(attribute.type instanceof DataTypes.VIRTUAL)) {
if (tmpColumns.length > 0){ if (tmpColumns.length > 0) {
tmpColumns += ','; tmpColumns += ',';
outputColumns += ','; outputColumns += ',';
} }
...@@ -307,10 +307,10 @@ const QueryGenerator = { ...@@ -307,10 +307,10 @@ const QueryGenerator = {
let tmpColumns = ''; let tmpColumns = '';
let outputColumns = ''; let outputColumns = '';
for (const modelKey in attributes){ for (const modelKey in attributes) {
const attribute = attributes[modelKey]; const attribute = attributes[modelKey];
if (!(attribute.type instanceof DataTypes.VIRTUAL)){ if (!(attribute.type instanceof DataTypes.VIRTUAL)) {
if (tmpColumns.length > 0){ if (tmpColumns.length > 0) {
tmpColumns += ','; tmpColumns += ',';
outputColumns += ','; outputColumns += ',';
} }
...@@ -726,7 +726,7 @@ const QueryGenerator = { ...@@ -726,7 +726,7 @@ const QueryGenerator = {
connector = connector || '.'; connector = connector || '.';
// just quote as identifiers if string // just quote as identifiers if string
if (typeof collection === 'string'){ if (typeof collection === 'string') {
return this.quoteIdentifiers(collection); return this.quoteIdentifiers(collection);
} else if (Array.isArray(collection)) { } else if (Array.isArray(collection)) {
// iterate through the collection and mutate objects into associations // iterate through the collection and mutate objects into associations
...@@ -736,7 +736,7 @@ const QueryGenerator = { ...@@ -736,7 +736,7 @@ const QueryGenerator = {
let previousModel; let previousModel;
// set the previous as the parent when previous is undefined or the target of the association // set the previous as the parent when previous is undefined or the target of the association
if (!previous && parent !== undefined){ if (!previous && parent !== undefined) {
previousModel = parent; previousModel = parent;
} else if (previous && previous instanceof Association) { } else if (previous && previous instanceof Association) {
previousAssociation = previous; previousAssociation = previous;
...@@ -1682,7 +1682,7 @@ const QueryGenerator = { ...@@ -1682,7 +1682,7 @@ const QueryGenerator = {
} }
mainQueryOrder.push(this.quote(order, model, '->')); mainQueryOrder.push(this.quote(order, model, '->'));
} }
} else if (options.order instanceof Utils.SequelizeMethod){ } else if (options.order instanceof Utils.SequelizeMethod) {
const sql = this.quote(options.order, model, '->'); const sql = this.quote(options.order, model, '->');
if (subQuery) { if (subQuery) {
subQueryOrder.push(sql); subQueryOrder.push(sql);
......
...@@ -869,7 +869,7 @@ const QueryGenerator = { ...@@ -869,7 +869,7 @@ const QueryGenerator = {
}; };
// private methods // private methods
function wrapSingleQuote(identifier){ function wrapSingleQuote(identifier) {
return Utils.addTicks(Utils.removeTicks(identifier, "'"), "'"); return Utils.addTicks(Utils.removeTicks(identifier, "'"), "'");
} }
......
...@@ -30,10 +30,10 @@ class Query extends AbstractQuery { ...@@ -30,10 +30,10 @@ class Query extends AbstractQuery {
} }
getSQLTypeFromJsType(value) { getSQLTypeFromJsType(value) {
const paramType = {type: TYPES.VarChar, typeOptions: {} }; const paramType = {type: TYPES.VarChar, typeOptions: {} };
paramType.type = TYPES.NVarChar; paramType.type = TYPES.NVarChar;
if (typeof value === 'number') { if (typeof value === 'number') {
if(Number.isInteger(value)){ if (Number.isInteger(value)) {
paramType.type = TYPES.Int; paramType.type = TYPES.Int;
} else { } else {
paramType.type = TYPES.Numeric; paramType.type = TYPES.Numeric;
...@@ -110,7 +110,7 @@ class Query extends AbstractQuery { ...@@ -110,7 +110,7 @@ class Query extends AbstractQuery {
} }
}); });
if(parameters){ if (parameters) {
_.forOwn(parameters, (value, key) => { _.forOwn(parameters, (value, key) => {
const paramType = this.getSQLTypeFromJsType(value); const paramType = this.getSQLTypeFromJsType(value);
request.addParameter(key, paramType.type, value, paramType.typeOptions); request.addParameter(key, paramType.type, value, paramType.typeOptions);
......
...@@ -365,7 +365,7 @@ const QueryGenerator = { ...@@ -365,7 +365,7 @@ const QueryGenerator = {
}; };
// private methods // private methods
function wrapSingleQuote(identifier){ function wrapSingleQuote(identifier) {
return Utils.addTicks(identifier, '\''); return Utils.addTicks(identifier, '\'');
} }
......
...@@ -159,7 +159,7 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -159,7 +159,7 @@ class ConnectionManager extends AbstractConnectionManager {
type = dataTypes.postgres.GEOMETRY; type = dataTypes.postgres.GEOMETRY;
} else if (row.typname === 'hstore') { } else if (row.typname === 'hstore') {
type = dataTypes.postgres.HSTORE; type = dataTypes.postgres.HSTORE;
} else if (row.typname === 'geography'){ } else if (row.typname === 'geography') {
type = dataTypes.postgres.GEOGRAPHY; type = dataTypes.postgres.GEOGRAPHY;
} }
......
...@@ -290,10 +290,10 @@ module.exports = BaseTypes => { ...@@ -290,10 +290,10 @@ module.exports = BaseTypes => {
GEOMETRY.prototype.toSql = function toSql() { GEOMETRY.prototype.toSql = function toSql() {
let result = this.key; let result = this.key;
if (this.type){ if (this.type) {
result += '(' + this.type; result += '(' + this.type;
if (this.srid){ if (this.srid) {
result += ',' + this.srid; result += ',' + this.srid;
} }
...@@ -326,10 +326,10 @@ module.exports = BaseTypes => { ...@@ -326,10 +326,10 @@ module.exports = BaseTypes => {
GEOGRAPHY.prototype.toSql = function toSql() { GEOGRAPHY.prototype.toSql = function toSql() {
let result = 'GEOGRAPHY'; let result = 'GEOGRAPHY';
if (this.type){ if (this.type) {
result += '(' + this.type; result += '(' + this.type;
if (this.srid){ if (this.srid) {
result += ',' + this.srid; result += ',' + this.srid;
} }
......
...@@ -56,7 +56,7 @@ class Query extends AbstractQuery { ...@@ -56,7 +56,7 @@ class Query extends AbstractQuery {
run(sql, parameters) { run(sql, parameters) {
this.sql = sql; this.sql = sql;
if (!Utils._.isEmpty(this.options.searchPath)){ if (!Utils._.isEmpty(this.options.searchPath)) {
this.sql = this.sequelize.queryInterface.QueryGenerator.setSearchPath(this.options.searchPath) + sql; this.sql = this.sequelize.queryInterface.QueryGenerator.setSearchPath(this.options.searchPath) + sql;
} }
......
...@@ -579,7 +579,7 @@ class Model { ...@@ -579,7 +579,7 @@ class Model {
} }
} else { } else {
association = this.getAssociationForAlias(targetModel, targetAlias); association = this.getAssociationForAlias(targetModel, targetAlias);
if (!association){ if (!association) {
throw new sequelizeErrors.EagerLoadingError(`${targetModel.name} is associated to ${this.name} multiple times. ` + throw new sequelizeErrors.EagerLoadingError(`${targetModel.name} is associated to ${this.name} multiple times. ` +
'To identify the correct association, you must use the \'as\' keyword to specify the alias of the association you want to include.'); 'To identify the correct association, you must use the \'as\' keyword to specify the alias of the association you want to include.');
} }
......
...@@ -207,7 +207,7 @@ class Sequelize { ...@@ -207,7 +207,7 @@ class Sequelize {
let Dialect; let Dialect;
// Requiring the dialect in a switch-case to keep the // Requiring the dialect in a switch-case to keep the
// require calls static. (Browserify fix) // require calls static. (Browserify fix)
switch (this.getDialect()){ switch (this.getDialect()) {
case 'mssql': case 'mssql':
Dialect = require('./dialects/mssql'); Dialect = require('./dialects/mssql');
break; break;
...@@ -362,7 +362,7 @@ class Sequelize { ...@@ -362,7 +362,7 @@ class Sequelize {
*/ */
import(path) { import(path) {
// is it a relative path? // is it a relative path?
if (Path.normalize(path) !== Path.resolve(path)){ if (Path.normalize(path) !== Path.resolve(path)) {
// make path relative to the caller // make path relative to the caller
const callerFilename = Utils.stack()[1].getFileName(); const callerFilename = Utils.stack()[1].getFileName();
const callerPath = Path.dirname(callerFilename); const callerPath = Path.dirname(callerFilename);
...@@ -1028,7 +1028,7 @@ class Sequelize { ...@@ -1028,7 +1028,7 @@ class Sequelize {
options = last; options = last;
// remove options from set of logged arguments if options.logging is equal to console.log // remove options from set of logged arguments if options.logging is equal to console.log
if (options.logging === console.log){ if (options.logging === console.log) {
args.splice(args.length-1, 1); args.splice(args.length-1, 1);
} }
} else { } else {
......
...@@ -123,7 +123,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -123,7 +123,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
}); });
describe('preserves changes to instance', () => { describe('preserves changes to instance', () => {
it('beforeValidate', function(){ it('beforeValidate', function() {
let hookCalled = 0; let hookCalled = 0;
this.User.beforeValidate(user => { this.User.beforeValidate(user => {
......
...@@ -97,7 +97,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -97,7 +97,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
}); });
describe('preserves changes to instance', () => { describe('preserves changes to instance', () => {
it('beforeValidate', function(){ it('beforeValidate', function() {
this.User.beforeValidate(user => { this.User.beforeValidate(user => {
user.mood = 'happy'; user.mood = 'happy';
......
...@@ -74,7 +74,7 @@ if (Support.sequelize.dialect.supports.upserts) { ...@@ -74,7 +74,7 @@ if (Support.sequelize.dialect.supports.upserts) {
}); });
describe('preserves changes to values', () => { describe('preserves changes to values', () => {
it('beforeUpsert', function(){ it('beforeUpsert', function() {
let hookCalled = 0; let hookCalled = 0;
const valuesOriginal = { mood: 'sad', username: 'leafninja' }; const valuesOriginal = { mood: 'sad', username: 'leafninja' };
......
...@@ -32,7 +32,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -32,7 +32,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
username: 'tony' username: 'tony'
} }
}, },
includeActiveProjects(){ includeActiveProjects() {
return { return {
include: [{ include: [{
model: sequelize.models.company, model: sequelize.models.company,
......
...@@ -520,7 +520,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => { ...@@ -520,7 +520,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
if (dialect === 'postgres' || dialect === 'sqlite') { if (dialect === 'postgres' || dialect === 'sqlite') {
expect(logSql.indexOf('$1')).to.be.above(-1); expect(logSql.indexOf('$1')).to.be.above(-1);
expect(logSql.indexOf('$2')).to.be.above(-1); expect(logSql.indexOf('$2')).to.be.above(-1);
} else if (dialect === 'mssql'){ } else if (dialect === 'mssql') {
expect(logSql.indexOf('@0')).to.be.above(-1); expect(logSql.indexOf('@0')).to.be.above(-1);
expect(logSql.indexOf('@1')).to.be.above(-1); expect(logSql.indexOf('@1')).to.be.above(-1);
} }
......
...@@ -248,7 +248,7 @@ if (current.dialect.supports.transactions) { ...@@ -248,7 +248,7 @@ if (current.dialect.supports.transactions) {
}); });
}); });
if (dialect === 'sqlite'){ if (dialect === 'sqlite') {
it('provides persistent transactions', () => { it('provides persistent transactions', () => {
const sequelize = new Support.Sequelize('database', 'username', 'password', {dialect: 'sqlite'}), const sequelize = new Support.Sequelize('database', 'username', 'password', {dialect: 'sqlite'}),
User = sequelize.define('user', { User = sequelize.define('user', {
......
...@@ -25,25 +25,25 @@ describe(Support.getTestDialectTeaser('associations'), () => { ...@@ -25,25 +25,25 @@ describe(Support.getTestDialectTeaser('associations'), () => {
this.C = this.sequelize.define('C', {}); this.C = this.sequelize.define('C', {});
}); });
it('should not be overwritten for belongsTo', function(){ it('should not be overwritten for belongsTo', function() {
const reqValidForeignKey = { foreignKey: { allowNull: false }}; const reqValidForeignKey = { foreignKey: { allowNull: false }};
this.A.belongsTo(this.B, reqValidForeignKey); this.A.belongsTo(this.B, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
}); });
it('should not be overwritten for belongsToMany', function(){ it('should not be overwritten for belongsToMany', function() {
const reqValidForeignKey = { foreignKey: { allowNull: false }, through: 'ABBridge'}; const reqValidForeignKey = { foreignKey: { allowNull: false }, through: 'ABBridge'};
this.B.belongsToMany(this.A, reqValidForeignKey); this.B.belongsToMany(this.A, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
}); });
it('should not be overwritten for hasOne', function(){ it('should not be overwritten for hasOne', function() {
const reqValidForeignKey = { foreignKey: { allowNull: false }}; const reqValidForeignKey = { foreignKey: { allowNull: false }};
this.B.hasOne(this.A, reqValidForeignKey); this.B.hasOne(this.A, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey);
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type);
}); });
it('should not be overwritten for hasMany', function(){ it('should not be overwritten for hasMany', function() {
const reqValidForeignKey = { foreignKey: { allowNull: false }}; const reqValidForeignKey = { foreignKey: { allowNull: false }};
this.B.hasMany(this.A, reqValidForeignKey); this.B.hasMany(this.A, reqValidForeignKey);
this.A.belongsTo(this.C, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey);
......
...@@ -15,7 +15,7 @@ describe('Transaction', function() { ...@@ -15,7 +15,7 @@ describe('Transaction', function() {
this.stubConnection = sinon.stub(current.connectionManager, 'getConnection') this.stubConnection = sinon.stub(current.connectionManager, 'getConnection')
.returns(Sequelize.Promise.resolve({ .returns(Sequelize.Promise.resolve({
uuid: 'ssfdjd-434fd-43dfg23-2d', uuid: 'ssfdjd-434fd-43dfg23-2d',
close(){} close() {}
})); }));
this.stubRelease = sinon.stub(current.connectionManager, 'releaseConnection') this.stubRelease = sinon.stub(current.connectionManager, 'releaseConnection')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!