'use strict';

const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
const pluralize = require('pluralize');
const CLIEngine = require('eslint').CLIEngine;

class ESLinter {
  constructor(brunchConfig) {
    this.config = brunchConfig || {};
    const config = brunchConfig.plugins && brunchConfig.plugins.eslint || {};
    this.warnOnly = config.warnOnly != null ? config.warnOnly : true;
    const configFile = path.join(process.cwd(), '.eslintrc');
    this.pattern = config.pattern || /^app\/.*\.js?$/;
    try {
      const stats = fs.statSync(configFile);
      if (stats.isFile()) {
        this.linter = new CLIEngine();
        this.linter.getConfigForFile(configFile);
      }
    } catch (_error) {
      const e = _error.toString().replace('Error: ENOENT, ', '');
      console.warn(`.eslintrc parsing error: ${e} \nESLint will run with default options.`);
      this.linter = new CLIEngine({useEslintrc: false});
    }
  }

  lint(data, path) {
    const result = this.linter.executeOnText(data, path).results[0];
    const errorCount = result.errorCount;
    if (errorCount === 0) {
      return Promise.resolve();
    }
    const errorMsg = result.messages.map(error => {
      return `${chalk.bold(error.message)} (${error.line}:${error.column})`;
    });
    errorMsg.unshift(`ESLint detected ${errorCount} ${(pluralize('problem', errorCount))}:`);
    let msg = errorMsg.join('\n');
    if (this.warnOnly) {
      msg = `warn: ${msg}`;
    }
    return (msg ? Promise.reject(msg) : Promise.resolve());
  }
}

ESLinter.prototype.brunchPlugin = true;
ESLinter.prototype.type = 'javascript';
ESLinter.prototype.extension = 'js';

module.exports = ESLinter;

@@ -44,38 +44,8 @@
 ');%0A
-const path = require('path');%0A
 cons
@@ -154,16 +154,55 @@
 ngine;%0A%0A
+const configFilePrefix = '.eslintrc';%0A%0A
 class ES
@@ -434,290 +434,306 @@
     
-const configFile = path.join(process.cwd(), '.eslintrc');%0A    this.pattern = config.pattern %7C%7C /%5Eapp%5C/.*%5C.js?$/;%0A    try %7B%0A      const stats = fs.statSync(configFile);%0A      if (
+this.pattern = config.pattern %7C%7C /%5Eapp%5C/.*%5C.js?$/;%0A%0A    var useConfig;%0A    try %7B%0A      useConfig = fs.readdirSync(process.cwd())%0A        .filter((filename) =%3E filename.
 sta
+r
 ts
-.isFile()) %7B%0A        this.linter = new CLIEngine();%0A        this.linter.getConfigForFile(config
+With(configFilePrefix))%0A        .filter((configFile) =%3E %7B%0A          try %7B%0A            return fs.statSync(configFile).is
 File
+(
 );%0A 
@@ -733,26 +733,24 @@
 le();%0A      
-%7D%0A
     %7D catch 
@@ -756,24 +756,30 @@
  (_error) %7B%0A
+      
       const 
@@ -828,24 +828,30 @@
 NT, ', '');%0A
+      
       consol
@@ -862,83 +862,361 @@
 rn(%60
-.eslintrc parsing error: $%7Be%7D %5CnESLint will run with default options.%60);%0A  
+$%7BconfigFile%7D read error: $%7Be%7D%60);%0A            return false;%0A          %7D%0A        %7D)%0A        .length %3E 0;%0A    %7D catch (_error) %7B%0A      useConfig = false;%0A    %7D%0A%0A    if (useConfig === false) %7B%0A      console.warn(%60no usable .eslintrc.* file can be found.%5CnESLint will run with default options.%60);%0A    %7D%0A    const engineConfig = %7B useEslintrc: useConfig %7D;%0A%0A
     
@@ -1247,36 +1247,22 @@
 ine(
-%7BuseEslintrc: false%7D);%0A    %7D
+engineConfig);
 %0A  %7D

allow for alternate .eslintrc.* extensions.