Skip to content

[clang-format] Add support for .cjs as JavaScript file extension #118188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 3, 2024
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: 1 addition & 1 deletion clang/docs/ClangFormat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
supported:
CSharp: .cs
Java: .java
JavaScript: .mjs .js .ts
JavaScript: .js .mjs .cjs .ts
Json: .json
Objective-C: .m .mm
Proto: .proto .protodevel
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3950,6 +3950,7 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
return FormatStyle::LK_Java;
if (FileName.ends_with_insensitive(".js") ||
FileName.ends_with_insensitive(".mjs") ||
FileName.ends_with_insensitive(".cjs") ||
FileName.ends_with_insensitive(".ts")) {
return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript.
}
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-format/ClangFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static cl::opt<std::string> AssumeFileName(
"supported:\n"
" CSharp: .cs\n"
" Java: .java\n"
" JavaScript: .mjs .js .ts\n"
" JavaScript: .js .mjs .cjs .ts\n"
" Json: .json\n"
" Objective-C: .m .mm\n"
" Proto: .proto .protodevel\n"
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/clang-format/git-clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def main():
# Other languages that clang-format supports
'proto', 'protodevel', # Protocol Buffers
'java', # Java
'mjs', 'js', # JavaScript
'js', 'mjs', 'cjs', # JavaScript
'ts', # TypeScript
'cs', # C Sharp
'json', # Json
Expand Down
Loading