This ESLint plugin enforces the no-function-without-logging rule:
Every function code block should contain a logging statement ( call to Log.debug), with the first argument having at least its filename/classname and function name, seperated by a colon: Log.debug('foo:bar').
In addition to debug, the following options are also possible: trace, warning, info, error.
| ❌ Incorrect | ✅ Correct |
function functionName(){} |
function functionName(){
Log.trace('file:functionName');
} |
const functionName = () => {} |
const functionName = () => {
Log.debug('file:functionName');
} |
static function functionName(){} |
static function functionName(){
Log.trace('file:functionName');
} |
class ClassName {
functionName(){}
} |
class ClassName {
functionName(){
Log.trace('ClassName:functionName');
}
} |
class ClassName {
functionName = () => {}
} |
class ClassName {
functionName = () => {
Log.debug('ClassName:functionName');
}
} |
function functionName(){
Log.debug('file')
} |
function functionName(){
Log.debug('file:functionName')
} |
function functionName(){
Log.debug('functionName')
} |
function functionName(){
Log.debug('file:functionName')
} |
const functionName = () => {
Log.debug()
} |
const functionName = () => {
Log.debug('file:functionName')
} |
Logging statement can include multiple arguments:
function functionName(){
Log.debug('file:functionName', 1)
}Logging statement can have extended text:
function functionName(){
Log.debug('file:functionName with extra text')
}Lambda function with body does not need logging statement:
const functionName = () => otherFunction()Component declaration does not need logging statement:
const Component = () => {}Component level logging only includes component name:
const Component = () => {
Log.debug('Component')
}Constructors do not need logging:
class ClassName {
constructor(){}
}Getter and setter functions do not need logging:
class ClassName {
_value: number
get value(){
return this.value
}
set value(value: nuber){
this._value = value
}
}Setter like functions (class method definition starting with set[A-Z] returning void) do not need logging:
class ClassName {
_value: number
setValue(value: nuber){
this._value = value
}
}This ESLint rule ensures that every call to i18n.t(...) in the codebase has a corresponding key in all translation files. A translation file is defined as an input file for the npm package i18n-js (https://www.npmjs.com/package/i18n-js).
Translation file (nl.json):
{
'Hello world!': "Hallo wereld!"
}
| ❌ Incorrect | ✅ Correct |
i18n.t('Missing translation key') |
i18n.t('Hello world') |
To configure the ESLint rule, specify the relative paths of the translation files in an array within the ESLint configuration:
...
rules: {
'observation/no-missing-translations': [
'error',
{
translationFiles: [
'src/app/translations/locales/en.json',
'src/app/translations/locales/nl.json'
],
}
]
}
...
- run
tscin the working folder, this creates the javascript files that will be run by ESLint - Get your changes to the
developbranch
Run the command:
yarn install -D observation/eslint-rulesYou need to have read access to the observation/eslint-rules repo to do this. If an automated process needs this rule set, you can set up github deploy keys.