Skip to content

Commit

Permalink
feat: display warning log message when it can not parse config
Browse files Browse the repository at this point in the history
  • Loading branch information
is2ei committed Jan 30, 2022
1 parent 200e2e5 commit 52ca8c9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dist/cli/htmlhint.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function getConfig(
configPath: configPath,
})
} catch (e) {
// ignore
console.log(chalk.yellow(`Could not parse config file (${configPath}).`))
}

return ruleset
Expand Down
3 changes: 3 additions & 0 deletions test/conf/invalid-json.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"attr-lowercase": false,
}
3 changes: 3 additions & 0 deletions test/conf/valid-json.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"attr-lowercase": false
}
42 changes: 42 additions & 0 deletions test/executable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,46 @@ describe('Executable', () => {
expect(stdoutEnd || processEnd).toBe(false)
})
})

it('should not display warning log message when it can parse config file', (done) => {
ChildProcess.exec(
[
'node',
path.resolve(__dirname, '../bin/htmlhint'),
path.resolve(__dirname, './html/executable.html'),
'--config',
path.resolve(__dirname, './conf/valid-json.conf'),
].join(' '),
(error, stdout) => {
expect(stdout).not.to.contain(
`Could not parse config file (${path.resolve(
__dirname,
'./conf/invalid-json.conf'
)}).`
)
done()
}
)
})

it('should display warning log message when it can not parse config file', (done) => {
ChildProcess.exec(
[
'node',
path.resolve(__dirname, '../bin/htmlhint'),
path.resolve(__dirname, './html/executable.html'),
'--config',
path.resolve(__dirname, './conf/invalid-json.conf'),
].join(' '),
(error, stdout) => {
expect(stdout).to.contain(
`Could not parse config file (${path.resolve(
__dirname,
'./conf/invalid-json.conf'
)}).`
)
done()
}
)
})
})

0 comments on commit 52ca8c9

Please sign in to comment.