11import type { Issues } from '#types'
2- import { fileExists , filesMustHaveContent } from '#common'
2+ import { fileExists , fileMustHaveName , filesMustHaveContent } from '#common'
33import * as yaml from 'std/yaml'
44import { execa } from 'execa'
55
66export const issues : Issues = async function * issues ( ) {
77 // Check that there is only one configuration file.
88 {
99 // https://lefthook.dev/configuration/index.html#config-file-name
10+ yield * fileMustHaveName ( {
11+ '.lefthook.yaml' : [
12+ '.lefthook.yml' ,
13+ 'lefthook.yaml' ,
14+ 'lefthook.yml' ,
15+ ] ,
16+ } )
17+
1018 yield * filesMustHaveContent ( {
11- 'lefthook.yml' : null ,
12- '.lefthook.yml' : null ,
13- 'lefthook.yaml' : null ,
14- '.lefthook.yaml' : `assert_lefthook_installed: true` ,
15- 'lefthook.toml' : null ,
1619 '.lefthook.toml' : null ,
17- 'lefthook.json' : null ,
1820 '.lefthook.json' : null ,
21+ 'lefthook.toml' : null ,
22+ 'lefthook.json' : null ,
1923 } )
24+
25+ if ( ! await fileExists ( '.lefthook.yaml' ) ) {
26+ yield {
27+ message : [
28+ `Expected to find a ".lefthook.yaml" file` ,
29+ ] ,
30+ fix : ( ) =>
31+ Deno . writeTextFile (
32+ '.lefthook.yaml' ,
33+ `assert_lefthook_installed: true\n` ,
34+ ) ,
35+ }
36+ }
2037 }
2138
2239 // Check that lefthook is activated for the current project.
@@ -26,17 +43,22 @@ export const issues: Issues = async function* issues() {
2643 message : [
2744 `Expected lefthook to be activated for current project` ,
2845 ] ,
29- fix : async ( ) => execa `lefthook install` ,
46+ fix : ( ) => execa `lefthook install` ,
3047 }
3148 }
3249 }
3350
51+ type LefthookConfig = { assert_lefthook_installed : boolean }
3452 // Check that specific values are set.
3553 {
36- const lefthookConfig = yaml . parse ( await Deno . readTextFile ( '.lefthook.yaml' ) ) as Record <
37- PropertyKey ,
38- unknown
39- >
54+ const lefthookConfig = yaml . parse ( await Deno . readTextFile ( '.lefthook.yaml' ) )
55+ if ( typeof lefthookConfig !== 'object' || lefthookConfig === null ) {
56+ yield {
57+ message : [
58+ `Expected ".lefthook.yaml" to contain an object` ,
59+ ] ,
60+ }
61+ }
4062 if ( lefthookConfig . assert_lefthook_installed != true ) {
4163 yield {
4264 message : [
0 commit comments