From 41b139f843bd7f148f32d6751876a899bcb0c6a3 Mon Sep 17 00:00:00 2001 From: Ourchitecture <97544811+ourchitectureio@users.noreply.github.com> Date: Wed, 20 Sep 2023 18:28:24 -0400 Subject: [PATCH] fix: markdown linting Signed-off-by: Ourchitecture <97544811+ourchitectureio@users.noreply.github.com> --- .markdownlint-cli2.yaml | 6 +++--- src/libraries/node/env.js | 18 +++++++++++++++++- src/libraries/node/log.js | 5 ++--- src/tasks/node/check/formatting.js | 6 ++++-- src/tasks/node/check/spelling.js | 5 ++++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.markdownlint-cli2.yaml b/.markdownlint-cli2.yaml index 9360b5e..95f5413 100644 --- a/.markdownlint-cli2.yaml +++ b/.markdownlint-cli2.yaml @@ -1,11 +1,11 @@ globs: - '**/*.md' ignores: - - '#node_modules' + - '**/node_modules' config: - list-marker-space: + MD030: ul_multi: 3 ul_single: 3 - ul-indent: + MD007: indent: 4 diff --git a/src/libraries/node/env.js b/src/libraries/node/env.js index c282b07..bb2241b 100644 --- a/src/libraries/node/env.js +++ b/src/libraries/node/env.js @@ -14,8 +14,9 @@ const get = (key) => { const getAsBoolean = (key) => { if (hasKey(key) && process.env[key]) { - return JSON.parse(process.env[key]) + return JSON.parse(process.env[key]) ? true : false } + return false } @@ -28,6 +29,18 @@ const isContinuousIntegrationMode = () => { return getAsBoolean('CI') === true } +const isDebugMode = () => { + return getAsBoolean('DEBUG') === true +} + +const isProductionMode = () => { + return get('NODE_ENV') === 'production' +} + +const isNonProductionMode = () => { + return !isProductionMode() +} + module.exports = { assertRequired, get, @@ -35,4 +48,7 @@ module.exports = { getRequired, hasKey, isContinuousIntegrationMode, + isDebugMode, + isNonProductionMode, + isProductionMode, } diff --git a/src/libraries/node/log.js b/src/libraries/node/log.js index 59913c3..04f2e4f 100644 --- a/src/libraries/node/log.js +++ b/src/libraries/node/log.js @@ -1,5 +1,4 @@ const winston = require('winston') -const path = require('path') const env = require('./env') const host = require('./host') @@ -54,7 +53,7 @@ const registerLoggerSingleton = (scriptFilePath) => { } logger = winston.createLogger({ - level: process.env['DEBUG'] ? 'debug' : 'info', + level: env.isDebugMode() ? 'debug' : 'info', format: winston.format.combine( winston.format.timestamp(), winston.format.json() @@ -73,7 +72,7 @@ const registerLoggerSingleton = (scriptFilePath) => { ], }) - if (env.get('NODE_ENV') !== 'production') { + if (env.isNonProductionMode()) { logger.add( new winston.transports.Console({ format: winston.format.simple(), diff --git a/src/tasks/node/check/formatting.js b/src/tasks/node/check/formatting.js index 23fbad6..3f7b98c 100644 --- a/src/tasks/node/check/formatting.js +++ b/src/tasks/node/check/formatting.js @@ -1,4 +1,5 @@ const cmd = require('../../../libraries/node/cmd') +const env = require('../../../libraries/node/env') const host = require('../../../libraries/node/host') const log = require('../../../libraries/node/log') @@ -51,6 +52,9 @@ const checkFormattingWithPrettier = async (scriptFilePath) => { const commandArgv = [ 'prettier', '--check', + ...(env.isDebugMode() + ? ['--log-level', 'debug'] + : ['--log-level', 'log']), '--config', host.getRelativeToRootPath('./.prettierrc.yaml'), '--ignore-path', @@ -66,8 +70,6 @@ const checkFormattingWithPrettier = async (scriptFilePath) => { const checkFormattingWithMarkdownlint = async (scriptFilePath) => { const commandArgv = [ 'markdownlint-cli2', - '**/*.md', - '#node_modules', '--config', host.getRelativeToRootPath('./.markdownlint-cli2.yaml'), ] diff --git a/src/tasks/node/check/spelling.js b/src/tasks/node/check/spelling.js index 8e7a6ac..a4c6283 100644 --- a/src/tasks/node/check/spelling.js +++ b/src/tasks/node/check/spelling.js @@ -1,4 +1,5 @@ const cmd = require('../../../libraries/node/cmd') +const env = require('../../../libraries/node/env') const host = require('../../../libraries/node/host') const log = require('../../../libraries/node/log') @@ -17,7 +18,9 @@ const main = async (scriptFilePath) => { 'cspell', host.getRelativeToRootPath('./'), '--gitignore', - '--no-progress', + ...(env.isDebugMode() + ? ['--show-context', '--show-suggestions'] + : ['--no-progress']), '--config', host.getRelativeToRootPath('./cspell.config.yaml'), '--locale',