Skip to content

Commit

Permalink
Merge pull request #56 from Turbo87/backport
Browse files Browse the repository at this point in the history
Backport commits from master to 2.x
  • Loading branch information
Turbo87 authored Aug 19, 2016
2 parents 3d766be + 2c54e05 commit 5072437
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 154 deletions.
22 changes: 0 additions & 22 deletions .eslintrc

This file was deleted.

13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 6
},
env: {
node: true
},
rules: {
}
};
126 changes: 62 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,96 @@
# [broccoli](https://github.com/joliss/broccoli)-lint-eslint
# broccoli-lint-eslint

[![build status](https://secure.travis-ci.org/jonathanKingston/broccoli-lint-eslint.svg)](http://travis-ci.org/jonathanKingston/broccoli-lint-eslint)
[![npm status](http://img.shields.io/npm/v/broccoli-lint-eslint.svg)](https://www.npmjs.org/package/broccoli-lint-eslint)
[![dependency status](https://david-dm.org/jonathanKingston/broccoli-lint-eslint.svg)](https://david-dm.org/jonathanKingston/broccoli-lint-eslint)
[![Latest NPM release][npm-badge]][npm-badge-url]
[![TravisCI Build Status][travis-badge]][travis-badge-url]
[![License][license-badge]][license-badge-url]
[![Dependencies][dependencies-badge]][dependencies-badge-url]
[![Dev Dependencies][devDependencies-badge]][devDependencies-badge-url]


> Lint JavaScript with [ESLint][eslint] as part of your [Broccoli][broccoli] build pipeline.
> Lint JavaScript using [Eslint](http://eslint.org/)

This is a fork of [makepanic/broccoli-eslint](https://github.com/makepanic/broccoli-eslint) used to add new features and keep up to date with the latest ESLint. This fork may go away however it will track any API changes made to it's fork as long as possible.
Most of the test setup and the build configuration is based on [sindresorhus/grunt-eslint](https://github.com/sindresorhus/grunt-eslint).
The internal validation is heavily inspired by [eslint cli.js](https://github.com/eslint/eslint/blob/master/lib/cli.js)
The internal validation is heavily inspired by [eslint cli.js](https://github.com/eslint/eslint/blob/master/lib/cli.js).

## Install
## Installation

```bash
npm install --save broccoli-lint-eslint
npm install broccoli-lint-eslint@2
```

## Example
## Usage

Note: The API will change in subsequent 0.x versions.

```js
```javascript
var eslint = require('broccoli-lint-eslint');
tree = eslint(tree, options);
var outputNode = eslint(inputNode, options);
```

## API

### eslint(tree, options)
### API

#### options
* `inputNode` A [Broccoli node](https://github.com/broccolijs/broccoli/blob/master/docs/node-api.md)

##### format
* `options` {Object}
* `format` {string|function}: The path, or function reference, to a custom formatter (See [eslint/tree/master/lib/formatters](https://github.com/eslint/eslint/tree/master/lib/formatters) for alternatives).

Type: `String`
Default: `'eslint/lib/formatters/stylish'`
Default: `'eslint/lib/formatters/stylish'`

Path path to a custom formatter (See [eslint/tree/master/lib/formatters](https://github.com/eslint/eslint/tree/master/lib/formatters) for alternatives).
* `testGenerator` {`string|function(relativePath, errors), returns reporter output string`}: The function used to generate test modules. You can provide a custom function for your client side testing framework of choice.

##### testGenerator
Default: `null`

Type: `function` or `string`
Default: `null`
If you provide a `string` one of the [predefined test generators](lib/test-generators.js) is used. Currently supported are `qunit` and `mocha`.

The function used to generate test modules. You can provide a custom function for your client side testing framework of choice.
Example usage:

The function receives the following arguments:
```javascript
var path = require('path');

- relativePath - The relative path to the file being tested.
- errors - An array of eslint error objects found.
function testGenerator(relativePath, errors) {
return "module('" + path.dirname(relativePath) + "');\n";
"test('" + relativePath + "' should pass ESLint', function() {\n" +
" ok(" + passed + ", '" + moduleName + " should pass ESLint." + (errors ? "\\n" + errors : '') + "');\n" +
"});\n";
};

If you provide a `string` one of the [predefined test generators](lib/test-generators.js) is used. Currently supported are `qunit` and `mocha`.

Example usage:
```
var path = require('path');
function testGenerator(relativePath, errors) {
return "module('" + path.dirname(relativePath) + "');";
"test('" + relativePath + "' should pass ESLint', function() { " +
" ok(" + passed + ", " + moduleName + " should pass ESLint." + (errors ? "\n" + errors : '')); " +
"});
};
return eslint(tree, {
options: {
configFile: this.jshintrc.app + '/eslint.json',
rulesdir: this.jshintrc.app
},
testGenerator: testGenerator
});
```
return eslint(inputNode, {
options: {
configFile: this.jshintrc.app + '/eslint.json',
rulesdir: this.jshintrc.app
},
testGenerator: testGenerator
});
```

##### throwOnError
* `throwOnError` {boolean}: Cause exception error on first severe error.

Type: `Boolean`
Default: `false`

Cause exception error on first severe error
* `options` {options}: [Options native to ESLint CLI](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) that `broccoli-lint-eslint` makes use of:

##### options
Options native to ESLint CLI: [CLIEngine options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine)
* `configFile` {string}: Path to eslint configuration file.

###### configFile
Default: `./eslintrc`

Type: `String`
Default: `./.eslintrc`
* `rulePaths` {Array}: Paths to a directory with custom rules. Your custom rules will be used in addition to the built-in ones. Recommended read: [Working with Rules](https://github.com/eslint/eslint/blob/master/docs/developer-guide/working-with-rules.md).

Path to eslint configuration file.
Default: [built-in rules directory](https://github.com/eslint/eslint/tree/master/lib/rules)

###### rulePaths
* `ignore` {boolean}: `false` disables use of `.eslintignore`, `ignorePath` and `ignorePattern`

Type: `Array`
Default: [built-in rules directory](https://github.com/eslint/eslint/tree/master/lib/rules)
Default: `true`

Paths to a directory with custom rules. Your custom rules will be used in addition to the built-in ones.
[eslint]: http://eslint.org/
[broccoli]: https://github.com/joliss/broccoli

Recommended read: [Working with Rules](https://github.com/eslint/eslint/blob/master/docs/developer-guide/working-with-rules.md)
<!-- Badging -->
[npm-badge]: https://img.shields.io/npm/v/broccoli-lint-eslint.svg
[npm-badge-url]: https://www.npmjs.com/package/broccoli-lint-eslint
[travis-badge]: https://img.shields.io/travis/ember-cli/broccoli-lint-eslint/2.x.svg?label=TravisCI
[travis-badge-url]: https://travis-ci.org/ember-cli/broccoli-lint-eslint
[license-badge]: https://img.shields.io/npm/l/broccoli-lint-eslint.svg
[license-badge-url]: LICENSE.md
[dependencies-badge]: https://img.shields.io/david/ember-cli/broccoli-lint-eslint.svg
[dependencies-badge-url]: https://david-dm.org/ember-cli/broccoli-lint-eslint
[devDependencies-badge]: https://img.shields.io/david/dev/ember-cli/broccoli-lint-eslint.svg
[devDependencies-badge-url]: https://david-dm.org/ember-cli/broccoli-lint-eslint#info=devDependencies
9 changes: 9 additions & 0 deletions conf/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = {
extends: 'eslint:recommended',
rules: {
'no-console': 'off',
quotes: ['warn', 'double']
}
};
7 changes: 0 additions & 7 deletions conf/eslint.json

This file was deleted.

16 changes: 10 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ function EslintValidationFilter(inputNode, options) {
this.formatter = require(this.options.format || 'eslint/lib/formatters/stylish');
}

this.console = options.console || console;

this.cli = new CLIEngine(eslintOptions);

this.eslintrc = resolveInputDirectory(inputNode);
Expand Down Expand Up @@ -175,9 +177,9 @@ EslintValidationFilter.prototype.processString = function processString(content,
output: content
};

if (this.testGenerator) {
const result = filteredOutput.results[0];
const messages = result.messages;
if (this.testGenerator && Array.isArray(filteredOutput.results)) {
const result = filteredOutput.results[0] || {};
const messages = result.messages || [];

toCache.output = this.testGenerator(relativePath, messages, result);
}
Expand All @@ -190,11 +192,13 @@ EslintValidationFilter.prototype.postProcess = function postProcess(fromCache) {
const output = fromCache.output;

// if verification has result
if (lint.results.length &&
lint.results[0].messages.length) {
if (lint.results.length && lint.results[0].messages.length) {

// log formatter output
console.log(this.formatter(lint.results));
const results = this.formatter(lint.results);
if (results) {
this.console.log(results);
}

if (getResultSeverity(lint.results) > 0) {
if ('throwOnError' in this.internalOptions && this.internalOptions.throwOnError === true) {
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@
},
"repository": {
"type": "git",
"url": "git://github.com/jonathanKingston/broccoli-lint-eslint.git"
"url": "git://github.com/ember-cli/broccoli-lint-eslint.git"
},
"keywords": [
"eslint",
"lint",
"broccoli",
"broccoli-eslint",
"broccoli-lint",
"validate",
"jshint",
"jslint",
"esprima",
"broccoli-plugin"
],
"files": [
"build",
"lib",
"tests",
"conf"
"build/index.js"
],
"author": "Jonathan Kingston",
"license": "MIT",
"bugs": {
"url": "https://github.com/jonathanKingston/broccoli-lint-eslint/issues"
"url": "https://github.com/ember-cli/broccoli-lint-eslint/issues"
},
"homepage": "https://github.com/jonathanKingston/broccoli-lint-eslint",
"homepage": "https://github.com/ember-cli/broccoli-lint-eslint",
"dependencies": {
"broccoli-persistent-filter": "^1.2.0",
"escape-string-regexp": "^1.0.5",
Expand All @@ -56,7 +55,7 @@
"chai": "^3.5.0",
"es6-promise": "^3.2.1",
"eslint-config-nightmare-mode": "^2.3.0",
"mocha": "^2.2.4",
"mocha": "^3.0.1",
"rimraf": "^2.5.1",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0"
Expand Down
13 changes: 0 additions & 13 deletions test/.eslintrc

This file was deleted.

15 changes: 15 additions & 0 deletions test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

module.exports = {
env: {
mocha: true
},
globals: {
chai: false,
expect: false
},
rules: {
'no-invalid-this': 'off',
'arrow-body-style': ['off', "as-needed"]
}
};
14 changes: 0 additions & 14 deletions test/file-format-tests/.eslintrc

This file was deleted.

16 changes: 16 additions & 0 deletions test/file-format-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

module.exports = {
env: {
mocha: true
},
globals: {
chai: false,
expect: false
},
rules: {
'quotes': 'off',
'no-invalid-this': 'off',
'arrow-body-style': ['off', "as-needed"]
}
};
3 changes: 1 addition & 2 deletions test/file-format-tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Supporting different config file formats', function describeMultipleFo

return new Promise((resolve) => {

it(`detects configuration files with the ${format} file type`, function configFileTypeSupport(done) {
it(`detects configuration files with the ${format} file type`, function configFileTypeSupport() {
const filesPath = path.join(process.cwd(), 'test/file-format-tests/formats', format);

const promise = runEslint(filesPath, {
Expand All @@ -37,7 +37,6 @@ describe('Supporting different config file formats', function describeMultipleFo
return promise.then(function assertLinting({buildLog}) {
expect(buildLog, 'Reported erroroneous single-quoted strings').to.have.string(MESSAGES.DOUBLEQUOTE);
expect(buildLog, 'Reported erroroneous use of alert').to.have.string(MESSAGES.ALERT);
done();
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/run-eslint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const broccoli = require('broccoli');
const eslint = require('../../');
const eslintValidationFilter = require('../../');

module.exports = function runEslint(path, _options) {
const options = _options || {};
Expand All @@ -15,10 +15,10 @@ module.exports = function runEslint(path, _options) {
};
options.options = options.options || {};

const tree = eslint(path, options);
const tree = eslintValidationFilter(path, options);
const builder = new broccoli.Builder(tree);
const promise = builder.build().then(function builderThen() {
return {buildLog: buildLog.join('\n'), outputPath: tree.outputPath};
return { buildLog: buildLog.join('\n'), outputPath: tree.outputPath };
});

promise.finally(function builderCleanup() {
Expand Down
Loading

0 comments on commit 5072437

Please sign in to comment.