How to use the eslint/lib/util/source-code-fixer.applyFixes 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 codesandbox / codesandbox-client / src / app / utils / codemirror / eslint-lint.js View on Github external
export function fix(source: string) {
  const errors = eslintValidate(source);
  return fixer.applyFixes(linter.getSourceCode(), errors);
}
github liferay / liferay-frontend-source-formatter / lib / lint_js.js View on Github external
var importedAliases = config.importedAliases;

	if (importedAliases) {
		var newGlobals = _.zipObject(importedAliases, _.times(importedAliases.length, _.stubTrue));

		config.globals = _.assign({}, originalGlobals, newGlobals);
	}

	var results = eslint.linter.verify(contents, config, file);

	if (importedAliases) {
		config.globals = originalGlobals;
	}

	if (results.length) {
		var fixedContent = SourceCodeFixer.applyFixes(contents, results);

		if (fixedContent.fixed) {
			contents = fixedContent.output;
		}
	}

	return {
		contents,
		results
	};
};
github codesandbox / codesandbox-client / packages / app / src / app / utils / codemirror / eslint-lint.js View on Github external
export function fix(source: string) {
  const errors = eslintValidate(source);
  return fixer.applyFixes(linter.getSourceCode(), errors);
}
github github / eslint-plugin-github / lib / formatters / stylish-fixes.js View on Github external
output += `${relativePath}\n`

    for (const message of messages) {
      output += `${message.line}:${message.column} ${message.ruleId || ''}`
      if (message.ruleId) {
        const ruleURI = getRuleURI(message.ruleId)
        if (ruleURI.found) {
          output += `  (${ruleURI.url})`
        }
      }
      output += `\n\t${message.message}\n`
    }

    if (messages.some(msg => msg.fix)) {
      const fixResult = SourceCodeFixer.applyFixes(result.source, messages)
      output += `\n\n$ eslint --fix ${relativePath}\n`
      output += diff(result.source, fixResult.output)
    }

    output += '\n\n'
  }

  const total = errors + warnings

  if (total > 0) {
    output += [
      '\u2716 ',
      total,
      pluralize(' problem', total),
      ' (',
      errors,