Skip to content
Snippets Groups Projects
Unverified Commit 6c2c2b0c authored by Philip's avatar Philip Committed by GitHub
Browse files

fix: error gracefully when .editorconfig parsing fails (#18541)

parent 67c32b86
No related branches found
No related tags found
No related merge requests found
#
# .editorconfig
#
# http://editorconfig.org
#
# The EditorConfig project consists of a file format for defining coding styles
# and a collection of text editor plugins that enable editors to read the file
# format and adhere to defined styles.
#
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
# package.json specific rules
[package.json]
indent_size = 2
# .yml specific rules
[*.yml]
indent_size = 2
...@@ -51,6 +51,18 @@ describe('util/json-writer/editor-config', () => { ...@@ -51,6 +51,18 @@ describe('util/json-writer/editor-config', () => {
expect(format.indentationType).toBe(IndentationType.Space); expect(format.indentationType).toBe(IndentationType.Space);
}); });
// temporary ignoring error https://github.com/renovatebot/renovate/issues/18540
it('should temporary give undefined until its fixed on the library', async () => {
expect.assertions(2);
Fixtures.mock({
'.editorconfig': Fixtures.get('.customer_file'),
});
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
expect(format.indentationSize).toBeUndefined();
expect(format.indentationType).toBeUndefined();
});
it('should not handle non json config from .editorconfig', async () => { it('should not handle non json config from .editorconfig', async () => {
expect.assertions(2); expect.assertions(2);
Fixtures.mock({ Fixtures.mock({
......
import { KnownProps, parse } from 'editorconfig'; import { KnownProps, parse } from 'editorconfig';
import upath from 'upath'; import upath from 'upath';
import { GlobalConfig } from '../../config/global'; import { GlobalConfig } from '../../config/global';
import { logger } from '../../logger';
import type { CodeFormat } from './code-format'; import type { CodeFormat } from './code-format';
import { IndentationType } from './indentation-type'; import { IndentationType } from './indentation-type';
export class EditorConfig { export class EditorConfig {
public static async getCodeFormat(fileName: string): Promise<CodeFormat> { public static async getCodeFormat(fileName: string): Promise<CodeFormat> {
const { localDir } = GlobalConfig.get(); const { localDir } = GlobalConfig.get();
try {
const knownProps = await parse(upath.join(localDir, fileName)); const knownProps = await parse(upath.join(localDir, fileName));
return { return {
indentationSize: EditorConfig.getIndentationSize(knownProps), indentationSize: EditorConfig.getIndentationSize(knownProps),
indentationType: EditorConfig.getIndentationType(knownProps), indentationType: EditorConfig.getIndentationType(knownProps),
}; };
} catch (err) {
logger.warn({ err }, 'Failed to parse editor config');
return {};
}
} }
private static getIndentationType( private static getIndentationType(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment