-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for eslint-webpack-plugin, close #847
- Loading branch information
Showing
11 changed files
with
442 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars | ||
const EslintPlugin = require('eslint-webpack-plugin'); //eslint-disable-line node/no-unpublished-require | ||
const applyOptionsCallback = require('../utils/apply-options-callback'); | ||
const pluginFeatures = require('../features'); | ||
|
||
function isMissingConfigError(e) { | ||
if (!e.message || !e.message.includes('No ESLint configuration found')) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Support for ESLint. | ||
* | ||
* @param {Array} plugins | ||
* @param {WebpackConfig} webpackConfig | ||
* @return {void} | ||
*/ | ||
module.exports = function(plugins, webpackConfig) { | ||
if (webpackConfig.useEslintPlugin) { | ||
pluginFeatures.ensurePackagesExistAndAreCorrectVersion('eslint_plugin'); | ||
|
||
const { ESLint } = require('eslint'); // eslint-disable-line node/no-unpublished-require | ||
const eslint = new ESLint({ | ||
cwd: webpackConfig.runtimeConfig.context, | ||
}); | ||
|
||
try { | ||
(async function() { | ||
await eslint.calculateConfigForFile('webpack.config.js'); | ||
})(); | ||
} catch (e) { | ||
if (isMissingConfigError(e)) { | ||
const chalk = require('chalk'); | ||
const packageHelper = require('../package-helper'); | ||
|
||
const message = `No ESLint configuration has been found. | ||
${chalk.bgGreen.black('', 'FIX', '')} Run command ${chalk.yellow('./node_modules/.bin/eslint --init')} or manually create a ${chalk.yellow('.eslintrc.js')} file at the root of your project. | ||
If you prefer to create a ${chalk.yellow('.eslintrc.js')} file by yourself, here is an example to get you started: | ||
${chalk.yellow(`// .eslintrc.js | ||
module.exports = { | ||
parser: 'babel-eslint', | ||
extends: ['eslint:recommended'], | ||
} | ||
`)} | ||
Install ${chalk.yellow('babel-eslint')} to prevent potential parsing issues: ${packageHelper.getInstallCommand([[{ name: 'babel-eslint' }]])} | ||
`; | ||
throw new Error(message); | ||
} | ||
|
||
throw e; | ||
} | ||
|
||
const eslintPluginOptions = { | ||
emitWarning: true, | ||
extensions: ['js', 'jsx'], | ||
}; | ||
|
||
plugins.push({ | ||
plugin: new EslintPlugin( | ||
applyOptionsCallback(webpackConfig.eslintPluginOptionsCallback, eslintPluginOptions) | ||
), | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.