@rollup/plugin-eslint
Advanced tools
Comparing version 8.0.4 to 9.0.0
@@ -9,27 +9,8 @@ '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__namespace.relative(process.cwd(), id).split(path__namespace.sep).join('/'); | ||
return path.relative(process.cwd(), id).split(path.sep).join('/'); | ||
} | ||
function eslint(options = {}) { | ||
if (typeof options === 'string') { | ||
const configFile = path__namespace.resolve(process.cwd(), options); | ||
const configFile = path.resolve(process.cwd(), options); | ||
// eslint-disable-next-line global-require, import/no-dynamic-require, no-param-reassign | ||
@@ -41,46 +22,39 @@ options = require(configFile); | ||
} | ||
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/); | ||
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); | ||
return { | ||
name: 'eslint', | ||
// eslint-disable-next-line consistent-return | ||
transform(code, id) { | ||
async transform(_, id) { | ||
const file = normalizePath(id); | ||
if (!filter(id) || cli.isPathIgnored(file)) { | ||
if (!filter(id) || (await eslintInstance.isPathIgnored(file))) { | ||
return null; | ||
} | ||
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); | ||
const results = await eslintInstance.lintFiles(file); | ||
const [result] = results; | ||
if (eslintOptions.fix) { | ||
await eslint$1.ESLint.outputFixes(results); | ||
} | ||
if (report.warningCount === 0 && report.errorCount === 0) { | ||
if (result.warningCount === 0 && result.errorCount === 0) { | ||
return null; | ||
} | ||
const result = formatter(report.results); | ||
if (result) { | ||
const eslintFormatter = typeof formatter === 'string' | ||
? await eslintInstance.loadFormatter(formatter) | ||
: { format: formatter }; | ||
const output = eslintFormatter.format(results); | ||
if (output) { | ||
// eslint-disable-next-line no-console | ||
console.log(result); | ||
console.log(output); | ||
} | ||
if (hasWarnings && hasErrors) { | ||
throw Error('Warnings or errors were found'); | ||
const errorMessages = []; | ||
if (result.warningCount > 0 && throwOnWarning) { | ||
errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`); | ||
} | ||
if (hasWarnings) { | ||
throw Error('Warnings were found'); | ||
if (result.errorCount > 0 && throwOnError) { | ||
errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`); | ||
} | ||
if (hasErrors) { | ||
throw Error('Errors were found'); | ||
if (errorMessages.length > 0) { | ||
throw new Error(`Found ${errorMessages.join(' and ')} in ${path.relative('.', result.filePath)}`); | ||
} | ||
return null; | ||
} | ||
@@ -87,0 +61,0 @@ }; |
@@ -1,11 +0,11 @@ | ||
import * as path from 'path'; | ||
import { resolve, relative, sep } from 'path'; | ||
import { createFilter } from '@rollup/pluginutils'; | ||
import { CLIEngine } from 'eslint'; | ||
import { ESLint } from 'eslint'; | ||
function normalizePath(id) { | ||
return path.relative(process.cwd(), id).split(path.sep).join('/'); | ||
return relative(process.cwd(), id).split(sep).join('/'); | ||
} | ||
function eslint(options = {}) { | ||
if (typeof options === 'string') { | ||
const configFile = path.resolve(process.cwd(), options); | ||
const configFile = resolve(process.cwd(), options); | ||
// eslint-disable-next-line global-require, import/no-dynamic-require, no-param-reassign | ||
@@ -17,46 +17,39 @@ options = require(configFile); | ||
} | ||
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/); | ||
const { include, exclude = /node_modules/, throwOnWarning = false, throwOnError = false, formatter = 'stylish', ...eslintOptions } = options; | ||
const eslintInstance = new ESLint(eslintOptions); | ||
const filter = createFilter(include, exclude); | ||
return { | ||
name: 'eslint', | ||
// eslint-disable-next-line consistent-return | ||
transform(code, id) { | ||
async transform(_, id) { | ||
const file = normalizePath(id); | ||
if (!filter(id) || cli.isPathIgnored(file)) { | ||
if (!filter(id) || (await eslintInstance.isPathIgnored(file))) { | ||
return null; | ||
} | ||
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); | ||
const results = await eslintInstance.lintFiles(file); | ||
const [result] = results; | ||
if (eslintOptions.fix) { | ||
await ESLint.outputFixes(results); | ||
} | ||
if (report.warningCount === 0 && report.errorCount === 0) { | ||
if (result.warningCount === 0 && result.errorCount === 0) { | ||
return null; | ||
} | ||
const result = formatter(report.results); | ||
if (result) { | ||
const eslintFormatter = typeof formatter === 'string' | ||
? await eslintInstance.loadFormatter(formatter) | ||
: { format: formatter }; | ||
const output = eslintFormatter.format(results); | ||
if (output) { | ||
// eslint-disable-next-line no-console | ||
console.log(result); | ||
console.log(output); | ||
} | ||
if (hasWarnings && hasErrors) { | ||
throw Error('Warnings or errors were found'); | ||
const errorMessages = []; | ||
if (result.warningCount > 0 && throwOnWarning) { | ||
errorMessages.push(`${result.warningCount} warning${result.warningCount > 1 ? 's' : ''}`); | ||
} | ||
if (hasWarnings) { | ||
throw Error('Warnings were found'); | ||
if (result.errorCount > 0 && throwOnError) { | ||
errorMessages.push(`${result.errorCount} error${result.errorCount > 1 ? 's' : ''}`); | ||
} | ||
if (hasErrors) { | ||
throw Error('Errors were found'); | ||
if (errorMessages.length > 0) { | ||
throw new Error(`Found ${errorMessages.join(' and ')} in ${relative('.', result.filePath)}`); | ||
} | ||
return null; | ||
} | ||
@@ -63,0 +56,0 @@ }; |
{ | ||
"name": "@rollup/plugin-eslint", | ||
"version": "8.0.4", | ||
"version": "9.0.0", | ||
"publishConfig": { | ||
@@ -16,6 +16,11 @@ "access": "public" | ||
"bugs": "https://github.com/rollup/plugins/issues", | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"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" | ||
}, | ||
"engines": { | ||
"node": ">= 10.0.0" | ||
"node": ">=14.0.0" | ||
}, | ||
@@ -38,2 +43,3 @@ "scripts": { | ||
"dist", | ||
"!dist/**/*.map", | ||
"types", | ||
@@ -53,26 +59,22 @@ "README.md", | ||
"peerDependencies": { | ||
"rollup": "^1.20.0||^2.0.0" | ||
"rollup": "^1.20.0||^2.0.0||^3.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"rollup": { | ||
"optional": true | ||
} | ||
}, | ||
"dependencies": { | ||
"@rollup/pluginutils": "^4.0.0", | ||
"eslint": "^7.12.0" | ||
"@rollup/pluginutils": "^4.2.1", | ||
"eslint": "^8.24.0" | ||
}, | ||
"devDependencies": { | ||
"@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" | ||
"@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" | ||
}, | ||
"types": "types/index.d.ts", | ||
"types": "./types/index.d.ts", | ||
"ava": { | ||
"babel": { | ||
"compileEnhancements": false | ||
}, | ||
"extensions": [ | ||
"ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"files": [ | ||
@@ -79,0 +81,0 @@ "!**/fixtures/**", |
@@ -1,5 +0,5 @@ | ||
[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 | ||
[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 | ||
@@ -14,2 +14,6 @@ [![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 | ||
@@ -42,14 +46,14 @@ | ||
See more options here [eslint-config](http://eslint.org/docs/developer-guide/nodejs-api#cliengine). | ||
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. | ||
You can also use eslint configuration in the form of a `.eslintrc.*` file in your project's root. It will be loaded automatically. | ||
### fix | ||
### exclude | ||
Type: `Boolean`<br> | ||
Default: `false` | ||
Type: `String | String[]`<br> | ||
Default: `node_modules/**` | ||
If true, will auto fix source code. | ||
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`. | ||
### throwOnError | ||
### fix | ||
@@ -59,31 +63,31 @@ Type: `Boolean`<br> | ||
If true, will throw an error if any errors were found. | ||
If true, will auto fix source code. | ||
### throwOnWarning | ||
### formatter | ||
Type: `Boolean`<br> | ||
Default: `false` | ||
Type: `Function | String`<br> | ||
Default: `stylish` | ||
If true, will throw an error if any warnings were found. | ||
Custom error formatter, the name of a built-in formatter, or the path to a custom formatter. | ||
### include | ||
Type: `Array | String`<br> | ||
Type: `String | String[]`<br> | ||
Default: `[]` | ||
A single file, or array of files, to include when linting. | ||
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`. | ||
### exclude | ||
### throwOnError | ||
Type: `Array | String`<br> | ||
Default: `node_modules/**` | ||
Type: `Boolean`<br> | ||
Default: `false` | ||
A single file, or array of files, to exclude when linting. | ||
If true, will throw an error and exit the process when ESLint reports any errors. | ||
### formatter | ||
### throwOnWarning | ||
Type: `Function | String`<br> | ||
Default: `stylish` | ||
Type: `Boolean`<br> | ||
Default: `false` | ||
Custom error formatter or the name of a built-in formatter. | ||
If true, will throw an error and exit the process when ESLint reports any warnings. | ||
@@ -90,0 +94,0 @@ ## Meta |
import { Plugin } from 'rollup'; | ||
import { CLIEngine } from 'eslint'; | ||
import { CLIEngine, ESLint } from 'eslint'; | ||
import { CreateFilter } from '@rollup/pluginutils'; | ||
export interface RollupEslintOptions extends CLIEngine.Options { | ||
export interface RollupEslintOptions extends ESLint.Options { | ||
/** | ||
@@ -7,0 +7,0 @@ * If true, will auto fix source code. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
96
0
11212
6
156
+ Added@eslint-community/eslint-utils@4.4.0(transitive)
+ Added@eslint-community/regexpp@4.11.0(transitive)
+ Added@eslint/eslintrc@2.1.4(transitive)
+ Added@eslint/js@8.57.0(transitive)
+ Added@humanwhocodes/config-array@0.11.14(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/object-schema@2.0.3(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@ungap/structured-clone@1.2.0(transitive)
+ Addedacorn@8.12.1(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedeslint@8.57.0(transitive)
+ Addedeslint-scope@7.2.2(transitive)
+ Addedeslint-visitor-keys@3.4.3(transitive)
+ Addedespree@9.6.1(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedgraphemer@1.4.0(transitive)
+ Addedignore@5.3.1(transitive)
+ Addedis-path-inside@3.0.3(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrollup@3.29.4(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removed@babel/code-frame@7.12.11(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@eslint/eslintrc@0.4.3(transitive)
- Removed@humanwhocodes/config-array@0.5.0(transitive)
- Removed@humanwhocodes/object-schema@1.2.1(transitive)
- Removedacorn@7.4.1(transitive)
- Removedajv@8.16.0(transitive)
- Removedansi-colors@4.1.3(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedargparse@1.0.10(transitive)
- Removedastral-regex@2.0.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedenquirer@2.4.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedeslint@7.32.0(transitive)
- Removedeslint-scope@5.1.1(transitive)
- Removedeslint-utils@2.1.0(transitive)
- Removedeslint-visitor-keys@1.3.02.1.0(transitive)
- Removedespree@7.3.1(transitive)
- Removedesprima@4.0.1(transitive)
- Removedestraverse@4.3.0(transitive)
- Removedfunctional-red-black-tree@1.0.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedignore@4.0.6(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjson-schema-traverse@1.0.0(transitive)
- Removedlodash.truncate@4.4.2(transitive)
- Removedpicocolors@1.0.1(transitive)
- Removedprogress@2.0.3(transitive)
- Removedregexpp@3.2.0(transitive)
- Removedrequire-from-string@2.0.2(transitive)
- Removedrollup@2.79.1(transitive)
- Removedsemver@7.6.2(transitive)
- Removedslice-ansi@4.0.0(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtable@6.8.2(transitive)
- Removedv8-compile-cache@2.4.0(transitive)
Updated@rollup/pluginutils@^4.2.1
Updatedeslint@^8.24.0