diff --git a/README.md b/README.md index e93f0a864a505e2a5a8560eaa934d25a6e5ca41e..4009b9e23f2f1ecdf7372c27d3a4c88b9b35ea7b 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,8 @@ variables: ### `node-lint` job -The Node template features a job `node-lint` that performs Node.js source code **lint**. This job is **disabled by default**. It can be activated by setting `NODE_LINT_ENABLED` +The Node template features a `node-lint` job that performs a code analysis with [ESLint](https://eslint.org/). +This job is **disabled by default**. It can be activated by setting `NODE_LINT_ENABLED`. It is bound to the `build` stage, and uses the following variable: @@ -99,7 +100,18 @@ It is bound to the `build` stage, and uses the following variable: | `lint-enabled` / `NODE_LINT_ENABLED` | Set to `true` to enable lint analysis | _none_ (disabled) | | `lint-args` / `NODE_LINT_ARGS` | npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments to execute the lint analysis <br/> yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments to execute the lint analysis <br/> pnpm [run script](https://pnpm.io/cli/run) arguments to execute the lint analysis | `run lint` | -The job generates a lint report that you will find here: `NODE_PROJECT_DIR/reports/node-lint.xslint.json`. +In addition to a textual report in the console, this job produces the following reports, kept for one day: + +| Report | Format | Usage | +|-------------------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| +| `$NODE_PROJECT_DIR/reports/node-lint.gitlab.json` | [GitLab](https://docs.gitlab.com/ee/ci/testing/code_quality.html#eslint) | [GitLab integration](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscodequality) | +| `$NODE_PROJECT_DIR/reports/node-lint.xslint.json` | JSON ESLint | [SonarQube integration](https://docs.sonarqube.org/latest/analysis/external-issues/) | + + + +| Report | Format | Usage | +| ------------------------------------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `$NODE_PROJECT_DIR/reports/npm-audit.native.json` | [JSON](https://docs.npmjs.com/cli/v9/commands/npm-audit#json) | [DefectDojo integration](https://documentation.defectdojo.com/integrations/parsers/#npm-audit)<br/>_This report is generated only if DefectDojo template is detected, if needed, you can force it with `$DEFECTDOJO_NPMAUDIT_REPORTS`_ | ### `node-build` job diff --git a/kicker.json b/kicker.json index fe6d12dbc5bfbf832a72c3155a0b172ffceadb01..b3cd5df508dfaa992c42eb60bff8cade702ce4a0 100644 --- a/kicker.json +++ b/kicker.json @@ -77,7 +77,7 @@ { "id": "node-lint", "name": "node lint", - "description": "node lint analysis", + "description": "code analysis with [ESLint](https://eslint.org/)", "enable_with": "NODE_LINT_ENABLED", "variables": [ { diff --git a/templates/gitlab-ci-node.yml b/templates/gitlab-ci-node.yml index 92c5e7d4ee6169f46262a323403c7f1cdea9504f..9cae13d4d3b2a364889c8c8a05e4c9b195df4c4a 100644 --- a/templates/gitlab-ci-node.yml +++ b/templates/gitlab-ci-node.yml @@ -539,16 +539,6 @@ stages: fi } - function sonar_lint_report() { - if [[ "$SONAR_HOST_URL" ]] || [[ "$SONAR_URL" ]] - then - mkdir -p -m 777 reports - # generate eslint report in json for SonarQube - # shellcheck disable=SC2086 - $NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json - fi - } - function configure_publish() { # get package scope+name, and target registry url pkg_fullname=$(node -pe "require('./package.json').name") @@ -689,16 +679,35 @@ node-lint: extends: .node-base stage: build script: - # generate lint report for sonar - - sonar_lint_report || true - # display lint result for console - - $NODE_MANAGER $NODE_LINT_ARGS + - mkdir -p -m 777 reports + # maybe generate ESLint report for SonarQube + - | + if [[ "$SONAR_HOST_URL" ]] || [[ "$SONAR_URL" ]] + then + # generate eslint report for SonarQube + # shellcheck disable=SC2086 + log_info "SonarQube detedted: producing ESLint JSON report..." + $NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json || true + fi + # maybe add eslint-formatter-gitlab + - | + if ! $NODE_MANAGER list | grep eslint-formatter-gitlab > /dev/null + then + log_info "Adding eslint-formatter-gitlab to produce ESLint GitLab report..." + $NODE_MANAGER add eslint-formatter-gitlab + fi + # run ESLint with console output and GitLab report + # shellcheck disable=SC2086 + - ESLINT_CODE_QUALITY_REPORT=reports/node-lint.gitlab.json $NODE_MANAGER $NODE_LINT_ARGS -- --format=gitlab artifacts: when: always # store artifact even if test Failed name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" - paths: - - $NODE_PROJECT_DIR/reports/node-lint.xslint.json expire_in: 1 day + paths: + - $NODE_PROJECT_DIR/reports/node-lint.* + reports: + codequality: + - $NODE_PROJECT_DIR/reports/node-lint.gitlab.json rules: # exclude if $NODE_LINT_ENABLED unset - if: '$NODE_LINT_ENABLED != "true"'