Skip to content

Commit

Permalink
Docs: Update example of results returned from executeOnFiles (eslin…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and nzakas committed Nov 3, 2016
1 parent 4613ba0 commit f5764ee
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions docs/developer-guide/nodejs-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,75 @@ The return value is an object containing the results of the linting operation. H
{
results: [
{
filePath: "./myfile.js",
output: "foo;",
filePath: "/Users/eslint/project/myfile.js",
messages: [{
ruleId: "semi",
severity: 2,
message: "Missing semicolon.",
line: 1,
column: 13,
nodeType: "ExpressionStatement",
source: "\"use strict\"", // Deprecated: see "please note" paragraph below.
fix: { range: [12, 12], text: ";" }
}],
errorCount: 1,
warningCount: 0,
source: "\"use strict\"\n"
}
],
errorCount: 1,
warningCount: 0
}
```

You can also pass `fix: true` when instantiating the `CLIEngine` in order to have it figure out what fixes can be applied.

```js
var CLIEngine = require("eslint").CLIEngine;

var cli = new CLIEngine({
envs: ["browser", "mocha"],
fix: true, // difference from last example
useEslintrc: false,
rules: {
semi: 2,
quotes: [2, "double"]
}
});

// lint myfile.js and all files in lib/
var report = cli.executeOnFiles(["myfile.js", "lib/"]);
```

```js
{
results: [
{
filePath: "/Users/eslint/project/myfile.js",
messages: [
{
severity: 2,
ruleId: "semi",
severity: 2,
message: "Missing semicolon.",
line: 1,
column: 23,
message: "Expected a semicolon."
column: 13,
nodeType: "ExpressionStatement",
source: "\"use strict\"", // Deprecated: see "please note" paragraph below.
fix: { range: [12, 12], text: ";" }
},
{
ruleId: "func-name-matching",
severity: 2,
message: "Function name `bar` should match variable name `foo`",
line: 2,
column: 5,
nodeType: "VariableDeclarator",
source: "var foo = function bar() {};"
}
],
errorCount: 1,
warningCount: 0
warningCount: 0,
output: "\"use strict\";\nvar foo = function bar() {};\nfoo();\n"
}
],
errorCount: 1,
Expand Down Expand Up @@ -482,6 +537,7 @@ var CLIEngine = require("eslint").CLIEngine;

var cli = new CLIEngine({
envs: ["browser", "mocha"],
fix: true,
useEslintrc: false,
rules: {
semi: 2
Expand Down

0 comments on commit f5764ee

Please sign in to comment.