Skip to content

Commit a60d030

Browse files
committed
Add eslint infrastructure
1 parent 0b489a0 commit a60d030

20 files changed

+567
-561
lines changed

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "loopback",
3+
"rules": {
4+
"max-len": ["error", 120, 4, {
5+
"ignoreComments": true,
6+
"ignoreUrls": true,
7+
"ignorePattern": "^\\s*var\\s.=\\s*(require\\s*\\()|(/)"
8+
}],
9+
"camelcase": 0,
10+
"one-var": "off",
11+
"no-unused-expressions": "off",
12+
"operator-linebreak": "off"
13+
}
14+
}

example/app.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

6+
'use strict';
67
var DataSource = require('loopback-datasource-juggler').DataSource;
78

89
var config = require('rc')('loopback', {dev: {postgresql: {}}}).dev.postgresql;
910

1011
var ds = new DataSource(require('../'), config);
1112

1213
function show(err, models) {
13-
if (err) {
14-
console.error(err);
15-
} else {
16-
models.forEach(function(m) {
17-
console.dir(m);
18-
});
19-
}
14+
if (err) {
15+
console.error(err);
16+
} else {
17+
models.forEach(function(m) {
18+
console.dir(m);
19+
});
20+
}
2021
}
2122

22-
2323
ds.discoverModelDefinitions({views: true, limit: 20}, show);
2424

2525
ds.discoverModelProperties('product', show);
@@ -60,6 +60,4 @@ ds.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associ
6060
});
6161
});
6262
63-
6463
*/
65-

example/model.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Node module: loopback-connector-postgresql
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
5+
'use strict';
56
var SG = require('strong-globalize');
67
var g = SG();
78

@@ -13,34 +14,33 @@ var ds = new DataSource(require('../'), config);
1314

1415
// Define a account model
1516
var Account = ds.createModel('account', {
16-
name: String,
17-
emails: [String],
18-
age: Number},
17+
name: String,
18+
emails: [String],
19+
age: Number},
1920
{strict: true});
2021

2122
ds.automigrate('account', function(err) {
2223
// Create two instances
23-
Account.create({
24+
Account.create({
2425
name: 'John1',
2526
emails: ['john@x.com', 'jhon@y.com'],
26-
age: 30
27-
}, function (err, account1) {
27+
age: 30,
28+
}, function(err, account1) {
2829
console.log('Account 1: ', account1.toObject());
2930
Account.create({
30-
name: 'John2',
31-
emails: ['john@x.com', 'jhon@y.com'],
32-
age: 30
33-
}, function (err, account2) {
34-
console.log('Account 2: ', account2.toObject());
35-
Account.findById(account2.id, function(err, account3) {
36-
console.log(account3.toObject());
37-
});
38-
Account.find({where: {name: 'John1'}, limit: 3}, function(err, accounts) {
39-
accounts.forEach(function(c) {
40-
console.log(c.toObject());
41-
});
31+
name: 'John2',
32+
emails: ['john@x.com', 'jhon@y.com'],
33+
age: 30,
34+
}, function(err, account2) {
35+
console.log('Account 2: ', account2.toObject());
36+
Account.findById(account2.id, function(err, account3) {
37+
console.log(account3.toObject());
38+
});
39+
Account.find({where: {name: 'John1'}, limit: 3}, function(err, accounts) {
40+
accounts.forEach(function(c) {
41+
console.log(c.toObject());
4242
});
43+
});
4344
});
44-
45-
});
45+
});
4646
});

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

6+
'use strict';
67
var SG = require('strong-globalize');
78
SG.SetRootDir(__dirname);
89

lib/discovery.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file is licensed under the Artistic License 2.0.
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

6+
'use strict';
67
var g = require('strong-globalize')();
78

89
module.exports = mixinDiscovery;
@@ -56,7 +57,6 @@ function mixinDiscovery(PostgreSQL) {
5657
function queryViews(options) {
5758
var sqlViews = null;
5859
if (options.views) {
59-
6060
var owner = options.owner || options.schema;
6161

6262
if (options.all && !owner) {
@@ -82,24 +82,24 @@ function mixinDiscovery(PostgreSQL) {
8282
* @param {Object} options Options for discovery
8383
* @param {Function} [cb] The callback function
8484
*/
85-
PostgreSQL.prototype.discoverModelDefinitions = function (options, cb) {
85+
PostgreSQL.prototype.discoverModelDefinitions = function(options, cb) {
8686
if (!cb && typeof options === 'function') {
8787
cb = options;
8888
options = {};
8989
}
9090
options = options || {};
9191

9292
var self = this;
93-
var calls = [function (callback) {
93+
var calls = [function(callback) {
9494
self.execute(queryTables(options), callback);
9595
}];
9696

9797
if (options.views) {
98-
calls.push(function (callback) {
98+
calls.push(function(callback) {
9999
self.execute(queryViews(options), callback);
100100
});
101101
}
102-
async.parallel(calls, function (err, data) {
102+
async.parallel(calls, function(err, data) {
103103
if (err) {
104104
cb(err, data);
105105
} else {
@@ -135,7 +135,7 @@ function mixinDiscovery(PostgreSQL) {
135135
owner: options.owner || options.schema,
136136
table: table,
137137
options: options,
138-
cb: cb
138+
cb: cb,
139139
};
140140
}
141141

@@ -148,15 +148,17 @@ function mixinDiscovery(PostgreSQL) {
148148
function queryColumns(owner, table) {
149149
var sql = null;
150150
if (owner) {
151-
sql = paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName", data_type AS "dataType",'
152-
+ ' character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision", numeric_scale AS "dataScale", is_nullable AS "nullable"'
151+
sql = paginateSQL('SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
152+
+ 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
153+
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
153154
+ ' FROM information_schema.columns'
154155
+ ' WHERE table_schema=\'' + owner + '\''
155156
+ (table ? ' AND table_name=\'' + table + '\'' : ''),
156157
'table_name, ordinal_position', {});
157158
} else {
158-
sql = paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName", column_name AS "columnName", data_type AS "dataType",'
159-
+ ' character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision", numeric_scale AS "dataScale", is_nullable AS "nullable"'
159+
sql = paginateSQL('SELECT current_schema() AS "owner", table_name AS "tableName", column_name AS "columnName",'
160+
+ ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
161+
+ ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
160162
+ ' FROM information_schema.columns'
161163
+ (table ? ' WHERE table_name=\'' + table + '\'' : ''),
162164
'table_name, ordinal_position', {});
@@ -171,19 +173,19 @@ function mixinDiscovery(PostgreSQL) {
171173
* @param {Function} [cb] The callback function
172174
*
173175
*/
174-
PostgreSQL.prototype.discoverModelProperties = function (table, options, cb) {
176+
PostgreSQL.prototype.discoverModelProperties = function(table, options, cb) {
175177
var args = getArgs(table, options, cb);
176178
var owner = args.owner;
177179
table = args.table;
178180
options = args.options;
179181
cb = args.cb;
180182

181183
var sql = queryColumns(owner, table);
182-
var callback = function (err, results) {
184+
var callback = function(err, results) {
183185
if (err) {
184186
cb(err, results);
185187
} else {
186-
results.map(function (r) {
188+
results.map(function(r) {
187189
r.type = mysqlDataTypeToJSONType(r.dataType, r.dataLength);
188190
});
189191
cb(err, results);
@@ -192,7 +194,6 @@ function mixinDiscovery(PostgreSQL) {
192194
this.execute(sql, callback);
193195
};
194196

195-
196197
// http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)
197198

198199
/*
@@ -238,7 +239,7 @@ function mixinDiscovery(PostgreSQL) {
238239
* @param {Object} options The options for discovery
239240
* @param {Function} [cb] The callback function
240241
*/
241-
PostgreSQL.prototype.discoverPrimaryKeys = function (table, options, cb) {
242+
PostgreSQL.prototype.discoverPrimaryKeys = function(table, options, cb) {
242243
var args = getArgs(table, options, cb);
243244
var owner = args.owner;
244245
table = args.table;
@@ -296,7 +297,7 @@ function mixinDiscovery(PostgreSQL) {
296297
* @param {Object} options The options for discovery
297298
* @param {Function} [cb] The callback function
298299
*/
299-
PostgreSQL.prototype.discoverForeignKeys = function (table, options, cb) {
300+
PostgreSQL.prototype.discoverForeignKeys = function(table, options, cb) {
300301
var args = getArgs(table, options, cb);
301302
var owner = args.owner;
302303
table = args.table;
@@ -341,7 +342,7 @@ function mixinDiscovery(PostgreSQL) {
341342
* @param {Object} options The options for discovery
342343
* @param {Function} [cb] The callback function
343344
*/
344-
PostgreSQL.prototype.discoverExportedForeignKeys = function (table, options, cb) {
345+
PostgreSQL.prototype.discoverExportedForeignKeys = function(table, options, cb) {
345346
var args = getArgs(table, options, cb);
346347
var owner = args.owner;
347348
table = args.table;
@@ -385,21 +386,19 @@ function mixinDiscovery(PostgreSQL) {
385386
}
386387
}
387388

388-
389389
/**
390390
* Discover database indexes for the specified table
391391
* @param {String} table The table name
392392
* @param {Function} [cb] The callback function
393393
*/
394-
PostgreSQL.prototype.discoverModelIndexes = function (model, cb) {
394+
PostgreSQL.prototype.discoverModelIndexes = function(model, cb) {
395395
this.getTableStatus(model, function(err, fields, indexes) {
396396
var indexData = {};
397-
indexes.forEach(function (index) {
397+
indexes.forEach(function(index) {
398398
indexData[index.name] = index;
399399
delete index.name;
400400
});
401401
cb(err, indexData);
402402
});
403-
}
404-
403+
};
405404
}

0 commit comments

Comments
 (0)