fix(fstab): Make options, freq and spec optional

This commit is contained in:
Myzel394 2024-10-09 22:04:29 +02:00
parent 3ca0ea8c35
commit 9f927b8685
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
2 changed files with 15 additions and 45 deletions

View File

@ -83,46 +83,8 @@ func analyzeFieldAreFilled(
Character: entry.Fields.FilesystemType.End.Character,
},
},
Message: "The options field is missing",
Severity: &common.SeverityError,
})
continue
}
if entry.Fields.Freq == nil || entry.Fields.Freq.Value.Value == "" {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: protocol.Range{
Start: protocol.Position{
Line: entry.Fields.Start.Line,
Character: entry.Fields.Options.End.Character,
},
End: protocol.Position{
Line: entry.Fields.Start.Line,
Character: entry.Fields.Options.End.Character,
},
},
Message: "The freq field is missing",
Severity: &common.SeverityError,
})
continue
}
if entry.Fields.Pass == nil || entry.Fields.Pass.Value.Value == "" {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: protocol.Range{
Start: protocol.Position{
Line: entry.Fields.Start.Line,
Character: entry.Fields.Freq.End.Character,
},
End: protocol.Position{
Line: entry.Fields.Start.Line,
Character: entry.Fields.Freq.End.Character,
},
},
Message: "The pass field is missing",
Severity: &common.SeverityError,
Message: `The options field is empty. The usual convention is to use at least "defaults" keyword there.`,
Severity: &common.SeverityWarning,
})
continue

View File

@ -16,20 +16,28 @@ func analyzeValuesAreValid(
for it.Next() {
entry := it.Value().(*ast.FstabEntry)
mountOptions := entry.FetchMountOptionsField(true)
checkField(ctx, entry.Fields.Spec, fields.SpecField)
checkField(ctx, entry.Fields.MountPoint, fields.MountPointField)
checkField(ctx, entry.Fields.FilesystemType, fields.FileSystemTypeField)
if entry.Fields.Options != nil {
mountOptions := entry.FetchMountOptionsField(true)
if mountOptions != nil {
checkField(ctx, entry.Fields.Options, mountOptions)
}
}
if entry.Fields.Freq != nil {
checkField(ctx, entry.Fields.Freq, fields.FreqField)
}
if entry.Fields.Pass != nil {
checkField(ctx, entry.Fields.Pass, fields.PassField)
}
}
}
func checkField(
ctx *analyzerContext,