Skip to content

Commit

Permalink
add: remove finding from log and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TOsmanov committed Dec 5, 2024
1 parent cae1534 commit a6b6b05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
14 changes: 7 additions & 7 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,17 @@ function createConfig (mode = 'full', source = '', project = '', configPath = ''
const content = []
json.globs = listOfFiles
content.push('// @ts-check\n\n"use strict";\n\n')
if (json.config.validateIntLinksConf) {
if (json.config['validate-internal-links']) {
content.push("const path = require('path')")
content.push("const repoName = require('git-repo-name')")
}

content.push(`const json = ${JSON.stringify(json, null, 4)}`)

if (json.config.validateIntLinksConf) {
if (json.config['validate-internal-links']) {
content.push('json.config[\'validate-internal-links\'].project = repoName.sync({cwd: __dirname})')
content.push('json.config[\'validate-internal-links\'].workingDir = __dirname')
}
if (includesMap) {
const includesMapPath = path.relative('./', includesMap)
content.push(`json.config['validate-internal-links'].includesMap = "./${includesMapPath}"`)
}

content.push('\n\nmodule.exports = json')

Expand All @@ -282,7 +278,11 @@ function createConfig (mode = 'full', source = '', project = '', configPath = ''
const data = JSON.parse(fs.readFileSync('package.json'))
data.dependencies['git-repo-name'] = '^1.0.1'
data.dependencies['markdownlint-rules-foliant'] = 'latest'
fs.writeFileSync('package.json', JSON.stringify(data, null, 2))
try {
fs.writeFileSync('package.json', JSON.stringify(data, null, 2))
} catch (error) {
console.log(error)
}
} else {
// write package.json
const packageJSONforCJS = {
Expand Down
21 changes: 21 additions & 0 deletions linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ function writeLog (logFile) {
return (isWin === true) ? `>> ${logFile} 2>&1` : `2>&1 | tee ${logFile}`
}

function removeFinding(logFile) {

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (macos-latest, 18.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (macos-latest, 19.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (macos-latest, 20.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (ubuntu-latest, 18.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (ubuntu-latest, 19.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (ubuntu-latest, 20.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (windows-latest, 18.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (windows-latest, 19.x)

Missing space before function parentheses

Check failure on line 192 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (windows-latest, 20.x)

Missing space before function parentheses
const regexFinding = /^(Finding: ).+/gm
try {
const text = readFileSync(logFile).toString('utf-8').split(/\r?\n/)
const lines = []
text.forEach((line) => {
if (!line.match(regexFinding)) {
lines.push(line)
} else {
console.log(line)
}
})
fs.writeFileSync(logFile, lines.join('\r\n'))
} catch(error) {

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (macos-latest, 18.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (macos-latest, 19.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (macos-latest, 20.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (ubuntu-latest, 18.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (ubuntu-latest, 19.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (ubuntu-latest, 20.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (windows-latest, 18.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (windows-latest, 19.x)

Expected space(s) after "catch"

Check failure on line 205 in linter.js

View workflow job for this annotation

GitHub Actions / buildAndTest (windows-latest, 20.x)

Expected space(s) after "catch"
console.log(error)
}
}

const commandsGen = function (src = defaultSrc, configPath = '', project = '',
markdownlintMode = 'slim', foliantConfig = defaultFoliantConfig,
nodeModules = '', workinDir = '', isFix = false, debug = false, format = '') {
Expand Down Expand Up @@ -315,6 +333,9 @@ function checkExitCode (allowfailure) {
}

function afterLint (verbose = false, clearConfig = false, allowFailure = false, debug = false, format = '') {
if (format === 'cjs') {
removeFinding(path.resolve(cwd, markdownLintLog))
}
printLintResults(verbose)
clearConfigFile(clearConfig, format)
if (!debug) {
Expand Down

0 comments on commit a6b6b05

Please sign in to comment.