Skip to content

Commit 26e2350

Browse files
RTLcoilstrausr
authored andcommitted
Fixed open linting issues (#279)
* Added missing dangling commas * General Formatting fixes * import ordering fixes * newline-after-import fixes * Consistent returns from functions * Removed bitwise operators from samples * No unused variables * Disallow variable declarations from shadowing variables declared in the outer scope
1 parent 0f5fb3a commit 26e2350

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

babel.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ const presets = [
33
[
44
"env",
55
{
6-
targets: { node: "4" }
7-
}
6+
targets: { node: "4" },
7+
},
88
],
9-
"stage-0"
9+
"stage-0",
1010
],
1111
];
1212
const plugins = ["transform-object-rest-spread"];

samples/basic/basic.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
var dotenv = require('dotenv');
2-
dotenv.load();
3-
1+
require('dotenv').load();
42
var fs = require('fs');
53
var cloudinary = require('cloudinary').v2;
64

7-
85
var uploads = {};
96

107
// set your env variable CLOUDINARY_URL or set the following configuration
@@ -38,7 +35,7 @@ var upload_stream = cloudinary.uploader.upload_stream({ tags: 'basic_sample' },
3835
console.log("* " + image.url);
3936
waitForAllUploads("pizza3", err, image);
4037
});
41-
var file_reader = fs.createReadStream('pizza.jpg').pipe(upload_stream);
38+
fs.createReadStream('pizza.jpg').pipe(upload_stream);
4239

4340

4441
// File upload (example for promise api)
@@ -72,7 +69,7 @@ cloudinary.uploader.upload('pizza.jpg', { tags: 'basic_sample', public_id: 'my_f
7269
// Eager Transformations:
7370
// Applied as soon as the file is uploaded, instead of lazily applying them when accessed by your site's visitors.
7471
var eager_options = {
75-
width: 200, height: 150, crop: 'scale', format: 'jpg'
72+
width: 200, height: 150, crop: 'scale', format: 'jpg',
7673
};
7774
cloudinary.uploader.upload("lake.jpg", { tags: "basic_sample", public_id: "blue_lake", eager: eager_options }, function (err, image) {
7875
// "eager" parameter accepts a hash (or just a single item). You can pass
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
var Schema = require('jugglingdb').Schema;
2+
23
var schema = new Schema('memory');
34
// Uncomment if you want to use mongodb adapter
45
// var schema = new Schema('mongodb');
56

67
// Define models
7-
var Photo = schema.define('Photo', {
8+
schema.define('Photo', {
89
title: { type: String, length: 255 },
9-
image: { type: JSON }
10+
image: { type: JSON },
1011
});
1112

1213
module.exports = schema;

samples/photo_album/controllers/photos_controller.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
var cloudinary = require('cloudinary').v2;
2-
var schema = require('../config/schema');
32
var crypto = require('crypto');
4-
var Photo = schema.models.Photo;
53
var multipart = require('connect-multiparty');
4+
var schema = require('../config/schema');
5+
6+
var Photo = schema.models.Photo;
7+
68
var multipartMiddleware = multipart();
79

810
function index(req, res) {
@@ -19,7 +21,7 @@ function add_through_server(req, res) {
1921
})
2022
.finally(function () {
2123
res.render('photos/add', {
22-
photo: photo
24+
photo: photo,
2325
});
2426
});
2527
}
@@ -48,7 +50,7 @@ function create_through_server(req, res) {
4850
// Save photo with image metadata
4951
return photo.save();
5052
})
51-
.then(function (photo) {
53+
.then(function () {
5254
console.log('** photo saved');
5355
})
5456
.finally(function () {
@@ -67,7 +69,7 @@ function add_direct(req, res) {
6769
.finally(function () {
6870
res.render('photos/add_direct', {
6971
photo: photo,
70-
cloudinary_cors: cloudinary_cors
72+
cloudinary_cors: cloudinary_cors,
7173
});
7274
});
7375
}
@@ -95,6 +97,7 @@ function add_direct_unsigned(req, res) {
9597
if (!preset.settings.return_delete_token) {
9698
return cloudinary.api.update_upload_preset(preset_name, { return_delete_token: true });
9799
}
100+
return undefined;
98101
})
99102
.catch(function (err) {
100103
// Creating an upload preset is done here only for demo purposes.
@@ -104,15 +107,15 @@ function add_direct_unsigned(req, res) {
104107
unsigned: true,
105108
name: preset_name,
106109
folder: "preset_folder",
107-
return_delete_token: true
110+
return_delete_token: true,
108111
});
109112
})
110113
.finally(function (preset) {
111114
res.render('photos/add_direct_unsigned',
112115
{
113116
photo: photo,
114117
cloudinary_cors: cloudinary_cors,
115-
preset_name: preset_name
118+
preset_name: preset_name,
116119
});
117120
});
118121
}
@@ -138,7 +141,7 @@ function create_direct(req, res) {
138141
photo.image = image.toJSON();
139142
console.dir(photo.image);
140143
}
141-
photo.save().then(function (photo) {
144+
photo.save().then(function () {
142145
console.log('** photo saved');
143146
})
144147
.catch(function (err) {

samples/photo_album/server.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Load environment variables
2-
var dotenv = require('dotenv');
3-
dotenv.load();
2+
require('dotenv').load();
3+
44
var cloudinary = require('cloudinary').v2;
5+
56
if (typeof (process.env.CLOUDINARY_URL) === 'undefined') {
67
console.warn('!! cloudinary config is undefined !!');
78
console.warn('export CLOUDINARY_URL or set dotenv file');
@@ -11,19 +12,17 @@ if (typeof (process.env.CLOUDINARY_URL) === 'undefined') {
1112
}
1213
console.log('-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --');
1314
var path = require('path');
14-
// Start express server
15-
var schema = require('./config/schema');
1615
var express = require('express');
1716
var engine = require('ejs-locals');
18-
var app = express();
1917
var bodyParser = require('body-parser');
2018
var methodOverride = require('method-override');
19+
require('./config/schema');
20+
21+
// Start express server
22+
var app = express();
2123
app.use(bodyParser.json());
2224
app.use(bodyParser.urlencoded({ extended: false }));
23-
2425
app.use(methodOverride());
25-
26-
2726
app.use(express.static(path.join(__dirname, '/public')));
2827
app.set('views', path.join(__dirname, '/views/'));
2928
app.use('/node_modules', express.static(path.join(__dirname, '/node_modules')));
@@ -34,13 +33,14 @@ app.set('view engine', 'ejs');
3433
wirePreRequest(app);
3534
// Wire request controllers
3635
var photosController = require('./controllers/photos_controller');
36+
3737
photosController.wire(app);
3838

3939
// Wire request 'post' actions
4040
wirePostRequest(app);
4141

42-
function wirePreRequest(app) {
43-
app.use(function (req, res, next) {
42+
function wirePreRequest(application) {
43+
application.use(function (req, res, next) {
4444
console.log(req.method + " " + req.url);
4545
res.locals.req = req;
4646
res.locals.res = res;
@@ -55,18 +55,19 @@ function wirePreRequest(app) {
5555
});
5656
}
5757

58-
function wirePostRequest(app) {
59-
app.use(function (err, req, res, next) {
60-
if (err.message && (~err.message.indexOf('not found') || (~err.message.indexOf('Cast to ObjectId failed')))) {
58+
function wirePostRequest(application) {
59+
application.use(function (err, req, res, next) {
60+
if (err.message && (err.message.indexOf('not found') !== -1 || err.message.indexOf('Cast to ObjectId failed') !== -1)) {
6161
return next();
6262
}
6363
console.log('error (500) ' + err.message);
6464
console.log(err.stack);
65-
if (~err.message.indexOf('CLOUDINARY_URL')) {
65+
if (err.message.indexOf('CLOUDINARY_URL') !== -1) {
6666
res.status(500).render('errors/dotenv', { error: err });
6767
} else {
6868
res.status(500).render('errors/500', { error: err });
6969
}
70+
return undefined;
7071
});
7172
}
7273

@@ -75,7 +76,7 @@ app.use(function (req, res, next) {
7576
console.log('error (404)');
7677
res.status(404).render('errors/404', {
7778
url: req.url,
78-
error: 'Not found'
79+
error: 'Not found',
7980
});
8081
});
8182

0 commit comments

Comments
 (0)