How to use the eslint.CLIEngine.outputFixes function in eslint

To help you get started, we’ve selected a few eslint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / eslint-plugin-unicorn / test / lint / lint.js View on Github external
// Make sure rules are loaded from codebase
const loadedRules = cli.getRules();
if (!ruleIds.every(ruleId => unicornRules.get(ruleId) === loadedRules.get(`unicorn/${ruleId}`))) {
	console.error('`eslint-plugin-unicorn` rules are not loaded from codebase.');
	process.exit(1);
}

const report = cli.executeOnFiles(files);

const {errorCount, warningCount, fixableErrorCount, fixableWarningCount} = report;

const hasFixable = fixableErrorCount || fixableWarningCount;

if (fix && hasFixable) {
	CLIEngine.outputFixes(report);
}

if (errorCount || warningCount) {
	const formatter = cli.getFormatter();
	console.log(formatter(report.results));

	console.log();
	console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run lint \` to check again.`);

	if (hasFixable) {
		console.log();
		console.log('You may also want run `npm run lint  --fix` to fix fixable problems.');
	}

	console.log();
	console.log('* If you\'re making a new rule, you can fix this later. *');
github kongnet / sky / lib / cc / index.js View on Github external
jtRule.resolvePluginsRelativeTo = path.join(__dirname, '../../node_modules')
    jtRule.useEslintrc = false // 忽略 .eslintrc文件
    jtRule.extensions = ['.js', '.html', '.htm', '.vue']
    jtRule.fix = isFixing
    const cli = new CLIEngine(jtRule)

    const report = cli.executeOnFiles(['.'])
    const formatHtml = cli.getFormatter(
      path.join(
        __dirname,
        '../../node_modules',
        'eslint-formatter-html-extended'
      )
    )
    const formatDefault = cli.getFormatter(isStat ? 'json' : '')
    CLIEngine.outputFixes(report)
    console.log(
      isStat ? eslintJson(report.results) : formatDefault(report.results)
    )
    // fs.writeFileSync('jtFrontCheck.html', formatHtml(report.results))
    console.log(
      $.c.y('jtFrontCheck.html 成功生成!'),
      '本次扫描耗时',
      Date.now() - t,
      'ms'
    )
  } catch (e) {
    if (e.toString().includes('No files matching')) {
      console.log($.c.c('您的项目没有任何问题,厉害'))
    } else {
      console.log(e.stack)
      console.log($.c.y('请尝试运行 skyjt ccjt '))
github kongnet / sky / lib / cc / index.js View on Github external
)
    jtRule.resolvePluginsRelativeTo = path.join(__dirname, '../../node_modules')
    jtRule.useEslintrc = false // 忽略 .eslintrc文件
    jtRule.extensions = ['.js', '.html', '.htm', '.vue']

    const cli = new CLIEngine(jtRule)
    const report = cli.executeOnFiles(['.'])
    const formatHtml = cli.getFormatter(
      path.join(
        __dirname,
        '../../node_modules',
        'eslint-formatter-html-extended'
      )
    )
    const formatDefault = cli.getFormatter('')
    CLIEngine.outputFixes(report)
    console.log(formatDefault(report.results))
    fs.writeFileSync('jtFrontEasyCheck.html', formatHtml(report.results))
    console.log(
      $.c.y('jtFrontEasyCheck.html 成功生成!'),
      '本次扫描耗时',
      Date.now() - t,
      'ms'
    )
  } catch (e) {
    if (e.toString().includes('No files matching')) {
      console.log($.c.c('您的项目没有任何问题,厉害'))
    } else {
      console.log(e.stack)
      console.log($.c.y('请尝试运行 skyjt ccjt '))
    }
  }
github ipfs / aegir / src / lint.js View on Github external
.then(files => {
      const report = cli.executeOnFiles(files)
      if (opts.fix) {
        CLIEngine.outputFixes(report)
      }
      console.log(formatter(report.results)) // eslint-disable-line no-console

      if (report.errorCount > 0) {
        throw new Error('Lint errors')
      }
      return report
    })
}
github curioswitch / curiostack / common / web / base-web / src / dev / scripts / check.ts View on Github external
diagnostics,
        new FormatTypescriptHost(),
      ),
    );
    process.exit(1);
  }

  const lintCli = new CLIEngine({
    fix: !!fix,
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
    ignorePattern: ['*.d.ts'],
  });

  const report = lintCli.executeOnFiles(['src/']);
  if (fix) {
    CLIEngine.outputFixes(report);
  }
  console.log(lintCli.getFormatter()(report.results));
  return report.errorCount === 0;
}
github mysticatea / eslint-plugin / scripts / generate-configs.js View on Github external
"use strict"

module.exports = {
${fs
    .readdirSync(path.resolve(__dirname, "../lib/configs"))
    .map(fileName => path.basename(fileName, ".js"))
    .filter(id => !id.startsWith("_"))
    .map(id => `    "${id}": require("./configs/${id}"),`)
    .join("\n")}
}
`
)

const linter = new CLIEngine({ fix: true })
const result = linter.executeOnFiles([targetFile])
CLIEngine.outputFixes(result)
github mysticatea / eslint-plugin / scripts / generate-rules.js View on Github external
.map(id => `    require("./foreign-rules/${id}"),`)
    .join("\n")}
    {
${fs
    .readdirSync(path.resolve(__dirname, "../lib/rules"))
    .map(fileName => path.basename(fileName, ".js"))
    .map(id => `        "${id}": require("./rules/${id}"),`)
    .join("\n")}
    }
)
`
)

const linter = new CLIEngine({ fix: true })
const result = linter.executeOnFiles([targetFile])
CLIEngine.outputFixes(result)
github qooxdoo / qooxdoo-compiler / source / class / qx / tool / cli / commands / Lint.js View on Github external
cache: this.argv.cache || false,
        baseConfig: lintOptions,
        useEslintrc: useEslintrc,
        fix: this.argv.fix
      });
      let files = this.argv.files || [];
      if (files.length === 0) {
        files.push("source/class/");
      }
      if (this.argv.config) {
        const fileConfig = linter.getConfigForFile(files[0]);
        qx.tool.compiler.Console.info(JSON.stringify(fileConfig, null, "  "));
      } else {
        let report = linter.executeOnFiles(files);
        if (this.argv.fix) {
          CLIEngine.outputFixes(report);
        }
        if (report.errorCount > 0 || report.warningCount > 0) {
          let outputFormat = this.argv.format || "codeframe";
          const formatter = linter.getFormatter(outputFormat);
          const s = formatter(report.results);
          if (this.argv.outputFile) {
            if (this.argv.verbose) {
              qx.tool.compiler.Console.info(`Report to be written to ${this.argv.outputFile}`);
            }
            await fs.writeFileAsync(this.argv.outputFile, s, "UTF-8")
              .then(() => {
                if (this.argv.verbose) {
                  qx.tool.compiler.Console.info(`Report written to ${this.argv.outputFile}`);
                } 
              })
              .catch(e => qx.tool.compiler.Console.error(`Error writing report to ${this.argv.outputFile}:` + e.message));
github cjihrig / belly-button / lib / cli.js View on Github external
function lintFiles (options) {
  const fix = options.fix;
  const linter = new CLIEngine({
    configFile: options.configFile,
    useEslintrc: false,
    fix,
    cache: options.cache
  });

  const result = linter.executeOnFiles(options.files);

  if (fix) {
    CLIEngine.outputFixes(result);
  }

  return result;
}