MCPcopy
hub / github.com/prettier/prettier / getLanguageByInterpreterNodejs

Function getLanguageByInterpreterNodejs

src/utilities/infer-parser.js:55–78  ·  view source on GitHub ↗

* @param {SupportLanguage[]} languages * @param {string | URL | undefined} [file] * @returns {SupportLanguage | undefined}

(languages, file)

Source from the content-addressed store, hash-verified

53 * @returns {SupportLanguage | undefined}
54 */
55function getLanguageByInterpreterNodejs(languages, file) {
56 if (!file || getFileBasename(file).includes(".")) {
57 return;
58 }
59
60 const languagesWithInterpreters = languages.filter(({ interpreters }) =>
61 isNonEmptyArray(interpreters),
62 );
63
64 /* c8 ignore next 3 */
65 if (languagesWithInterpreters.length === 0) {
66 return;
67 }
68
69 const interpreter = getInterpreter(file);
70
71 if (!interpreter) {
72 return;
73 }
74
75 return languagesWithInterpreters.find(({ interpreters }) =>
76 interpreters.includes(interpreter),
77 );
78}
79
80const getLanguageByInterpreter =
81 process.env.PRETTIER_TARGET === "universal"

Callers

nothing calls this directly

Calls 3

isNonEmptyArrayFunction · 0.85
getInterpreterFunction · 0.85
getFileBasenameFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…