Skip to content

Commit

Permalink
Run lint script instead of eslint directly
Browse files Browse the repository at this point in the history
Closes #532.
  • Loading branch information
michaelsauter committed May 30, 2022
1 parent f56cb0b commit ab8d0a1
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ listed in the changelog.
- Update skopeo to 1.6, buildah to 1.24 and git to 2.31 ([#519](https://github.com/opendevstack/ods-pipeline/issues/519))
- Update Go to 1.17 ([#528](https://github.com/opendevstack/ods-pipeline/issues/528))
- Rename `ods-build-typescript` task to `ods-build-npm` ([#503](https://github.com/opendevstack/ods-pipeline/issues/503))
- Run `lint` script instead of `eslint` directly ([#532](https://github.com/opendevstack/ods-pipeline/issues/532))

### Fixed
- Pipelines fail in clusters with private / self-signed certificates ([#518](https://github.com/opendevstack/ods-pipeline/issues/518))
Expand Down
8 changes: 1 addition & 7 deletions build/package/scripts/build-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ while [[ "$#" -gt 0 ]]; do
--debug) DEBUG="$2"; shift;;
--debug=*) DEBUG="${1#*=}";;

--max-lint-warnings) MAX_LINT_WARNINGS="$2"; shift;;
--max-lint-warnings=*) MAX_LINT_WARNINGS="${1#*=}";;

--lint-file-ext) LINT_FILE_EXT="$2"; shift;;
--lint-file-ext=*) LINT_FILE_EXT="${1#*=}";;

--build-dir) BUILD_DIR="$2"; shift;;
--build-dir=*) BUILD_DIR="${1#*=}";;

Expand Down Expand Up @@ -101,7 +95,7 @@ npm ci --ignore-scripts

echo "Linting ..."
set +e
npx eslint src --ext "${LINT_FILE_EXT}" --format compact --max-warnings "${MAX_LINT_WARNINGS}" > eslint-report.txt
npm run lint > eslint-report.txt
exitcode=$?
set -e

Expand Down
21 changes: 6 additions & 15 deletions deploy/ods-pipeline/charts/tasks/templates/task-ods-build-npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ spec:
The following steps are executed:
- checks that package.json and package-lock.json exists to require best practice of using lock files. See also link:https://github.com/opendevstack/ods-pipeline/discussions/411[discussion 411]
- linting using `eslint`
- linting using `npm run lint`
- build application, using `npm run build`
- test execution
- SonarQube quality scan
For `eslint` to work there needs to be a config file (`eslintrc.json` or similar) at the root of the working directory.
This can be done by running `eslint --init` or by following the link:https://eslint.org/docs/user-guide/getting-started[official documentation]
For linting to work there needs to be a `lint` task in the `package.json` file,
for example `npx eslint src --format compact`, together with a config file
(`eslintrc.json` or similar) at the root of the working directory. This can
be done by running `eslint --init` or by following the
ink:https://eslint.org/docs/user-guide/getting-started[official documentation]
The exact build recipe can be found at
link:https://github.com/opendevstack/ods-pipeline/blob/master/build/package/scripts/build-npm.sh[build/package/scripts/build-npm.sh].
Expand Down Expand Up @@ -68,16 +71,6 @@ spec:
For single build repos enabling build caching has limited benefits. For multi build repos enabling this is recommended unless the build is dependant on files outside of the working directory. See ADR caching-build-tasks for more details and workarounds.
type: string
default: "false"
- name: max-lint-warnings
description: >-
Maximum of allowed linting warnings after which eslint will exit with an error.
Set to "-1" to never exit with an error due to warnings.
type: string
default: "0"
- name: lint-file-ext
description: File extensions to lint separated by a comma.
type: string
default: ".js,.ts,.jsx,.tsx,.svelte"
- name: sonar-quality-gate
description: Whether quality gate needs to pass.
type: string
Expand Down Expand Up @@ -163,8 +156,6 @@ spec:
--working-dir=$(params.working-dir) \
--output-dir=$(params.output-dir) \
--debug=${DEBUG} \
--max-lint-warnings=$(params.max-lint-warnings) \
--lint-file-ext=$(params.lint-file-ext) \
--build-dir=$(params.build-dir) \
--copy-node-modules=$(params.copy-node-modules)
build_exit=$?
Expand Down
19 changes: 6 additions & 13 deletions docs/tasks/ods-build-npm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ Builds Node.js applications using NPM.
The following steps are executed:

- checks that package.json and package-lock.json exists to require best practice of using lock files. See also link:https://github.com/opendevstack/ods-pipeline/discussions/411[discussion 411]
- linting using `eslint`
- linting using `npm run lint`
- build application, using `npm run build`
- test execution
- SonarQube quality scan

For `eslint` to work there needs to be a config file (`eslintrc.json` or similar) at the root of the working directory.
This can be done by running `eslint --init` or by following the link:https://eslint.org/docs/user-guide/getting-started[official documentation]
For linting to work there needs to be a `lint` task in the `package.json` file,
for example `npx eslint src --format compact`, together with a config file
(`eslintrc.json` or similar) at the root of the working directory. This can
be done by running `eslint --init` or by following the
ink:https://eslint.org/docs/user-guide/getting-started[official documentation]

The exact build recipe can be found at
link:https://github.com/opendevstack/ods-pipeline/blob/master/build/package/scripts/build-npm.sh[build/package/scripts/build-npm.sh].
Expand Down Expand Up @@ -68,16 +71,6 @@ without leading `./` and trailing `/`.
| If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that a build can be skipped if the `working-dir` contents did not change. For single build repos enabling build caching has limited benefits. For multi build repos enabling this is recommended unless the build is dependant on files outside of the working directory. See ADR caching-build-tasks for more details and workarounds.


| max-lint-warnings
| 0
| Maximum of allowed linting warnings after which eslint will exit with an error. Set to "-1" to never exit with an error due to warnings.


| lint-file-ext
| .js,.ts,.jsx,.tsx,.svelte
| File extensions to lint separated by a comma.


| sonar-quality-gate
| false
| Whether quality gate needs to pass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"lint": "echo 'no linting'",
"build": "mkdir -p build && cp -r src build/",
"test": "JEST_JUNIT_OUTPUT_DIR='build/test-results/test' JEST_JUNIT_OUTPUT_NAME='report.xml' npx jest --reporters=default --reporters=jest-junit --coverage --coverageDirectory=build/coverage --forceExit",
"start": "node build/src/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"lint": "echo 'no linting'",
"build": "mkdir -p dist && cp -r src dist/",
"test": "JEST_JUNIT_OUTPUT_DIR='build/test-results/test' JEST_JUNIT_OUTPUT_NAME='report.xml' npx jest --reporters=default --reporters=jest-junit --coverage --coverageDirectory=build/coverage --forceExit",
"start": "node dist/src/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"lint": "npx eslint src --ext=.js,.ts --format=compact --max-warnings=0",
"build": "tsc",
"test": "JEST_JUNIT_OUTPUT_DIR='build/test-results/test' JEST_JUNIT_OUTPUT_NAME='report.xml' npx jest --reporters=default --reporters=jest-junit --coverage --coverageDirectory=build/coverage --forceExit ./dist",
"start": "node dist/src/index.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"lint": "npx eslint src --ext=.js,.ts --format=compact --max-warnings=0",
"build": "tsc",
"test": "JEST_JUNIT_OUTPUT_DIR='build/test-results/test' JEST_JUNIT_OUTPUT_NAME='report.xml' npx jest --reporters=default --reporters=jest-junit --coverage --coverageDirectory=build/coverage --forceExit ./dist",
"start": "node dist/src/index.js"
Expand Down

0 comments on commit ab8d0a1

Please sign in to comment.