Skip to content

Commit

Permalink
fix(eslint): Revert accidental patch release (#1309)
Browse files Browse the repository at this point in the history
This reverts commit 552728b.
  • Loading branch information
lukastaegert committed Oct 7, 2022
1 parent 552728b commit f336198
Show file tree
Hide file tree
Showing 10 changed files with 1,989 additions and 2,199 deletions.
54 changes: 25 additions & 29 deletions packages/eslint/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[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

[![npm][npm]][npm-url]
[![size][size]][size-url]
Expand All @@ -11,10 +11,6 @@

🍣 A Rollup plugin to lint entry points and all imported files with ESLint.

## Requirements

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

## Install

Using npm:
Expand Down Expand Up @@ -42,51 +38,51 @@ export default {

## Options

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

Type: `Boolean`<br>
Default: `false`

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.

## Meta

Expand Down
44 changes: 21 additions & 23 deletions packages/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
"author": "Bogdan Chadkin <[email protected]>",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/eslint#readme",
"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"
},
"scripts": {
"build": "rollup -c",
Expand All @@ -39,7 +34,6 @@
},
"files": [
"dist",
"!dist/**/*.map",
"types",
"README.md",
"LICENSE"
Expand All @@ -54,26 +48,30 @@
"lint"
],
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
"rollup": "^1.20.0||^2.0.0"
},
"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": [
"!**/fixtures/**",
"!**/helpers/**",
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import typescript from '@rollup/plugin-typescript';

import pkg from './package.json';

export default {
input: 'src/index.ts',
external: [...Object.keys(pkg.dependencies), 'path'],
output: [
{ file: pkg.main, format: 'cjs', exports: 'auto' },
{ file: pkg.module, format: 'es' }
],
plugins: [typescript({ sourceMap: false })]
};
7 changes: 0 additions & 7 deletions packages/eslint/rollup.config.mjs

This file was deleted.

78 changes: 38 additions & 40 deletions packages/eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,81 @@
import { relative, resolve, sep } from 'path';
import * as path from 'path';

import { Plugin } from 'rollup';
import { createFilter } from '@rollup/pluginutils';
import { ESLint } from 'eslint';
import { CLIEngine } from 'eslint';

import type { RollupEslintOptions } from '../types';
import { RollupEslintOptions } from '../types';

function normalizePath(id: string) {
return relative(process.cwd(), id).split(sep).join('/');
return path.relative(process.cwd(), id).split(path.sep).join('/');
}

export default function eslint(options = {} as RollupEslintOptions): Plugin {
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
options = require(configFile);
// Tell eslint not to look for configuration files.
// eslint-disable-next-line no-param-reassign
options.useEslintrc = false;
}

const {
include,
exclude = /node_modules/,
throwOnWarning = false,
throwOnError = false,
formatter = 'stylish',
...eslintOptions
} = options;
const cli = new CLIEngine(options);
let formatter: CLIEngine.Formatter;

switch (typeof options.formatter) {
case 'string':
formatter = cli.getFormatter(options.formatter);
break;
case 'function':
({ formatter } = options);
break;
default:
formatter = cli.getFormatter('stylish');
}

const eslintInstance = new ESLint(eslintOptions);
const filter = createFilter(include, exclude);
const filter = createFilter(options.include, options.exclude || /node_modules/);

return {
name: 'eslint',
async transform(_, id: string) {

// 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;
const report = cli.executeOnText(code, file);
const hasWarnings = options.throwOnWarning && report.warningCount !== 0;
const hasErrors = options.throwOnError && report.errorCount !== 0;

if (eslintOptions.fix) {
await ESLint.outputFixes(results);
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: ESLint.Formatter =
typeof formatter === 'string'
? await eslintInstance.loadFormatter(formatter)
: { format: formatter };
const output = eslintFormatter.format(results);
const result = formatter(report.results);

if (output) {
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;
}
};
}
1 change: 0 additions & 1 deletion packages/eslint/test/node_modules/current-package

This file was deleted.

Loading

0 comments on commit f336198

Please sign in to comment.