Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
eslint-loader
Advanced tools
eslint-loader is a webpack loader that integrates ESLint into the webpack build process. It allows you to lint your JavaScript code as part of the build process, ensuring that your code adheres to specified coding standards and conventions.
Linting JavaScript files
This feature allows you to lint JavaScript files using ESLint as part of the webpack build process. The configuration specifies that all `.js` files, excluding those in `node_modules`, should be processed by `eslint-loader`.
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'eslint-loader',
options: {
// eslint options (if necessary)
}
}
]
}
]
}
};
Custom ESLint options
This feature allows you to specify custom ESLint options, such as the path to the ESLint configuration file (`configFile`) and whether to emit warnings instead of errors (`emitWarning`).
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'eslint-loader',
options: {
configFile: 'path/to/.eslintrc',
emitWarning: true
}
}
]
}
]
}
};
eslint-webpack-plugin is a modern alternative to eslint-loader. It provides similar functionality by integrating ESLint into the webpack build process but is designed to work with webpack 5 and above. It offers better performance and more features compared to eslint-loader.
stylelint-webpack-plugin is a webpack plugin that integrates Stylelint into the webpack build process. While it focuses on linting CSS and other style files, it provides similar functionality to eslint-loader for stylesheets.
tslint-loader is a webpack loader that integrates TSLint into the webpack build process. It is similar to eslint-loader but is specifically designed for linting TypeScript files.
A ESlint loader for webpack
npm install eslint-loader --save-dev
Note: You also need to install eslint
from npm, if you haven't already:
npm install eslint --save-dev
In your webpack configuration:
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 checked after being processed by babel-loader
:
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
):
module.exports = {
// ...
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
// ...
};
You can pass eslint options using standard webpack loader options.
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 for more detail.
cache
Boolean|String
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.
This can either be a boolean
value or the cache directory path(ex: './.eslint-loader-cache'
).
If cache: true
is used, the cache is written to the ./node_modules/.cache/eslint-loader
directory. This is the recommended usage.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
cache: true,
},
},
],
},
};
eslintPath
String
eslint
Path to eslint
instance that will be used for linting. If the eslintPath
is a folder like a official eslint, or specify a formatter
option. Now you dont have to install eslint
.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
eslintPath: path.join(__dirname, 'reusable-eslint'),
},
},
],
},
};
fix
Boolean
false
This option will enable ESLint autofix feature.
Be careful: this option will change source files.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
fix: true,
},
},
],
},
};
formatter
String|Function
stylish
This option 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.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
// several examples !
// default value
formatter: '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';
},
},
},
],
},
};
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
Boolean
false
Will always return errors, if this option is set to true
.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitError: true,
},
},
],
},
};
emitWarning
Boolean
false
Will always return warnings, if option is set to true
. If you're using hot module replacement, you may wish to enable this in development, or else updates will be skipped when there's an eslint error.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: true,
},
},
],
},
};
failOnError
Boolean
false
Will cause the module build to fail if there are any errors, if option is set to true
.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
failOnError: true,
},
},
],
},
};
failOnWarning
Boolean
false
Will cause the module build to fail if there are any warnings, if option is set to true
.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
failOnWarning: true,
},
},
],
},
};
quiet
Boolean
false
Will process and report errors only and ignore warnings, if this option is set to true
.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
quiet: true,
},
},
],
},
};
outputReport
Boolean|Object
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 an absolute path or 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.
module.exports = {
entry: '...',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
outputReport: {
filePath: 'checkstyle.xml',
formatter: 'checkstyle',
},
},
},
],
},
};
NoEmitOnErrorsPlugin
is now automatically enabled in webpack 4, when mode is either unset, or set to production. So even ESLint warnings will fail the build. No matter what error settings are used for eslint-loader
, except if emitWarning
enabled.
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. See #129.
FAQs
A ESlint loader for webpack
The npm package eslint-loader receives a total of 834,278 weekly downloads. As such, eslint-loader popularity was classified as popular.
We found that eslint-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.