Use eslint and be compliant. (mostly)

This commit is contained in:
Alexis Lahouze 2016-10-12 19:57:19 +02:00
parent d7ead2aa5c
commit 606cde59f8
8 changed files with 320 additions and 291 deletions

20
.eslintrc.json Normal file
View File

@ -0,0 +1,20 @@
{
"extends": "google",
"installedESLint": true,
"rules": {
"indent": ["error", 4]
},
"plugins": [
"angular",
"html",
"jquery",
"security",
"this"
],
"globals": {
"angular": false,
"moment": false,
"Highcharts": false,
"$": false
}
}

View File

@ -38,8 +38,7 @@ module.exports = function(grunt) {
grunt.registerTask('jsdev', [ grunt.registerTask('jsdev', [
'wiredep', 'wiredep',
'newer:jshint', 'newer:eslint'
'newer:jscs'
]); ]);
grunt.registerTask('htmldev', [ grunt.registerTask('htmldev', [

View File

@ -56,29 +56,25 @@ angular.module('accountant.accounts', [
return Account; return Account;
}]) }])
.controller( .controller('AccountController', [
'AccountController', [
'$scope', '$ngBootbox', 'Account', 'Notification', '$scope', '$ngBootbox', 'Account', 'Notification',
function($scope, $ngBootbox, Account, Notification) { function($scope, $ngBootbox, Account, Notification) {
/* /*
* Return the class for an account current value compared to authorized * Return the class for an account current value compared to authorized
* overdraft. * overdraft.
*/ */
$scope.rowClass = function(account) { $scope.rowClass = function(account) {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
if (!account || !account.authorized_overdraft || !account.current) { if (!account || !account.authorized_overdraft || !account.current) {
return; return;
} }
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
if (account.current < account.authorized_overdraft) { if (account.current < account.authorized_overdraft) {
return 'danger'; return 'danger';
} else if (account.current < 0) { } else if (account.current < 0) {
return 'warning'; return 'warning';
} }
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}; };
/* /*
@ -89,13 +85,12 @@ angular.module('accountant.accounts', [
return; return;
} }
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
if (value < account.authorized_overdraft) { if (value < account.authorized_overdraft) {
return 'text-danger'; return 'text-danger';
} else if (value < 0) { } else if (value < 0) {
return 'text-warning'; return 'text-warning';
} }
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}; };
/* /*
@ -103,9 +98,8 @@ angular.module('accountant.accounts', [
*/ */
$scope.add = function() { $scope.add = function() {
var account = new Account({ var account = new Account({
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
authorized_overdraft: 0 authorized_overdraft: 0
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}); });
// Insert account at the begining of the array. // Insert account at the begining of the array.
@ -128,9 +122,9 @@ angular.module('accountant.accounts', [
* Save account. * Save account.
*/ */
$scope.save = function(account) { $scope.save = function(account) {
//var account = $scope.accounts[$index]; // var account = $scope.accounts[$index];
//account = angular.merge(account, $data); // account = angular.merge(account, $data);
return account.$save().then(function(data) { return account.$save().then(function(data) {
Notification.success('Account #' + data.id + ' saved.'); Notification.success('Account #' + data.id + ' saved.');
@ -164,11 +158,10 @@ angular.module('accountant.accounts', [
// Load accounts. // Load accounts.
$scope.accounts = Account.query(); $scope.accounts = Account.query();
}]
)
}]) .directive('accountFormDialog', function(Account, $ngBootbox, Notification) {
.directive(
'accountFormDialog', function(Account, $ngBootbox, Notification) {
return { return {
restrict: 'A', restrict: 'A',
scope: { scope: {
@ -190,9 +183,8 @@ angular.module('accountant.accounts', [
} }
// Authorized overdraft is a positive integer but data is a negative integer. // Authorized overdraft is a positive integer but data is a negative integer.
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
scope.data.authorized_overdraft = -scope.data.authorized_overdraft; scope.data.authorized_overdraft = -scope.data.authorized_overdraft;
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
angular.copy(scope.data, scope.account); angular.copy(scope.data, scope.account);
@ -205,7 +197,8 @@ angular.module('accountant.accounts', [
scope.account.getSolds(); scope.account.getSolds();
return data; return data;
}, function(data) { },
function(data) {
Notification.error('Error while saving account #' + data.id); Notification.error('Error while saving account #' + data.id);
scope.account.getSolds(); scope.account.getSolds();
console.log(data); console.log(data);
@ -218,9 +211,8 @@ angular.module('accountant.accounts', [
// Create new account if not passed in ng-model. // Create new account if not passed in ng-model.
if (!scope.account) { if (!scope.account) {
scope.account = new Account({ scope.account = new Account({
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
authorized_overdraft: 0 authorized_overdraft: 0
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}); });
} }
@ -228,9 +220,8 @@ angular.module('accountant.accounts', [
angular.copy(scope.account, scope.data); angular.copy(scope.account, scope.data);
// Authorized overdraft must be positive in form. // Authorized overdraft must be positive in form.
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
scope.data.authorized_overdraft = -scope.data.authorized_overdraft; scope.data.authorized_overdraft = -scope.data.authorized_overdraft;
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
// Open dialog with form. // Open dialog with form.
$ngBootbox.customDialog({ $ngBootbox.customDialog({
@ -254,5 +245,4 @@ angular.module('accountant.accounts', [
}); });
} }
}; };
} });
);

View File

@ -121,8 +121,8 @@ angular.module('accountant', [
$http.post( $http.post(
'/api/user/login', '/api/user/login',
{ {
'email': email, email: email,
'password': password password: password
} }
).success(function(result) { ).success(function(result) {
// TODO Alexis Lahouze 2015-08-28 Handle callback. // TODO Alexis Lahouze 2015-08-28 Handle callback.
@ -152,6 +152,7 @@ angular.module('accountant', [
}; };
$rootScope.$on('event:auth-loginRequired', $scope.showLoginForm); $rootScope.$on('event:auth-loginRequired', $scope.showLoginForm);
}]) }
])
; ;

View File

@ -40,38 +40,38 @@ angular.module('accountant.operations', [
); );
}]) }])
.factory('OHLC', ['$resource', '$routeParams', .factory('OHLC', [
function($resource, $routeParams) { '$resource', '$routeParams', function($resource, $routeParams) {
return $resource( return $resource(
'/api/account/:account_id/ohlc', { '/api/account/:account_id/ohlc', {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
} }
); );
}]) }
])
.factory('Category', ['$resource', '$routeParams', .factory('Category', [
function($resource, $routeParams) { '$resource', '$routeParams', function($resource, $routeParams) {
return $resource( return $resource(
'/api/account/:account_id/category', { '/api/account/:account_id/category', {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
} }
); );
}]) }
])
.factory('Balance', ['$resource', '$routeParams', .factory('Balance', [
function($resource, $routeParams) { '$resource', '$routeParams', function($resource, $routeParams) {
return $resource( return $resource(
'/api/account/:account_id/balance', { '/api/account/:account_id/balance', {
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
} }
); );
}]) }
])
/* /*
* Controller for category chart. * Controller for category chart.
@ -131,8 +131,8 @@ angular.module('accountant.operations', [
size: '60%', size: '60%',
dataLabels: { dataLabels: {
formatter: function() { formatter: function() {
return this.point.name !== null && this.percentage >= 2.5 ? this.point.name : null; return this.point.name !== null && this.percentage >=
} 2.5 ? this.point.name : null; }
} }
}] }]
}; };
@ -140,6 +140,7 @@ angular.module('accountant.operations', [
$scope.brightenColor = function(color) { $scope.brightenColor = function(color) {
var brightness = 0.2; var brightness = 0.2;
// eslint-disable-next-line new-cap
return Highcharts.Color(color).brighten(brightness).get(); return Highcharts.Color(color).brighten(brightness).get();
}; };
@ -367,9 +368,8 @@ angular.module('accountant.operations', [
*/ */
$scope.add = function() { $scope.add = function() {
var operation = new Operation({ var operation = new Operation({
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}); });
$scope.operations.splice(0, 0, operation); $scope.operations.splice(0, 0, operation);
@ -380,9 +380,8 @@ angular.module('accountant.operations', [
*/ */
$scope.load = function(begin, end) { $scope.load = function(begin, end) {
$scope.operations = Operation.query({ $scope.operations = Operation.query({
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId, account_id: $routeParams.accountId,
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
begin: begin.format('YYYY-MM-DD'), begin: begin.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD') end: end.format('YYYY-MM-DD')
}); });

View File

@ -49,9 +49,8 @@ angular.module('accountant.scheduler', [
*/ */
$scope.add = function() { $scope.add = function() {
var operation = new ScheduledOperation({ var operation = new ScheduledOperation({
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}); });
// Insert new operation at the beginning of the array. // Insert new operation at the beginning of the array.
@ -63,9 +62,8 @@ angular.module('accountant.scheduler', [
*/ */
$scope.load = function() { $scope.load = function() {
$scope.operations = ScheduledOperation.query({ $scope.operations = ScheduledOperation.query({
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers // eslint-disable-next-line camelcase
account_id: $routeParams.accountId account_id: $routeParams.accountId
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
}); });
}; };

13
grunt-config/eslint.js Normal file
View File

@ -0,0 +1,13 @@
'use strict';
module.exports = {
frontend: [
'<%= accountant.frontend.src %>/index.html',
'<%= accountant.frontend.src %>/views/*.html',
'<%= accountant.frontend.src %>/js/*.js'
],
toolchain: [
'Gruntfile.js',
'grunt-config/*.js'
]
};

View File

@ -6,6 +6,14 @@
"devDependencies": { "devDependencies": {
"connect-logger": "0.0.1", "connect-logger": "0.0.1",
"connect-proxy-layer": "^0.1.2", "connect-proxy-layer": "^0.1.2",
"eslint": "^3.7.1",
"eslint-config-google": "~0.6",
"eslint-plugin-angular": "^1.4.1",
"eslint-plugin-html": "^1.5.3",
"eslint-plugin-jquery": "^1.0.1",
"eslint-plugin-promise": "^3.0.0",
"eslint-plugin-security": "^1.2.0",
"eslint-plugin-this": "^0.1.4",
"grunt": "~1.0", "grunt": "~1.0",
"grunt-bg-shell": "^2.3.1", "grunt-bg-shell": "^2.3.1",
"grunt-contrib-clean": "~1.0", "grunt-contrib-clean": "~1.0",
@ -16,6 +24,7 @@
"grunt-contrib-uglify": "~1.0", "grunt-contrib-uglify": "~1.0",
"grunt-contrib-watch": "~1.0", "grunt-contrib-watch": "~1.0",
"grunt-copy": "^0.1.0", "grunt-copy": "^0.1.0",
"grunt-eslint": "~19.0",
"grunt-filerev": "^2.3.1", "grunt-filerev": "^2.3.1",
"grunt-flake8": "^0.1.3", "grunt-flake8": "^0.1.3",
"grunt-htmllint": "^0.2.7", "grunt-htmllint": "^0.2.7",