From ddee9172463e6e4605fd1f2a2e22f3efbf73938d Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sat, 17 Nov 2018 18:13:03 -0800 Subject: [PATCH] chore: include format and lint tools for samples --- .gitignore | 2 +- .prettierignore | 3 + .prettierrc | 8 +++ package.json | 12 ++-- publish-gh-pages.sh | 56 ----------------- src/.eslintrc.yml | 6 -- src/path_template_parser.js | 116 ++++++++++++++++++++---------------- system-test/.eslintrc.yml | 3 - system-test/system.ts | 2 +- verify_build.sh | 23 ------- 10 files changed, 85 insertions(+), 146 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc delete mode 100755 publish-gh-pages.sh delete mode 100644 src/.eslintrc.yml delete mode 100644 system-test/.eslintrc.yml delete mode 100644 verify_build.sh diff --git a/.gitignore b/.gitignore index a0c2758f1..29ef47482 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ system-test/*key.json build .vscode package-lock.json -system-test-run/ +.system-test-run/ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..f6fac98b0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +node_modules/* +samples/node_modules/* +src/**/doc/* diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..df6eac074 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +--- +bracketSpacing: false +printWidth: 80 +semi: true +singleQuote: true +tabWidth: 2 +trailingComma: es5 +useTabs: false diff --git a/package.json b/package.json index 039c8a31c..149935583 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,10 @@ "@types/through2": "^2.0.33", "chai": "*", "codecov": "^3.1.0", + "eslint": "^5.9.0", + "eslint-config-prettier": "^3.3.0", + "eslint-plugin-node": "^8.0.0", + "eslint-plugin-prettier": "^3.0.0", "gts": "^0.9.0", "ink-docstrap": "^1.3.2", "intelli-espower-loader": "^1.0.1", @@ -46,6 +50,7 @@ "mocha": "~5.2.0", "nyc": "^13.1.0", "pegjs": "~0.10.0", + "prettier": "^1.15.2", "proxyquire": "^2.0.1", "pumpify": "^1.5.1", "rimraf": "^2.6.2", @@ -61,11 +66,10 @@ "gen-parser": "pegjs lib/path_template_parser.pegjs", "test": "npm run test-only", "test-only": "nyc mocha build/test --reporter spec --slow 500", - "publish-gh-pages": "bash ./publish-gh-pages.sh", - "lint": "gts check", + "lint": "gts check && eslint samples/*.js samples/**/*.js", "clean": "gts clean", "compile": "tsc -p . && cp src/*.json build/src && cp src/*.js build/src", - "fix": "gts fix", + "fix": "gts fix && eslint --fix samples/*.js samples/**/*.js", "prepare": "npm run compile", "pretest-only": "npm run compile", "posttest": "npm run lint", @@ -88,7 +92,7 @@ "nyc": { "exclude": [ "build/system-test/**", - "system-test-run/**" + ".system-test-run/**" ] } } diff --git a/publish-gh-pages.sh b/publish-gh-pages.sh deleted file mode 100755 index 47cf5990f..000000000 --- a/publish-gh-pages.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -original_branch=`git branch | grep '^\*' | sed -e 's/^\* //'` -dry_run_command='' - -if [ "$1" = "-n" -o "$1" = "--dry_run" ]; then - dry_run_command='echo' -fi - -remote_name=`git remote -v | grep 'git@github.com:googleapis/gax-nodejs.git' | sed -e 's/[[:space:]].*//' | head -n 1` -if [ -z "${remote_name}" ]; then - # TODO: avoid conflict in case the remote setting already has the same name but a different - # remote. - git remote add gh-pages-push 'git@github.com:googleapis/gax-nodejs.git' - remote_name='gh-pages-push' -fi - -# re-generate the doc files. -npm run doc - -if [ $? -ne 0 ]; then - ehco "failed to generate the documents. Quiting..." - exit 1 -fi - -if [ -n "${dry_run_command}" ]; then - echo "dry-run mode: the following commands will be executed." - echo "" -fi - -$dry_run_command git checkout -b gh-pages "${remote_name}/gh-pages" - -if [ $? -ne 0 ]; then - echo "failed to switch to the branch. Quitting..." - exit 1 -fi - -$dry_run_command cp -rf doc/google-gax/*/* . - -if [ -z "${dry_run_command}" ]; then - diffs=`git diff` - - if [ -z "${diffs}" ]; then - echo 'nothing to be updated!' - exit 0 - fi - - echo "git diffs: " - echo "$diffs" -fi - -$dry_run_command git commit -a -m "update gh-pages" -$dry_run_command git push ${remote_name} gh-pages - -echo "done" -$dry_run_command git checkout "${original_branch}" diff --git a/src/.eslintrc.yml b/src/.eslintrc.yml deleted file mode 100644 index 6921a65c2..000000000 --- a/src/.eslintrc.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -env: - mocha: true -rules: - no-warning-comments: off - no-console: off diff --git a/src/path_template_parser.js b/src/path_template_parser.js index 791a26007..5e704b16d 100644 --- a/src/path_template_parser.js +++ b/src/path_template_parser.js @@ -35,7 +35,7 @@ module.exports = (() => { let peg$startRuleFunction = peg$parsetemplate; const peg$c0 = '/'; const peg$c1 = {type: 'literal', value: '/', description: '"/"'}; - const peg$c2 = (segments) => { + const peg$c2 = segments => { return segments; }; const peg$c3 = (s, segments) => { @@ -51,12 +51,11 @@ module.exports = (() => { const peg$c9 = '}'; const peg$c10 = {type: 'literal', value: '}', description: '"}"'}; const peg$c11 = (l, segments) => { - return ([ - {kind: extras.BINDING, literal: l}, - segments, - {kind: extras.END_BINDING, literal: ''}, - ]) - .reduce((a, b) => a.concat(b), []); + return [ + {kind: extras.BINDING, literal: l}, + segments, + {kind: extras.END_BINDING, literal: ''}, + ].reduce((a, b) => a.concat(b), []); }; const peg$c12 = l => { return [ @@ -104,7 +103,8 @@ module.exports = (() => { if ('startRule' in options) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error( - 'Can\'t start parsing from rule "' + options.startRule + '".'); + 'Can\'t start parsing from rule "' + options.startRule + '".' + ); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; @@ -120,19 +120,26 @@ module.exports = (() => { function expected(description) { throw peg$buildException( - null, [{type: 'other', description}], - input.substring(peg$savedPos, peg$currPos), - peg$computeLocation(peg$savedPos, peg$currPos)); + null, + [{type: 'other', description}], + input.substring(peg$savedPos, peg$currPos), + peg$computeLocation(peg$savedPos, peg$currPos) + ); } function error(message) { throw peg$buildException( - message, null, input.substring(peg$savedPos, peg$currPos), - peg$computeLocation(peg$savedPos, peg$currPos)); + message, + null, + input.substring(peg$savedPos, peg$currPos), + peg$computeLocation(peg$savedPos, peg$currPos) + ); } function peg$computePosDetails(pos) { - let details = peg$posDetailsCache[pos], p, ch; + let details = peg$posDetailsCache[pos], + p, + ch; if (details) { return details; @@ -176,7 +183,7 @@ module.exports = (() => { function peg$computeLocation(startPos, endPos) { const startPosDetails = peg$computePosDetails(startPos), - endPosDetails = peg$computePosDetails(endPos); + endPosDetails = peg$computePosDetails(endPos); return { start: { @@ -231,34 +238,32 @@ module.exports = (() => { function buildMessage(expected, found) { function stringEscape(s) { function hex(ch) { - return ch.charCodeAt(0).toString(16).toUpperCase(); + return ch + .charCodeAt(0) + .toString(16) + .toUpperCase(); } - return s.replace(/\\/g, '\\\\') - .replace(/"/g, '\\"') - .replace(/\x08/g, '\\b') - .replace(/\t/g, '\\t') - .replace(/\n/g, '\\n') - .replace(/\f/g, '\\f') - .replace(/\r/g, '\\r') - .replace( - /[\x00-\x07\x0B\x0E\x0F]/g, - ch => { - return '\\x0' + hex(ch); - }) - .replace( - /[\x10-\x1F\x80-\xFF]/g, - ch => { - return '\\x' + hex(ch); - }) - .replace( - /[\u0100-\u0FFF]/g, - ch => { - return '\\u0' + hex(ch); - }) - .replace(/[\u1000-\uFFFF]/g, ch => { - return '\\u' + hex(ch); - }); + return s + .replace(/\\/g, '\\\\') + .replace(/"/g, '\\"') + .replace(/\x08/g, '\\b') + .replace(/\t/g, '\\t') + .replace(/\n/g, '\\n') + .replace(/\f/g, '\\f') + .replace(/\r/g, '\\r') + .replace(/[\x00-\x07\x0B\x0E\x0F]/g, ch => { + return '\\x0' + hex(ch); + }) + .replace(/[\x10-\x1F\x80-\xFF]/g, ch => { + return '\\x' + hex(ch); + }) + .replace(/[\u0100-\u0FFF]/g, ch => { + return '\\u0' + hex(ch); + }) + .replace(/[\u1000-\uFFFF]/g, ch => { + return '\\u' + hex(ch); + }); } const expectedDescs = new Array(expected.length); @@ -268,10 +273,12 @@ module.exports = (() => { expectedDescs[i] = expected[i].description; } - expectedDesc = expected.length > 1 ? - expectedDescs.slice(0, -1).join(', ') + ' or ' + - expectedDescs[expected.length - 1] : - expectedDescs[0]; + expectedDesc = + expected.length > 1 + ? expectedDescs.slice(0, -1).join(', ') + + ' or ' + + expectedDescs[expected.length - 1] + : expectedDescs[0]; foundDesc = found ? '"' + stringEscape(found) + '"' : 'end of input'; @@ -283,8 +290,11 @@ module.exports = (() => { } return new peg$SyntaxError( - message !== null ? message : buildMessage(expected, found), expected, - found, location); + message !== null ? message : buildMessage(expected, found), + expected, + found, + location + ); } function peg$parsetemplate() { @@ -630,11 +640,13 @@ module.exports = (() => { } throw peg$buildException( - null, peg$maxFailExpected, - peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, - peg$maxFailPos < input.length ? - peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : - peg$computeLocation(peg$maxFailPos, peg$maxFailPos)); + null, + peg$maxFailExpected, + peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, + peg$maxFailPos < input.length + ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) + : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) + ); } } diff --git a/system-test/.eslintrc.yml b/system-test/.eslintrc.yml deleted file mode 100644 index 282535f55..000000000 --- a/system-test/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - no-console: off diff --git a/system-test/system.ts b/system-test/system.ts index c44f0eab7..c19e76348 100644 --- a/system-test/system.ts +++ b/system-test/system.ts @@ -24,7 +24,7 @@ const mkdir = util.promisify(fs.mkdir); const rmrf = util.promisify(rimraf); const baseRepoUrl = 'https://github.com/googleapis/'; -const testDir = path.join(process.cwd(), 'system-test-run'); +const testDir = path.join(process.cwd(), '.system-test-run'); interface ExecuteResult { stdout: string; diff --git a/verify_build.sh b/verify_build.sh deleted file mode 100644 index aeb759558..000000000 --- a/verify_build.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# This script verifies the google-gax package can be -# loaded after it's published. -# This script was added because it failed to load for -# normal installations due to devDependencies of chai. - -set -x - -current_dir=`pwd` -tmpdir=`mktemp -d` - -cd ${tmpdir} -npm install "file://${current_dir}" -exitcode=$? -if [ ${exitcode} -eq 0 ]; then - node -e 'require("google-gax")' - exitcode=$? -fi - -cd ${current_dir} -rm -rf ${tmpdir} -exit ${exitcode}