jscpd-rs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/Cargo.lock +1323 -0
- package/Cargo.toml +54 -0
- package/LICENSE +21 -0
- package/README.md +372 -0
- package/docs/api-parity.md +49 -0
- package/docs/cloning-plan.md +281 -0
- package/docs/compat-baseline.md +535 -0
- package/docs/format-porting.md +86 -0
- package/docs/junior-task-template.md +62 -0
- package/docs/junior-workflow.md +87 -0
- package/docs/migrating-from-jscpd.md +193 -0
- package/docs/npm-release.md +116 -0
- package/docs/public-benchmark-suite.md +81 -0
- package/docs/release-checklist.md +200 -0
- package/docs/release-decisions.md +103 -0
- package/docs/release-readiness.md +51 -0
- package/docs/upstream-bugs.md +501 -0
- package/docs/upstream-issue-drafts.md +393 -0
- package/docs/user-guide.md +309 -0
- package/examples/dump_oxc_tokens.rs +112 -0
- package/examples/library_api.rs +42 -0
- package/npm/bin/jscpd-rs.js +6 -0
- package/npm/bin/jscpd-server.js +6 -0
- package/npm/lib/run-binary.js +68 -0
- package/npm/scripts/postinstall.js +50 -0
- package/package.json +53 -0
- package/skills/dry-refactoring/SKILL.md +63 -0
- package/skills/jscpd/SKILL.md +85 -0
- package/src/app.rs +512 -0
- package/src/bin/jscpd-server.rs +429 -0
- package/src/blame.rs +130 -0
- package/src/cli/config.rs +543 -0
- package/src/cli/parsing.rs +301 -0
- package/src/cli/tests.rs +543 -0
- package/src/cli.rs +671 -0
- package/src/detector/matching/secondary.rs +387 -0
- package/src/detector/matching.rs +274 -0
- package/src/detector/model.rs +190 -0
- package/src/detector/prepare.rs +71 -0
- package/src/detector/skip_local.rs +40 -0
- package/src/detector/statistics.rs +138 -0
- package/src/detector/store.rs +96 -0
- package/src/detector/tests.rs +238 -0
- package/src/detector.rs +265 -0
- package/src/files/discovery.rs +508 -0
- package/src/files/gitignore.rs +203 -0
- package/src/files/paths.rs +68 -0
- package/src/files/shebang.rs +106 -0
- package/src/files/tests.rs +523 -0
- package/src/files.rs +25 -0
- package/src/formats.rs +570 -0
- package/src/lib.rs +433 -0
- package/src/main.rs +26 -0
- package/src/report/ai.rs +125 -0
- package/src/report/badge.rs +238 -0
- package/src/report/console.rs +180 -0
- package/src/report/console_common.rs +37 -0
- package/src/report/console_full.rs +139 -0
- package/src/report/csv.rs +65 -0
- package/src/report/escape.rs +8 -0
- package/src/report/file_output.rs +28 -0
- package/src/report/html/assets.rs +47 -0
- package/src/report/html.rs +336 -0
- package/src/report/json.rs +119 -0
- package/src/report/markdown.rs +125 -0
- package/src/report/sarif.rs +302 -0
- package/src/report/silent.rs +22 -0
- package/src/report/source.rs +38 -0
- package/src/report/summary.rs +50 -0
- package/src/report/test_support.rs +133 -0
- package/src/report/threshold.rs +76 -0
- package/src/report/xcode.rs +90 -0
- package/src/report/xml.rs +119 -0
- package/src/report.rs +250 -0
- package/src/server/mcp.rs +942 -0
- package/src/server.rs +1081 -0
- package/src/tokenizer/apex.rs +97 -0
- package/src/tokenizer/blocks.rs +532 -0
- package/src/tokenizer/embedded.rs +106 -0
- package/src/tokenizer/generic.rs +511 -0
- package/src/tokenizer/hash.rs +27 -0
- package/src/tokenizer/ignore.rs +33 -0
- package/src/tokenizer/line_index.rs +33 -0
- package/src/tokenizer/markdown.rs +289 -0
- package/src/tokenizer/markup_attrs.rs +289 -0
- package/src/tokenizer/oxc/fallback.rs +275 -0
- package/src/tokenizer/oxc/jsx.rs +168 -0
- package/src/tokenizer/oxc/kind.rs +177 -0
- package/src/tokenizer/oxc/lexical.rs +67 -0
- package/src/tokenizer/oxc.rs +659 -0
- package/src/tokenizer/scan.rs +88 -0
- package/src/tokenizer/tap.rs +150 -0
- package/src/tokenizer/tests.rs +915 -0
- package/src/tokenizer.rs +328 -0
- package/src/verbose.rs +195 -0
package/src/files.rs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
mod discovery;
|
|
2
|
+
mod gitignore;
|
|
3
|
+
mod paths;
|
|
4
|
+
mod shebang;
|
|
5
|
+
|
|
6
|
+
#[cfg(test)]
|
|
7
|
+
mod tests;
|
|
8
|
+
|
|
9
|
+
pub use discovery::discover;
|
|
10
|
+
pub(crate) use gitignore::collect_cwd_gitignore_patterns;
|
|
11
|
+
|
|
12
|
+
/// Source content prepared by the caller for in-memory detection.
|
|
13
|
+
///
|
|
14
|
+
/// Use this with `detect_source_files` when an integration already owns file
|
|
15
|
+
/// contents or wants to check generated snippets without reading from disk.
|
|
16
|
+
#[derive(Clone, Debug)]
|
|
17
|
+
pub struct SourceFile {
|
|
18
|
+
/// Stable source identifier used in clone reports, usually a file path.
|
|
19
|
+
pub source_id: String,
|
|
20
|
+
/// Source format name, for example `javascript`, `typescript`, `rust`, or
|
|
21
|
+
/// another value returned by `get_supported_formats`.
|
|
22
|
+
pub format: String,
|
|
23
|
+
/// Full source text.
|
|
24
|
+
pub content: String,
|
|
25
|
+
}
|
package/src/formats.rs
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
3
|
+
use crate::cli::FormatMappings;
|
|
4
|
+
|
|
5
|
+
// Generated by scripts/sync-formats.mjs from jscpd/packages/tokenizer/dist/index.mjs.
|
|
6
|
+
// Upstream getFormatByFile() uses first-writer-wins extension mappings and no
|
|
7
|
+
// built-in filename mappings; extensionless names are supported through
|
|
8
|
+
// --formats-names only.
|
|
9
|
+
|
|
10
|
+
pub const SUPPORTED_FORMATS: &[&str] = &[
|
|
11
|
+
"abap",
|
|
12
|
+
"actionscript",
|
|
13
|
+
"ada",
|
|
14
|
+
"apacheconf",
|
|
15
|
+
"apl",
|
|
16
|
+
"applescript",
|
|
17
|
+
"arduino",
|
|
18
|
+
"arff",
|
|
19
|
+
"asciidoc",
|
|
20
|
+
"asm6502",
|
|
21
|
+
"aspnet",
|
|
22
|
+
"autohotkey",
|
|
23
|
+
"autoit",
|
|
24
|
+
"bash",
|
|
25
|
+
"basic",
|
|
26
|
+
"batch",
|
|
27
|
+
"bison",
|
|
28
|
+
"brainfuck",
|
|
29
|
+
"bro",
|
|
30
|
+
"c",
|
|
31
|
+
"c-header",
|
|
32
|
+
"clike",
|
|
33
|
+
"clojure",
|
|
34
|
+
"coffeescript",
|
|
35
|
+
"comments",
|
|
36
|
+
"cpp",
|
|
37
|
+
"cpp-header",
|
|
38
|
+
"crystal",
|
|
39
|
+
"csharp",
|
|
40
|
+
"csp",
|
|
41
|
+
"css-extras",
|
|
42
|
+
"css",
|
|
43
|
+
"d",
|
|
44
|
+
"dart",
|
|
45
|
+
"diff",
|
|
46
|
+
"django",
|
|
47
|
+
"docker",
|
|
48
|
+
"eiffel",
|
|
49
|
+
"elixir",
|
|
50
|
+
"elm",
|
|
51
|
+
"erb",
|
|
52
|
+
"erlang",
|
|
53
|
+
"flow",
|
|
54
|
+
"fortran",
|
|
55
|
+
"fsharp",
|
|
56
|
+
"gdscript",
|
|
57
|
+
"gedcom",
|
|
58
|
+
"gherkin",
|
|
59
|
+
"git",
|
|
60
|
+
"glsl",
|
|
61
|
+
"go",
|
|
62
|
+
"graphql",
|
|
63
|
+
"groovy",
|
|
64
|
+
"haml",
|
|
65
|
+
"handlebars",
|
|
66
|
+
"haskell",
|
|
67
|
+
"haxe",
|
|
68
|
+
"hpkp",
|
|
69
|
+
"hsts",
|
|
70
|
+
"http",
|
|
71
|
+
"ichigojam",
|
|
72
|
+
"icon",
|
|
73
|
+
"inform7",
|
|
74
|
+
"ini",
|
|
75
|
+
"io",
|
|
76
|
+
"j",
|
|
77
|
+
"java",
|
|
78
|
+
"javascript",
|
|
79
|
+
"jolie",
|
|
80
|
+
"json",
|
|
81
|
+
"jsx",
|
|
82
|
+
"julia",
|
|
83
|
+
"keymap",
|
|
84
|
+
"kotlin",
|
|
85
|
+
"latex",
|
|
86
|
+
"less",
|
|
87
|
+
"liquid",
|
|
88
|
+
"lisp",
|
|
89
|
+
"livescript",
|
|
90
|
+
"lolcode",
|
|
91
|
+
"lua",
|
|
92
|
+
"makefile",
|
|
93
|
+
"markdown",
|
|
94
|
+
"markup",
|
|
95
|
+
"matlab",
|
|
96
|
+
"mel",
|
|
97
|
+
"mizar",
|
|
98
|
+
"monkey",
|
|
99
|
+
"n4js",
|
|
100
|
+
"nasm",
|
|
101
|
+
"nginx",
|
|
102
|
+
"nim",
|
|
103
|
+
"nix",
|
|
104
|
+
"nsis",
|
|
105
|
+
"objectivec",
|
|
106
|
+
"ocaml",
|
|
107
|
+
"opencl",
|
|
108
|
+
"oz",
|
|
109
|
+
"parigp",
|
|
110
|
+
"pascal",
|
|
111
|
+
"perl",
|
|
112
|
+
"php",
|
|
113
|
+
"plsql",
|
|
114
|
+
"powershell",
|
|
115
|
+
"processing",
|
|
116
|
+
"prolog",
|
|
117
|
+
"properties",
|
|
118
|
+
"protobuf",
|
|
119
|
+
"pug",
|
|
120
|
+
"puppet",
|
|
121
|
+
"pure",
|
|
122
|
+
"python",
|
|
123
|
+
"q",
|
|
124
|
+
"qore",
|
|
125
|
+
"r",
|
|
126
|
+
"reason",
|
|
127
|
+
"renpy",
|
|
128
|
+
"rest",
|
|
129
|
+
"rip",
|
|
130
|
+
"roboconf",
|
|
131
|
+
"ruby",
|
|
132
|
+
"rust",
|
|
133
|
+
"sas",
|
|
134
|
+
"sass",
|
|
135
|
+
"scala",
|
|
136
|
+
"scheme",
|
|
137
|
+
"scss",
|
|
138
|
+
"svelte",
|
|
139
|
+
"smalltalk",
|
|
140
|
+
"smarty",
|
|
141
|
+
"soy",
|
|
142
|
+
"sql",
|
|
143
|
+
"stylus",
|
|
144
|
+
"swift",
|
|
145
|
+
"tap",
|
|
146
|
+
"tcl",
|
|
147
|
+
"textile",
|
|
148
|
+
"tsx",
|
|
149
|
+
"tt2",
|
|
150
|
+
"twig",
|
|
151
|
+
"typescript",
|
|
152
|
+
"txt",
|
|
153
|
+
"vbnet",
|
|
154
|
+
"velocity",
|
|
155
|
+
"verilog",
|
|
156
|
+
"vhdl",
|
|
157
|
+
"vim",
|
|
158
|
+
"visual-basic",
|
|
159
|
+
"astro",
|
|
160
|
+
"vue",
|
|
161
|
+
"wasm",
|
|
162
|
+
"wiki",
|
|
163
|
+
"xeora",
|
|
164
|
+
"xojo",
|
|
165
|
+
"xquery",
|
|
166
|
+
"yaml",
|
|
167
|
+
"abnf",
|
|
168
|
+
"agda",
|
|
169
|
+
"antlr4",
|
|
170
|
+
"apex",
|
|
171
|
+
"aql",
|
|
172
|
+
"armasm",
|
|
173
|
+
"awk",
|
|
174
|
+
"bicep",
|
|
175
|
+
"bnf",
|
|
176
|
+
"cfscript",
|
|
177
|
+
"cfml",
|
|
178
|
+
"cmake",
|
|
179
|
+
"cobol",
|
|
180
|
+
"csv",
|
|
181
|
+
"cypher",
|
|
182
|
+
"dhall",
|
|
183
|
+
"dns-zone-file",
|
|
184
|
+
"dot",
|
|
185
|
+
"ebnf",
|
|
186
|
+
"editorconfig",
|
|
187
|
+
"excel-formula",
|
|
188
|
+
"factor",
|
|
189
|
+
"ftl",
|
|
190
|
+
"gcode",
|
|
191
|
+
"gettext",
|
|
192
|
+
"gml",
|
|
193
|
+
"go-module",
|
|
194
|
+
"hcl",
|
|
195
|
+
"hlsl",
|
|
196
|
+
"idris",
|
|
197
|
+
"ignore",
|
|
198
|
+
"jq",
|
|
199
|
+
"json5",
|
|
200
|
+
"kusto",
|
|
201
|
+
"lilypond",
|
|
202
|
+
"linker-script",
|
|
203
|
+
"llvm",
|
|
204
|
+
"log",
|
|
205
|
+
"mermaid",
|
|
206
|
+
"mongodb",
|
|
207
|
+
"n1ql",
|
|
208
|
+
"odin",
|
|
209
|
+
"openqasm",
|
|
210
|
+
"plant-uml",
|
|
211
|
+
"powerquery",
|
|
212
|
+
"promql",
|
|
213
|
+
"purescript",
|
|
214
|
+
"qsharp",
|
|
215
|
+
"racket",
|
|
216
|
+
"regex",
|
|
217
|
+
"rego",
|
|
218
|
+
"rescript",
|
|
219
|
+
"robotframework",
|
|
220
|
+
"shell-session",
|
|
221
|
+
"smali",
|
|
222
|
+
"solidity",
|
|
223
|
+
"sparql",
|
|
224
|
+
"stata",
|
|
225
|
+
"toml",
|
|
226
|
+
"turtle",
|
|
227
|
+
"typoscript",
|
|
228
|
+
"unrealscript",
|
|
229
|
+
"uri",
|
|
230
|
+
"vala",
|
|
231
|
+
"wgsl",
|
|
232
|
+
"wolfram",
|
|
233
|
+
"zig",
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
const EXTENSION_FORMATS: &[(&str, &str)] = &[
|
|
237
|
+
("as", "actionscript"),
|
|
238
|
+
("ada", "ada"),
|
|
239
|
+
("apl", "apl"),
|
|
240
|
+
("asp", "aspnet"),
|
|
241
|
+
("aspx", "aspnet"),
|
|
242
|
+
("sh", "bash"),
|
|
243
|
+
("ksh", "bash"),
|
|
244
|
+
("bash", "bash"),
|
|
245
|
+
("bas", "basic"),
|
|
246
|
+
("b", "brainfuck"),
|
|
247
|
+
("bf", "brainfuck"),
|
|
248
|
+
("c", "c"),
|
|
249
|
+
("z80", "c"),
|
|
250
|
+
("h", "c-header"),
|
|
251
|
+
("cljs", "clojure"),
|
|
252
|
+
("clj", "clojure"),
|
|
253
|
+
("cljc", "clojure"),
|
|
254
|
+
("cljx", "clojure"),
|
|
255
|
+
("edn", "clojure"),
|
|
256
|
+
("coffee", "coffeescript"),
|
|
257
|
+
("cpp", "cpp"),
|
|
258
|
+
("c++", "cpp"),
|
|
259
|
+
("cc", "cpp"),
|
|
260
|
+
("cxx", "cpp"),
|
|
261
|
+
("hpp", "cpp-header"),
|
|
262
|
+
("h++", "cpp-header"),
|
|
263
|
+
("hh", "cpp-header"),
|
|
264
|
+
("hxx", "cpp-header"),
|
|
265
|
+
("cr", "crystal"),
|
|
266
|
+
("cs", "csharp"),
|
|
267
|
+
("css", "css"),
|
|
268
|
+
("gss", "css"),
|
|
269
|
+
("d", "d"),
|
|
270
|
+
("dart", "dart"),
|
|
271
|
+
("diff", "diff"),
|
|
272
|
+
("patch", "diff"),
|
|
273
|
+
("e", "eiffel"),
|
|
274
|
+
("elm", "elm"),
|
|
275
|
+
("erl", "erlang"),
|
|
276
|
+
("erlang", "erlang"),
|
|
277
|
+
("f", "fortran"),
|
|
278
|
+
("for", "fortran"),
|
|
279
|
+
("f77", "fortran"),
|
|
280
|
+
("f90", "fortran"),
|
|
281
|
+
("fs", "fsharp"),
|
|
282
|
+
("gd", "gdscript"),
|
|
283
|
+
("feature", "gherkin"),
|
|
284
|
+
("go", "go"),
|
|
285
|
+
("graphql", "graphql"),
|
|
286
|
+
("groovy", "groovy"),
|
|
287
|
+
("gradle", "groovy"),
|
|
288
|
+
("haml", "haml"),
|
|
289
|
+
("hb", "handlebars"),
|
|
290
|
+
("hbs", "handlebars"),
|
|
291
|
+
("handlebars", "handlebars"),
|
|
292
|
+
("hs", "haskell"),
|
|
293
|
+
("lhs", "haskell"),
|
|
294
|
+
("hx", "haxe"),
|
|
295
|
+
("hxml", "haxe"),
|
|
296
|
+
("ini", "ini"),
|
|
297
|
+
("java", "java"),
|
|
298
|
+
("js", "javascript"),
|
|
299
|
+
("es", "javascript"),
|
|
300
|
+
("es6", "javascript"),
|
|
301
|
+
("mjs", "javascript"),
|
|
302
|
+
("cjs", "javascript"),
|
|
303
|
+
("json", "json"),
|
|
304
|
+
("map", "json"),
|
|
305
|
+
("jsonld", "json"),
|
|
306
|
+
("jsx", "jsx"),
|
|
307
|
+
("jl", "julia"),
|
|
308
|
+
("kt", "kotlin"),
|
|
309
|
+
("kts", "kotlin"),
|
|
310
|
+
("tex", "latex"),
|
|
311
|
+
("less", "less"),
|
|
312
|
+
("cl", "lisp"),
|
|
313
|
+
("lisp", "lisp"),
|
|
314
|
+
("el", "lisp"),
|
|
315
|
+
("ls", "livescript"),
|
|
316
|
+
("lua", "lua"),
|
|
317
|
+
("md", "markdown"),
|
|
318
|
+
("markdown", "markdown"),
|
|
319
|
+
("mkd", "markdown"),
|
|
320
|
+
("html", "markup"),
|
|
321
|
+
("htm", "markup"),
|
|
322
|
+
("xml", "markup"),
|
|
323
|
+
("xsl", "markup"),
|
|
324
|
+
("xslt", "markup"),
|
|
325
|
+
("svg", "markup"),
|
|
326
|
+
("ejs", "markup"),
|
|
327
|
+
("jsp", "markup"),
|
|
328
|
+
("nsh", "nsis"),
|
|
329
|
+
("nsi", "nsis"),
|
|
330
|
+
("m", "objectivec"),
|
|
331
|
+
("mm", "objectivec"),
|
|
332
|
+
("ocaml", "ocaml"),
|
|
333
|
+
("ml", "ocaml"),
|
|
334
|
+
("mli", "ocaml"),
|
|
335
|
+
("mll", "ocaml"),
|
|
336
|
+
("mly", "ocaml"),
|
|
337
|
+
("oz", "oz"),
|
|
338
|
+
("pas", "pascal"),
|
|
339
|
+
("p", "pascal"),
|
|
340
|
+
("pl", "perl"),
|
|
341
|
+
("pm", "perl"),
|
|
342
|
+
("php", "php"),
|
|
343
|
+
("phtml", "php"),
|
|
344
|
+
("plsql", "plsql"),
|
|
345
|
+
("ps1", "powershell"),
|
|
346
|
+
("psd1", "powershell"),
|
|
347
|
+
("psm1", "powershell"),
|
|
348
|
+
("pro", "prolog"),
|
|
349
|
+
("properties", "properties"),
|
|
350
|
+
("proto", "protobuf"),
|
|
351
|
+
("pug", "pug"),
|
|
352
|
+
("jade", "pug"),
|
|
353
|
+
("pp", "puppet"),
|
|
354
|
+
("puppet", "puppet"),
|
|
355
|
+
("py", "python"),
|
|
356
|
+
("pyx", "python"),
|
|
357
|
+
("pxd", "python"),
|
|
358
|
+
("pxi", "python"),
|
|
359
|
+
("q", "q"),
|
|
360
|
+
("r", "r"),
|
|
361
|
+
("R", "r"),
|
|
362
|
+
("rb", "ruby"),
|
|
363
|
+
("rs", "rust"),
|
|
364
|
+
("sas", "sas"),
|
|
365
|
+
("sass", "sass"),
|
|
366
|
+
("scala", "scala"),
|
|
367
|
+
("scm", "scheme"),
|
|
368
|
+
("ss", "scheme"),
|
|
369
|
+
("scss", "scss"),
|
|
370
|
+
("svelte", "svelte"),
|
|
371
|
+
("st", "smalltalk"),
|
|
372
|
+
("smarty", "smarty"),
|
|
373
|
+
("tpl", "smarty"),
|
|
374
|
+
("soy", "soy"),
|
|
375
|
+
("sql", "sql"),
|
|
376
|
+
("cql", "sql"),
|
|
377
|
+
("styl", "stylus"),
|
|
378
|
+
("stylus", "stylus"),
|
|
379
|
+
("swift", "swift"),
|
|
380
|
+
("tap", "tap"),
|
|
381
|
+
("tcl", "tcl"),
|
|
382
|
+
("textile", "textile"),
|
|
383
|
+
("tsx", "tsx"),
|
|
384
|
+
("tt2", "tt2"),
|
|
385
|
+
("twig", "twig"),
|
|
386
|
+
("ts", "typescript"),
|
|
387
|
+
("mts", "typescript"),
|
|
388
|
+
("cts", "typescript"),
|
|
389
|
+
("txt", "txt"),
|
|
390
|
+
("vb", "vbnet"),
|
|
391
|
+
("vtl", "velocity"),
|
|
392
|
+
("v", "verilog"),
|
|
393
|
+
("vhd", "vhdl"),
|
|
394
|
+
("vhdl", "vhdl"),
|
|
395
|
+
("astro", "astro"),
|
|
396
|
+
("vue", "vue"),
|
|
397
|
+
("xy", "xquery"),
|
|
398
|
+
("xquery", "xquery"),
|
|
399
|
+
("yaml", "yaml"),
|
|
400
|
+
("yml", "yaml"),
|
|
401
|
+
("g4", "antlr4"),
|
|
402
|
+
("cls", "apex"),
|
|
403
|
+
("trigger", "apex"),
|
|
404
|
+
("apex", "apex"),
|
|
405
|
+
("awk", "awk"),
|
|
406
|
+
("bicep", "bicep"),
|
|
407
|
+
("cfc", "cfscript"),
|
|
408
|
+
("cfm", "cfml"),
|
|
409
|
+
("cmake", "cmake"),
|
|
410
|
+
("csv", "csv"),
|
|
411
|
+
("dot", "dot"),
|
|
412
|
+
("gv", "dot"),
|
|
413
|
+
("xlsx", "excel-formula"),
|
|
414
|
+
("xls", "excel-formula"),
|
|
415
|
+
("po", "gettext"),
|
|
416
|
+
("tf", "hcl"),
|
|
417
|
+
("hcl", "hcl"),
|
|
418
|
+
("idr", "idris"),
|
|
419
|
+
("gitignore", "ignore"),
|
|
420
|
+
("json5", "json5"),
|
|
421
|
+
("ly", "lilypond"),
|
|
422
|
+
("ld", "linker-script"),
|
|
423
|
+
("ll", "llvm"),
|
|
424
|
+
("log", "log"),
|
|
425
|
+
("qasm", "openqasm"),
|
|
426
|
+
("puml", "plant-uml"),
|
|
427
|
+
("plantuml", "plant-uml"),
|
|
428
|
+
("pq", "powerquery"),
|
|
429
|
+
("purs", "purescript"),
|
|
430
|
+
("qs", "qsharp"),
|
|
431
|
+
("rkt", "racket"),
|
|
432
|
+
("res", "rescript"),
|
|
433
|
+
("robot", "robotframework"),
|
|
434
|
+
("sol", "solidity"),
|
|
435
|
+
("rq", "sparql"),
|
|
436
|
+
("toml", "toml"),
|
|
437
|
+
("ttl", "turtle"),
|
|
438
|
+
("uc", "unrealscript"),
|
|
439
|
+
("wgsl", "wgsl"),
|
|
440
|
+
("wl", "wolfram"),
|
|
441
|
+
("nb", "wolfram"),
|
|
442
|
+
("zig", "zig"),
|
|
443
|
+
];
|
|
444
|
+
|
|
445
|
+
pub fn format_for_path<'a>(
|
|
446
|
+
path: &Path,
|
|
447
|
+
formats_exts: &'a FormatMappings,
|
|
448
|
+
formats_names: &'a FormatMappings,
|
|
449
|
+
) -> Option<&'a str> {
|
|
450
|
+
let file_name = path.file_name()?.to_string_lossy();
|
|
451
|
+
if !formats_names.is_empty()
|
|
452
|
+
&& let Some(format) = formats_names.find_format_for_value(&file_name)
|
|
453
|
+
{
|
|
454
|
+
return Some(format);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
let ext = path.extension()?.to_string_lossy();
|
|
458
|
+
if !formats_exts.is_empty() {
|
|
459
|
+
return formats_exts.find_format_for_value(&ext);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
EXTENSION_FORMATS
|
|
463
|
+
.iter()
|
|
464
|
+
.find_map(|(candidate, format)| (*candidate == ext).then_some(*format))
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
pub fn supported_formats() -> Vec<&'static str> {
|
|
468
|
+
SUPPORTED_FORMATS.to_vec()
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
#[cfg(test)]
|
|
472
|
+
mod tests {
|
|
473
|
+
use std::path::Path;
|
|
474
|
+
|
|
475
|
+
use crate::cli::FormatMappings;
|
|
476
|
+
|
|
477
|
+
#[test]
|
|
478
|
+
fn maps_module_typescript_extensions_like_upstream() {
|
|
479
|
+
let formats_exts = FormatMappings::default();
|
|
480
|
+
let formats_names = FormatMappings::default();
|
|
481
|
+
|
|
482
|
+
assert_eq!(
|
|
483
|
+
super::format_for_path(Path::new("index.mts"), &formats_exts, &formats_names),
|
|
484
|
+
Some("typescript")
|
|
485
|
+
);
|
|
486
|
+
assert_eq!(
|
|
487
|
+
super::format_for_path(Path::new("index.cts"), &formats_exts, &formats_names),
|
|
488
|
+
Some("typescript")
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
#[test]
|
|
493
|
+
fn maps_javascript_module_extensions_like_upstream() {
|
|
494
|
+
let formats_exts = FormatMappings::default();
|
|
495
|
+
let formats_names = FormatMappings::default();
|
|
496
|
+
|
|
497
|
+
assert_eq!(
|
|
498
|
+
super::format_for_path(Path::new("index.es"), &formats_exts, &formats_names),
|
|
499
|
+
Some("javascript")
|
|
500
|
+
);
|
|
501
|
+
assert_eq!(
|
|
502
|
+
super::format_for_path(Path::new("index.es6"), &formats_exts, &formats_names),
|
|
503
|
+
Some("javascript")
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
#[test]
|
|
508
|
+
fn syncs_supported_format_surface_from_upstream() {
|
|
509
|
+
assert_eq!(super::SUPPORTED_FORMATS.len(), 223);
|
|
510
|
+
assert_eq!(super::EXTENSION_FORMATS.len(), 206);
|
|
511
|
+
assert_eq!(super::supported_formats().first(), Some(&"abap"));
|
|
512
|
+
assert!(super::supported_formats().contains(&"typescript"));
|
|
513
|
+
assert!(super::supported_formats().contains(&"excel-formula"));
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
#[test]
|
|
517
|
+
fn maps_long_tail_extensions_like_upstream() {
|
|
518
|
+
let formats_exts = FormatMappings::default();
|
|
519
|
+
let formats_names = FormatMappings::default();
|
|
520
|
+
|
|
521
|
+
assert_eq!(
|
|
522
|
+
super::format_for_path(Path::new("schema.g4"), &formats_exts, &formats_names),
|
|
523
|
+
Some("antlr4")
|
|
524
|
+
);
|
|
525
|
+
assert_eq!(
|
|
526
|
+
super::format_for_path(Path::new("component.bicep"), &formats_exts, &formats_names),
|
|
527
|
+
Some("bicep")
|
|
528
|
+
);
|
|
529
|
+
assert_eq!(
|
|
530
|
+
super::format_for_path(Path::new("formula.xlsx"), &formats_exts, &formats_names),
|
|
531
|
+
Some("excel-formula")
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
#[test]
|
|
536
|
+
fn maps_header_extensions_like_upstream() {
|
|
537
|
+
let formats_exts = FormatMappings::default();
|
|
538
|
+
let formats_names = FormatMappings::default();
|
|
539
|
+
|
|
540
|
+
assert_eq!(
|
|
541
|
+
super::format_for_path(Path::new("foo.h"), &formats_exts, &formats_names),
|
|
542
|
+
Some("c-header")
|
|
543
|
+
);
|
|
544
|
+
assert_eq!(
|
|
545
|
+
super::format_for_path(Path::new("foo.hpp"), &formats_exts, &formats_names),
|
|
546
|
+
Some("cpp-header")
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
#[test]
|
|
551
|
+
fn extensionless_names_require_formats_names_like_upstream() {
|
|
552
|
+
let formats_exts = FormatMappings::default();
|
|
553
|
+
let formats_names = FormatMappings::default();
|
|
554
|
+
|
|
555
|
+
assert_eq!(
|
|
556
|
+
super::format_for_path(Path::new("Makefile"), &formats_exts, &formats_names),
|
|
557
|
+
None
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
let formats_names = FormatMappings::from_pairs(vec![(
|
|
561
|
+
"makefile".to_string(),
|
|
562
|
+
vec!["Makefile".to_string(), "GNUmakefile".to_string()],
|
|
563
|
+
)]);
|
|
564
|
+
|
|
565
|
+
assert_eq!(
|
|
566
|
+
super::format_for_path(Path::new("Makefile"), &formats_exts, &formats_names),
|
|
567
|
+
Some("makefile")
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
}
|