From b2c47bff49c2069330c55ef5acdedcec18d378cd Mon Sep 17 00:00:00 2001 From: Simon Fridlund Date: Wed, 10 Jan 2018 23:42:34 +0100 Subject: [PATCH] fix: Work around eslint globals config bug ESLint have a weird behaviour that I would like to categorize as a bug, but it's not really a bug, in where using their API to get/create a config you get the globals property as an object but their `CLIEngine` class expects it to be an array. I now convert the property from an object to an array before using the options. https://github.com/eslint/eslint/issues/7967 --- src/__tests__/index.js | 12 ++++++++++++ src/index.js | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 15db3b6a..7fc129cd 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -193,6 +193,18 @@ const tests = [ filePath: path.resolve("./test.md") }, output: "# Foo\n\n_bar_" + }, + { + title: "Test eslintConfig.globals as an object", + input: { + text: 'var foo = { "bar": "baz"}', + eslintConfig: { + globals: { + someGlobal: true + } + } + }, + output: 'var foo = { bar: "baz" };' } ]; diff --git a/src/index.js b/src/index.js index c79ca76c..99aafdd5 100644 --- a/src/index.js +++ b/src/index.js @@ -63,6 +63,12 @@ function format(options) { getESLintConfig(filePath) ); + if (typeof eslintConfig.globals === "object") { + eslintConfig.globals = Object.entries(eslintConfig.globals).map( + ([key, value]) => `${key}:${value}` + ); + } + const prettierOptions = merge( {}, filePath && { filepath: filePath },