Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 15, 2021
1 parent dbaf9d5 commit 7bb705b
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 63 deletions.
4 changes: 0 additions & 4 deletions .github/funding.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
8 changes: 4 additions & 4 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ module.exports = grunt => {
eslint: {
command: 'grunt eslint',
options: {
callback: (err, stdout, stderr, cb) => {
callback: (error, stdout, stderr, callback) => {
if (/test\/fixture\/2\.js/.test(stdout)) {
if (/camelcase/.test(stdout) && !/\swarning\s/.test(stdout)) {
cb();
callback();
} else {
cb(false);
callback(false);
}
} else {
cb(false);
callback(false);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"report"
],
"dependencies": {
"chalk": "^4.0.0",
"eslint": "^8.0.0"
"chalk": "^4.1.2",
"eslint": "^8.0.1"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-cli": "^1.4.3",
"grunt-shell": "^3.0.1"
},
"peerDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

## Install

```
$ npm install --save-dev grunt-eslint
```sh
npm install --save-dev grunt-eslint
```

## Usage
Expand Down Expand Up @@ -64,7 +64,7 @@ In addition the following options are supported:
Type: `string`\
Default: `'stylish'`

Name of a [built-in formatter](https://github.com/eslint/eslint/tree/master/lib/cli-engine/formatters) or path to a custom one.
The name of a [built-in formatter](https://github.com/eslint/eslint/tree/master/lib/cli-engine/formatters) or path to a custom one.

Some formatters you might find useful: [eslint-json](https://github.com/sindresorhus/eslint-json), [eslint-tap](https://github.com/sindresorhus/eslint-tap).

Expand All @@ -87,7 +87,7 @@ Report errors only.
Type: `number`\
Default: `-1` *(Means no limit)*

Number of warnings to trigger non-zero exit code.
The nmber of warnings to trigger non-zero exit code.

### failOnError

Expand Down
103 changes: 56 additions & 47 deletions tasks/eslint.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,76 @@
'use strict';
const chalk = require('chalk');
const { ESLint } = require('eslint');
const {ESLint} = require('eslint');

module.exports = grunt => {
grunt.registerMultiTask('eslint', 'Validate files with ESLint', async function () {
grunt.registerMultiTask('eslint', 'Validate files with ESLint', function () {
const done = this.async();

try {
const { format, quiet, maxWarnings, failOnError, outputFile, ...options } = this.options({
outputFile: false,
quiet: false,
maxWarnings: -1,
failOnError: true,
format: "stylish"
});
(async () => {
try {
const {
format,
quiet,
maxWarnings,
failOnError,
outputFile,
...options
} = this.options({
outputFile: false,
quiet: false,
maxWarnings: -1,
failOnError: true,
format: 'stylish'
});

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

const engine = new ESLint(options);
const engine = new ESLint(options);

const formatter = await engine.loadFormatter(format);
const formatter = await engine.loadFormatter(format);

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

let results = await engine.lintFiles(this.filesSrc);
let results = await engine.lintFiles(this.filesSrc);

if (options.fix) {
await ESLint.outputFixes(results);
}
if (options.fix) {
await ESLint.outputFixes(results);
}

if (quiet) {
results = ESLint.getErrorResults(results);
}
if (quiet) {
results = ESLint.getErrorResults(results);
}

const output = formatter.format(results);
const output = formatter.format(results);

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

const { warningCount, errorCount } = results.reduce((count, { warningCount, errorCount }) => {
count.warningCount += warningCount;
count.errorCount += errorCount;
return count;
}, { warningCount: 0, errorCount: 0 });
const {warningCount, errorCount} = results.reduce((count, {warningCount, errorCount}) => {
count.warningCount += warningCount;
count.errorCount += errorCount;
return count;
}, {warningCount: 0, errorCount: 0});

const tooManyWarnings = maxWarnings >= 0 && warningCount > maxWarnings;
const tooManyWarnings = maxWarnings >= 0 && warningCount > maxWarnings;

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

done(failOnError ? errorCount === 0 : 0);
} catch (err) {
done(err);
}
done(failOnError ? errorCount === 0 : 0);
} catch (error) {
done(error);
}
})();
});
};
};

0 comments on commit 7bb705b

Please sign in to comment.