Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Allow formatter to receive string (path) to file exporting formatte…
Browse files Browse the repository at this point in the history
…r function (#247)

* Only load standard formatter in appropriate scenario

* Allow file path to be used for formatter

Closes #246 
Closes #239
  • Loading branch information
Timer authored and MoOx committed Sep 19, 2018
1 parent 3d63b44 commit 7108379
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions index.js
Expand Up @@ -155,20 +155,10 @@ module.exports = function(input, map) {
);

var userEslintPath = userOptions.eslintPath;
var formatter = require("eslint/lib/formatters/stylish");

if (userEslintPath) {
try {
formatter = require(userEslintPath + "/lib/formatters/stylish");
} catch (e) {
formatter = require("eslint/lib/formatters/stylish");
}
}

var config = assign(
// loader defaults
{
formatter: formatter,
cacheIdentifier: JSON.stringify({
"eslint-loader": pkg.version,
eslint: require(userEslintPath || "eslint").version
Expand All @@ -178,6 +168,32 @@ module.exports = function(input, map) {
userOptions
);

if (typeof config.formatter === "string") {
try {
config.formatter = require(config.formatter);
if (
config.formatter &&
typeof config.formatter !== "function" &&
typeof config.formatter.default === "function"
) {
config.formatter = config.formatter.default;
}
} catch (_) {
// ignored
}
}
if (config.formatter == null || typeof config.formatter !== "function") {
if (userEslintPath) {
try {
config.formatter = require(userEslintPath + "/lib/formatters/stylish");
} catch (e) {
config.formatter = require("eslint/lib/formatters/stylish");
}
} else {
config.formatter = require("eslint/lib/formatters/stylish");
}
}

var cacheDirectory = config.cache;
var cacheIdentifier = config.cacheIdentifier;

Expand Down

0 comments on commit 7108379

Please sign in to comment.