@thedanbob/esbuild-plugin-eslint 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +40 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +38 -0
- package/license +21 -0
- package/package.json +62 -0
- package/readme.md +85 -0
- package/src/index.ts +70 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const eslint_1 = require("eslint");
|
|
4
|
+
exports.default = ({ filter = /\.(?:jsx?|tsx?|mts|cts|mjs|cjs|vue|svelte)$/, throwOnWarning = false, throwOnError = false, ...eslintOptions } = {}) => ({
|
|
5
|
+
name: "eslint",
|
|
6
|
+
setup: async ({ onStart, onLoad, onEnd }) => {
|
|
7
|
+
const eslint = new eslint_1.ESLint(eslintOptions);
|
|
8
|
+
const formatter = await eslint.loadFormatter();
|
|
9
|
+
const filesToLint = [];
|
|
10
|
+
onStart(() => {
|
|
11
|
+
// Clear list of files from previous run in watch mode
|
|
12
|
+
filesToLint.splice(0);
|
|
13
|
+
});
|
|
14
|
+
onLoad({ filter }, ({ path }) => {
|
|
15
|
+
if (!path.includes("node_modules")) {
|
|
16
|
+
filesToLint.push(path);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
onEnd(async () => {
|
|
20
|
+
const results = await eslint.lintFiles(filesToLint);
|
|
21
|
+
const output = await formatter.format(results);
|
|
22
|
+
const warnings = results.reduce((count, result) => count + result.warningCount, 0);
|
|
23
|
+
const errors = results.reduce((count, result) => count + result.errorCount, 0);
|
|
24
|
+
if (eslintOptions.fix) {
|
|
25
|
+
await eslint_1.ESLint.outputFixes(results);
|
|
26
|
+
}
|
|
27
|
+
if (output.length > 0) {
|
|
28
|
+
console.log(output);
|
|
29
|
+
}
|
|
30
|
+
const errorsList = [];
|
|
31
|
+
throwOnWarning && warnings > 0 && errorsList.push({ text: `${warnings} warnings were found by eslint!` });
|
|
32
|
+
throwOnError && errors > 0 && errorsList.push({ text: `${errors} errors were found by eslint!` });
|
|
33
|
+
return {
|
|
34
|
+
...errorsList.length > 0 && {
|
|
35
|
+
errors: errorsList
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from "esbuild";
|
|
2
|
+
import { ESLint } from "eslint";
|
|
3
|
+
interface Options extends ESLint.Options {
|
|
4
|
+
/**
|
|
5
|
+
* tells esbuild what files to look at; only matches will be processed
|
|
6
|
+
*/
|
|
7
|
+
filter?: RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* controls whether or not to forward an error to esbuild when eslint reports any warnings
|
|
10
|
+
*/
|
|
11
|
+
throwOnWarning?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* controls whether or not to forward an error to esbuild when eslint reports any errors
|
|
14
|
+
*/
|
|
15
|
+
throwOnError?: boolean;
|
|
16
|
+
}
|
|
17
|
+
declare const _default: ({ filter, throwOnWarning, throwOnError, ...eslintOptions }?: Options) => Plugin;
|
|
18
|
+
export default _default;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ESLint } from "eslint";
|
|
2
|
+
export default ({ filter = /\.(?:jsx?|tsx?|mts|cts|mjs|cjs|vue|svelte)$/, throwOnWarning = false, throwOnError = false, ...eslintOptions } = {}) => ({
|
|
3
|
+
name: "eslint",
|
|
4
|
+
setup: async ({ onStart, onLoad, onEnd }) => {
|
|
5
|
+
const eslint = new ESLint(eslintOptions);
|
|
6
|
+
const formatter = await eslint.loadFormatter();
|
|
7
|
+
const filesToLint = [];
|
|
8
|
+
onStart(() => {
|
|
9
|
+
// Clear list of files from previous run in watch mode
|
|
10
|
+
filesToLint.splice(0);
|
|
11
|
+
});
|
|
12
|
+
onLoad({ filter }, ({ path }) => {
|
|
13
|
+
if (!path.includes("node_modules")) {
|
|
14
|
+
filesToLint.push(path);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
onEnd(async () => {
|
|
18
|
+
const results = await eslint.lintFiles(filesToLint);
|
|
19
|
+
const output = await formatter.format(results);
|
|
20
|
+
const warnings = results.reduce((count, result) => count + result.warningCount, 0);
|
|
21
|
+
const errors = results.reduce((count, result) => count + result.errorCount, 0);
|
|
22
|
+
if (eslintOptions.fix) {
|
|
23
|
+
await ESLint.outputFixes(results);
|
|
24
|
+
}
|
|
25
|
+
if (output.length > 0) {
|
|
26
|
+
console.log(output);
|
|
27
|
+
}
|
|
28
|
+
const errorsList = [];
|
|
29
|
+
throwOnWarning && warnings > 0 && errorsList.push({ text: `${warnings} warnings were found by eslint!` });
|
|
30
|
+
throwOnError && errors > 0 && errorsList.push({ text: `${errors} errors were found by eslint!` });
|
|
31
|
+
return {
|
|
32
|
+
...errorsList.length > 0 && {
|
|
33
|
+
errors: errorsList
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
package/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Robin Löffel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thedanbob/esbuild-plugin-eslint",
|
|
3
|
+
"version": "0.3.13",
|
|
4
|
+
"description": "Lint your esbuild bundles with ESLint. 🧐",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"esbuild",
|
|
7
|
+
"plugin",
|
|
8
|
+
"esbuild-plugin",
|
|
9
|
+
"eslint",
|
|
10
|
+
"lint"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/thedanbob/esbuild-plugin-eslint",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/thedanbob/esbuild-plugin-eslint.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Dan Arnfield <npm@thedanbob.com>",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"src",
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "concurrently npm:build:* -m 1",
|
|
34
|
+
"build:cjs": "tsc --project tsconfig.cjs.json && mv dist/index.js dist/index.cjs",
|
|
35
|
+
"build:mjs": "tsc --project tsconfig.mjs.json && mv dist/index.js dist/index.mjs",
|
|
36
|
+
"build:types": "tsc --project tsconfig.types.json",
|
|
37
|
+
"clean": "rm -rf dist",
|
|
38
|
+
"prepack": "npm run clean && npm run build",
|
|
39
|
+
"start": "npm run clean && npm run build && npm run watch",
|
|
40
|
+
"watch": "concurrently npm:watch:*",
|
|
41
|
+
"watch:build": "chokidar 'source/**/*' -c 'npm run build' --initial",
|
|
42
|
+
"watch:test": "chokidar 'test/**/*' -c 'node test/esbuild.js' --initial"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@tsconfig/strictest": "^2.0.3",
|
|
46
|
+
"@types/eslint": "^8.56.5",
|
|
47
|
+
"chokidar-cli": "^3.0.0",
|
|
48
|
+
"concurrently": "^8.2.2",
|
|
49
|
+
"esbuild": ">=0.20",
|
|
50
|
+
"eslint": "^8 || ^9",
|
|
51
|
+
"eslint-config-sweet": "^19.0.2",
|
|
52
|
+
"eslint-define-config": "^2.1.0",
|
|
53
|
+
"typescript": "^5.4.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"esbuild": ">=0.20",
|
|
57
|
+
"eslint": "^8 || ^9"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=18"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# `esbuild-plugin-eslint`
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/esbuild-plugin-eslint)
|
|
4
|
+
[](https://www.npmjs.com/package/esbuild-plugin-eslint)
|
|
5
|
+
[](https://github.com/nodejs/Release)
|
|
6
|
+
[](https://github.com/evanw/esbuild)
|
|
7
|
+
[](https://github.com/eslint/eslint)
|
|
8
|
+
[](license)
|
|
9
|
+
|
|
10
|
+
> Lint your [`esbuild`](https://github.com/evanw/esbuild) bundles with [`eslint`](https://github.com/eslint/eslint). 🧐
|
|
11
|
+
|
|
12
|
+
Nicely integrates the most recent version of [`eslint`](https://github.com/eslint/eslint) into an [`esbuild`](https://github.com/evanw/esbuild) plugin.
|
|
13
|
+
|
|
14
|
+
## How
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm i esbuild-plugin-eslint eslint --save-dev
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { build } from 'esbuild';
|
|
22
|
+
import eslint from 'esbuild-plugin-eslint';
|
|
23
|
+
|
|
24
|
+
await build({
|
|
25
|
+
// ...
|
|
26
|
+
plugins: [
|
|
27
|
+
eslint({ /* config */ })
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
node esbuild.config.js
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Config
|
|
37
|
+
|
|
38
|
+
This plugin respects your [ESLint configuration](https://eslint.org/docs/user-guide/configuring) as per default. It also takes a configuration object intended for the [ESLint constructor](https://eslint.org/docs/latest/developer-guide/nodejs-api#parameters) with the addition of a `filter`, `throwOnError`, and `throwOnWarning` property. The most important options are:
|
|
39
|
+
|
|
40
|
+
### `filter`
|
|
41
|
+
|
|
42
|
+
Type: `RegExp`<br>
|
|
43
|
+
Default: `/\.(?:jsx?|tsx?|mts|cts|mjs|cjs|vue|svelte)$/`<br>
|
|
44
|
+
Used by: [`esbuild`](https://github.com/evanw/esbuild)<br>
|
|
45
|
+
Reference: [esbuild.github.io](https://esbuild.github.io/plugins/#on-load-options)
|
|
46
|
+
|
|
47
|
+
Tells esbuild what files to look at. Only files matching this pattern will be handled by the plugin.
|
|
48
|
+
|
|
49
|
+
### `throwOnError`
|
|
50
|
+
|
|
51
|
+
Type: `boolean`<br>
|
|
52
|
+
Default: `false`<br>
|
|
53
|
+
Used by: [The plugin itself](https://github.com/robinloeffel/esbuild-plugin-eslint)<br>
|
|
54
|
+
|
|
55
|
+
Instructs the plugin to forward errors found by ESLint to esbuild and throw an error.
|
|
56
|
+
|
|
57
|
+
### `throwOnWarning`
|
|
58
|
+
|
|
59
|
+
Type: `boolean`<br>
|
|
60
|
+
Default: `false`<br>
|
|
61
|
+
Used by: [The plugin itself](https://github.com/robinloeffel/esbuild-plugin-eslint)<br>
|
|
62
|
+
|
|
63
|
+
Instructs the plugin to forward warnings found by ESLint to esbuild and throw an error.
|
|
64
|
+
|
|
65
|
+
### `fix`
|
|
66
|
+
|
|
67
|
+
Type: `boolean`<br>
|
|
68
|
+
Default: `false`<br>
|
|
69
|
+
Used by: [`eslint`](https://github.com/eslint/eslint)<br>
|
|
70
|
+
Reference: [eslint.org (`options.fix`)](https://eslint.org/docs/latest/developer-guide/nodejs-api#parameters)<br>
|
|
71
|
+
|
|
72
|
+
Controls whether to enable or disable the autofix feature of ESLint.
|
|
73
|
+
|
|
74
|
+
### `useEslintrc`
|
|
75
|
+
|
|
76
|
+
Type: `boolean`<br>
|
|
77
|
+
Default: `true`<br>
|
|
78
|
+
Used by: [`eslint`](https://github.com/eslint/eslint)<br>
|
|
79
|
+
Reference: [eslint.org (`options.useEslintrc`)](https://eslint.org/docs/latest/developer-guide/nodejs-api#parameters)<br>
|
|
80
|
+
|
|
81
|
+
If set to `false`, ESLint will not respect any configuration files it finds.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { OnLoadArgs, Plugin } from "esbuild";
|
|
2
|
+
import { ESLint } from "eslint";
|
|
3
|
+
|
|
4
|
+
interface Options extends ESLint.Options {
|
|
5
|
+
/**
|
|
6
|
+
* tells esbuild what files to look at; only matches will be processed
|
|
7
|
+
*/
|
|
8
|
+
filter?: RegExp;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* controls whether or not to forward an error to esbuild when eslint reports any warnings
|
|
12
|
+
*/
|
|
13
|
+
throwOnWarning?: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* controls whether or not to forward an error to esbuild when eslint reports any errors
|
|
17
|
+
*/
|
|
18
|
+
throwOnError?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default ({
|
|
22
|
+
filter = /\.(?:jsx?|tsx?|mts|cts|mjs|cjs|vue|svelte)$/,
|
|
23
|
+
throwOnWarning = false,
|
|
24
|
+
throwOnError = false,
|
|
25
|
+
...eslintOptions
|
|
26
|
+
}: Options = {}): Plugin => ({
|
|
27
|
+
name: "eslint",
|
|
28
|
+
setup: async ({ onStart, onLoad, onEnd }) => {
|
|
29
|
+
const eslint = new ESLint(eslintOptions);
|
|
30
|
+
const formatter = await eslint.loadFormatter();
|
|
31
|
+
const filesToLint: OnLoadArgs["path"][] = [];
|
|
32
|
+
|
|
33
|
+
onStart(() => {
|
|
34
|
+
// Clear list of files from previous run in watch mode
|
|
35
|
+
filesToLint.splice(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
onLoad({ filter }, ({ path }): undefined => {
|
|
39
|
+
if (!path.includes("node_modules")) {
|
|
40
|
+
filesToLint.push(path);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
onEnd(async() => {
|
|
45
|
+
const results = await eslint.lintFiles(filesToLint);
|
|
46
|
+
const output = await formatter.format(results);
|
|
47
|
+
|
|
48
|
+
const warnings = results.reduce((count, result) => count + result.warningCount, 0);
|
|
49
|
+
const errors = results.reduce((count, result) => count + result.errorCount, 0);
|
|
50
|
+
|
|
51
|
+
if (eslintOptions.fix) {
|
|
52
|
+
await ESLint.outputFixes(results);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (output.length > 0) {
|
|
56
|
+
console.log(output);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const errorsList = [];
|
|
60
|
+
throwOnWarning && warnings > 0 && errorsList.push({ text: `${warnings} warnings were found by eslint!` });
|
|
61
|
+
throwOnError && errors > 0 && errorsList.push({ text: `${errors} errors were found by eslint!` });
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
...errorsList.length > 0 && {
|
|
65
|
+
errors: errorsList
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|