Skip to content

Commit bad68d9

Browse files
authored
feat(cli): display warning log message when it can not parse config (#893)
fix #662
1 parent 09a0c86 commit bad68d9

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

dist/cli/htmlhint.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/htmlhint.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ function getConfig(
407407
configPath: configPath,
408408
})
409409
} catch (e) {
410-
// ignore
410+
console.log(' Config could not be parsed: %s', chalk.yellow(configPath))
411+
console.log('')
411412
}
412413

413414
return ruleset

test/conf/invalid-json.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"attr-lowercase": false,
3+
}

test/conf/valid-json.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"attr-lowercase": false
3+
}

test/executable.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,37 @@ describe('Executable', () => {
3535
})
3636
})
3737
})
38+
39+
describe('Config', () => {
40+
it('should not display warning log message when it can parse config file', (done) => {
41+
ChildProcess.exec(
42+
[
43+
'node',
44+
path.resolve(__dirname, '../bin/htmlhint'),
45+
path.resolve(__dirname, './html/executable.html'),
46+
'--config',
47+
path.resolve(__dirname, './conf/valid-json.conf'),
48+
].join(' '),
49+
(error, stdout) => {
50+
expect(stdout).toContain('Config loaded:')
51+
done()
52+
}
53+
)
54+
})
55+
56+
it('should display warning log message when it can not parse config file', (done) => {
57+
ChildProcess.exec(
58+
[
59+
'node',
60+
path.resolve(__dirname, '../bin/htmlhint'),
61+
path.resolve(__dirname, './html/executable.html'),
62+
'--config',
63+
path.resolve(__dirname, './conf/invalid-json.conf'),
64+
].join(' '),
65+
(error, stdout) => {
66+
expect(stdout).toContain('Config could not be parsed:')
67+
done()
68+
}
69+
)
70+
})
71+
})

0 commit comments

Comments
 (0)