From: Rubén Beltran del Río Date: Mon, 21 Sep 2020 13:14:32 +0000 (+0000) Subject: Merge branch 'rbdr-address-sonarqube-issues' into 'master' X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/commitdiff_plain/8e5bbf83935b23b635a6d6881cc344b535b9b956?hp=6d04afffcaa63ad9326db360bc3abedcedfd6c7e Merge branch 'rbdr-address-sonarqube-issues' into 'master' Integrate Sonarcloud See merge request rbdr/cologne!1 --- diff --git a/.gitignore b/.gitignore index 3bbc2f1..c2a8529 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ ## PROJECT::SPECIFIC .nyc_output +coverage node_modules +.scannerwork diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cc95c38..fe65211 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,18 +1,50 @@ +.only-default: &only-default + only: + - branches + - merge_requests + - tags + - refs + image: node:14 +variables: + SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache + stages: - lint - test + - quality before_script: - npm install +cache: + key: ${CI_COMMIT_REF_SLUG} + paths: + - node_modules/ + - .nyc_output/ + - .sonar/cache + lint: + <<: *only-default stage: lint script: - npm run lint test: + <<: *only-default stage: test script: - npm test + +quality: + <<: *only-default + stage: quality + needs: + - test + image: + name: sonarsource/sonar-scanner-cli:latest + entrypoint: [""] + script: + - npm run coverage + - sonar-scanner diff --git a/CHANGELOG.md b/CHANGELOG.md index b1e8999..c485e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.1] - 2020-09-20 +### Added +- Sonarcloud config for code quality + +### Changed +- Limits token size to 255 to avoid regex abuse +- Changes file test time to allow flushing stream in CI + ## [2.0.0] - 2020-09-20 ### Changed - CHANGELOG format is now using `Keep a Changelog` format. diff --git a/lib/formatters/token.js b/lib/formatters/token.js index 2ec3a17..05895fa 100644 --- a/lib/formatters/token.js +++ b/lib/formatters/token.js @@ -34,9 +34,9 @@ module.exports = class TokenFormatter { * @instance * @memberof Formatters.Token * @type RegExp - * @default /{{(.*)}}/g + * @default /{{(.{1,255}?)}}/g */ - this.replaceRule = /{{(.*?)}}/g; + this.replaceRule = /{{(.{1,255}?)}}/g; /** * Flag that specifies whether or not to use an isoDate when using diff --git a/lib/utilities.js b/lib/utilities.js index 1c930af..8bb226b 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -2,6 +2,37 @@ const internals = { kCircularString: '[Circular]', + kAnsiCodes: { + bold: '[1m', + italics: '[3m', + underline: '[4m', + inverse: '[7m', + strikethrough: '[9m', + bold_off: '[22m', + italics_off: '[23m', + underline_off: '[24m', + inverse_off: '[27m', + strikethrough_off: '[29m', + black: '[30m', + red: '[31m', + green: '[32m', + yellow: '[33m', + blue: '[34m', + magenta: '[35m', + cyan: '[36m', + white: '[37m', + default: '[39m', + black_bg: '[40m', + red_bg: '[41m', + green_bg: '[42m', + yellow_bg: '[43m', + blue_bg: '[44m', + magenta_bg: '[45m', + cyan_bg: '[46m', + white_bg: '[47m', + default_bg: '[49m', + reset: '[0m' + }, // Get High Res time depending on platform. Currently only supporting node. @@ -75,67 +106,7 @@ module.exports = { */ getAnsiCode(ansiString) { - switch (ansiString) { - case 'bold': - return '[1m'; - case 'italics': - return '[3m'; - case 'underline': - return '[4m'; - case 'inverse': - return '[7m'; - case 'strikethrough': - return '[9m'; - case 'bold_off': - return '[22m'; - case 'italics_off': - return '[23m'; - case 'underline_off': - return '[24m'; - case 'inverse_off': - return '[27m'; - case 'strikethrough_off': - return '[29m'; - case 'black': - return '[30m'; - case 'red': - return '[31m'; - case 'green': - return '[32m'; - case 'yellow': - return '[33m'; - case 'blue': - return '[34m'; - case 'magenta': - return '[35m'; - case 'cyan': - return '[36m'; - case 'white': - return '[37m'; - case 'default': - return '[39m'; - case 'black_bg': - return '[40m'; - case 'red_bg': - return '[41m'; - case 'green_bg': - return '[42m'; - case 'yellow_bg': - return '[43m'; - case 'blue_bg': - return '[44m'; - case 'magenta_bg': - return '[45m'; - case 'cyan_bg': - return '[46m'; - case 'white_bg': - return '[47m'; - case 'default_bg': - return '[49m'; - case 'reset': // for informative purpouses - default: - return '[0m'; - } + return internals.kAnsiCodes[ansiString] || internals.kAnsiCodes.reset; }, /** diff --git a/package-lock.json b/package-lock.json index 7641e25..8e31432 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cologne", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c6d4bdc..ab2feef 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "bugs": { "url": "https://gitlab.com/rbdr/cologne/issues" }, - "version": "2.0.0", + "version": "2.0.1", "devDependencies": { "@hapi/eslint-config-hapi": "^13.0.2", "@hapi/eslint-plugin-hapi": "^4.3.6", @@ -20,7 +20,8 @@ "scripts": { "document": "jsdoc2md lib/**/*.js > doc/README.md; tap -R markdown > doc/COVERAGE.md", "lint": "eslint .", - "test": "tap" + "test": "tap", + "coverage": "nyc report --reporter=text-lcov" }, "main": "./lib/cologne.js" } diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..08b778a --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,12 @@ +sonar.projectKey=rbdr_cologne +sonar.organization=rbdr + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +sonar.sources=. + +# Encoding of the source code. Default is default system encoding +sonar.sourceEncoding=UTF-8 + +# Coverage path +sonar.javascript.lcov.reportPaths=coverage/lcov.info +sonar.coverage.exclusions='test/**/*' diff --git a/test/cologne.js b/test/cologne.js index 3f06763..1fce740 100644 --- a/test/cologne.js +++ b/test/cologne.js @@ -23,7 +23,7 @@ const createDummyLogger = function () { const levelChecker = function (level) { - return (count, log) => (log._level === level ? ++count : count); + return (count, log) => (log._level === level ? count + 1 : count); }; @@ -42,74 +42,74 @@ const co = new Cologne({ ] }); -const logs = ['example1', null, undefined, 1, { example: true }]; +const exampleLogs = ['example1', null, undefined, 1, { example: true }]; /** * TEST: #log() */ -co.log(...logs); +co.log(...exampleLogs); // Calculate values -const valueCheck = dummyLoggerA.values.reduce((count, log) => (typeof log._cologneLog === 'string' ? ++count : count), 0); +const valueCheck = dummyLoggerA.values.reduce((count, log) => (typeof log._cologneLog === 'string' ? count + 1 : count), 0); let levelCheck = dummyLoggerA.values.reduce(levelChecker(6), 0); // Now check the values -Tap.equal(dummyLoggerA.values.length, logs.length, +Tap.equal(dummyLoggerA.values.length, exampleLogs.length, '#log() should send every argument to the loggers'); Tap.similar(dummyLoggerA.values, dummyLoggerB.values, '#log() should send the same arguments to all the loggers'); -Tap.equal(valueCheck, logs.length, +Tap.equal(valueCheck, exampleLogs.length, '#log() should send all objects in cologne log format'); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#log() should default to level 6'); /** * TEST: #debug() */ -co.debug(...logs); +co.debug(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(7), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#debug() should set to level 7'); /** * TEST: #info() */ -co.info(...logs); +co.info(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(6), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#info() should set to level 6'); /** * TEST: #notice() */ -co.notice(...logs); +co.notice(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(5), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#notice() should set to level 5'); /** * TEST: #warn() */ -co.warn(...logs); +co.warn(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(4), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#warn() should set to level 4'); /** * TEST: #error() */ -co.error(...logs); +co.error(...exampleLogs); levelCheck = dummyLoggerA.values.reduce(levelChecker(3), 0); -Tap.equal(levelCheck, logs.length, +Tap.equal(levelCheck, exampleLogs.length, '#error() should set to level 3'); /** @@ -156,7 +156,7 @@ co.removeLogger(dummyLoggerC); Tap.equal(co.loggers.length, 2, '#removeLogger() should do nothing if it can\'t find a logger'); -co.log(...logs); +co.log(...exampleLogs); co.removeLogger(dummyLoggerB); co.log(1); @@ -171,7 +171,7 @@ Tap.notEqual(dummyLoggerB.values.length, dummyLoggerA.values.length, */ co.addLogger(dummyLoggerC); -co.log(...logs); +co.log(...exampleLogs); -Tap.equal(dummyLoggerC.values.length, logs.length, +Tap.equal(dummyLoggerC.values.length, exampleLogs.length, '#addLogger() should add loggers after instance is live'); diff --git a/test/loggers/console.js b/test/loggers/console.js index 3358837..87dbc23 100644 --- a/test/loggers/console.js +++ b/test/loggers/console.js @@ -62,7 +62,7 @@ const logObjectB = { message: 'MessageTwo' }; -const logs = [logObjectA, logObjectB]; +const exampleLogs = [logObjectA, logObjectB]; const regularLogger = new ConsoleLogger({}); const overrideLogger = new ConsoleLogger({ @@ -86,38 +86,38 @@ Tap.equal(regularLogger.console, global.console, logObjectA._level = 5; logObjectB._level = 6; -overrideLogger.log(...logs); // should go to info +overrideLogger.log(...exampleLogs); // should go to info logObjectA._level = 4; logObjectB._level = 4; -overrideLogger.log(...logs); // should go to warn +overrideLogger.log(...exampleLogs); // should go to warn logObjectA._level = 1; logObjectB._level = 3; -overrideLogger.log(...logs); // should go to error +overrideLogger.log(...exampleLogs); // should go to error logObjectA._level = 0; logObjectB._level = 2; -overrideLogger.log(...logs); // should go to error +overrideLogger.log(...exampleLogs); // should go to error logObjectA._level = 7; logObjectB._level = 8; -overrideLogger.log(...logs); // should go to log +overrideLogger.log(...exampleLogs); // should go to log -Tap.equal(dummyConsole.values.log, logs.length, +Tap.equal(dummyConsole.values.log, exampleLogs.length, 'It should send debug messages to console\'s #log'); -Tap.equal(dummyConsole.values.info, logs.length, +Tap.equal(dummyConsole.values.info, exampleLogs.length, 'It should send info and notice messages to console\'s #info'); -Tap.equal(dummyConsole.values.warn, logs.length, +Tap.equal(dummyConsole.values.warn, exampleLogs.length, 'It should send warn messages to console\'s #warn'); -Tap.equal(dummyConsole.values.error, logs.length * 2, +Tap.equal(dummyConsole.values.error, exampleLogs.length * 2, 'It should send error messages to console\'s #error'); /** * TEST: #log() - with formatter */ -formattedLogger.log(...logs); // should go to log +formattedLogger.log(...exampleLogs); // should go to log -Tap.similar(dummyFormatter.values, logs, +Tap.similar(dummyFormatter.values, exampleLogs, 'If available, it should send the objects to the formatter'); diff --git a/test/loggers/file.js b/test/loggers/file.js index 5e73d82..d07b5af 100644 --- a/test/loggers/file.js +++ b/test/loggers/file.js @@ -76,7 +76,7 @@ setTimeout(() => { }); }); }); -}, 10); // allow for flush +}, 100); // allow for flush /** * TEST: #log() - formatter */ @@ -103,4 +103,4 @@ setTimeout(() => { }); }); }); -}, 10); +}, 100);