Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,188 @@
# 1.9.0 - 2017-07-06
- Added: `eslintPath` option so you can provide your own eslint path.
([#183](https://github.com/MoOx/eslint-loader/pull/183) - @trungdq88)
# 1.8.0 - 2017-06-15
- Added: support for eslint@^4.0.0
([#178](https://github.com/MoOx/eslint-loader/issues/178) - @Aladdin-ADD)
# 1.7.1 - 2017-03-31
- Fixed: Remove duplicate output with webpack 2
([#169](https://github.com/MoOx/eslint-loader/pull/169) - @jaridmargolin)
# 1.7.0 - 2017-03-23
- Fixed: outputReport option writes report for last file checked only
([#160](https://github.com/MoOx/eslint-loader/pull/160) - @deryni)
- Added: use babel loader fs cache as the default caching engine
([#159](https://github.com/MoOx/eslint-loader/pull/159) - @viankakrisna)
# 1.6.3 - 2017-02-22
- Fixed: ignore cache when eslint rules have changed
([#151](https://github.com/MoOx/eslint-loader/pull/151) - @wrakky)
# 1.6.2 - 2017-02-22
- Fixed: fallback to OS temp directory if findCacheDir fails
([#154](https://github.com/MoOx/eslint-loader/pull/154) - @viankakrisna)
- Fixed: `loader-utils` deprecation warning by upgrading to v1.0.0
([#155](https://github.com/MoOx/eslint-loader/pull/155) - @fknussel)
# 1.6.1 - 2016-11-02
- Fixed: multiples config per instance are now supported
([#105](https://github.com/MoOx/eslint-loader/issues/105) -
@jaythomas and @jameslnewell)
# 1.6.0 - 2016-10-17
- Added: Option to generate report file
([#118](https://github.com/MoOx/eslint-loader/pull/118) - @vidhill)
# 1.5.0 - 2016-07-28
- Added: `cache` options
([#93](https://github.com/MoOx/eslint-loader/pull/93) - @genintho)
# 1.4.1 - 2016-06-07
- Fixed: .eslintignore is not ignored anymore (eslint 3.x regression)
([#99](https://github.com/MoOx/eslint-loader/pull/99) - @waiterZen)
# 1.4.0 - 2016-06-02
- Added: support for eslint@^3.0.0
([#96](https://github.com/MoOx/eslint-loader/issues/96))
# 1.3.0 - 2016-02-17
- Added: support for eslint@^2.0.0
([#81](https://github.com/MoOx/eslint-loader/pull/81))
# 1.2.1 - 2016-01-26
- Updated: object-assign dependency
([#77](https://github.com/MoOx/eslint-loader/pull/77))
# 1.2.0 - 2016-01-02
- Added: this loader now pass down the input source map to the next chained
loader if it exists
([#70](https://github.com/MoOx/eslint-loader/pull/70)).
# 1.1.1 - 2015-10-08
- Fixed: `failOnError` and `failOnWarning` now print messages.
# 1.1.0 - 2015-10-08
- Added: `fix` option to enable ESLint auto fix feature.
# 1.0.0 - 2015-08-08
- Added: support for eslint 1.x
- Removed: support for eslint 1.x-rc*
- Removed: support for eslint 0.x
# 0.14.2 - 2015-07-18
- Fixed: support for eslint 1.x-rc
# 0.14.1 - 2015-06-15
- Fixed: support for eslint 0.24.x
# 0.14.0 - 2015-06-15
- Added: support for eslint 0.23.x
# 0.13.0 - 2015-06-14
- Changed: a file that should be ignored doesn't trigger a warning
([#44](https://github.com/MoOx/eslint-loader/issues/44))
# 0.12.0 - 2015-06-04
- Changed: upgrade to eslint 0.22.x
- Fixed: respect .eslintrc/eslintignore files in directory tree
([#21](https://github.com/MoOx/eslint-loader/issues/21))
# 0.11.2 - 2015-05-11
- Fixed: eslint range from 0.17 to 0.21
# 0.11.1 - 2015-04-27
- Fixed: eslint range from 0.17 to 0.20
# 0.11.0 - 2015-04-27
- Changed: upgrade to eslint 0.20.x
# 0.10.0 - 2015-04-13
- Changed: upgrade to eslint 0.19.x
# 0.9.0 - 2015-03-29
- Changed: upgrade to eslint 0.18.x
# 0.8.0 - 2015-03-27
- Changed: `reporter` is now `formatter` option to fit eslint name
- Changed: plugin is now async as it don't need to be sync
- Added: options are supported as query strings
# 0.7.0 - 2015-03-15
- Changed: upgrade to eslint 0.17.x
- Added: `failOnError` option
- Added: `failOnWarning` option
# 0.6.0 - 2015-03-11
- Changed: `reporter` now automatically drop lines that contains the filename in
the reporter output.
That mean you can use official or community reporters without worrying to see
lot of lines with `<text>` as filename :)
# 0.5.0 - 2015-03-11
- Changed: upgrade to eslint 0.16.x
- Changed: `emitErrors` is now `emitError`
- Changed: loader now use `webpack.emitError` or `webpack.emitWarning`
automatically (according to eslint configuration).
You can still override by using `emitError` or `emitWarning` options to override
this behavior
- Added: `emitWarning` can force eslint to report warning instead of the default
behavior (see above)
- Added: `quiet` option to hide warnings
# 0.4.0 - 2015-02-23
- Changed: upgrade to eslint 0.15.x
- Changed: more readable default reporter
- Added: `reporter` options allow to define a custom reporter function
# 0.3.0 - 2015-02-10
- Changed: upgrade to eslint 0.14.x
# 0.2.1 - 2015-01-27
- Changed: upgrade to eslint 0.13.x
# 0.2.0 - 2015-01-23
- Changed: upgrade to eslint 0.12.x
- Added: enable loading of eslint config from webpack config, `.eslintrc`, or
`package.json`
# 0.1.0 - 2014-12-05
✨ Initial release

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Maxime Thirouin
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 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.

View File

@@ -0,0 +1,314 @@
# eslint-loader [![Build Status](http://img.shields.io/travis/MoOx/eslint-loader.svg)](https://travis-ci.org/MoOx/eslint-loader)
> eslint loader for webpack
## Install
```console
$ npm install eslint-loader --save-dev
```
## Usage
In your webpack configuration
```js
module.exports = {
// ...
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
// eslint options (if necessary)
}
},
],
},
// ...
}
```
When using with transpiling loaders (like `babel-loader`), make sure they are in correct order
(bottom to top). Otherwise files will be check after being processed by `babel-loader`
```js
module.exports = {
// ...
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
"babel-loader",
"eslint-loader",
],
},
],
},
// ...
}
```
To be safe, you can use `enforce: "pre"` section to check source files, not modified
by other loaders (like `babel-loader`)
```js
module.exports = {
// ...
module: {
rules: [
{
enforce: "pre",
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
],
},
// ...
}
```
### Options
You can pass [eslint options](http://eslint.org/docs/developer-guide/nodejs-api#cliengine)
using standard webpack [loader options](https://webpack.js.org/configuration/module/#useentry).
Note that the config option you provide will be passed to the `CLIEngine`.
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
See the [eslint docs](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) for more detail.
#### `fix` (default: false)
This option will enable
[ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).
**Be careful: this option might cause webpack to enter an infinite build loop if
some issues cannot be fixed properly.**
#### `cache` (default: false)
This option will enable caching of the linting results into a file.
This is particularly useful in reducing linting time when doing a full build.
The cache file is written to the `./node_modules/.cache` directory.
#### `formatter` (default: eslint stylish formatter)
Loader accepts a function that will have one argument: an array of eslint messages (object).
The function must return the output as a string.
You can use official eslint formatters.
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
// several examples !
// default value
formatter: require("eslint/lib/formatters/stylish"),
// community formatter
formatter: require("eslint-friendly-formatter"),
// custom formatter
formatter: function(results) {
// `results` format is available here
// http://eslint.org/docs/developer-guide/nodejs-api.html#executeonfiles()
// you should return a string
// DO NOT USE console.*() directly !
return "OUTPUT"
}
}
},
],
},
}
```
#### `eslintPath` (default: "eslint")
Path to `eslint` instance that will be used for linting.
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
eslintPath: path.join(__dirname, "reusable-eslint-rules.js"),
}
},
],
},
}
```
#### Errors and Warning
**By default the loader will auto adjust error reporting depending
on eslint errors/warnings counts.**
You can still force this behavior by using `emitError` **or** `emitWarning` options:
##### `emitError` (default: `false`)
Loader will always return errors if this option is set to `true`.
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
emitError: true,
}
},
],
},
}
```
##### `emitWarning` (default: `false`)
Loader will always return warnings if option is set to `true`.
#### `quiet` (default: `false`)
Loader will process and report errors only and ignore warnings if this option is set to true
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
quiet: true,
}
},
],
},
}
```
##### `failOnWarning` (default: `false`)
Loader will cause the module build to fail if there are any eslint warnings.
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
failOnWarning: true,
}
},
],
},
}
```
##### `failOnError` (default: `false`)
Loader will cause the module build to fail if there are any eslint errors.
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
failOnError: true,
}
},
],
},
}
```
##### `outputReport` (default: `false`)
Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI
The `filePath` is relative to the webpack config: output.path
You can pass in a different formatter for the output file, if none is passed in the default/configured formatter will be used
```js
module.exports = {
entry: "...",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
options: {
outputReport: {
filePath: 'checkstyle.xml',
formatter: require('eslint/lib/formatters/checkstyle')
}
}
},
],
},
}
```
## Gotchas
### NoErrorsPlugin
`NoErrorsPlugin` prevents webpack from outputting anything into a bundle. So even ESLint warnings
will fail the build. No matter what error settings are used for `eslint-loader`.
So if you want to see ESLint warnings in console during development using `WebpackDevServer`
remove `NoErrorsPlugin` from webpack config.
### Defining `configFile` or using `eslint -c path/.eslintrc`
Bear in mind that when you define `configFile`, `eslint` doesn't automatically look for
`.eslintrc` files in the directory of the file to be linted.
More information is available in official eslint documentation in section [_Using Configuration Files_](http://eslint.org/docs/user-guide/configuring#using-configuration-files).
See [#129](https://github.com/MoOx/eslint-loader/issues/129).
---
## [Changelog](CHANGELOG.md)
## [License](LICENSE)

View File

@@ -0,0 +1,219 @@
"use strict"
var assign = require("object-assign")
var loaderUtils = require("loader-utils")
var objectHash = require("object-hash")
var pkg = require("./package.json")
var createCache = require("loader-fs-cache")
var cache = createCache("eslint-loader")
var engines = {}
/**
* Class representing an ESLintError.
* @extends Error
*/
class ESLintError extends Error {
/**
* Create an ESLintError.
* @param {string} messages - Formatted eslint errors.
*/
constructor(messages) {
super()
this.name = "ESLintError"
this.message = messages
this.stack = ""
}
/**
* Returns a stringified representation of our error. This method is called
* when an error is consumed by console methods
* ex: console.error(new ESLintError(formattedMessage))
* @return {string} error - A stringified representation of the error.
*/
inspect() {
return this.message
}
}
/**
* printLinterOutput
*
* @param {Object} eslint.executeOnText return value
* @param {Object} config eslint configuration
* @param {Object} webpack webpack instance
* @return {void}
*/
function printLinterOutput(res, config, webpack) {
// skip ignored file warning
if (
!(res.warningCount === 1 &&
res.results[0].messages[0] &&
res.results[0].messages[0].message &&
res.results[0].messages[0].message.indexOf("ignore") > 1)
) {
// quiet filter done now
// eslint allow rules to be specified in the input between comments
// so we can found warnings defined in the input itself
if (res.warningCount && config.quiet) {
res.warningCount = 0
res.results[0].warningCount = 0
res.results[0].messages = res.results[0].messages.filter(function(
message
) {
return message.severity !== 1
})
}
// if enabled, use eslint auto-fixing where possible
if (config.fix && res.results[0].output) {
var eslint = require(config.eslintPath)
eslint.CLIEngine.outputFixes(res)
}
if (res.errorCount || res.warningCount) {
// add filename for each results so formatter can have relevant filename
res.results.forEach(function(r) {
r.filePath = webpack.resourcePath
})
var messages = config.formatter(res.results)
if (config.outputReport && config.outputReport.filePath) {
var reportOutput
// if a different formatter is passed in as an option use that
if (config.outputReport.formatter) {
reportOutput = config.outputReport.formatter(res.results)
}
else {
reportOutput = messages
}
var filePath = loaderUtils.interpolateName(webpack,
config.outputReport.filePath, {
content: res.results.map(function(r) {
return r.source
}).join("\n"),
}
)
webpack.emitFile(filePath, reportOutput)
}
// default behavior: emit error only if we have errors
var emitter = res.errorCount ? webpack.emitError : webpack.emitWarning
// force emitError or emitWarning if user want this
if (config.emitError) {
emitter = webpack.emitError
}
else if (config.emitWarning) {
emitter = webpack.emitWarning
}
if (emitter) {
if (config.failOnError && res.errorCount) {
throw new ESLintError(
"Module failed because of a eslint error.\n" + messages
)
}
else if (config.failOnWarning && res.warningCount) {
throw new ESLintError(
"Module failed because of a eslint warning.\n" + messages
)
}
emitter(webpack.version === 2 ? new ESLintError(messages) : messages)
}
else {
throw new Error(
"Your module system doesn't support emitWarning. " +
"Update available? \n" +
messages
)
}
}
}
}
/**
* webpack loader
*
* @param {String|Buffer} input JavaScript string
* @param {Object} map input source map
* @return {void}
*/
module.exports = function(input, map) {
var webpack = this
var userOptions = assign(
// user defaults
this.options.eslint || {},
// loader query string
loaderUtils.getOptions(this)
)
var config = assign(
// loader defaults
{
formatter: require("eslint/lib/formatters/stylish"),
cacheIdentifier: JSON.stringify({
"eslint-loader": pkg.version,
eslint: require(userOptions.eslintPath || "eslint").version,
}),
eslintPath: "eslint",
},
userOptions
)
var cacheDirectory = config.cache
var cacheIdentifier = config.cacheIdentifier
delete config.cacheDirectory
delete config.cacheIdentifier
// Create the engine only once per config
var configHash = objectHash(config)
if (!engines[configHash]) {
var eslint = require(config.eslintPath)
engines[configHash] = new eslint.CLIEngine(config)
}
this.cacheable()
var resourcePath = webpack.resourcePath
var cwd = process.cwd()
// remove cwd from resource path in case webpack has been started from project
// root, to allow having relative paths in .eslintignore
if (resourcePath.indexOf(cwd) === 0) {
resourcePath = resourcePath.substr(cwd.length + 1)
}
var engine = engines[configHash]
// return early if cached
if (config.cache) {
var callback = this.async()
return cache(
{
directory: cacheDirectory,
identifier: cacheIdentifier,
options: config,
source: input,
transform: function() {
return lint(engine, input, resourcePath)
},
},
function(err, res) {
if (err) {
return callback(err)
}
printLinterOutput(res || {}, config, webpack)
return callback(null, input, map)
}
)
}
printLinterOutput(lint(engine, input, resourcePath), config, this)
this.callback(null, input, map)
}
function lint(engine, input, resourcePath) {
return engine.executeOnText(input, resourcePath, true)
}

View File

@@ -0,0 +1,84 @@
{
"_args": [
[
"eslint-loader@1.9.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "eslint-loader@1.9.0",
"_id": "eslint-loader@1.9.0",
"_inBundle": false,
"_integrity": "sha512-40aN976qSNPyb9ejTqjEthZITpls1SVKtwguahmH1dzGCwQU/vySE+xX33VZmD8csU0ahVNCtFlsPgKqRBiqgg==",
"_location": "/react-scripts/eslint-loader",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "eslint-loader@1.9.0",
"name": "eslint-loader",
"escapedName": "eslint-loader",
"rawSpec": "1.9.0",
"saveSpec": null,
"fetchSpec": "1.9.0"
},
"_requiredBy": [
"/react-scripts"
],
"_resolved": "https://registry.npmjs.org/eslint-loader/-/eslint-loader-1.9.0.tgz",
"_spec": "1.9.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Maxime Thirouin"
},
"ava": {
"files": [
"test/*.js"
],
"verbose": true
},
"bugs": {
"url": "https://github.com/MoOx/eslint-loader/issues"
},
"dependencies": {
"loader-fs-cache": "^1.0.0",
"loader-utils": "^1.0.2",
"object-assign": "^4.0.1",
"object-hash": "^1.1.4",
"rimraf": "^2.6.1"
},
"description": "eslint loader (for webpack)",
"devDependencies": {
"ava": "^0.17.0",
"eslint": "^4.0.0",
"eslint-friendly-formatter": "^2.0.4",
"npmpub": "^3.0.1",
"webpack": "^2.2.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/MoOx/eslint-loader#readme",
"keywords": [
"lint",
"linter",
"eslint",
"loader",
"webpack"
],
"license": "MIT",
"name": "eslint-loader",
"peerDependencies": {
"eslint": ">=1.6.0 <5.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MoOx/eslint-loader.git"
},
"scripts": {
"ava": "ava",
"lint": "eslint .",
"release": "npmpub",
"test": "npm run lint && npm run ava"
},
"version": "1.9.0"
}