Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

formatter setting should be easy to fix #25

Open
bcosca opened this issue Feb 26, 2019 · 0 comments
Open

formatter setting should be easy to fix #25

bcosca opened this issue Feb 26, 2019 · 0 comments

Comments

@bcosca
Copy link

bcosca commented Feb 26, 2019

See code for index.js below:

'use strict';

const CLIEngine = require('eslint').CLIEngine;

class ESLinter {
  constructor(brunchConfig) {
    this.config = (brunchConfig && brunchConfig.plugins && brunchConfig.plugins.eslint) || {};
    this.warnOnly = (typeof this.config.warnOnly === 'boolean') ? this.config.warnOnly : true;
    this.pattern = this.config.pattern || /^app[\/\\].*\.js?$/;
    this.engineOptions = this.config.config || {};
    this.formatter = this.config.formatter || 'stylish';
    this.linter = new CLIEngine(this.engineOptions);
  }

  lint(data, path) {
    const report = this.linter.executeOnText(data, path);
    if (report.errorCount === 0 && report.warningCount === 0) {
      return Promise.resolve();
    }
    const formatter = CLIEngine.getFormatter(this.formatter);
    let msg = 'ESLint reported:\n' + formatter(report.results);
    if (this.warnOnly) {
      msg = `warn: ${msg}`;
    }
    return Promise.reject(msg);
  }
}

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

module.exports = ESLinter;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant