Skip to content
Permalink
Browse files

Use eslint and prettier (#239)

  • Loading branch information...
fhinkel committed Nov 9, 2018
1 parent 092728c commit b939a8763cbbf573774ece272aa0bbbaed023e2c
Showing with 1,966 additions and 1,894 deletions.
  1. +2 −0 .eslintignore
  2. +19 −0 .eslintrc.yml
  3. +3 −0 .prettierignore
  4. +8 −0 .prettierrc
  5. +0 −28 1-hello-world/package.json
  6. +1 −1 2-structured-data/app.js
  7. +4 −4 2-structured-data/books/api.js
  8. +7 −7 2-structured-data/books/crud.js
  9. +38 −26 2-structured-data/books/model-cloudsql.js
  10. +23 −22 2-structured-data/books/model-datastore.js
  11. +8 −6 2-structured-data/config.js
  12. +0 −28 2-structured-data/package.json
  13. +8 −8 2-structured-data/test/_api-tests.js
  14. +27 −28 2-structured-data/test/_crud-tests.js
  15. +2 −2 2-structured-data/test/_test-config.js
  16. +9 −8 2-structured-data/test/app.test.js
  17. +5 −2 2-structured-data/test/cloudsql.test.js
  18. +5 −2 2-structured-data/test/datastore.test.js
  19. +1 −1 3-binary-data/app.js
  20. +4 −4 3-binary-data/books/api.js
  21. +7 −7 3-binary-data/books/crud.js
  22. +38 −26 3-binary-data/books/model-cloudsql.js
  23. +23 −22 3-binary-data/books/model-datastore.js
  24. +8 −6 3-binary-data/config.js
  25. +9 −9 3-binary-data/lib/images.js
  26. +0 −28 3-binary-data/package.json
  27. +8 −8 3-binary-data/test/_api-tests.js
  28. +27 −28 3-binary-data/test/_crud-tests.js
  29. +2 −2 3-binary-data/test/_test-config.js
  30. +9 −8 3-binary-data/test/app.test.js
  31. +5 −2 3-binary-data/test/cloudsql.test.js
  32. +5 −2 3-binary-data/test/datastore.test.js
  33. +6 −5 4-auth/app.js
  34. +4 −4 4-auth/books/api.js
  35. +8 −8 4-auth/books/crud.js
  36. +41 −28 4-auth/books/model-cloudsql.js
  37. +29 −24 4-auth/books/model-datastore.js
  38. +8 −6 4-auth/config.js
  39. +9 −9 4-auth/lib/images.js
  40. +27 −18 4-auth/lib/oauth2.js
  41. +2 −29 4-auth/package.json
  42. +8 −8 4-auth/test/_api-tests.js
  43. +26 −26 4-auth/test/_crud-tests.js
  44. +2 −2 4-auth/test/_test-config.js
  45. +9 −8 4-auth/test/app.test.js
  46. +5 −2 4-auth/test/cloudsql.test.js
  47. +5 −2 4-auth/test/datastore.test.js
  48. +39 −40 4-auth/test/oauth2.test.js
  49. +6 −5 5-logging/app.js
  50. +4 −4 5-logging/books/api.js
  51. +8 −8 5-logging/books/crud.js
  52. +41 −28 5-logging/books/model-cloudsql.js
  53. +29 −24 5-logging/books/model-datastore.js
  54. +8 −6 5-logging/config.js
  55. +9 −9 5-logging/lib/images.js
  56. +9 −8 5-logging/lib/logging.js
  57. +27 −18 5-logging/lib/oauth2.js
  58. +0 −28 5-logging/package.json
  59. +8 −8 5-logging/test/_api-tests.js
  60. +27 −28 5-logging/test/_crud-tests.js
  61. +2 −2 5-logging/test/_test-config.js
  62. +9 −8 5-logging/test/app.test.js
  63. +5 −2 5-logging/test/cloudsql.test.js
  64. +5 −2 5-logging/test/datastore.test.js
  65. +39 −40 5-logging/test/oauth2.test.js
  66. +6 −5 6-pubsub/app.js
  67. +4 −4 6-pubsub/books/api.js
  68. +8 −8 6-pubsub/books/crud.js
  69. +44 −31 6-pubsub/books/model-cloudsql.js
  70. +35 −30 6-pubsub/books/model-datastore.js
  71. +8 −6 6-pubsub/config.js
  72. +6 −6 6-pubsub/lib/background.js
  73. +17 −15 6-pubsub/lib/images.js
  74. +9 −8 6-pubsub/lib/logging.js
  75. +27 −18 6-pubsub/lib/oauth2.js
  76. +0 −28 6-pubsub/package.json
  77. +8 −8 6-pubsub/test/_api-tests.js
  78. +26 −26 6-pubsub/test/_crud-tests.js
  79. +2 −2 6-pubsub/test/_test-config.js
  80. +2 −2 6-pubsub/test/_test-config.worker.js
  81. +9 −8 6-pubsub/test/app.test.js
  82. +27 −26 6-pubsub/test/background.test.js
  83. +5 −2 6-pubsub/test/cloudsql.test.js
  84. +5 −2 6-pubsub/test/datastore.test.js
  85. +39 −40 6-pubsub/test/oauth2.test.js
  86. +15 −13 6-pubsub/test/worker.test.js
  87. +41 −36 6-pubsub/worker.js
  88. +3 −3 7-gce/app.js
  89. +4 −4 7-gce/books/api.js
  90. +8 −8 7-gce/books/crud.js
  91. +44 −31 7-gce/books/model-cloudsql.js
  92. +35 −30 7-gce/books/model-datastore.js
  93. +53 −42 7-gce/books/model-mongodb.js
  94. +8 −6 7-gce/config.js
  95. +12 −10 7-gce/lib/background.js
  96. +12 −12 7-gce/lib/images.js
  97. +9 −8 7-gce/lib/logging.js
  98. +27 −18 7-gce/lib/oauth2.js
  99. +0 −28 7-gce/package.json
  100. +8 −8 7-gce/test/_api-tests.js
  101. +26 −26 7-gce/test/_crud-tests.js
  102. +2 −2 7-gce/test/_test-config.js
  103. +2 −2 7-gce/test/_test-config.worker.js
  104. +9 −8 7-gce/test/app.test.js
  105. +34 −33 7-gce/test/background.test.js
  106. +5 −2 7-gce/test/cloudsql.test.js
  107. +5 −2 7-gce/test/datastore.test.js
  108. +5 −2 7-gce/test/mongodb.test.js
  109. +39 −40 7-gce/test/oauth2.test.js
  110. +15 −13 7-gce/test/worker.test.js
  111. +39 −35 7-gce/worker.js
  112. +3 −3 optional-kubernetes-engine/app.js
  113. +4 −4 optional-kubernetes-engine/books/api.js
  114. +8 −8 optional-kubernetes-engine/books/crud.js
  115. +44 −31 optional-kubernetes-engine/books/model-cloudsql.js
  116. +35 −30 optional-kubernetes-engine/books/model-datastore.js
  117. +53 −42 optional-kubernetes-engine/books/model-mongodb.js
  118. +8 −6 optional-kubernetes-engine/config.js
  119. +12 −10 optional-kubernetes-engine/lib/background.js
  120. +12 −12 optional-kubernetes-engine/lib/images.js
  121. +9 −8 optional-kubernetes-engine/lib/logging.js
  122. +27 −18 optional-kubernetes-engine/lib/oauth2.js
  123. +0 −28 optional-kubernetes-engine/package.json
  124. +8 −8 optional-kubernetes-engine/test/_api-tests.js
  125. +27 −28 optional-kubernetes-engine/test/_crud-tests.js
  126. +2 −2 optional-kubernetes-engine/test/_test-config.js
  127. +2 −2 optional-kubernetes-engine/test/_test-config.worker.js
  128. +9 −8 optional-kubernetes-engine/test/app.test.js
  129. +34 −33 optional-kubernetes-engine/test/background.test.js
  130. +5 −2 optional-kubernetes-engine/test/cloudsql.test.js
  131. +5 −2 optional-kubernetes-engine/test/datastore.test.js
  132. +5 −2 optional-kubernetes-engine/test/mongodb.test.js
  133. +39 −40 optional-kubernetes-engine/test/oauth2.test.js
  134. +15 −13 optional-kubernetes-engine/test/worker.test.js
  135. +39 −35 optional-kubernetes-engine/worker.js
  136. +6 −30 package.json
  137. +29 −20 test/e2e.js
@@ -0,0 +1,2 @@
**/node_modules/*

@@ -0,0 +1,19 @@
---
extends:
- 'eslint:recommended'
- 'plugin:node/recommended'
- prettier
env:
mocha: true
plugins:
- node
- prettier
rules:
prettier/prettier: error
block-scoped-var: error
eqeqeq: error
no-warning-comments: warn
no-console: off
node/no-missing-require: off
node/no-unpublished-require: off

@@ -0,0 +1,3 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
@@ -0,0 +1,8 @@
---
bracketSpacing: false
printWidth: 80
semi: true
singleQuote: true
tabWidth: 2
trailingComma: es5
useTabs: false
@@ -22,34 +22,6 @@
}
}
},
"semistandard": {
"globals": [
"after",
"afterEach",
"before",
"beforeEach",
"describe",
"it"
]
},
"contributors": [
"Ace Nassri <anassri@google.com>",
"Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>",
"Allen Day <allenday@users.noreply.github.com>",
"André Cipriani Bandarra <andreban@gmail.com>",
"Dominik Staskiewicz <stadominik@gmail.com>",
"F. Hinkelmann <fhinkel@vt.edu>",
"Jason Dobry <jdobry@google.com>",
"Jon Wayne Parrott <jonwayne@google.com>",
"Justin Beckwith <justin.beckwith@gmail.com>",
"Michael McDonald <mcdonald@firebase.com>",
"Sean McBreen <seanmcb@google.com>",
"Steren <steren.giannini@gmail.com>",
"Steve Perry <steveperry-53@users.noreply.github.com>",
"chenyumic <chenyumic@google.com>",
"renovate[bot] <renovate[bot]@users.noreply.github.com>",
"shollyman <shollyman@google.com>"
],
"scripts": {
"start": "node app.js",
"e2e": "repo-tools test deploy",
@@ -39,7 +39,7 @@ app.use((req, res) => {
});

// Basic error handler
app.use((err, req, res, next) => {
app.use((err, req, res) => {
/* jshint unused:false */
console.error(err);
// If our routes specified a specific response, then send that. Otherwise,
@@ -16,7 +16,7 @@
const express = require('express');
const bodyParser = require('body-parser');

function getModel () {
function getModel() {
return require(`./model-${require('../config').get('DATA_BACKEND')}`);
}

@@ -38,7 +38,7 @@ router.get('/', (req, res, next) => {
}
res.json({
items: entities,
nextPageToken: cursor
nextPageToken: cursor,
});
});
});
@@ -94,7 +94,7 @@ router.put('/:book', (req, res, next) => {
* Delete a book.
*/
router.delete('/:book', (req, res, next) => {
getModel().delete(req.params.book, (err) => {
getModel().delete(req.params.book, err => {
if (err) {
next(err);
return;
@@ -111,7 +111,7 @@ router.use((err, req, res, next) => {
// responding to the request
err.response = {
message: err.message,
internalCode: err.code
internalCode: err.code,
};
next(err);
});
@@ -16,14 +16,14 @@
const express = require('express');
const bodyParser = require('body-parser');

function getModel () {
function getModel() {
return require(`./model-${require('../config').get('DATA_BACKEND')}`);
}

const router = express.Router();

// Automatically parse request body as form data
router.use(bodyParser.urlencoded({ extended: false }));
router.use(bodyParser.urlencoded({extended: false}));

// Set Content-Type for all responses for these routes
router.use((req, res, next) => {
@@ -44,7 +44,7 @@ router.get('/', (req, res, next) => {
}
res.render('books/list.pug', {
books: entities,
nextPageToken: cursor
nextPageToken: cursor,
});
});
});
@@ -58,7 +58,7 @@ router.get('/', (req, res, next) => {
router.get('/add', (req, res) => {
res.render('books/form.pug', {
book: {},
action: 'Add'
action: 'Add',
});
});
// [END add_get]
@@ -96,7 +96,7 @@ router.get('/:book/edit', (req, res, next) => {
}
res.render('books/form.pug', {
book: entity,
action: 'Edit'
action: 'Edit',
});
});
});
@@ -130,7 +130,7 @@ router.get('/:book', (req, res, next) => {
return;
}
res.render('books/view.pug', {
book: entity
book: entity,
});
});
});
@@ -141,7 +141,7 @@ router.get('/:book', (req, res, next) => {
* Delete a book.
*/
router.get('/:book/delete', (req, res, next) => {
getModel().delete(req.params.book, (err) => {
getModel().delete(req.params.book, err => {
if (err) {
next(err);
return;
@@ -20,20 +20,24 @@ const config = require('../config');
const options = {
user: config.get('MYSQL_USER'),
password: config.get('MYSQL_PASSWORD'),
database: 'bookshelf'
database: 'bookshelf',
};

if (config.get('INSTANCE_CONNECTION_NAME') && config.get('NODE_ENV') === 'production') {
if (
config.get('INSTANCE_CONNECTION_NAME') &&
config.get('NODE_ENV') === 'production'
) {
options.socketPath = `/cloudsql/${config.get('INSTANCE_CONNECTION_NAME')}`;
}

const connection = mysql.createConnection(options);

// [START list]
function list (limit, token, cb) {
function list(limit, token, cb) {
token = token ? parseInt(token, 10) : 0;
connection.query(
'SELECT * FROM `books` LIMIT ? OFFSET ?', [limit, token],
'SELECT * FROM `books` LIMIT ? OFFSET ?',
[limit, token],
(err, results) => {
if (err) {
cb(err);
@@ -47,7 +51,7 @@ function list (limit, token, cb) {
// [END list]

// [START create]
function create (data, cb) {
function create(data, cb) {
connection.query('INSERT INTO `books` SET ?', data, (err, res) => {
if (err) {
cb(err);
@@ -58,37 +62,39 @@ function create (data, cb) {
}
// [END create]

function read (id, cb) {
function read(id, cb) {
connection.query(
'SELECT * FROM `books` WHERE `id` = ?', id, (err, results) => {
'SELECT * FROM `books` WHERE `id` = ?',
id,
(err, results) => {
if (!err && !results.length) {
err = {
code: 404,
message: 'Not found'
message: 'Not found',
};
}
if (err) {
cb(err);
return;
}
cb(null, results[0]);
});
}
);
}

// [START update]
function update (id, data, cb) {
connection.query(
'UPDATE `books` SET ? WHERE `id` = ?', [data, id], (err) => {
if (err) {
cb(err);
return;
}
read(id, cb);
});
function update(id, data, cb) {
connection.query('UPDATE `books` SET ? WHERE `id` = ?', [data, id], err => {
if (err) {
cb(err);
return;
}
read(id, cb);
});
}
// [END update]

function _delete (id, cb) {
function _delete(id, cb) {
connection.query('DELETE FROM `books` WHERE `id` = ?', id, cb);
}

@@ -98,7 +104,7 @@ module.exports = {
create: create,
read: read,
update: update,
delete: _delete
delete: _delete,
};

if (module === require.main) {
@@ -107,7 +113,8 @@ if (module === require.main) {

console.log(
`Running this script directly will allow you to initialize your mysql database.
This script will not modify any existing tables.`);
This script will not modify any existing tables.`
);

prompt.get(['user', 'password'], (err, result) => {
if (err) {
@@ -117,10 +124,15 @@ if (module === require.main) {
});
}

function createSchema (config) {
const connection = mysql.createConnection(extend({
multipleStatements: true
}, config));
function createSchema(config) {
const connection = mysql.createConnection(
extend(
{
multipleStatements: true,
},
config
)
);

connection.query(
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
@@ -137,7 +149,7 @@ function createSchema (config) {
\`createdBy\` VARCHAR(255) NULL,
\`createdById\` VARCHAR(255) NULL,
PRIMARY KEY (\`id\`));`,
(err) => {
err => {
if (err) {
throw err;
}
Oops, something went wrong.

0 comments on commit b939a87

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.