Skip to content

Commit

Permalink
build(1.3.0): static code analysis and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rondinif committed Jun 9, 2019
2 parents 2d3af4b + 70c36aa commit 1976dc3
Show file tree
Hide file tree
Showing 29 changed files with 5,331 additions and 1,606 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.scannerwork
.coveralls.yml
.eslint
_private
_config

Expand Down
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
// "eslint.enable": false,
"xo.enable": true,
"xo.format.enable": true,
"xo.options": {
"semicolon": true
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 1.2.1
# 1.3.0
- ci(sca): arranged for automated [static code analysis](https://sonarcloud.io/dashboard?id=rondinif%3Aphytojs-js)
- ci(xo): eslinted with xo

# 1.2.1 - 1.2.3
## Fixed inconsitent auto-generated references in umd
see diff in a1fac62c8757926c579f0882ded17aba3fcd7e45

Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# PhytoJS: @rondinif/phytojs
[![Travis build status](http://img.shields.io/travis/rondinif/phytojs/master.svg?style=flat-square)](https://travis-ci.org/rondinif/phytojs)
[![Travis build status](https://img.shields.io/travis/rondinif/phytojs/master.svg?style=flat-square)](https://travis-ci.org/rondinif/phytojs)
[![Coveralls](https://img.shields.io/coveralls/rondinif/phytojs.svg?style=flat-square)](https://coveralls.io/github/rondinif/phytojs)
[![NPM version](https://img.shields.io/npm/v/@rondinif/phytojs.svg?style=flat-square)](https://www.npmjs.org/package/@rondinif/phytojs)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Twitter Follow](https://img.shields.io/twitter/follow/rondinif.svg?style=social&label=Follow)](https://twitter.com/rondinif)


[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=rondinif:phytojs-js&metric=alert_status)](https://sonarcloud.io/dashboard?id=rondinif:phytojs-js)
[![Sonarcloud coverage](https://sonarcloud.io/api/project_badges/measure?project=rondinif:phytojs-js&metric=coverage)](https://sonarcloud.io/dashboard?id=rondinif:phytojs-js)
[![Sonarcloud sqale_index](https://sonarcloud.io/api/project_badges/measure?project=rondinif:phytojs-js&metric=sqale_index)](https://sonarcloud.io/dashboard?id=rondinif:phytojs-js)

[![Sonarcloud security_rating](https://sonarcloud.io/api/project_badges/measure?project=rondinif:phytojs-js&metric=security_rating)](https://sonarcloud.io/dashboard?id=rondinif:phytojs-js)
[![Sonarcloud sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=rondinif:phytojs-js&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=rondinif:phytojs-js)
[![Sonarcloud reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=rondinif:phytojs-js&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=rondinif:phytojs-js)

A modern javascript library to search about plants on open data
- The prefix [phyto-](https://en.wiktionary.org/wiki/phyto-) , comes from Ancient Greek φυτόν (phutón, “plant”), is used when something is **pertaining** to or derived from **plants**.
- [js](https://en.wiktionary.org/wiki/js) is the abbreviation of **javascript**.
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ module.exports = {
]
]
}
};
};
64 changes: 35 additions & 29 deletions esm/config.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
import dotenv from 'dotenv-flow';

dotenv.config();
/*
usage in programs:
/*
Usage in programs:
import { config } from './lib/config.mjs';
to check the effective configuration:
@see ../config.checher.mjs
WARNING: to avoid circular reference this module **MUST** not import moduled that consumes configuration, such as:
- <module-that-use-config-here>.mjs
- <module-that-use-config-here>.mjs
Coding Conventions: before each configuration a comment SHOULD be written; the comment also shows the names of the environment variables that can influence the effective configuration value. When present this comment MUST be updated also in the config.checker.mjs program.
*/

const DEFAULT_IS_UNDER_TEST = false;

const castToBoolen = (anyValue) => {
// console.log(`castToBoolen::anyValue: ${anyValue}`);
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`);
// if (typeof anyValue === "string") {
anyValue = anyValue.trim().toLowerCase();
// } else { console.log('branch never reached in tests'); }
switch (anyValue) {
case 'true':
return true;
case 'false':
return false;
default:
const value = parseInt(anyValue);
if (isNaN(value)) {
throw new TypeError(`{anyValue} is not acceptable value for boolean configurable options`);
}
console.log(`castToBoolen::value: ${value}`);
return value !== 0 ? true : false;
}
const castToBoolen = anyValue => {
// Console.log(`castToBoolen::anyValue: ${anyValue}`);
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`);
// if (typeof anyValue === "string") {
anyValue = anyValue.trim().toLowerCase();
// } else { console.log('branch never reached in tests'); }
switch (anyValue) {
case 'true': {
return true;
}

case 'false': {
return false;
}

default: {
const value = parseInt(anyValue, 10);
if (isNaN(value)) {
throw new TypeError('{anyValue} is not acceptable value for boolean configurable options');
}

console.log(`castToBoolen::value: ${value}`);
return value !== 0;
}
}
};

const config = {
/*
the test features are enabed
/*
The test features are enabed
affected by .env IS_FILESTORE_WRITING_ENABLED
*/
isUnderTest: function () {
return process.env.IS_UNDER_TEST ?
castToBoolen(process.env.IS_UNDER_TEST) :
DEFAULT_IS_UNDER_TEST;
}
isUnderTest() {
return process.env.IS_UNDER_TEST ?
castToBoolen(process.env.IS_UNDER_TEST) :
DEFAULT_IS_UNDER_TEST;
}
};

export { DEFAULT_IS_UNDER_TEST, config };
129 changes: 67 additions & 62 deletions esm/log.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,79 @@
// import { logFactory } from './log.mjs';
// Import { logFactory } from './log.mjs';

const logFactory = {
makeTraceFunction: (config) => {
return (...args) => {
if (config.isLogVerbose()) {
console.trace(...args);
}
}},
makeDebugFunction: (config) => {
return (...args) => {
if (config.isLogVerbose()) {
console.debug(...args);
}
}},
makeInfoFunction: (config) => {
return (...args) => {
if (!config.isLogSilent()) {
console.info(...args);
}
}},
makeWarnFunction: (config) => {
return (...args) => {
if (!config.isLogSilent()) {
console.warn(...args);
}
}},
makeErrorFunction: (config) => {
return (...args) => {
console.error(...args);
}}
};
makeTraceFunction: config => {
return (...args) => {
if (config.isLogVerbose()) {
console.trace(...args);
}
};
},
makeDebugFunction: config => {
return (...args) => {
if (config.isLogVerbose()) {
console.debug(...args);
}
};
},
makeInfoFunction: config => {
return (...args) => {
if (!config.isLogSilent()) {
console.info(...args);
}
};
},
makeWarnFunction: config => {
return (...args) => {
if (!config.isLogSilent()) {
console.warn(...args);
}
};
},
makeErrorFunction: () => {
return (...args) => {
console.error(...args);
};
}
};

class Log {
constructor(config) {
if ( config.isLogVerbose() && config.isLogSilent() ) {
throw new Error(`log misconfiguration : isLogVerbose:${config.isLogVerbose()} && isLogSilent:${config.isLogSilent()}`);
}
this._trace = logFactory.makeTraceFunction(config);
this._debug = logFactory.makeDebugFunction(config);
this._info = logFactory.makeInfoFunction(config);
this._warn = logFactory.makeWarnFunction(config);
this._error = logFactory.makeErrorFunction(config);
constructor(config) {
if (config.isLogVerbose() && config.isLogSilent()) {
throw new Error(`log misconfiguration : isLogVerbose:${config.isLogVerbose()} && isLogSilent:${config.isLogSilent()}`);
}

this._config = config;
}

trace(...args) {
return this._trace(...args);
}
this._trace = logFactory.makeTraceFunction(config);
this._debug = logFactory.makeDebugFunction(config);
this._info = logFactory.makeInfoFunction(config);
this._warn = logFactory.makeWarnFunction(config);
this._error = logFactory.makeErrorFunction(config);

debug(...args) {
return this._debug(...args);
}

info(...args) {
return this._info(...args);
}
this._config = config;
}

warn(...args) {
return this._warn(...args);
}

error(...args) {
return this._error(...args);
}
trace(...args) {
return this._trace(...args);
}

getLogConfig(...args) {
return this._config;
}
debug(...args) {
return this._debug(...args);
}

info(...args) {
return this._info(...args);
}

warn(...args) {
return this._warn(...args);
}

error(...args) {
return this._error(...args);
}

getLogConfig() {
return this._config;
}
}

export { Log };
78 changes: 42 additions & 36 deletions esm/logconfig.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
import dotenv from 'dotenv-flow';

dotenv.config();
/*
usage in programs:
/*
Usage in programs:
import { config } from './lib/config.mjs';
to check the effective configuration:
@see ../config.checher.mjs
WARNING: to avoid circular reference this module **MUST** not import moduled that consumes configuration, such as:
- <module-that-use-config-here>.mjs
- <module-that-use-config-here>.mjs
Coding Conventions: before each configuration a comment SHOULD be written; the comment also shows the names of the environment variables that can influence the effective configuration value. When present this comment MUST be updated also in the config.checker.mjs program.
*/

const DEFAULT_IS_LOG_VERBOSE = false;
const DEFAULT_IS_LOG_SILENT = true;

const castToBoolen = (anyValue) => {
// console.log(`castToBoolen::anyValue: ${anyValue}`);
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`);
// if (typeof anyValue === "string") {
anyValue = anyValue.trim().toLowerCase();
// } else { console.log('branch never reached in tests'); }
switch (anyValue) {
case 'true':
return true;
case 'false':
return false;
default:
const value = parseInt(anyValue);
if (isNaN(value)) {
throw new TypeError(`{anyValue} is not acceptable value for boolean configurable options`);
}
console.log(`castToBoolen::value: ${value}`);
return value !== 0 ? true : false;
}
const castToBoolen = anyValue => {
// Console.log(`castToBoolen::anyValue: ${anyValue}`);
// console.log(`castToBoolen::anyValue:typeof: ${typeof anyValue}`);
// if (typeof anyValue === "string") {
anyValue = anyValue.trim().toLowerCase();
// } else { console.log('branch never reached in tests'); }
switch (anyValue) {
case 'true': {
return true;
}

case 'false': {
return false;
}

default: {
const value = parseInt(anyValue, 10);
if (isNaN(value)) {
throw new TypeError('{anyValue} is not acceptable value for boolean configurable options');
}

console.log(`castToBoolen::value: ${value}`);
return value !== 0;
}
}
};

const logconfig = {
/*
the log is verbose enabed
/*
The log is verbose enabed
affected by .env IS_LOG_VERBOSE
*/
isLogVerbose: function () {
return process.env.IS_LOG_VERBOSE ?
castToBoolen(process.env.IS_LOG_VERBOSE) :
DEFAULT_IS_LOG_VERBOSE;
},
/*
the log is verbose enabed
isLogVerbose() {
return process.env.IS_LOG_VERBOSE ?
castToBoolen(process.env.IS_LOG_VERBOSE) :
DEFAULT_IS_LOG_VERBOSE;
},
/*
The log is verbose enabed
affected by .env IS_LOG_VERBOSE
*/
isLogSilent: function () {
return process.env.IS_LOG_SILENT ?
castToBoolen(process.env.IS_LOG_SILENT) :
DEFAULT_IS_LOG_SILENT;
}
isLogSilent() {
return process.env.IS_LOG_SILENT ?
castToBoolen(process.env.IS_LOG_SILENT) :
DEFAULT_IS_LOG_SILENT;
}
};

export { DEFAULT_IS_LOG_SILENT, DEFAULT_IS_LOG_VERBOSE, logconfig };
Loading

0 comments on commit 1976dc3

Please sign in to comment.