Skip to content

Commit 116436f

Browse files
callmehiphopstephenplusplus
authored andcommitted
docs: lint code snippets (#1772)
1 parent b6270e5 commit 116436f

File tree

7 files changed

+47
-15
lines changed

7 files changed

+47
-15
lines changed

packages/bigtable/src/instance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function Instance(bigtable, name) {
8787
* instance.create().then(function(data) {
8888
* var instance = data[0];
8989
* var operation = data[1];
90-
* var apiResponse = data[2]
90+
* var apiResponse = data[2];
9191
* });
9292
*/
9393
create: true,

packages/bigtable/src/row.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ Row.prototype.getMetadata = function(options, callback) {
744744
* }
745745
* };
746746
*
747-
* row.increment('follows:gwashington', callback)
747+
* row.increment('follows:gwashington', callback);
748748
*
749749
* //-
750750
* // Specify a custom amount to increment the column by.

packages/bigtable/src/table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ Table.prototype.insert = function(entries, callback) {
792792
* }
793793
* ];
794794
*
795-
* table.mutate(entries, callback)
795+
* table.mutate(entries, callback);
796796
*
797797
* //-
798798
* // Delete entities. See {module:bigtable/row#deleteCells}

packages/compute/src/instance-group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function InstanceGroup(zone, name) {
7070
* instanceGroup.create().then(function(data) {
7171
* var instanceGroup = data[0];
7272
* var operation = data[1];
73-
* var apiResponse = data[2]
73+
* var apiResponse = data[2];
7474
* });
7575
*/
7676
create: true,

packages/datastore/src/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ DatastoreRequest.prototype.runQueryStream = function(query, options) {
750750
* name: 'DonutShack',
751751
* rating: 8
752752
* }
753-
* }
753+
* };
754754
*
755755
* datastore.save(entity, function(err) {
756756
* console.log(key.path); // ['Company', 'donutshack']

scripts/docs/builder.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function Builder(name, version, cwd) {
5656
this.version = version || config.DEFAULT_VERSION;
5757
this.dir = path.join(cwd || '', DOCS_ROOT, name, this.version);
5858
this.isUmbrella = name === UMBRELLA_PACKAGE;
59-
this.isMaster = this.version === config.DEFAULT_VERSION;
59+
this.isRelease = !!semver.valid(this.version);
6060
}
6161

6262
/**
@@ -112,7 +112,7 @@ Builder.prototype.build = function() {
112112
* var tagName = builder.getTagName(); // bigtable-0.2.0
113113
*/
114114
Builder.prototype.getTagName = function() {
115-
if (this.isMaster) {
115+
if (!semver.valid(this.version)) {
116116
return this.version;
117117
}
118118

@@ -233,7 +233,7 @@ function Bundler(builder) {
233233
* Bundler.updateDep(builder);
234234
*/
235235
Bundler.updateDep = function(builder) {
236-
if (builder.isMaster) {
236+
if (!builder.isRelease) {
237237
throw new Error('Must supply valid version to update bundles with.');
238238
}
239239

@@ -252,7 +252,7 @@ Bundler.updateDep = function(builder) {
252252
bundleTag = bundler.builder.getTagName();
253253
git.checkout(bundleTag);
254254

255-
dep = findWhere(bundler.getDeps(), { name: builder.name });
255+
dep = findWhere(bundler.getDeps(), { name: builder.name }) || {};
256256
git.checkout('-');
257257

258258
if (semver.maxSatisfying(versions, dep.version) !== builder.version) {
@@ -440,10 +440,13 @@ function build(name, version) {
440440
git.checkout(builder.getTagName());
441441
builder.build();
442442
git.checkout('-');
443-
builder.updateManifest();
444443

445-
if (!builder.isUmbrella && !builder.isMaster) {
446-
Bundler.updateDep(builder);
444+
if (builder.isRelease) {
445+
builder.updateManifest();
446+
447+
if (!builder.isUmbrella) {
448+
Bundler.updateDep(builder);
449+
}
447450
}
448451
}
449452

@@ -456,13 +459,14 @@ module.exports.build = build;
456459
* builder.buildAll();
457460
*/
458461
function buildAll() {
462+
var currentBranch = git.branch.current;
459463
var modules = globby.sync('*', {
460464
cwd: PACKAGES_ROOT,
461465
ignore: config.IGNORE
462466
});
463467

464468
modules.forEach(function(name) {
465-
build(name, config.DEFAULT_VERSION);
469+
build(name, currentBranch);
466470
});
467471
}
468472

test/docs.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var createErrorClass = require('create-error-class');
2020
var format = require('string-format-obj');
2121
var fs = require('fs');
2222
var glob = require('glob');
23+
var jshint = require('jshint').JSHINT;
2324
var mitm = require('mitm');
2425
var multiline = require('multiline');
2526
var overviews = require('../scripts/docs/config').OVERVIEW;
@@ -41,7 +42,19 @@ var DocsError = createErrorClass('DocsError', function(err, code) {
4142
})
4243
.join('\n');
4344

44-
this.message = '\n' + lines + '\n\n' + err.message;
45+
this.message = format('\n{lines}\n\n{message}', {
46+
lines: lines,
47+
message: err.message
48+
});
49+
});
50+
51+
var JSHintError = createErrorClass('JSHintError', function(err) {
52+
this.message = format('"{evidence}" - {reason}', {
53+
evidence: err.evidence.trim(),
54+
reason: err.reason
55+
});
56+
57+
this.code = err.code;
4558
});
4659

4760
var FakeConsole = Object.keys(console)
@@ -144,6 +157,21 @@ modules.forEach(function(mod) {
144157
var snippet = createSnippet(mod, moduleInstantationCode, method);
145158

146159
it('should run ' + name + ' examples without errors', function() {
160+
jshint(snippet, {
161+
// in several snippets we give an example as to how to access
162+
// a property (like metadata) without doing anything with it
163+
// e.g. `list[0].metadata`
164+
expr: true,
165+
166+
// this allows us to redefine variables, generally it's bad, buuut
167+
// for copy/paste purposes this is desirable within the docs
168+
shadow: true
169+
});
170+
171+
if (jshint.errors.length) {
172+
throw new JSHintError(jshint.errors[0]);
173+
}
174+
147175
runCodeInSandbox(snippet, sandbox);
148176
});
149177
});
@@ -153,7 +181,7 @@ modules.forEach(function(mod) {
153181

154182
function getDocs(mod) {
155183
return glob
156-
.sync('docs/json/' + mod + '/master/*.json', {
184+
.sync('docs/json/' + mod + '/*/*.json', {
157185
ignore: [
158186
'**/toc.json',
159187
'**/types.json'

0 commit comments

Comments
 (0)