Skip to content

Commit

Permalink
Respect Prettier’s use of .editorconfig (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersk committed Aug 10, 2020
1 parent 084e7a3 commit f45ab80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/options-manager.js
Expand Up @@ -99,7 +99,7 @@ const mergeWithFileConfig = options => {
({options} = applyOverrides(options.filename, options));
}

const prettierOptions = options.prettier ? prettier.resolveConfig.sync(searchPath) || {} : {};
const prettierOptions = options.prettier ? prettier.resolveConfig.sync(searchPath, {editorconfig: true}) || {} : {};

if (options.filename && isTypescript(options.filename)) {
const tsConfigExplorer = cosmiconfigSync([], {searchPlaces: ['tsconfig.json'], loaders: {'.json': (_, content) => JSON5.parse(content)}});
Expand Down Expand Up @@ -133,8 +133,7 @@ const mergeWithFileConfigs = async (files, options, configFiles) => {
const {hash, options: optionsWithOverrides} = applyOverrides(file, fileOptions);
fileOptions = optionsWithOverrides;

const prettierConfigPath = fileOptions.prettier ? await prettier.resolveConfigFile(file) : undefined;
const prettierOptions = prettierConfigPath ? await prettier.resolveConfig(file, {config: prettierConfigPath}) : {};
const prettierOptions = fileOptions.prettier ? await prettier.resolveConfig(file, {editorconfig: true}) || {} : {};

let tsConfigPath;
if (isTypescript(file)) {
Expand All @@ -147,7 +146,7 @@ const mergeWithFileConfigs = async (files, options, configFiles) => {
fileOptions.ts = true;
}

const cacheKey = stringify({xoConfigPath, enginesConfigPath, prettierConfigPath, hash, tsConfigPath: fileOptions.tsConfigPath, ts: fileOptions.ts});
const cacheKey = stringify({xoConfigPath, enginesConfigPath, prettierOptions, hash, tsConfigPath: fileOptions.tsConfigPath, ts: fileOptions.ts});
const cachedGroup = configs.get(cacheKey);

configs.set(cacheKey, {
Expand Down
2 changes: 1 addition & 1 deletion test/options-manager.js
Expand Up @@ -638,7 +638,7 @@ test('mergeWithFileConfigs: nested configs with prettier', async t => {
extensions: DEFAULT_EXTENSION,
ignores: DEFAULT_IGNORES
},
prettierOptions: {semi: false}
prettierOptions: {endOfLine: 'lf', semi: false, useTabs: true}
}
]);
});
Expand Down

0 comments on commit f45ab80

Please sign in to comment.