Skip to content

Commit 56ab56c

Browse files
authored
[clang-format] Add support for .cjs as JavaScript file extension (llvm#118188)
Node uses `.cjs` as an extension for 'common javascript' modules.
1 parent 68112f0 commit 56ab56c

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

clang/docs/ClangFormat.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
4949
supported:
5050
CSharp: .cs
5151
Java: .java
52-
JavaScript: .mjs .js .ts
52+
JavaScript: .js .mjs .cjs .ts
5353
Json: .json
5454
Objective-C: .m .mm
5555
Proto: .proto .protodevel

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,6 +3950,7 @@ static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
39503950
return FormatStyle::LK_Java;
39513951
if (FileName.ends_with_insensitive(".js") ||
39523952
FileName.ends_with_insensitive(".mjs") ||
3953+
FileName.ends_with_insensitive(".cjs") ||
39533954
FileName.ends_with_insensitive(".ts")) {
39543955
return FormatStyle::LK_JavaScript; // (module) JavaScript or TypeScript.
39553956
}

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static cl::opt<std::string> AssumeFileName(
8787
"supported:\n"
8888
" CSharp: .cs\n"
8989
" Java: .java\n"
90-
" JavaScript: .mjs .js .ts\n"
90+
" JavaScript: .js .mjs .cjs .ts\n"
9191
" Json: .json\n"
9292
" Objective-C: .m .mm\n"
9393
" Proto: .proto .protodevel\n"

clang/tools/clang-format/git-clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def main():
9494
# Other languages that clang-format supports
9595
'proto', 'protodevel', # Protocol Buffers
9696
'java', # Java
97-
'mjs', 'js', # JavaScript
97+
'js', 'mjs', 'cjs', # JavaScript
9898
'ts', # TypeScript
9999
'cs', # C Sharp
100100
'json', # Json

0 commit comments

Comments
 (0)