From: Tiago Melo Date: Tue, 25 Sep 2018 17:02:01 +0000 (+0100) Subject: mgr/dashboard: Update frontend linting scripts and documentation X-Git-Tag: v14.0.1~175^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=00ab84abaf0a20a02dc3dbe648ae87446031e585;p=ceph.git mgr/dashboard: Update frontend linting scripts and documentation Signed-off-by: Tiago Melo --- diff --git a/src/pybind/mgr/dashboard/HACKING.rst b/src/pybind/mgr/dashboard/HACKING.rst index 3c9f588f91611..83f7ff2109216 100644 --- a/src/pybind/mgr/dashboard/HACKING.rst +++ b/src/pybind/mgr/dashboard/HACKING.rst @@ -63,18 +63,21 @@ Run ``npm run build`` to build the project. The build artifacts will be stored in the ``dist/`` directory. Use the ``-prod`` flag for a production build. Navigate to ``https://localhost:8443``. -Formatting TS and SCSS files +Code linting and formatting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -We use `Prettier `_ to automatically format TS and SCSS -files. -To use this plugin you can either install it in your IDE, if supported, or use -it via the cli. +We use the following tools to lint and format the code in all our TS, SCSS and +HTML files: -We added 2 npm scripts to help running prettier commands: +- `codelyzer `_ +- `html-linter `_ +- `Prettier `_ +- `TSLint `_ -- ``npm run prettier``, will run prettier formatter on all frontend files -- ``npm run prettier:lint``, will check all frontend files against prettier linter +We added 2 npm scripts to help run these tools: + +- ``npm run lint``, will check frontend files against all linters +- ``npm run fix``, will try to fix all the detected linting errors Running Unit Tests ~~~~~~~~~~~~~~~~~~ diff --git a/src/pybind/mgr/dashboard/frontend/package.json b/src/pybind/mgr/dashboard/frontend/package.json index 7678416a5991b..7f388544b512e 100644 --- a/src/pybind/mgr/dashboard/frontend/package.json +++ b/src/pybind/mgr/dashboard/frontend/package.json @@ -8,11 +8,15 @@ "build": "ng build", "test": "jest --watch", "test:ci": "jest --coverage", - "lint": "ng lint", "e2e": "ng e2e", - "prettier": "prettier --write \"{src,e2e}/**/*.{ts,scss}\"", - "prettier:lint": "prettier --list-different \"{src,e2e}/**/*.{ts,scss}\"", - "lint:html": "html-linter --config html-linter.config.json" + "lint:tslint": "ng lint ceph-dashboard ceph-dashboard-e2e", + "lint:prettier": "prettier --list-different \"{src,e2e}/**/*.{ts,scss}\"", + "lint:html": "html-linter --config html-linter.config.json", + "lint": "npm run lint:tslint && npm run lint:prettier && npm run lint:html", + "fix:prettier": "prettier --write \"{src,e2e}/**/*.{ts,scss}\"", + "fix:tslint": "npm run lint:tslint -- --fix", + "fix": "npm run fix:tslint; npm run fix:prettier" + }, "private": true, "jest": { diff --git a/src/pybind/mgr/dashboard/run-frontend-unittests.sh b/src/pybind/mgr/dashboard/run-frontend-unittests.sh index b546f5337eb56..403775af0a877 100755 --- a/src/pybind/mgr/dashboard/run-frontend-unittests.sh +++ b/src/pybind/mgr/dashboard/run-frontend-unittests.sh @@ -27,18 +27,13 @@ fi npm run lint --silent if [ $? -gt 0 ]; then failed=true - echo -e "\nTry running 'npm run lint -- --fix' to fix some linting errors." -fi - -npm run prettier:lint --silent -if [ $? -gt 0 ]; then - failed=true - echo -e "\nTry running 'npm run prettier' to fix linting errors." + echo -e "\nTry running 'npm run fix' to fix some linting errors. \ +Some errors might need a manual fix." fi if [ `uname` != "FreeBSD" ]; then deactivate -fi +fi if [ "$failed" = "true" ]; then exit 1