Skip to content

Commit

Permalink
fix: Work around eslint globals config bug
Browse files Browse the repository at this point in the history
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.

eslint/eslint#7967
  • Loading branch information
zimme committed Jan 10, 2018
1 parent d3e61b0 commit b2c47bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };'
}
];

Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit b2c47bf

Please sign in to comment.