Skip to content

Commit

Permalink
Merge PR #12 from 'nodech/ts-lint'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 31, 2023
2 parents e9f5da8 + 8407152 commit 5ee9ec6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ jobs:
node-version: 20.x

- name: Install tools
run: npm install --location=global bslint
run: npm install --location=global bslint typescript

- name: Install dependencies
run: npm install

- name: Lint
run: npm run lint

- name: Lint types
run: npm run lint-types

test:
name: Test
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function promisify(func) {
return function(...args) {
return new Promise((resolve, reject) => {
args.push(wrap(resolve, reject));
// @ts-ignore
func.call(this, ...args);
});
};
Expand Down Expand Up @@ -33,3 +34,4 @@ exports.rename = promisify(fs.rename);
exports.readdir = promisify(fs.readdir);
exports.stat = promisify(fs.stat);
exports.unlink = promisify(fs.unlink);
exports.unsupported = false;
41 changes: 19 additions & 22 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ const assert = require('bsert');
const format = require('./format');
const fs = require('./fs');

/**
* @typedef {Object} LoggerOptions
* @property {String} [level=none]
* @property {Boolean} [colors]
* @property {Boolean} [console]
* @property {String} [filename]
* @property {Number} [maxFileSize]
* @property {Number} [maxFiles]
*/

/**
* Logger
*/
Expand All @@ -19,9 +29,7 @@ class Logger {
/**
* Create a logger.
* @constructor
* @param {(String|Object)?} options/level
* @param {String?} options.level
* @param {Boolean} [options.colors=true]
* @param {(String|LoggerOptions)} [options]
*/

constructor(options) {
Expand Down Expand Up @@ -317,18 +325,17 @@ class Logger {

/**
* Set or reset the log level.
* @param {String} level
* @param {String} levelName
*/

setLevel(name) {
const level = Logger.levels[name.toUpperCase()];
setLevel(levelName) {
const level = Logger.levels[levelName.toUpperCase()];
assert(level != null, 'Invalid log level.');
this.level = level;
}

/**
* Output a log to the `error` log level.
* @param {String|Object|Error} err
* @param {...Object} args
*/

Expand All @@ -348,7 +355,6 @@ class Logger {

/**
* Output a log to the `warning` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -368,7 +374,6 @@ class Logger {

/**
* Output a log to the `info` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -388,7 +393,6 @@ class Logger {

/**
* Output a log to the `debug` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -408,7 +412,6 @@ class Logger {

/**
* Output a log to the `spam` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -429,7 +432,7 @@ class Logger {
/**
* Output a log to the desired log level.
* Note that this bypasses the level check.
* @param {String} level
* @param {Number} level
* @param {String|null} module
* @param {Object[]} args
*/
Expand Down Expand Up @@ -464,7 +467,7 @@ class Logger {

/**
* Write log to the console.
* @param {String} level
* @param {Number} level
* @param {String|null} module
* @param {Object[]} args
*/
Expand Down Expand Up @@ -525,7 +528,7 @@ class Logger {

/**
* Write a string to the output stream (usually a file).
* @param {String} level
* @param {Number} level
* @param {String|null} module
* @param {Object[]} args
*/
Expand Down Expand Up @@ -564,7 +567,6 @@ class Logger {
/**
* Helper to parse an error into a nicer
* format. Call's `log` internally.
* @private
* @param {Number} level
* @param {String|null} module
* @param {Error} err
Expand Down Expand Up @@ -689,7 +691,7 @@ class LoggerContext {

/**
* Set or reset the log level.
* @param {String} level
* @param {String} name
*/

setLevel(name) {
Expand All @@ -698,7 +700,6 @@ class LoggerContext {

/**
* Output a log to the `error` log level.
* @param {String|Object|Error} err
* @param {...Object} args
*/

Expand All @@ -718,7 +719,6 @@ class LoggerContext {

/**
* Output a log to the `warning` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -738,7 +738,6 @@ class LoggerContext {

/**
* Output a log to the `info` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -758,7 +757,6 @@ class LoggerContext {

/**
* Output a log to the `debug` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -778,7 +776,6 @@ class LoggerContext {

/**
* Output a log to the `spam` log level.
* @param {String|Object} obj
* @param {...Object} args
*/

Expand All @@ -799,7 +796,7 @@ class LoggerContext {
/**
* Output a log to the desired log level.
* Note that this bypasses the level check.
* @param {String} level
* @param {Number} level
* @param {Object[]} args
*/

Expand Down
9 changes: 8 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
"main": "./lib/blgr.js",
"scripts": {
"lint": "eslint lib/",
"lint-types": "tsc -p .",
"test": "bmocha --reporter spec test/*-test.js"
},
"dependencies": {
"bsert": "~0.0.12"
},
"devDependencies": {
"bmocha": "^2.1.8"
"bmocha": "^2.1.8",
"bts-type-deps": "^0.0.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"include": [
"lib/**/*.js"
],
"compilerOptions": {
"rootDir": ".",
"target": "ES2020",
"lib": [
"ES2020"
],

"noEmit": true,

"allowJs": true,
"checkJs": true,
"maxNodeModuleJsDepth": 10,

"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,

"stripInternal": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": false,

"typeRoots": [
"node_modules/bts-type-deps/types"
]
}
}

0 comments on commit 5ee9ec6

Please sign in to comment.