Skip to content

Commit

Permalink
Adds liniting into the workflow (parse-community#3082)
Browse files Browse the repository at this point in the history
* initial linting of src

* fix indent to 2 spaces

* Removes unnecessary rules

* ignore spec folder for now

* Spec linting

* Fix spec indent

* nits

* nits

* no no-empty rule
  • Loading branch information
flovilmart authored and Rafael Santos committed Dec 3, 2016
1 parent 0d416bc commit bad820e
Show file tree
Hide file tree
Showing 149 changed files with 3,480 additions and 3,509 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/*
coverage/*
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
},
"parser": "babel-eslint",
"plugins": [
"flowtype"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"]
}
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ before_script:
- psql -c 'create database parse_server_postgres_adapter_test_database;' -U postgres
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d parse_server_postgres_adapter_test_database
- psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d parse_server_postgres_adapter_test_database
- npm run lint
env:
global:
- COVERAGE_OPTION='./node_modules/.bin/istanbul cover'
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"devDependencies": {
"babel-cli": "6.18.0",
"babel-core": "6.18.2",
"babel-eslint": "^7.1.1",
"babel-plugin-syntax-flow": "6.13.0",
"babel-plugin-transform-flow-strip-types": "6.18.0",
"babel-preset-es2015": "6.14.0",
Expand All @@ -54,6 +55,8 @@
"bcrypt-nodejs": "0.0.3",
"cross-env": "3.1.3",
"deep-diff": "0.3.4",
"eslint": "^3.10.2",
"eslint-plugin-flowtype": "^2.25.0",
"gaze": "1.1.1",
"istanbul": "1.0.0-alpha.1",
"jasmine": "2.5.2",
Expand All @@ -64,6 +67,7 @@
},
"scripts": {
"dev": "npm run build && node bin/dev",
"lint": "eslint ./",
"build": "babel src/ -d lib/",
"test": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 NODE_ENV=test TESTING=1 $COVERAGE_OPTION jasmine",
"test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 node ./node_modules/jasmine/bin/jasmine.js && npm run posttest",
Expand Down
35 changes: 35 additions & 0 deletions spec/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true,
"jasmine": true
},
"globals": {
"Parse": true,
"reconfigureServer": true,
"createTestUser": true,
"jfail": true,
"ok": true,
"strictEqual": true,
"TestObject": true,
"Item": true,
"Container": true,
"equal": true,
"notEqual": true,
"it_exclude_dbs": true,
"describe_only_db": true,
"on_db": true,
"defaultConfiguration": true,
"expectSuccess": true,
"range": true,
"expectError": true,
"jequal": true,
"create": true,
"arrayContains": true
},
"rules": {
"no-console": [0],
"indent": ["error", 2]
}
}
22 changes: 11 additions & 11 deletions spec/AccountLockoutPolicy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Config = require("../src/Config");
var loginWithWrongCredentialsShouldFail = function(username, password) {
return new Promise((resolve, reject) => {
Parse.User.logIn(username, password)
.then(user => reject('login should have failed'))
.then(() => reject('login should have failed'))
.catch(err => {
if (err.message === 'Invalid username/password.') {
resolve();
Expand All @@ -20,7 +20,7 @@ var isAccountLockoutError = function(username, password, duration, waitTime) {
return new Promise((resolve, reject) => {
setTimeout(() => {
Parse.User.logIn(username, password)
.then(user => reject('login should have failed'))
.then(() => reject('login should have failed'))
.catch(err => {
if (err.message === 'Your account is locked due to multiple failed login attempts. Please try again after ' + duration + ' minute(s)') {
resolve();
Expand All @@ -45,7 +45,7 @@ describe("Account Lockout Policy: ", () => {
user.setPassword('password');
return user.signUp(null);
})
.then(user => {
.then(() => {
return loginWithWrongCredentialsShouldFail('username1', 'incorrect password 1');
})
.then(() => {
Expand All @@ -71,7 +71,7 @@ describe("Account Lockout Policy: ", () => {
publicServerURL: "https://my.public.server.com/1"
})
.then(() => {
var config = new Config('test');
new Config('test');
fail('set duration to an invalid number test failed');
done();
})
Expand All @@ -95,7 +95,7 @@ describe("Account Lockout Policy: ", () => {
publicServerURL: "https://my.public.server.com/1"
})
.then(() => {
var config = new Config('test');
new Config('test');
fail('set threshold to an invalid number test failed');
done();
})
Expand All @@ -119,7 +119,7 @@ describe("Account Lockout Policy: ", () => {
publicServerURL: "https://my.public.server.com/1"
})
.then(() => {
var config = new Config('test');
new Config('test');
fail('threshold value < 1 is invalid test failed');
done();
})
Expand All @@ -143,7 +143,7 @@ describe("Account Lockout Policy: ", () => {
publicServerURL: "https://my.public.server.com/1"
})
.then(() => {
var config = new Config('test');
new Config('test');
fail('threshold value > 999 is invalid test failed');
done();
})
Expand All @@ -167,7 +167,7 @@ describe("Account Lockout Policy: ", () => {
publicServerURL: "https://my.public.server.com/1"
})
.then(() => {
var config = new Config('test');
new Config('test');
fail('duration value < 1 is invalid test failed');
done();
})
Expand All @@ -191,7 +191,7 @@ describe("Account Lockout Policy: ", () => {
publicServerURL: "https://my.public.server.com/1"
})
.then(() => {
var config = new Config('test');
new Config('test');
fail('duration value > 99999 is invalid test failed');
done();
})
Expand Down Expand Up @@ -230,7 +230,7 @@ describe("Account Lockout Policy: ", () => {
return isAccountLockoutError('username2', 'wrong password', 1, 1);
})
.then(() => {
done();
done();
})
.catch(err => {
fail('lock account after failed login attempts test failed: ' + JSON.stringify(err));
Expand Down Expand Up @@ -301,7 +301,7 @@ describe("Account Lockout Policy: ", () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
Parse.User.logIn('username4', 'correct password')
.then(user => resolve())
.then(() => resolve())
.catch(err => reject(err));
}, 3001);
});
Expand Down
22 changes: 11 additions & 11 deletions spec/AdaptableController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("AdaptableController", ()=>{
});

it("should fail setting the wrong adapter to the controller", (done) => {
function WrongAdapter() {};
function WrongAdapter() {}
var adapter = new FilesAdapter();
var controller = new FilesController(adapter);
var otherAdapter = new WrongAdapter();
Expand All @@ -42,7 +42,7 @@ describe("AdaptableController", ()=>{
});

it("should fail to instantiate a controller with wrong adapter", (done) => {
function WrongAdapter() {};
function WrongAdapter() {}
var adapter = new WrongAdapter();
expect(() => {
new FilesController(adapter);
Expand All @@ -59,10 +59,10 @@ describe("AdaptableController", ()=>{

it("should accept an object adapter", (done) => {
var adapter = {
createFile: function(config, filename, data) { },
deleteFile: function(config, filename) { },
getFileData: function(config, filename) { },
getFileLocation: function(config, filename) { },
createFile: function() { },
deleteFile: function() { },
getFileData: function() { },
getFileLocation: function() { },
}
expect(() => {
new FilesController(adapter);
Expand All @@ -71,11 +71,11 @@ describe("AdaptableController", ()=>{
});

it("should accept an object adapter", (done) => {
function AGoodAdapter() {};
AGoodAdapter.prototype.createFile = function(config, filename, data) { };
AGoodAdapter.prototype.deleteFile = function(config, filename) { };
AGoodAdapter.prototype.getFileData = function(config, filename) { };
AGoodAdapter.prototype.getFileLocation = function(config, filename) { };
function AGoodAdapter() {}
AGoodAdapter.prototype.createFile = function() { };
AGoodAdapter.prototype.deleteFile = function() { };
AGoodAdapter.prototype.getFileData = function() { };
AGoodAdapter.prototype.getFileLocation = function() { };

var adapter = new AGoodAdapter();
expect(() => {
Expand Down
12 changes: 6 additions & 6 deletions spec/Analytics.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const analyticsAdapter = {
appOpened: function(parameters, req) {},
trackEvent: function(eventName, parameters, req) {}
appOpened: function() {},
trackEvent: function() {}
}

describe('AnalyticsController', () => {
Expand All @@ -9,7 +9,7 @@ describe('AnalyticsController', () => {
spyOn(analyticsAdapter, 'trackEvent').and.callThrough();
reconfigureServer({
analyticsAdapter
}).then(() => {
}).then(() => {
return Parse.Analytics.track('MyEvent', {
key: 'value',
count: '0'
Expand All @@ -26,7 +26,7 @@ describe('AnalyticsController', () => {
}
});
done();
}, (err) => {
}, (err) => {
fail(JSON.stringify(err));
done();
})
Expand All @@ -37,7 +37,7 @@ describe('AnalyticsController', () => {
spyOn(analyticsAdapter, 'appOpened').and.callThrough();
reconfigureServer({
analyticsAdapter
}).then(() => {
}).then(() => {
return Parse.Analytics.track('AppOpened', {
key: 'value',
count: '0'
Expand All @@ -53,7 +53,7 @@ describe('AnalyticsController', () => {
}
});
done();
}, (err) => {
}, (err) => {
fail(JSON.stringify(err));
done();
})
Expand Down
7 changes: 3 additions & 4 deletions spec/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ describe('Auth', () => {
describe('getUserRoles', () => {
var auth;
var config;
var cacheController;
var currentRoles = null;
var currentUserId = 'userId';

Expand Down Expand Up @@ -51,8 +50,8 @@ describe('Auth', () => {
expect(roles).toEqual(currentRoles);
return auth.getUserRoles()
})
.then((roles) => auth.getUserRoles())
.then((roles) => auth.getUserRoles())
.then(() => auth.getUserRoles())
.then(() => auth.getUserRoles())
.then((roles) => {
// Should only call the cache adapter once.
expect(config.cacheController.role.get.calls.count()).toEqual(1);
Expand All @@ -79,7 +78,7 @@ describe('Auth', () => {
.then(() => done());
});

it('should properly handle bcrypt upgrade', (done) => {
it('should properly handle bcrypt upgrade', (done) => {
var bcryptOriginal = require('bcrypt-nodejs');
var bcryptNew = require('bcryptjs');
bcryptOriginal.hash('my1Long:password', null, null, function(err, res) {
Expand Down
10 changes: 5 additions & 5 deletions spec/CacheController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ describe('CacheController', function() {

it('should handle cache rejections', (done) => {

FakeCacheAdapter.get = () => Promise.reject();
FakeCacheAdapter.get = () => Promise.reject();

var cache = new CacheController(FakeCacheAdapter, FakeAppID);
var cache = new CacheController(FakeCacheAdapter, FakeAppID);

cache.get('foo').then(done, () => {
fail('Promise should not be rejected.');
});
cache.get('foo').then(done, () => {
fail('Promise should not be rejected.');
});
});

});
40 changes: 20 additions & 20 deletions spec/ClientSDK.spec.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
var ClientSDK = require('../src/ClientSDK');

describe('ClientSDK', () => {
it('should properly parse the SDK versions', () => {
let clientSDKFromVersion = ClientSDK.fromString;
expect(clientSDKFromVersion('i1.1.1')).toEqual({
sdk: 'i',
version: '1.1.1'
});
expect(clientSDKFromVersion('i1')).toEqual({
sdk: 'i',
version: '1'
});
expect(clientSDKFromVersion('apple-tv1.13.0')).toEqual({
sdk: 'apple-tv',
version: '1.13.0'
});
expect(clientSDKFromVersion('js1.9.0')).toEqual({
sdk: 'js',
version: '1.9.0'
});
describe('ClientSDK', () => {
it('should properly parse the SDK versions', () => {
let clientSDKFromVersion = ClientSDK.fromString;
expect(clientSDKFromVersion('i1.1.1')).toEqual({
sdk: 'i',
version: '1.1.1'
});
expect(clientSDKFromVersion('i1')).toEqual({
sdk: 'i',
version: '1'
});
expect(clientSDKFromVersion('apple-tv1.13.0')).toEqual({
sdk: 'apple-tv',
version: '1.13.0'
});
expect(clientSDKFromVersion('js1.9.0')).toEqual({
sdk: 'js',
version: '1.9.0'
});
});

it('should properly sastisfy', () => {
it('should properly sastisfy', () => {
expect(ClientSDK.compatible({
js: '>=1.9.0'
})("js1.9.0")).toBe(true);
Expand Down
Loading

0 comments on commit bad820e

Please sign in to comment.