diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 76b465a..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: ESLint - -on: - pull_request: - -jobs: - eslint: - name: Run eslint scanning - runs-on: ubuntu-latest - permissions: - contents: read - security-events: write - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install dependencies - run: npm ci - - - name: Run ESLint - run: npm run lint diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 45d41fc..d808d40 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -1,8 +1,13 @@ name: Build Project on: + push: + branches: ["main"] pull_request: +permissions: + pull-requests: read # allows SonarCloud to decorate PRs with analysis results + jobs: build: strategy: @@ -16,12 +21,14 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - - name: Check Node.js version - run: node -v - - - name: Check npm versions - run: npm -v + - name: Cache node_modules + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-${{ matrix.os }}-node-${{ matrix.node-version }}-${{ hashFiles('package-lock.json') }} + restore-keys: | + node_modules-${{ matrix.os }}-node-${{ matrix.node-version }} - name: Run clean install run: npm ci @@ -29,3 +36,46 @@ jobs: if: runner.os == 'Linux' - run: npm test if: runner.os != 'Linux' + + sonar: + name: Run eslint and sonar scanning + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Restore cached node_modules + uses: actions/cache@v4 + with: + path: node_modules + key: node_modules-ubuntu-latest-node-22.x-${{ hashFiles('package-lock.json') }} + restore-keys: | + node_modules-ubuntu-latest-node-22.x + - name: Run ESLint + run: npm run lint -- --format json --output-file eslint-results.json || true + + - name: Install Mocha reporters + run: npm install -d mocha-multi-reporters mocha-junit-reporter mocha-sonarqube-reporter + - name: create mocha config + run: | + echo '{ + "reporterEnabled": "spec, mocha-junit-reporter, mocha-sonarqube-reporter" + }' > config.json + - name: Run tests with coverage + run: xvfb-run -a npm test -- --coverage --coverage-output ./coverage --coverage-reporter lcovonly --reporter mocha-multi-reporters --reporter-options configFile=config.json + + - name: Analyze with SonarCloud + uses: SonarSource/sonarcloud-github-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: -Dsonar.projectKey=aditosoftware_vscode-logging + -Dsonar.organization=aditosoftware + -Dsonar.eslint.reportPaths=eslint-results.json + -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info diff --git a/.vscode-test.mjs b/.vscode-test.mjs index 5af0e70..a348b7c 100644 --- a/.vscode-test.mjs +++ b/.vscode-test.mjs @@ -4,7 +4,7 @@ export default defineConfig({ files: "out/test/**/*.test.js", version: "insiders", mocha: { - retries: 3, + retries: 5, parallel: false, }, }); diff --git a/README.md b/README.md index ee095dd..e33189e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # vscode-logging +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging) +[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=coverage)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging) +[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=aditosoftware_vscode-logging&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=aditosoftware_vscode-logging) + This is used to add a simple and easy to use logging to any VS Code extension. The key idea is that you do not need to call `vscode.window.showInformationMessage` (or similar methods) and do not need to write any additional logs, because this module will take care of everything. diff --git a/src/Logger.ts b/src/Logger.ts index 67940ae..e7ff011 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -20,8 +20,8 @@ export class Logger { * @param outputChannel - the output channel were all the messages should be written to */ private constructor( - private logger: winston.Logger, - private outputChannel: vscode.OutputChannel + private readonly logger: winston.Logger, + private readonly outputChannel: vscode.OutputChannel ) { this.logger = logger; this.outputChannel = outputChannel; @@ -262,7 +262,7 @@ class VSCodeOutputChannelTransport extends TransportStream { * @param opts - the options for the transport */ constructor( - private outputChannel: vscode.OutputChannel, + private readonly outputChannel: vscode.OutputChannel, opts?: TransportStreamOptions ) { super(opts);