Skip to content

Instantly share code, notes, and snippets.

@alexamies
Last active October 5, 2018 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexamies/8e7aa81d1078ceadc2298e0df92f9865 to your computer and use it in GitHub Desktop.
Save alexamies/8e7aa81d1078ceadc2298e0df92f9865 to your computer and use it in GitHub Desktop.
Cloud Builder JavaScript Lint Example
{
"extends": "google"
}

Cloud Builder JavaScript Lint Example

This example demonstrates the use of Cloud Build to do style checking with eslint.

To build and run manually with Docker run

docker build -t eslint .
docker run -w /app eslint

To run with Cloud Build use the command

gcloud builds submit . --config=cloudbuild.yaml

You will see that there are several style errors reported for the the sum.js file, including . Edit sum.js to be like this:

/**
 * Add two numbers together
 * @param {number} a - The first operand
 * @param {number} b - The second operand
 * @return {number} The sum of the two operands
 */
function sum(a, b) {
  return a + b;
}
console.log('1 + 1 = ' + sum(1, 1));

Then run cloud build again. It should succeed this time.

steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/eslint', '.' ]
- name: gcr.io/cloud-builders/docker
args: ['run', '-w', '/app', 'gcr.io/$PROJECT_ID/eslint']
FROM node:10.10.0
RUN mkdir /app
COPY *.js /app/
COPY *.json /app/
RUN npm install -g eslint eslint-config-google
CMD ["/usr/local/bin/npm", "run", "lint"]
{
"name": "javascript",
"version": "1.0.0",
"description": "",
"main": "sum.js",
"scripts": {
"lint":"eslint ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^5.5.0",
"eslint-config-google": "^0.10.0"
}
}
function sum(a, b) {
sum = a + b
return sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment