Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/vale/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func init() {
pflag.StringVar(&Flags.Output, "output", "CLI", `An output style ("line", "JSON", or a template file).`)
pflag.StringVar(&Flags.InExt, "ext", ".txt",
fmt.Sprintf(`An extension to associate with stdin (%s).`, toCodeStyle(`--ext=.md`)))
pflag.StringVar(&Flags.InPath, "path", "",
fmt.Sprintf(`A file path to associate with stdin (%s).`, toCodeStyle(`--path=docs/example.md`)))

pflag.StringVar(&Flags.AlertLevel, "minAlertLevel", "",
fmt.Sprintf(`The minimum level to display (%s).`, toCodeStyle(`--minAlertLevel=error`)))
Expand Down
1 change: 1 addition & 0 deletions internal/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ type CLIFlags struct {
Built string
Glob string
InExt string
InPath string
Output string
Path string
Sources string
Expand Down
29 changes: 20 additions & 9 deletions internal/core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func NewFile(src string, config *Config) (*File, error) {
var format, ext string
var fbytes []byte
var lookup bool
path := src

if system.FileExists(src) {
fbytes, _ = os.ReadFile(src)
Expand All @@ -62,14 +63,24 @@ func NewFile(src string, config *Config) (*File, error) {
ext, format = FormatFromExt(src, config.Formats)
}
} else {
ext, format = FormatFromExt(config.Flags.InExt, config.Formats)
fbytes = []byte(src)
src = "stdin" + config.Flags.InExt
lookup = true
// For stdin, allow an explicit path override to drive path-based config.
if config.Flags.InPath != "" {
path = config.Flags.InPath
} else {
path = "stdin" + config.Flags.InExt
}
// If --ext was explicitly set, respect it; otherwise infer from the path.
if config.Flags.InExt != ".txt" {
ext, format = FormatFromExt(config.Flags.InExt, config.Formats)
} else {
ext, format = FormatFromExt(path, config.Formats)
}
}

filepaths := []string{src}
normed := system.ReplaceFileExt(src, config.Formats)
filepaths := []string{path}
normed := system.ReplaceFileExt(path, config.Formats)

baseStyles := config.GBaseStyles
checks := make(map[string]bool)
Expand All @@ -95,7 +106,7 @@ func NewFile(src string, config *Config) (*File, error) {
sec, err := glob.Compile(syntax)
if err != nil {
return &File{}, err
} else if sec.Match(src) {
} else if sec.Match(path) {
lang = code
break
}
Expand All @@ -105,8 +116,8 @@ func NewFile(src string, config *Config) (*File, error) {
for sec, p := range config.Stylesheets {
pat, err := glob.Compile(sec)
if err != nil {
return &File{}, NewE100(src, err)
} else if pat.Match(src) {
return &File{}, NewE100(path, err)
} else if pat.Match(path) {
transform = p
break
}
Expand All @@ -120,11 +131,11 @@ func NewFile(src string, config *Config) (*File, error) {
lines := strings.SplitAfter(strings.Clone(content), "\n")

file := File{
NormedExt: ext, Format: format, RealExt: filepath.Ext(src),
NormedExt: ext, Format: format, RealExt: filepath.Ext(path),
BaseStyles: baseStyles, Checks: checks, Lines: lines, Content: content,
Comments: make(map[string]bool), history: make(map[string]int),
simple: config.Flags.Simple, Transform: transform,
limits: make(map[string]int), Path: src, Metrics: make(map[string]int),
limits: make(map[string]int), Path: path, Metrics: make(map[string]int),
NLP: nlp.Info{Endpoint: config.NLPEndpoint, Lang: lang},
Lookup: lookup, NormedPath: normed,
}
Expand Down