Skip to content

Commit c722f82

Browse files
authored
Merge pull request #82 from paparomeo/standard-js-linting
Standard.js for code style and linting.
2 parents d9414a9 + 2e5938c commit c722f82

File tree

10 files changed

+1995
-547
lines changed

10 files changed

+1995
-547
lines changed

.eslintrc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
12
{
2-
"extends": "eslint:recommended",
3-
"globals": {
4-
},
3+
"extends": "standard",
4+
"plugins": [
5+
"standard",
6+
"promise",
7+
"mocha"
8+
],
59
"env": {
6-
"node": true,
7-
"mocha": true
10+
"mocha": true,
11+
"node": true
812
},
913
"rules": {
10-
"no-underscore-dangle": [ 0 ],
11-
"curly": [2, "multi-line"]
14+
"mocha/no-exclusive-tests": "error",
15+
"mocha/no-global-tests": "error",
16+
"mocha/no-identical-title": "error",
17+
"mocha/no-nested-tests": "error",
18+
"mocha/no-sibling-hooks": "error"
1219
}
1320
}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm start
1515

1616
Every pull request that changes code in this project needs to either fix an existing tst case or have some form of regression test with it. That might take the shape of some additional asserts in key places within existing tests, it might involve new tests. We write tests to ensure features don't get lost - protect your feature by writing good tests!
1717

18-
To verify all the code changes pass our style guidelines:
18+
To verify all the code changes pass our [JavaScript Standard Style](https://standardjs.com/) guidelines:
1919
```
2020
npm run lint
2121
```

example/server.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
"use strict";
2-
var async = require("async");
3-
var config = require("../lib/config.js");
4-
var JsonapiStoreRelationalDb = require("..");
1+
'use strict'
2+
var async = require('async')
3+
var config = require('../lib/config.js')
4+
var JsonapiStoreRelationalDb = require('..')
55

6-
var instances = [ ];
6+
var instances = [ ]
77

8-
var DATABASE = "jsonapi-relationaldb";
8+
var DATABASE = 'jsonapi-relationaldb'
99

1010
// Replace the MemoryStore default handler with our own version
11-
require("jsonapi-server/lib/MemoryHandler");
12-
module.children[3].exports = function() {
13-
var dbStore = new JsonapiStoreRelationalDb(config(DATABASE));
11+
require('jsonapi-server/lib/MemoryHandler')
12+
module.children[3].exports = function () {
13+
var dbStore = new JsonapiStoreRelationalDb(config(DATABASE))
1414
// Keep the handler around for after the test rig is live
15-
instances.push(dbStore);
16-
return dbStore;
17-
};
15+
instances.push(dbStore)
16+
return dbStore
17+
}
1818

19-
var jsonApiTestServer = require("jsonapi-server/example/server.js");
20-
jsonApiTestServer.start();
19+
var jsonApiTestServer = require('jsonapi-server/example/server.js')
20+
jsonApiTestServer.start()
2121

2222
// MySQL doesn't differentiate between undefined and null.
2323
// Tweak the created field to allow null fields to pass Joi validation.
24-
var articles = require("jsonapi-server")._resources.articles;
25-
articles.attributes.created = articles.attributes.created.allow(null);
26-
articles.onCreate.created = articles.onCreate.created.allow(null);
24+
var articles = require('jsonapi-server')._resources.articles
25+
articles.attributes.created = articles.attributes.created.allow(null)
26+
articles.onCreate.created = articles.onCreate.created.allow(null)
2727

2828
// Before starting the test suite, load all example resouces, aka
2929
// the test fixtures, into the databases
30-
async.map(instances, function(dbStore, callback) {
31-
dbStore.populate(callback);
32-
}, function() { });
30+
async.map(instances, function (dbStore, callback) {
31+
dbStore.populate(callback)
32+
}, function () { })

lib/config.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
"use strict";
1+
'use strict'
22

33
var CONFIGURATIONS = {
44
mysql: {
5-
dialect: "mysql",
6-
username: "root"
5+
dialect: 'mysql',
6+
username: 'root'
77
},
88
postgres: {
9-
dialect: "postgres",
10-
username: "postgres"
9+
dialect: 'postgres',
10+
username: 'postgres'
1111
},
1212
sqlite: {
13-
dialect: "sqlite",
14-
storage: ":memory:"
13+
dialect: 'sqlite',
14+
storage: ':memory:'
1515
}
1616
}
1717

18-
module.exports = function(database) {
19-
var config = CONFIGURATIONS[process.env.SEQUELIZE_DIALECT] || CONFIGURATIONS.mysql;
20-
config.database = database;
21-
return config;
22-
};
18+
module.exports = function (database) {
19+
var config = CONFIGURATIONS[process.env.SEQUELIZE_DIALECT] || CONFIGURATIONS.mysql
20+
config.database = database
21+
return config
22+
}

lib/modelGenerators/default.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var DataTypes = require('sequelize').DataTypes
22

3-
exports.joiSchemaToSequelizeModel = function(resourceName, joiSchema) {
3+
exports.joiSchemaToSequelizeModel = function (resourceName, joiSchema) {
44
var model = {
55
id: { type: new DataTypes.STRING(38), primaryKey: true },
66
type: {
7-
type: DataTypes.VIRTUAL, //We do not actually save this to DB, but API needs this
7+
type: DataTypes.VIRTUAL, // We do not actually save this to DB, but API needs this
88
set: function (val) {
99
this.setDataValue('type', val)
1010
},
@@ -14,39 +14,38 @@ exports.joiSchemaToSequelizeModel = function(resourceName, joiSchema) {
1414
},
1515
meta: {
1616
type: DataTypes.STRING,
17-
get: function() {
18-
var data = this.getDataValue("meta");
19-
if (!data) return undefined;
20-
return JSON.parse(data);
17+
get: function () {
18+
var data = this.getDataValue('meta')
19+
if (!data) return undefined
20+
return JSON.parse(data)
2121
},
22-
set: function(val) {
23-
return this.setDataValue("meta", JSON.stringify(val));
22+
set: function (val) {
23+
return this.setDataValue('meta', JSON.stringify(val))
2424
}
2525
}
26-
};
26+
}
2727

28-
Object.keys(joiSchema).forEach(function(attributeName) {
29-
var attribute = joiSchema[attributeName];
30-
if (attribute._type === "string") model[attributeName] = { type: DataTypes.TEXT, allowNull: true };
31-
if (attribute._type === "date") model[attributeName] = { type: DataTypes.DATE, allowNull: true };
32-
if (attribute._type === "number") model[attributeName] = { type: DataTypes.NUMERIC, allowNull: true };
33-
if (attribute._type === "boolean") model[attributeName] = { type: DataTypes.BOOLEAN, allowNull: true };
34-
if (attribute._type === "array") {
35-
//Serialize array to ';'-separated string for most SQL dbs.
28+
Object.keys(joiSchema).forEach(function (attributeName) {
29+
var attribute = joiSchema[attributeName]
30+
if (attribute._type === 'string') model[attributeName] = { type: DataTypes.TEXT, allowNull: true }
31+
if (attribute._type === 'date') model[attributeName] = { type: DataTypes.DATE, allowNull: true }
32+
if (attribute._type === 'number') model[attributeName] = { type: DataTypes.NUMERIC, allowNull: true }
33+
if (attribute._type === 'boolean') model[attributeName] = { type: DataTypes.BOOLEAN, allowNull: true }
34+
if (attribute._type === 'array') {
35+
// Serialize array to ';'-separated string for most SQL dbs.
3636
model[attributeName] = {
3737
type: DataTypes.STRING,
3838
allowNull: true,
3939
get: function () {
40-
var data = this.getDataValue(attributeName);
40+
var data = this.getDataValue(attributeName)
4141
return data ? data.split(';') : []
4242
},
4343
set: function (val) {
44-
this.setDataValue(attributeName, val.join(';'));
44+
this.setDataValue(attributeName, val.join(';'))
4545
}
4646
}
47-
4847
}
49-
});
48+
})
5049

51-
return model;
52-
};
50+
return model
51+
}

lib/modelGenerators/postgres.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var DataTypes = require('sequelize').DataTypes
22

3-
exports.joiSchemaToSequelizeModel = function(resourceName, joiSchema) {
3+
exports.joiSchemaToSequelizeModel = function (resourceName, joiSchema) {
44
var model = {
55
id: { type: new DataTypes.STRING(38), primaryKey: true },
66
type: {
7-
type: DataTypes.VIRTUAL, //We do not actually save this to DB, but API needs this
7+
type: DataTypes.VIRTUAL, // We do not actually save this to DB, but API needs this
88
set: function (val) {
99
this.setDataValue('type', val)
1010
},
@@ -14,44 +14,44 @@ exports.joiSchemaToSequelizeModel = function(resourceName, joiSchema) {
1414
},
1515
meta: {
1616
type: DataTypes.JSONB,
17-
get: function() {
18-
var data = this.getDataValue("meta");
19-
if (!data) return undefined;
20-
return data;
17+
get: function () {
18+
var data = this.getDataValue('meta')
19+
if (!data) return undefined
20+
return data
2121
},
22-
set: function(val) {
23-
return this.setDataValue("meta", val);
22+
set: function (val) {
23+
return this.setDataValue('meta', val)
2424
}
2525
}
26-
};
26+
}
2727

28-
Object.keys(joiSchema).forEach(function(attributeName) {
29-
var attribute = joiSchema[attributeName];
30-
if (attribute._type === "string") model[attributeName] = { type: DataTypes.TEXT, allowNull: true };
31-
if (attribute._type === "date") model[attributeName] = { type: DataTypes.DATE, allowNull: true };
32-
if (attribute._type === "number") {
33-
if (typeof attribute._flags.precision !== "undefined") {
34-
model[attributeName] = { type: DataTypes.NUMERIC(32, attribute._flags.precision), allowNull: true };
28+
Object.keys(joiSchema).forEach(function (attributeName) {
29+
var attribute = joiSchema[attributeName]
30+
if (attribute._type === 'string') model[attributeName] = { type: DataTypes.TEXT, allowNull: true }
31+
if (attribute._type === 'date') model[attributeName] = { type: DataTypes.DATE, allowNull: true }
32+
if (attribute._type === 'number') {
33+
if (typeof attribute._flags.precision !== 'undefined') {
34+
model[attributeName] = { type: DataTypes.NUMERIC(32, attribute._flags.precision), allowNull: true }
3535
} else {
36-
model[attributeName] = { type: DataTypes.NUMERIC, allowNull: true };
36+
model[attributeName] = { type: DataTypes.NUMERIC, allowNull: true }
3737
}
3838
}
39-
if (attribute._type === "boolean") model[attributeName] = { type: DataTypes.BOOLEAN, allowNull: true };
40-
if (attribute._type === "array") {
41-
//PostgreSQL has proper array support, so lets use that
39+
if (attribute._type === 'boolean') model[attributeName] = { type: DataTypes.BOOLEAN, allowNull: true }
40+
if (attribute._type === 'array') {
41+
// PostgreSQL has proper array support, so lets use that
4242
switch (attribute._inner.items[0]._type) {
43-
case "string": model[attributeName] = {type: DataTypes.ARRAY(DataTypes.STRING), allowNull: true}; break;
44-
case "number": model[attributeName] = {type: DataTypes.ARRAY(DataTypes.NUMERIC), allowNull: true}; break;
45-
case "boolean": model[attributeName] = {type: DataTypes.ARRAY(DataTypes.BOOLEAN), allowNull: true}; break;
43+
case 'string': model[attributeName] = {type: DataTypes.ARRAY(DataTypes.STRING), allowNull: true}; break
44+
case 'number': model[attributeName] = {type: DataTypes.ARRAY(DataTypes.NUMERIC), allowNull: true}; break
45+
case 'boolean': model[attributeName] = {type: DataTypes.ARRAY(DataTypes.BOOLEAN), allowNull: true}; break
4646
}
4747
model[attributeName].get = function () {
4848
return this.getDataValue(attributeName) || []
4949
}
5050
model[attributeName].set = function (val) {
51-
this.setDataValue(attributeName, val ? val : [])
51+
this.setDataValue(attributeName, val || [])
5252
}
5353
}
54-
});
54+
})
5555

56-
return model;
57-
};
56+
return model
57+
}

0 commit comments

Comments
 (0)