Socket
Socket
Sign inDemoInstall

@rollup/plugin-eslint

Package Overview
Dependencies
3
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.3 to 8.0.4

dist/cjs/index.js.map

78

dist/cjs/index.js

@@ -9,8 +9,27 @@ 'use strict';

function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
function normalizePath(id) {
return path.relative(process.cwd(), id).split(path.sep).join('/');
return path__namespace.relative(process.cwd(), id).split(path__namespace.sep).join('/');
}
function eslint(options = {}) {
if (typeof options === 'string') {
const configFile = path.resolve(process.cwd(), options);
const configFile = path__namespace.resolve(process.cwd(), options);
// eslint-disable-next-line global-require, import/no-dynamic-require, no-param-reassign

@@ -22,39 +41,46 @@ options = require(configFile);

}
const { include, exclude = /node_modules/, throwOnWarning = false, throwOnError = false, formatter = 'stylish', ...eslintOptions } = options;
const eslintInstance = new eslint$1.ESLint(eslintOptions);
const filter = pluginutils.createFilter(include, exclude);
const cli = new eslint$1.CLIEngine(options);
let formatter;
switch (typeof options.formatter) {
case 'string':
formatter = cli.getFormatter(options.formatter);
break;
case 'function':
({ formatter } = options);
break;
default:
formatter = cli.getFormatter('stylish');
}
const filter = pluginutils.createFilter(options.include, options.exclude || /node_modules/);
return {
name: 'eslint',
async transform(_, id) {
// eslint-disable-next-line consistent-return
transform(code, id) {
const file = normalizePath(id);
if (!filter(id) || (await eslintInstance.isPathIgnored(file))) {
if (!filter(id) || cli.isPathIgnored(file)) {
return null;
}
const results = await eslintInstance.lintFiles(file);
const [result] = results;
if (eslintOptions.fix) {
await eslint$1.ESLint.outputFixes(results);
const report = cli.executeOnText(code, file);
const hasWarnings = options.throwOnWarning && report.warningCount !== 0;
const hasErrors = options.throwOnError && report.errorCount !== 0;
if (options.fix && report) {
eslint$1.CLIEngine.outputFixes(report);
}
if (result.warningCount === 0 && result.errorCount === 0) {
if (report.warningCount === 0 && report.errorCount === 0) {
return null;
}
const eslintFormatter = typeof formatter === 'string'
? await eslintInstance.loadFormatter(formatter)
: { format: formatter };
const output = eslintFormatter.format(results);
if (output) {
const result = formatter(report.results);
if (result) {
// eslint-disable-next-line no-console
console.log(output);
console.log(result);
}
const errorMessages = [];
if (result.warningCount > 0 && throwOnWarning) {
errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`);
if (hasWarnings && hasErrors) {
throw Error('Warnings or errors were found');
}
if (result.errorCount > 0 && throwOnError) {
errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`);
if (hasWarnings) {
throw Error('Warnings were found');
}
if (errorMessages.length > 0) {
throw new Error(`Found ${errorMessages.join(' and ')} in ${path.relative('.', result.filePath)}`);
if (hasErrors) {
throw Error('Errors were found');
}
return null;
}

@@ -61,0 +87,0 @@ };

@@ -1,11 +0,11 @@

import { resolve, relative, sep } from 'path';
import * as path from 'path';
import { createFilter } from '@rollup/pluginutils';
import { ESLint } from 'eslint';
import { CLIEngine } from 'eslint';
function normalizePath(id) {
return relative(process.cwd(), id).split(sep).join('/');
return path.relative(process.cwd(), id).split(path.sep).join('/');
}
function eslint(options = {}) {
if (typeof options === 'string') {
const configFile = resolve(process.cwd(), options);
const configFile = path.resolve(process.cwd(), options);
// eslint-disable-next-line global-require, import/no-dynamic-require, no-param-reassign

@@ -17,39 +17,46 @@ options = require(configFile);

}
const { include, exclude = /node_modules/, throwOnWarning = false, throwOnError = false, formatter = 'stylish', ...eslintOptions } = options;
const eslintInstance = new ESLint(eslintOptions);
const filter = createFilter(include, exclude);
const cli = new CLIEngine(options);
let formatter;
switch (typeof options.formatter) {
case 'string':
formatter = cli.getFormatter(options.formatter);
break;
case 'function':
({ formatter } = options);
break;
default:
formatter = cli.getFormatter('stylish');
}
const filter = createFilter(options.include, options.exclude || /node_modules/);
return {
name: 'eslint',
async transform(_, id) {
// eslint-disable-next-line consistent-return
transform(code, id) {
const file = normalizePath(id);
if (!filter(id) || (await eslintInstance.isPathIgnored(file))) {
if (!filter(id) || cli.isPathIgnored(file)) {
return null;
}
const results = await eslintInstance.lintFiles(file);
const [result] = results;
if (eslintOptions.fix) {
await ESLint.outputFixes(results);
const report = cli.executeOnText(code, file);
const hasWarnings = options.throwOnWarning && report.warningCount !== 0;
const hasErrors = options.throwOnError && report.errorCount !== 0;
if (options.fix && report) {
CLIEngine.outputFixes(report);
}
if (result.warningCount === 0 && result.errorCount === 0) {
if (report.warningCount === 0 && report.errorCount === 0) {
return null;
}
const eslintFormatter = typeof formatter === 'string'
? await eslintInstance.loadFormatter(formatter)
: { format: formatter };
const output = eslintFormatter.format(results);
if (output) {
const result = formatter(report.results);
if (result) {
// eslint-disable-next-line no-console
console.log(output);
console.log(result);
}
const errorMessages = [];
if (result.warningCount > 0 && throwOnWarning) {
errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`);
if (hasWarnings && hasErrors) {
throw Error('Warnings or errors were found');
}
if (result.errorCount > 0 && throwOnError) {
errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`);
if (hasWarnings) {
throw Error('Warnings were found');
}
if (errorMessages.length > 0) {
throw new Error(`Found ${errorMessages.join(' and ')} in ${relative('.', result.filePath)}`);
if (hasErrors) {
throw Error('Errors were found');
}
return null;
}

@@ -56,0 +63,0 @@ };

{
"name": "@rollup/plugin-eslint",
"version": "8.0.3",
"version": "8.0.4",
"publishConfig": {

@@ -16,11 +16,6 @@ "access": "public"

"bugs": "https://github.com/rollup/plugins/issues",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"exports": {
"import": "./dist/es/index.js",
"types": "./types/index.d.ts",
"default": "./dist/cjs/index.js"
},
"main": "dist/index.js",
"module": "dist/index.es.js",
"engines": {
"node": ">=14.0.0"
"node": ">= 10.0.0"
},

@@ -43,3 +38,2 @@ "scripts": {

"dist",
"!dist/**/*.map",
"types",

@@ -59,22 +53,26 @@ "README.md",

"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
"rollup": "^1.20.0||^2.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
},
"dependencies": {
"@rollup/pluginutils": "^4.2.1",
"eslint": "^8.24.0"
"@rollup/pluginutils": "^4.0.0",
"eslint": "^7.12.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-typescript": "^8.5.0",
"@types/eslint": "^8.4.6",
"rollup": "^3.0.0-7",
"typescript": "^4.8.3"
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/eslint": "^7.2.2",
"rollup": "^2.67.3",
"typescript": "^4.1.2"
},
"types": "./types/index.d.ts",
"types": "types/index.d.ts",
"ava": {
"babel": {
"compileEnhancements": false
},
"extensions": [
"ts"
],
"require": [
"ts-node/register"
],
"files": [

@@ -81,0 +79,0 @@ "!**/fixtures/**",

@@ -1,5 +0,5 @@

[npm]: https://img.shields.io/npm/v/@rollup/plugin-eslint
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-eslint
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-eslint
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-eslint
[npm]: https://img.shields.io/npm/v/@rollup/plugin-alias
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-alias
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-alias
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-alias

@@ -14,6 +14,2 @@ [![npm][npm]][npm-url]

## Requirements
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
## Install

@@ -46,14 +42,14 @@

This plugin takes a configuration object intended for the [ESLint constructor](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) with the addition of a `throwOnWarning`, `throwOnError`, `formatter`, `include` and `exclude` prop.
See more options here [eslint-config](http://eslint.org/docs/developer-guide/nodejs-api#cliengine).
You can also use eslint configuration in the form of a `.eslintrc.*` file in your project's root. It will be loaded automatically.
### exclude
### fix
Type: `String | String[]`<br>
Default: `node_modules/**`
Type: `Boolean`<br>
Default: `false`
A single [`picomatch`](https://github.com/micromatch/picomatch) pattern or an array of patterns controlling which files this plugin should explicitly include. Gets forwarded to the [`createFilter`](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) method of `@rollup/pluginutils`.
If true, will auto fix source code.
### fix
### throwOnError

@@ -63,31 +59,31 @@ Type: `Boolean`<br>

If true, will auto fix source code.
If true, will throw an error if any errors were found.
### formatter
### throwOnWarning
Type: `Function | String`<br>
Default: `stylish`
Type: `Boolean`<br>
Default: `false`
Custom error formatter, the name of a built-in formatter, or the path to a custom formatter.
If true, will throw an error if any warnings were found.
### include
Type: `String | String[]`<br>
Type: `Array | String`<br>
Default: `[]`
A single [`picomatch`](https://github.com/micromatch/picomatch) pattern or an array of patterns controlling which files this plugin should explicitly include. Gets forwarded to the [`createFilter`](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) method of `@rollup/pluginutils`.
A single file, or array of files, to include when linting.
### throwOnError
### exclude
Type: `Boolean`<br>
Default: `false`
Type: `Array | String`<br>
Default: `node_modules/**`
If true, will throw an error and exit the process when ESLint reports any errors.
A single file, or array of files, to exclude when linting.
### throwOnWarning
### formatter
Type: `Boolean`<br>
Default: `false`
Type: `Function | String`<br>
Default: `stylish`
If true, will throw an error and exit the process when ESLint reports any warnings.
Custom error formatter or the name of a built-in formatter.

@@ -94,0 +90,0 @@ ## Meta

import { Plugin } from 'rollup';
import { CLIEngine, ESLint } from 'eslint';
import { CLIEngine } from 'eslint';
import { CreateFilter } from '@rollup/pluginutils';
export interface RollupEslintOptions extends ESLint.Options {
export interface RollupEslintOptions extends CLIEngine.Options {
/**

@@ -7,0 +7,0 @@ * If true, will auto fix source code.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc