tweaks eslint rules, fixes gulp-eslint, adds some comments

This commit is contained in:
Matteo Pagliazzi
2015-11-04 18:50:08 +01:00
parent 235f1977ba
commit 3135613be3
7 changed files with 19 additions and 15 deletions

View File

@@ -68,12 +68,12 @@
"no-this-before-super": 2, "no-this-before-super": 2,
"no-var": 2, "no-var": 2,
"object-shorthand": 2, "object-shorthand": 2,
"prefer-const": 2, "prefer-const": 0,
"prefer-spread": 2, "prefer-spread": 2,
"prefer-template": 2, "prefer-template": 2,
"array-bracket-spacing": [2, "never"], "array-bracket-spacing": [2, "never"],
"brace-style": [2, "1tbs", { "allowSingleLine": false }], "brace-style": [2, "1tbs", { "allowSingleLine": false }],
"camel-case": 2, "camelcase": 2,
"comma-spacing": 2, "comma-spacing": 2,
"comma-style": [2, "last"], "comma-style": [2, "last"],
"computed-property-spacing": [2, "never"], "computed-property-spacing": [2, "never"],
@@ -98,7 +98,7 @@
"operator-linebreak": [2, "after"], "operator-linebreak": [2, "after"],
"quote-props": [2, "as-needed", { "keywords": true }], "quote-props": [2, "as-needed", { "keywords": true }],
"semi-spacing": [2, {"before": false, "after": true}], "semi-spacing": [2, {"before": false, "after": true}],
"space-after-keyword": 2, "space-after-keywords": 2,
"space-before-blocks": 2, "space-before-blocks": 2,
"space-before-function-paren": 2, "space-before-function-paren": 2,
"space-before-keywords": 2, "space-before-keywords": 2,
@@ -109,7 +109,7 @@
"spaced-comment": [2, "always", { exceptions: ["-"]}], "spaced-comment": [2, "always", { exceptions: ["-"]}],
"padded-blocks": [2, "never"], "padded-blocks": [2, "never"],
"no-multiple-empty-lines": [2, {max: 2}], "no-multiple-empty-lines": [2, {max: 2}],
"lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true }] "lines-around-comment": [2, { "beforeBlockComment": true, "beforeLineComment": true, "allowBlockStart": true }]
}, },
"env": { "env": {
"es6": true, "es6": true,

View File

@@ -21,6 +21,7 @@
"cookie-session": "^1.2.0", "cookie-session": "^1.2.0",
"coupon-code": "~0.3.0", "coupon-code": "~0.3.0",
"domain-middleware": "~0.1.0", "domain-middleware": "~0.1.0",
"estraverse": "^4.1.1",
"express": "~4.13.3", "express": "~4.13.3",
"express-csv": "~0.6.0", "express-csv": "~0.6.0",
"firebase": "^2.2.9", "firebase": "^2.2.9",

View File

@@ -3,6 +3,9 @@ import eslint from 'gulp-eslint';
// TODO lint client // TODO lint client
// TDOO separate linting cong between // TDOO separate linting cong between
// TODO lint gulp tasks, tests, ...?
// TODO what about prefer-const rule?
// TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out
gulp.task('lint:server', () => { gulp.task('lint:server', () => {
// Ignore .coffee files // Ignore .coffee files
return gulp return gulp

View File

@@ -3,7 +3,7 @@
// Base class for custom application errors // Base class for custom application errors
// It extends Error and capture the stack trace // It extends Error and capture the stack trace
class CustomError extends Error { class CustomError extends Error {
constructor() { constructor () {
super(); super();
Error.captureStackTrace(this, this.constructor); Error.captureStackTrace(this, this.constructor);
} }
@@ -12,7 +12,7 @@ class CustomError extends Error {
// NotAuthorized error with a 401 http error code // NotAuthorized error with a 401 http error code
// used when a request is not authorized // used when a request is not authorized
class NotAuthorized extends CustomError { class NotAuthorized extends CustomError {
constructor(customMessage) { constructor (customMessage) {
super(); super();
this.name = this.constructor.name; this.name = this.constructor.name;
this.httpCode = 401; this.httpCode = 401;
@@ -24,7 +24,7 @@ class NotAuthorized extends CustomError {
// used for requests not formatted correctly // used for requests not formatted correctly
// TODO use for validation errors too? // TODO use for validation errors too?
class BadRequest extends CustomError { class BadRequest extends CustomError {
constructor(customMessage) { constructor (customMessage) {
super(); super();
this.name = this.constructor.name; this.name = this.constructor.name;
this.httpCode = 400; this.httpCode = 400;
@@ -35,7 +35,7 @@ class BadRequest extends CustomError {
// InternalError error with a 500 http error code // InternalError error with a 500 http error code
// used when an unexpected, internal server error is thrown // used when an unexpected, internal server error is thrown
class InternalServerError extends CustomError { class InternalServerError extends CustomError {
constructor(customMessage) { constructor (customMessage) {
super(); super();
this.name = this.constructor.name; this.name = this.constructor.name;
this.httpCode = 500; this.httpCode = 500;

View File

@@ -7,9 +7,10 @@ let errors = require('../../libs/api-v3/errors');
let CustomError = errors.CustomError; let CustomError = errors.CustomError;
let InternalServerError = errors.InternalServerError; let InternalServerError = errors.InternalServerError;
module.exports = function (err, req, res, next) { module.exports = function errorHandlerMiddleware (err, req, res, next) {
// Log the original error with some metadata // Log the original error with some metadata
let stack = err.stack || err.message || err; let stack = err.stack || err.message || err;
logger.error(stack, { logger.error(stack, {
originalUrl: req.originalUrl, originalUrl: req.originalUrl,
headers: req.headers, headers: req.headers,

View File

@@ -4,8 +4,7 @@
let errorHandler = require('./errorHandler'); let errorHandler = require('./errorHandler');
module.exports = function (app) { module.exports = function attachMiddlewares (app) {
// Error handler middleware, define as the last one // Error handler middleware, define as the last one
app.use(errorHandler); app.use(errorHandler);
}; };