## PROJECT::SPECIFIC
.nyc_output
+coverage
node_modules
+.scannerwork
+.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
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.
* @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
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.
*/
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;
},
/**
{
"name": "cologne",
- "version": "2.0.0",
+ "version": "2.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"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",
"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"
}
--- /dev/null
+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/**/*'
const levelChecker = function (level) {
- return (count, log) => (log._level === level ? ++count : count);
+ return (count, log) => (log._level === level ? count + 1 : count);
};
]
});
-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');
/**
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);
*/
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');
message: 'MessageTwo'
};
-const logs = [logObjectA, logObjectB];
+const exampleLogs = [logObjectA, logObjectB];
const regularLogger = new ConsoleLogger({});
const overrideLogger = new ConsoleLogger({
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');
});
});
});
-}, 10); // allow for flush
+}, 100); // allow for flush
/**
* TEST: #log() - formatter
*/
});
});
});
-}, 10);
+}, 100);