Use eslint and be compliant. (mostly)
This commit is contained in:
parent
d7ead2aa5c
commit
606cde59f8
20
.eslintrc.json
Normal file
20
.eslintrc.json
Normal 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
|
||||
}
|
||||
}
|
@ -38,8 +38,7 @@ module.exports = function(grunt) {
|
||||
|
||||
grunt.registerTask('jsdev', [
|
||||
'wiredep',
|
||||
'newer:jshint',
|
||||
'newer:jscs'
|
||||
'newer:eslint'
|
||||
]);
|
||||
|
||||
grunt.registerTask('htmldev', [
|
||||
|
@ -56,29 +56,25 @@ angular.module('accountant.accounts', [
|
||||
return Account;
|
||||
}])
|
||||
|
||||
.controller(
|
||||
'AccountController', [
|
||||
.controller('AccountController', [
|
||||
'$scope', '$ngBootbox', 'Account', 'Notification',
|
||||
function($scope, $ngBootbox, Account, Notification) {
|
||||
|
||||
/*
|
||||
* Return the class for an account current value compared to authorized
|
||||
* overdraft.
|
||||
*/
|
||||
$scope.rowClass = function(account) {
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
if (!account || !account.authorized_overdraft || !account.current) {
|
||||
return;
|
||||
}
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
if (account.current < account.authorized_overdraft) {
|
||||
return 'danger';
|
||||
} else if (account.current < 0) {
|
||||
return 'warning';
|
||||
}
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
};
|
||||
|
||||
/*
|
||||
@ -89,13 +85,12 @@ angular.module('accountant.accounts', [
|
||||
return;
|
||||
}
|
||||
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
if (value < account.authorized_overdraft) {
|
||||
return 'text-danger';
|
||||
} else if (value < 0) {
|
||||
return 'text-warning';
|
||||
}
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
};
|
||||
|
||||
/*
|
||||
@ -103,9 +98,8 @@ angular.module('accountant.accounts', [
|
||||
*/
|
||||
$scope.add = function() {
|
||||
var account = new Account({
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
authorized_overdraft: 0
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
});
|
||||
|
||||
// Insert account at the begining of the array.
|
||||
@ -128,9 +122,9 @@ angular.module('accountant.accounts', [
|
||||
* Save 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) {
|
||||
Notification.success('Account #' + data.id + ' saved.');
|
||||
@ -164,11 +158,10 @@ angular.module('accountant.accounts', [
|
||||
|
||||
// Load accounts.
|
||||
$scope.accounts = Account.query();
|
||||
}]
|
||||
)
|
||||
|
||||
}])
|
||||
|
||||
.directive(
|
||||
'accountFormDialog', function(Account, $ngBootbox, Notification) {
|
||||
.directive('accountFormDialog', function(Account, $ngBootbox, Notification) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
@ -190,9 +183,8 @@ angular.module('accountant.accounts', [
|
||||
}
|
||||
|
||||
// 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;
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
angular.copy(scope.data, scope.account);
|
||||
|
||||
@ -205,7 +197,8 @@ angular.module('accountant.accounts', [
|
||||
scope.account.getSolds();
|
||||
|
||||
return data;
|
||||
}, function(data) {
|
||||
},
|
||||
function(data) {
|
||||
Notification.error('Error while saving account #' + data.id);
|
||||
scope.account.getSolds();
|
||||
console.log(data);
|
||||
@ -218,9 +211,8 @@ angular.module('accountant.accounts', [
|
||||
// Create new account if not passed in ng-model.
|
||||
if (!scope.account) {
|
||||
scope.account = new Account({
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
authorized_overdraft: 0
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
});
|
||||
}
|
||||
|
||||
@ -228,9 +220,8 @@ angular.module('accountant.accounts', [
|
||||
angular.copy(scope.account, scope.data);
|
||||
|
||||
// Authorized overdraft must be positive in form.
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
scope.data.authorized_overdraft = -scope.data.authorized_overdraft;
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
// Open dialog with form.
|
||||
$ngBootbox.customDialog({
|
||||
@ -254,5 +245,4 @@ angular.module('accountant.accounts', [
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -121,8 +121,8 @@ angular.module('accountant', [
|
||||
$http.post(
|
||||
'/api/user/login',
|
||||
{
|
||||
'email': email,
|
||||
'password': password
|
||||
email: email,
|
||||
password: password
|
||||
}
|
||||
).success(function(result) {
|
||||
// TODO Alexis Lahouze 2015-08-28 Handle callback.
|
||||
@ -152,6 +152,7 @@ angular.module('accountant', [
|
||||
};
|
||||
|
||||
$rootScope.$on('event:auth-loginRequired', $scope.showLoginForm);
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
;
|
||||
|
@ -40,38 +40,38 @@ angular.module('accountant.operations', [
|
||||
);
|
||||
}])
|
||||
|
||||
.factory('OHLC', ['$resource', '$routeParams',
|
||||
function($resource, $routeParams) {
|
||||
.factory('OHLC', [
|
||||
'$resource', '$routeParams', function($resource, $routeParams) {
|
||||
return $resource(
|
||||
'/api/account/:account_id/ohlc', {
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
}
|
||||
);
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
.factory('Category', ['$resource', '$routeParams',
|
||||
function($resource, $routeParams) {
|
||||
.factory('Category', [
|
||||
'$resource', '$routeParams', function($resource, $routeParams) {
|
||||
return $resource(
|
||||
'/api/account/:account_id/category', {
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
}
|
||||
);
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
.factory('Balance', ['$resource', '$routeParams',
|
||||
function($resource, $routeParams) {
|
||||
.factory('Balance', [
|
||||
'$resource', '$routeParams', function($resource, $routeParams) {
|
||||
return $resource(
|
||||
'/api/account/:account_id/balance', {
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
}
|
||||
);
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
/*
|
||||
* Controller for category chart.
|
||||
@ -131,8 +131,8 @@ angular.module('accountant.operations', [
|
||||
size: '60%',
|
||||
dataLabels: {
|
||||
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) {
|
||||
var brightness = 0.2;
|
||||
|
||||
// eslint-disable-next-line new-cap
|
||||
return Highcharts.Color(color).brighten(brightness).get();
|
||||
};
|
||||
|
||||
@ -367,9 +368,8 @@ angular.module('accountant.operations', [
|
||||
*/
|
||||
$scope.add = function() {
|
||||
var operation = new Operation({
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
});
|
||||
|
||||
$scope.operations.splice(0, 0, operation);
|
||||
@ -380,9 +380,8 @@ angular.module('accountant.operations', [
|
||||
*/
|
||||
$scope.load = function(begin, end) {
|
||||
$scope.operations = Operation.query({
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId,
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
begin: begin.format('YYYY-MM-DD'),
|
||||
end: end.format('YYYY-MM-DD')
|
||||
});
|
||||
|
@ -49,9 +49,8 @@ angular.module('accountant.scheduler', [
|
||||
*/
|
||||
$scope.add = function() {
|
||||
var operation = new ScheduledOperation({
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
});
|
||||
|
||||
// Insert new operation at the beginning of the array.
|
||||
@ -63,9 +62,8 @@ angular.module('accountant.scheduler', [
|
||||
*/
|
||||
$scope.load = function() {
|
||||
$scope.operations = ScheduledOperation.query({
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
// eslint-disable-next-line camelcase
|
||||
account_id: $routeParams.accountId
|
||||
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
||||
});
|
||||
};
|
||||
|
||||
|
13
grunt-config/eslint.js
Normal file
13
grunt-config/eslint.js
Normal 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'
|
||||
]
|
||||
};
|
@ -6,6 +6,14 @@
|
||||
"devDependencies": {
|
||||
"connect-logger": "0.0.1",
|
||||
"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-bg-shell": "^2.3.1",
|
||||
"grunt-contrib-clean": "~1.0",
|
||||
@ -16,6 +24,7 @@
|
||||
"grunt-contrib-uglify": "~1.0",
|
||||
"grunt-contrib-watch": "~1.0",
|
||||
"grunt-copy": "^0.1.0",
|
||||
"grunt-eslint": "~19.0",
|
||||
"grunt-filerev": "^2.3.1",
|
||||
"grunt-flake8": "^0.1.3",
|
||||
"grunt-htmllint": "^0.2.7",
|
||||
|
Loading…
Reference in New Issue
Block a user