MCPcopy Create free account
hub / github.com/ampproject/amphtml / runValidation

Function runValidation

validator/js/gulpjs/index.js:26–54  ·  view source on GitHub ↗
(file, encoding, callback)

Source from the content-addressed store, hash-verified

24 }
25
26 function runValidation(file, encoding, callback) {
27 if (file.isNull()) {
28 return callback(null, file);
29 }
30 if (file.isStream()) {
31 this.emit('error', new PluginError(PLUGIN_NAME,
32 'Streams not supported!'));
33 }
34 if (file.isBuffer()) {
35 validator.getInstance()
36 .then(function(validatorInstance) {
37 const inputString = file.contents.toString();
38 file.ampValidationResult =
39 validatorInstance.validateString(inputString);
40 return callback(null, file);
41 })
42 .catch(function(err) {
43 // This happens if the validator download failed. We don't fail the
44 // build, but map the exception to an validation error instead. This
45 // makes it possible to configure via failAfterError whether this
46 // should fail the build or not.
47 console.log(colors.red(err.message));
48 file.ampValidationResult = {
49 status: STATUS_UNKNOWN,
50 };
51 return callback(null, file);
52 });
53 }
54 }
55 return through.obj(runValidation);
56};
57

Callers

nothing calls this directly

Calls 5

catchMethod · 0.80
callbackFunction · 0.50
thenMethod · 0.45
toStringMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected