-
-
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.
Move from eslint-loader to eslint-webpack-plugin, close #847
- Loading branch information
1 parent
17ed0a8
commit 8c33cb1
Showing
14 changed files
with
618 additions
and
81 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
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,64 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const forceSync = require('sync-rpc'); | ||
const hasEslintConfiguration = forceSync(require.resolve('../utils/has-eslint-configuration')); | ||
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'); | ||
|
||
/** | ||
* Support for ESLint. | ||
* | ||
* @param {Array} plugins | ||
* @param {WebpackConfig} webpackConfig | ||
* @return {void} | ||
*/ | ||
module.exports = function(plugins, webpackConfig) { | ||
if (webpackConfig.useEslintPlugin) { | ||
pluginFeatures.ensurePackagesExistAndAreCorrectVersion('eslint_plugin'); | ||
|
||
if (!hasEslintConfiguration(webpackConfig)) { | ||
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); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
function isMissingConfigError(e) { | ||
if (!e.message || !e.message.includes('No ESLint configuration found')) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @returns {Promise<boolean>} | ||
*/ | ||
module.exports = async function() { | ||
/** | ||
* @param {WebpackConfig} webpackConfig | ||
* @returns {Promise<boolean>} | ||
*/ | ||
return async function(webpackConfig) { | ||
const { ESLint } = require('eslint'); // eslint-disable-line node/no-unpublished-require | ||
const eslint = new ESLint({ | ||
cwd: webpackConfig.runtimeConfig.context, | ||
}); | ||
|
||
try { | ||
await eslint.calculateConfigForFile('webpack.config.js'); | ||
} catch (e) { | ||
return !isMissingConfigError(e); | ||
} | ||
|
||
return true; | ||
}; | ||
}; |
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.