Skip to content

Commit

Permalink
Stop formatting unknown files with babel parser
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Apr 17, 2023
1 parent b232005 commit 4a45846
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/main/normalize-format-options.js
Expand Up @@ -20,6 +20,17 @@ const formatOptionsHiddenDefaults = {
async function normalizeFormatOptions(options, opts = {}) {
const rawOptions = { ...options };

if (!rawOptions.parser && rawOptions.filepath) {
rawOptions.parser = inferParser(rawOptions, {
physicalFile: rawOptions.filepath,
});
if (!rawOptions.parser) {
throw new UndefinedParserError(
`No parser could be inferred for file "${rawOptions.filepath}".`
);
}
}

const supportOptions = getSupportInfo({
plugins: options.plugins,
showDeprecated: true,
Expand All @@ -33,26 +44,6 @@ async function normalizeFormatOptions(options, opts = {}) {
.map((option) => [option.name, option.default])
),
};
if (!rawOptions.parser) {
if (!rawOptions.filepath) {
const logger = opts.logger || console;
logger.warn(
"No parser and no filepath given, using 'babel' the parser now " +
"but this will throw an error in the future. " +
"Please specify a parser or a filepath so one can be inferred."
);
rawOptions.parser = "babel";
} else {
rawOptions.parser = inferParser(rawOptions, {
physicalFile: rawOptions.filepath,
});
if (!rawOptions.parser) {
throw new UndefinedParserError(
`No parser could be inferred for file "${rawOptions.filepath}".`
);
}
}
}

const parserPlugin = getParserPluginByParserName(
rawOptions.plugins,
Expand Down

0 comments on commit 4a45846

Please sign in to comment.