From 569a1f58245c41ba5cfcf1f821bb917215779017 Mon Sep 17 00:00:00 2001 From: Tim Alby Date: Wed, 6 May 2020 12:04:19 +0200 Subject: [PATCH] decaffeinate: update build scripts to es --- services/document-updater/.dockerignore | 2 - services/document-updater/.eslintrc | 64 +++++++++++++++++++++++ services/document-updater/.prettierrc | 7 +++ services/document-updater/Dockerfile | 1 - services/document-updater/Jenkinsfile | 7 +++ services/document-updater/Makefile | 15 ++++-- services/document-updater/buildscript.txt | 2 +- services/document-updater/nodemon.json | 7 ++- services/document-updater/package.json | 32 ++++++++---- 9 files changed, 113 insertions(+), 24 deletions(-) create mode 100644 services/document-updater/.eslintrc create mode 100644 services/document-updater/.prettierrc diff --git a/services/document-updater/.dockerignore b/services/document-updater/.dockerignore index 386f26df30..ba1c3442de 100644 --- a/services/document-updater/.dockerignore +++ b/services/document-updater/.dockerignore @@ -5,5 +5,3 @@ gitrev .npm .nvmrc nodemon.json -app.js -**/js/* diff --git a/services/document-updater/.eslintrc b/services/document-updater/.eslintrc new file mode 100644 index 0000000000..2e945d6ffb --- /dev/null +++ b/services/document-updater/.eslintrc @@ -0,0 +1,64 @@ +// this file was auto-generated, do not edit it directly. +// instead run bin/update_build_scripts from +// https://github.com/sharelatex/sharelatex-dev-environment +{ + "extends": [ + "standard", + "prettier", + "prettier/standard" + ], + "parserOptions": { + "ecmaVersion": 2017 + }, + "plugins": [ + "mocha", + "chai-expect", + "chai-friendly" + ], + "env": { + "node": true, + "mocha": true + }, + "rules": { + // Swap the no-unused-expressions rule with a more chai-friendly one + "no-unused-expressions": 0, + "chai-friendly/no-unused-expressions": "error" + }, + "overrides": [ + { + // Test specific rules + "files": ["test/**/*.js"], + "globals": { + "expect": true + }, + "rules": { + // mocha-specific rules + "mocha/handle-done-callback": "error", + "mocha/no-exclusive-tests": "error", + "mocha/no-global-tests": "error", + "mocha/no-identical-title": "error", + "mocha/no-nested-tests": "error", + "mocha/no-pending-tests": "error", + "mocha/no-skipped-tests": "error", + "mocha/no-mocha-arrows": "error", + + // chai-specific rules + "chai-expect/missing-assertion": "error", + "chai-expect/terminating-properties": "error", + + // prefer-arrow-callback applies to all callbacks, not just ones in mocha tests. + // we don't enforce this at the top-level - just in tests to manage `this` scope + // based on mocha's context mechanism + "mocha/prefer-arrow-callback": "error" + } + }, + { + // Backend specific rules + "files": ["app/**/*.js", "app.js", "index.js"], + "rules": { + // don't allow console.log in backend code + "no-console": "error" + } + } + ] +} diff --git a/services/document-updater/.prettierrc b/services/document-updater/.prettierrc new file mode 100644 index 0000000000..24f9ec526f --- /dev/null +++ b/services/document-updater/.prettierrc @@ -0,0 +1,7 @@ +# This file was auto-generated, do not edit it directly. +# Instead run bin/update_build_scripts from +# https://github.com/sharelatex/sharelatex-dev-environment +{ + "semi": false, + "singleQuote": true +} diff --git a/services/document-updater/Dockerfile b/services/document-updater/Dockerfile index 4c269d5a49..4242e7d3be 100644 --- a/services/document-updater/Dockerfile +++ b/services/document-updater/Dockerfile @@ -16,7 +16,6 @@ RUN npm ci --quiet COPY . /app -RUN npm run compile:all FROM base diff --git a/services/document-updater/Jenkinsfile b/services/document-updater/Jenkinsfile index 92db215930..803963773e 100644 --- a/services/document-updater/Jenkinsfile +++ b/services/document-updater/Jenkinsfile @@ -37,6 +37,13 @@ pipeline { } } + stage('Linting') { + steps { + sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make format' + sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make lint' + } + } + stage('Unit Tests') { steps { sh 'DOCKER_COMPOSE_FLAGS="-f docker-compose.ci.yml" make test_unit' diff --git a/services/document-updater/Makefile b/services/document-updater/Makefile index c020c537e6..df879265c9 100644 --- a/services/document-updater/Makefile +++ b/services/document-updater/Makefile @@ -23,12 +23,17 @@ DOCKER_COMPOSE_TEST_UNIT = \ clean: docker rmi ci/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) docker rmi gcr.io/overleaf-ops/$(PROJECT_NAME):$(BRANCH_NAME)-$(BUILD_NUMBER) - rm -f app.js - rm -rf app/js - rm -rf test/unit/js - rm -rf test/acceptance/js -test: test_unit test_acceptance +format: + $(DOCKER_COMPOSE) run --rm test_unit npm run format + +format_fix: + $(DOCKER_COMPOSE) run --rm test_unit npm run format:fix + +lint: + $(DOCKER_COMPOSE) run --rm test_unit npm run lint + +test: format lint test_unit test_acceptance test_unit: ifneq (,$(wildcard test/unit)) diff --git a/services/document-updater/buildscript.txt b/services/document-updater/buildscript.txt index 9b20b21f85..b234a9b3ac 100644 --- a/services/document-updater/buildscript.txt +++ b/services/document-updater/buildscript.txt @@ -4,7 +4,7 @@ document-updater --docker-repos=gcr.io/overleaf-ops --env-add= --env-pass-through= ---language=coffeescript +--language=es --node-version=10.19.0 --public-repo=True --script-version=2.2.0 diff --git a/services/document-updater/nodemon.json b/services/document-updater/nodemon.json index 98db38d71b..5826281b84 100644 --- a/services/document-updater/nodemon.json +++ b/services/document-updater/nodemon.json @@ -10,10 +10,9 @@ }, "watch": [ - "app/coffee/", - "app.coffee", + "app/js/", + "app.js", "config/" ], - "ext": "coffee" - + "ext": "js" } diff --git a/services/document-updater/package.json b/services/document-updater/package.json index 706a382d6f..43c40ce469 100644 --- a/services/document-updater/package.json +++ b/services/document-updater/package.json @@ -7,17 +7,15 @@ "url": "https://github.com/sharelatex/document-updater-sharelatex.git" }, "scripts": { - "compile:app": "([ -e app/coffee ] && coffee -m $COFFEE_OPTIONS -o app/js -c app/coffee || echo 'No CoffeeScript folder to compile') && ( [ -e app.coffee ] && coffee -m $COFFEE_OPTIONS -c app.coffee || echo 'No CoffeeScript app to compile')", - "start": "npm run compile:app && node $NODE_APP_OPTIONS app.js", - "test:acceptance:_run": "mocha --recursive --reporter spec --timeout 30000 --exit $@ test/acceptance/js", - "test:acceptance": "npm run compile:app && npm run compile:acceptance_tests && npm run test:acceptance:_run -- --grep=$MOCHA_GREP", - "test:unit:_run": "mocha --recursive --reporter spec --exit $@ test/unit/js", - "test:unit": "npm run compile:app && npm run compile:unit_tests && npm run test:unit:_run -- --grep=$MOCHA_GREP", - "compile:unit_tests": "[ ! -e test/unit/coffee ] && echo 'No unit tests to compile' || coffee -o test/unit/js -c test/unit/coffee", - "compile:acceptance_tests": "[ ! -e test/acceptance/coffee ] && echo 'No acceptance tests to compile' || coffee -o test/acceptance/js -c test/acceptance/coffee", - "compile:all": "npm run compile:app && npm run compile:unit_tests && npm run compile:acceptance_tests && npm run compile:smoke_tests", + "start": "node $NODE_APP_OPTIONS app.js", + "test:acceptance:_run": "mocha --recursive --reporter spec --timeout 15000 --exit $@ test/acceptance/js", + "test:acceptance": "npm run test:acceptance:_run -- --grep=$MOCHA_GREP", + "test:unit:_run": "mocha --recursive --reporter spec $@ test/unit/js", + "test:unit": "npm run test:unit:_run -- --grep=$MOCHA_GREP", "nodemon": "nodemon --config nodemon.json", - "compile:smoke_tests": "[ ! -e test/smoke/coffee ] && echo 'No smoke tests to compile' || coffee -o test/smoke/js -c test/smoke/coffee" + "lint": "node_modules/.bin/eslint .", + "format": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --list-different", + "format:fix": "node_modules/.bin/prettier-eslint $PWD'/**/*.js' --write" }, "dependencies": { "async": "^2.5.0", @@ -41,6 +39,18 @@ "mocha": "^5.0.1", "sandboxed-module": "~0.2.0", "sinon": "~1.5.2", - "timekeeper": "^2.0.0" + "timekeeper": "^2.0.0", + "eslint": "^6.8.0", + "eslint-config-prettier": "^6.10.0", + "eslint-config-standard": "^14.1.0", + "eslint-plugin-chai-expect": "^2.1.0", + "eslint-plugin-chai-friendly": "^0.5.0", + "eslint-plugin-import": "^2.20.1", + "eslint-plugin-mocha": "^6.3.0", + "eslint-plugin-node": "^11.0.0", + "eslint-plugin-prettier": "^3.1.2", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-standard": "^4.0.1", + "prettier-eslint-cli": "^5.0.0" } }