Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit db83b0a

Browse files
author
Michael Sauter
committed
Run lint script instead of eslint directly
Closes #532.
1 parent 15dfa8b commit db83b0a

File tree

11 files changed

+28
-44
lines changed

11 files changed

+28
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ listed in the changelog.
2323
- Update Go to 1.17 ([#528](https://github.com/opendevstack/ods-pipeline/issues/528))
2424
- Rename `ods-build-typescript` task to `ods-build-npm` ([#503](https://github.com/opendevstack/ods-pipeline/issues/503))
2525
- Implement global caching for Gradle build task ([#490](https://github.com/opendevstack/ods-pipeline/issues/490))
26+
- Run `lint` script instead of `eslint` directly ([#532](https://github.com/opendevstack/ods-pipeline/issues/532))
2627

2728
### Fixed
2829
- Pipelines fail in clusters with private / self-signed certificates ([#518](https://github.com/opendevstack/ods-pipeline/issues/518))

build/package/scripts/build-npm.sh

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ OUTPUT_DIR="docker"
2828
WORKING_DIR="."
2929
ARTIFACT_PREFIX=""
3030
DEBUG="${DEBUG:-false}"
31-
MAX_LINT_WARNINGS="0"
32-
LINT_FILE_EXT=".js,.ts,.jsx,.tsx,.svelte"
3331
COPY_NODE_MODULES="false"
3432

3533
while [[ "$#" -gt 0 ]]; do
@@ -44,12 +42,6 @@ while [[ "$#" -gt 0 ]]; do
4442
--debug) DEBUG="$2"; shift;;
4543
--debug=*) DEBUG="${1#*=}";;
4644

47-
--max-lint-warnings) MAX_LINT_WARNINGS="$2"; shift;;
48-
--max-lint-warnings=*) MAX_LINT_WARNINGS="${1#*=}";;
49-
50-
--lint-file-ext) LINT_FILE_EXT="$2"; shift;;
51-
--lint-file-ext=*) LINT_FILE_EXT="${1#*=}";;
52-
5345
--build-dir) BUILD_DIR="$2"; shift;;
5446
--build-dir=*) BUILD_DIR="${1#*=}";;
5547

@@ -101,7 +93,7 @@ npm ci --ignore-scripts
10193

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

deploy/ods-pipeline/charts/tasks/templates/task-ods-build-npm.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ spec:
1212
The following steps are executed:
1313
1414
- 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]
15-
- linting using `eslint`
15+
- linting using `npm run lint`
1616
- build application, using `npm run build`
1717
- test execution
1818
- SonarQube quality scan
1919
20-
For `eslint` to work there needs to be a config file (`eslintrc.json` or similar) at the root of the working directory.
21-
This can be done by running `eslint --init` or by following the link:https://eslint.org/docs/user-guide/getting-started[official documentation]
20+
For linting to work there needs to be a `lint` task in the `package.json` file,
21+
for example `npx eslint src --format compact`, together with a config file
22+
(`eslintrc.json` or similar) at the root of the working directory. This can
23+
be done by running `eslint --init` or by following the
24+
ink:https://eslint.org/docs/user-guide/getting-started[official documentation]
2225
2326
The exact build recipe can be found at
2427
link:https://github.com/opendevstack/ods-pipeline/blob/master/build/package/scripts/build-npm.sh[build/package/scripts/build-npm.sh].
@@ -68,16 +71,6 @@ spec:
6871
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.
6972
type: string
7073
default: "false"
71-
- name: max-lint-warnings
72-
description: >-
73-
Maximum of allowed linting warnings after which eslint will exit with an error.
74-
Set to "-1" to never exit with an error due to warnings.
75-
type: string
76-
default: "0"
77-
- name: lint-file-ext
78-
description: File extensions to lint separated by a comma.
79-
type: string
80-
default: ".js,.ts,.jsx,.tsx,.svelte"
8174
- name: sonar-quality-gate
8275
description: Whether quality gate needs to pass.
8376
type: string
@@ -163,8 +156,6 @@ spec:
163156
--working-dir=$(params.working-dir) \
164157
--output-dir=$(params.output-dir) \
165158
--debug=${DEBUG} \
166-
--max-lint-warnings=$(params.max-lint-warnings) \
167-
--lint-file-ext=$(params.lint-file-ext) \
168159
--build-dir=$(params.build-dir) \
169160
--copy-node-modules=$(params.copy-node-modules)
170161
build_exit=$?

docs/design/software-design-specification.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ For traceability package.json and package-lock.json are copied into the `dist` d
331331

332332
Runs `npm run test`, creating code coverage and xUnit reports. The artifacts are placed in the working directory and in `.ods/artifacts/code-coverage` and `.ods/artifacts/xunit-reports`, respectively.
333333

334-
Runs `eslint` to lint the source code and fails if there are any errors or warnings. The files to lint default to all files with an `.js`, `.ts`, `.jsx`, `.tsx`, `.svelte` extension inside `src` and can be set by the `lint-file-ext` task parameter. The amount of allowed warnings defaults to 0 and can be set by the `max-lint-warnings` task parameter.
334+
Runs `npm run lint` to lint the source code. If there are any errors or warnings, the script should exit with a non-zero exit code.
335335

336336
Supplies default SonarQube project properties file if required (SDS-SHARED-3).
337337

docs/design/software-requirements-specification.adoc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,25 @@ a| The task shall build a Python application.
224224
[cols="1,3"]
225225
|===
226226
| SRS-TASK-BUILD-NPM-1
227-
a| The task shall run test, creating code coverage and xUnit reports.
227+
| The task shall run the NPM lint script.
228+
229+
| SRS-TASK-BUILD-NPM-2
230+
a| The task shall run the NPM test script, creating code coverage and xUnit reports.
228231

229232
* Artifacts shall be made available to SonarQube and designated for upload to Nexus.
230233

231-
| SRS-TASK-BUILD-NPM-2
234+
| SRS-TASK-BUILD-NPM-3
232235
a| The task shall build a Node.JS application using NPM.
233236

234237
* Destination directory shall be customizable
235238

236-
| SRS-TASK-BUILD-NPM-3
239+
| SRS-TASK-BUILD-NPM-4
237240
| See SRS-TASK-SHARED-1.
238241

239-
| SRS-TASK-BUILD-NPM-4
242+
| SRS-TASK-BUILD-NPM-5
240243
| See SRS-TASK-SHARED-2.
241244

242-
| SRS-TASK-BUILD-NPM-5
245+
| SRS-TASK-BUILD-NPM-6
243246
| See SRS-TASK-SHARED-3.
244247

245248
|===

docs/tasks/ods-build-npm.adoc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ Builds Node.js applications using NPM.
77
The following steps are executed:
88

99
- 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]
10-
- linting using `eslint`
10+
- linting using `npm run lint`
1111
- build application, using `npm run build`
1212
- test execution
1313
- SonarQube quality scan
1414

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

1821
The exact build recipe can be found at
1922
link:https://github.com/opendevstack/ods-pipeline/blob/master/build/package/scripts/build-npm.sh[build/package/scripts/build-npm.sh].
@@ -68,16 +71,6 @@ without leading `./` and trailing `/`.
6871
| 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.
6972

7073

71-
| max-lint-warnings
72-
| 0
73-
| 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.
74-
75-
76-
| lint-file-ext
77-
| .js,.ts,.jsx,.tsx,.svelte
78-
| File extensions to lint separated by a comma.
79-
80-
8174
| sonar-quality-gate
8275
| false
8376
| Whether quality gate needs to pass.

test/tasks/ods-build-npm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestTaskODSBuildNPM(t *testing.T) {
112112
checkFilesExist(t, wsDir, wantFile)
113113

114114
wantLintReportContent := "/workspace/source/src/index.ts: line 3, col 31, Warning - Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)\n\n1 problem"
115-
checkFileContent(t, wsDir, filepath.Join(pipelinectxt.LintReportsPath, "report.txt"), wantLintReportContent)
115+
checkFileContentContains(t, wsDir, filepath.Join(pipelinectxt.LintReportsPath, "report.txt"), wantLintReportContent)
116116
},
117117
},
118118
"fail pulling image if unsupported node version is specified": {

test/testdata/workspaces/javascript-sample-app-build-dir/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6+
"lint": "echo 'no linting'",
67
"build": "mkdir -p build && cp -r src build/",
78
"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",
89
"start": "node build/src/index.js"

test/testdata/workspaces/javascript-sample-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6+
"lint": "echo 'no linting'",
67
"build": "mkdir -p dist && cp -r src dist/",
78
"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",
89
"start": "node dist/src/index.js"

test/testdata/workspaces/typescript-sample-app-lint-error/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6+
"lint": "npx eslint src --ext=.js,.ts --format=compact --max-warnings=0",
67
"build": "tsc",
78
"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",
89
"start": "node dist/src/index.js"

0 commit comments

Comments
 (0)