Skip to content

Commit

Permalink
feat(cli): 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 Sep 6, 2022
1 parent 09a0c86 commit bad68d9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dist/cli/htmlhint.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ function getConfig(
configPath: configPath,
})
} catch (e) {
// ignore
console.log(' Config could not be parsed: %s', chalk.yellow(configPath))
console.log('')
}

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
}
34 changes: 34 additions & 0 deletions test/executable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,37 @@ describe('Executable', () => {
})
})
})

describe('Config', () => {
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).toContain('Config loaded:')
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).toContain('Config could not be parsed:')
done()
}
)
})
})

0 comments on commit bad68d9

Please sign in to comment.