google / vim-codefmt

Vim plugin for syntax-aware code formatting
Apache License 2.0
1.11k stars 114 forks source link

Implement a codefmt#formatterhelpers#FiletypeMatches helper #212

Closed dbarnett closed 1 year ago

dbarnett commented 1 year ago

We should define a little filetype check helper to turn formatters' common (and ugly) checks against multiple filetypes like

if &filetype is# 'c' || &filetype is# 'cpp' ||
        \ &filetype is# 'proto' || &filetype is# 'javascript' ||
        \ &filetype is# 'objc' || &filetype is# 'objcpp' ||
        \ &filetype is# 'typescript' || &filetype is# 'arduino'

into a simpler concise function call like

if codefmt#formatterhelpers#FiletypeMatches(
    \ &filetype,
    \ ['c', 'cpp', 'proto', 'javascript', 'objc', 'objcpp', 'typescript', 'arduino'])

It could also help ensure they properly support dotted filenames like 'c.doxygen' (see :help 'filetype').