Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/grunt-eslint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c4d67329e8fe14f0c02006f847681697cefc12ce
Choose a base ref
...
head repository: sindresorhus/grunt-eslint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2922b4c624ceb003106c74f75087070e1a43aaf9
Choose a head ref
  • 16 commits
  • 11 files changed
  • 6 contributors

Commits on Jun 12, 2017

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    addaleax Anna Henningsen
    Copy the full SHA
    eab8924 View commit details

Commits on Jun 13, 2017

  1. Update to ESLint 4 (#143)

    ChristianMurphy authored and sindresorhus committed Jun 13, 2017

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    addaleax Anna Henningsen
    Copy the full SHA
    79d5e1f View commit details
  2. 20.0.0

    sindresorhus committed Jun 13, 2017

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    addaleax Anna Henningsen
    Copy the full SHA
    fdbd6b0 View commit details

Commits on Aug 31, 2017

  1. Use to latest Chalk (#151)

    enure authored and sindresorhus committed Aug 31, 2017

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    addaleax Anna Henningsen
    Copy the full SHA
    d3746ac View commit details
  2. Meta tweaks

    sindresorhus committed Aug 31, 2017

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    addaleax Anna Henningsen
    Copy the full SHA
    7cb3039 View commit details
  3. 20.1.0

    sindresorhus committed Aug 31, 2017

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    addaleax Anna Henningsen
    Copy the full SHA
    1d97ae7 View commit details

Commits on Jun 9, 2018

  1. Add failOnError option (#154)

    iudelsmann authored and sindresorhus committed Jun 9, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    chjj Christopher Jeffrey (JJ)
    Copy the full SHA
    1154917 View commit details
  2. 20.2.0

    sindresorhus committed Jun 9, 2018

    Unverified

    The committer email address is not verified.
    Copy the full SHA
    f7a2a05 View commit details
  3. Unverified

    The committer email address is not verified.
    Copy the full SHA
    e1d6368 View commit details

Commits on Jun 23, 2018

  1. Unverified

    The committer email address is not verified.
    Copy the full SHA
    476f21e View commit details
  2. 21.0.0

    sindresorhus committed Jun 23, 2018

    Unverified

    The committer email address is not verified.
    Copy the full SHA
    f30dd97 View commit details

Commits on May 23, 2019

  1. Unverified

    The committer email address is not verified.
    Copy the full SHA
    31a8b14 View commit details

Commits on Jun 12, 2019

  1. Unverified

    The committer email address is not verified.
    Copy the full SHA
    7950891 View commit details
  2. 21.1.0

    sindresorhus committed Jun 12, 2019

    Unverified

    The committer email address is not verified.
    Copy the full SHA
    a18f9ee View commit details

Commits on Jun 30, 2019

  1. Unverified

    The committer email address is not verified.
    Copy the full SHA
    7707f60 View commit details
  2. 22.0.0

    sindresorhus committed Jun 30, 2019

    Unverified

    The committer email address is not verified.
    Copy the full SHA
    2922b4c View commit details
Showing with 77 additions and 86 deletions.
  1. +1 −1 .editorconfig
  2. +1 −1 .gitattributes
  3. +4 −0 .github/funding.yml
  4. +1 −0 .gitignore
  5. +1 −0 .npmrc
  6. +3 −3 .travis.yml
  7. +1 −1 conf/rules/no-alert.js
  8. +4 −16 license
  9. +38 −44 package.json
  10. +8 −6 readme.md
  11. +15 −14 tasks/eslint.js
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
4 changes: 4 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: sindresorhus
open_collective: sindresorhus
patreon: sindresorhus
custom: https://sindresorhus.com/donate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sudo: false
language: node_js
node_js:
- '6'
- '4'
- '12'
- '10'
- '8'
2 changes: 1 addition & 1 deletion conf/rules/no-alert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
module.exports = function (context) {
return {
CallExpression: function (node) {
CallExpression(node) {
if (node.callee.name === 'alert') {
context.report(node, 'testing custom rules.');
}
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
82 changes: 38 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
{
"name": "grunt-eslint",
"version": "19.0.0",
"description": "Validate files with ESLint",
"license": "MIT",
"repository": "sindresorhus/grunt-eslint",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "grunt"
},
"files": [
"tasks"
],
"keywords": [
"gruntplugin",
"lint",
"validate",
"report",
"jshint",
"jslint",
"ecmascript",
"esprima"
],
"dependencies": {
"chalk": "^1.0.0",
"eslint": "^3.0.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-shell": "^1.1.1"
},
"peerDependencies": {
"grunt": ">=0.4.0"
},
"xo": {
"esnext": true
}
"name": "grunt-eslint",
"version": "22.0.0",
"description": "Validate files with ESLint",
"license": "MIT",
"repository": "sindresorhus/grunt-eslint",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "grunt"
},
"files": [
"tasks"
],
"keywords": [
"gruntplugin",
"eslint",
"lint",
"validate",
"report"
],
"dependencies": {
"chalk": "^2.1.0",
"eslint": "^6.0.1"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-shell": "^3.0.1"
},
"peerDependencies": {
"grunt": ">=1"
}
}
14 changes: 8 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# grunt-eslint [![Build Status](https://travis-ci.org/sindresorhus/grunt-eslint.svg?branch=master)](https://travis-ci.org/sindresorhus/grunt-eslint)

> Validate files with [ESLint](http://eslint.org)
> Validate files with [ESLint](https://eslint.org)
![](screenshot.png)

@@ -15,7 +15,7 @@ $ npm install --save-dev grunt-eslint
## Usage

```js
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
require('load-grunt-tasks')(grunt);

grunt.initConfig({
eslint: {
@@ -59,7 +59,7 @@ grunt.initConfig({

## Options

See the [ESLint options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine).
See the [ESLint options](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).

In addition the following options are supported:

@@ -89,11 +89,13 @@ Report errors only.
### maxWarnings

Type: `number`<br>
Default: `-1` *(means no limit)*
Default: `-1` *(Means no limit)*

Number of warnings to trigger non-zero exit code.

### failOnError

## License
Type: `boolean`<br>
Default: `true`

MIT © [Sindre Sorhus](https://sindresorhus.com)
Fail the build if ESLint found any errors.
29 changes: 15 additions & 14 deletions tasks/eslint.js
Original file line number Diff line number Diff line change
@@ -4,58 +4,59 @@ const eslint = require('eslint');

module.exports = grunt => {
grunt.registerMultiTask('eslint', 'Validate files with ESLint', function () {
const opts = this.options({
const options = this.options({
outputFile: false,
quiet: false,
maxWarnings: -1
maxWarnings: -1,
failOnError: true,
});

if (this.filesSrc.length === 0) {
grunt.log.writeln(chalk.magenta('Could not find any files to validate'));
return true;
}

const formatter = eslint.CLIEngine.getFormatter(opts.format);
const formatter = eslint.CLIEngine.getFormatter(options.format);

if (!formatter) {
grunt.warn(`Could not find formatter ${opts.format}`);
grunt.warn(`Could not find formatter ${options.format}`);
return false;
}

const engine = new eslint.CLIEngine(opts);
const engine = new eslint.CLIEngine(options);

let report;
try {
report = engine.executeOnFiles(this.filesSrc);
} catch (err) {
grunt.warn(err);
} catch (error) {
grunt.warn(error);
return false;
}

if (opts.fix) {
if (options.fix) {
eslint.CLIEngine.outputFixes(report);
}

let results = report.results;

if (opts.quiet) {
if (options.quiet) {
results = eslint.CLIEngine.getErrorResults(results);
}

const output = formatter(results);

if (opts.outputFile) {
grunt.file.write(opts.outputFile, output);
if (options.outputFile) {
grunt.file.write(options.outputFile, output);
} else if (output) {
console.log(output);
}

const tooManyWarnings = opts.maxWarnings >= 0 && report.warningCount > opts.maxWarnings;
const tooManyWarnings = options.maxWarnings >= 0 && report.warningCount > options.maxWarnings;

if (report.errorCount === 0 && tooManyWarnings) {
grunt.warn(`ESLint found too many warnings (maximum: ${opts.maxWarnings})`);
grunt.warn(`ESLint found too many warnings (maximum: ${options.maxWarnings})`);
}

return report.errorCount === 0;
return options.failOnError ? report.errorCount === 0 : 0;
});
};