@rsbuild/plugin-eslint 1.0.0-alpha.2 → 1.0.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
3
+ Copyright (c) 2024 Rspack Contrib
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,124 @@
1
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
1
+ # @rsbuild/plugin-eslint
2
+
3
+ An Rsbuild plugin to run ESLint checks during the compilation.
4
+
5
+ The plugin has integrated [eslint-webpack-plugin](https://www.npmjs.com/package/eslint-webpack-plugin) internally.
6
+
7
+ <p>
8
+ <a href="https://npmjs.com/package/@rsbuild/plugin-eslint">
9
+ <img src="https://img.shields.io/npm/v/@rsbuild/plugin-eslint?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
10
+ </a>
11
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
3
12
  </p>
4
13
 
5
- # Rsbuild
14
+ ## Usage
15
+
16
+ Install:
17
+
18
+ ```bash
19
+ npm add @rsbuild/plugin-eslint -D
20
+ ```
21
+
22
+ Add plugin to your `rsbuild.config.ts`:
23
+
24
+ ```ts
25
+ // rsbuild.config.ts
26
+ import { pluginEslint } from "@rsbuild/plugin-eslint";
27
+
28
+ export default {
29
+ plugins: [pluginEslint()],
30
+ };
31
+ ```
32
+
33
+ ## Example Projects
34
+
35
+ - [React + ESLint project](https://github.com/rspack-contrib/rspack-examples/tree/main/rsbuild/react-eslint)
36
+ - [Vue 3 + ESLint project](https://github.com/rspack-contrib/rspack-examples/tree/main/rsbuild/vue3-eslint)
37
+
38
+ ## Options
39
+
40
+ ### enable
41
+
42
+ Whether to enable ESLint checking.
43
+
44
+ - **Type:** `boolean`
45
+ - **Default:** `true`
46
+ - **Example:**
47
+
48
+ Disable ESLint checking:
49
+
50
+ ```js
51
+ pluginEslint({
52
+ enable: false,
53
+ });
54
+ ```
55
+
56
+ Enable ESLint checking only during production builds:
57
+
58
+ ```js
59
+ pluginEslint({
60
+ enable: process.env.NODE_ENV === "production",
61
+ });
62
+ ```
63
+
64
+ Enable ESLint checking only during development builds:
65
+
66
+ ```js
67
+ pluginEslint({
68
+ enable: process.env.NODE_ENV === "development",
69
+ });
70
+ ```
71
+
72
+ ### eslintPluginOptions
73
+
74
+ To modify the options of `eslint-webpack-plugin`, please refer to [eslint-webpack-plugin - README](https://github.com/webpack-contrib/eslint-webpack-plugin#readme) to learn about available options.
75
+
76
+ - **Type:** [Options](https://github.com/webpack-contrib/eslint-webpack-plugin/blob/master/types/options.d.ts)
77
+ - **Default:**
78
+
79
+ ```ts
80
+ const defaultOptions = {
81
+ extensions: ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts"],
82
+ exclude: [
83
+ "node_modules",
84
+ "dist", // -> rsbuildConfig.output.distPath.root
85
+ ],
86
+ };
87
+ ```
88
+
89
+ The `eslintPluginOptions` object will be shallowly merged with the default configuration object.
90
+
91
+ - For example, enable ESLint v9's flat config:
6
92
 
7
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
93
+ ```ts
94
+ pluginEslint({
95
+ eslintPluginOptions: {
96
+ cwd: __dirname,
97
+ configType: "flat",
98
+ },
99
+ });
100
+ ```
8
101
 
9
- ## Documentation
102
+ - For example, exclude some files using `exclude`:
10
103
 
11
- https://rsbuild.dev/
104
+ ```ts
105
+ pluginEslint({
106
+ eslintPluginOptions: {
107
+ exclude: ["node_modules", "dist", "./src/foo.js"],
108
+ },
109
+ });
110
+ ```
12
111
 
13
- ## Contributing
112
+ - Extend `extensions` to validate `.vue` or `.svelte` files:
14
113
 
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
114
+ ```ts
115
+ pluginEslint({
116
+ eslintPluginOptions: {
117
+ extensions: ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "vue"],
118
+ },
119
+ });
120
+ ```
16
121
 
17
122
  ## License
18
123
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
124
+ [MIT](./LICENSE).
package/dist/index.cjs CHANGED
@@ -34,7 +34,7 @@ __export(src_exports, {
34
34
  pluginEslint: () => pluginEslint
35
35
  });
36
36
  module.exports = __toCommonJS(src_exports);
37
- var import_node_path = __toESM(require("path"));
37
+ var import_node_path = __toESM(require("path"), 1);
38
38
  var PLUGIN_ESLINT_NAME = "rsbuild:eslint";
39
39
  var pluginEslint = (options = {}) => ({
40
40
  name: PLUGIN_ESLINT_NAME,
@@ -0,0 +1,19 @@
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
+ import { Options } from 'eslint-webpack-plugin';
3
+
4
+ type PluginEslintOptions = {
5
+ /**
6
+ * Whether to enable ESLint checking.
7
+ * @default true
8
+ */
9
+ enable?: boolean;
10
+ /**
11
+ * To modify the options of `eslint-webpack-plugin`.
12
+ * @see https://github.com/webpack-contrib/eslint-webpack-plugin
13
+ */
14
+ eslintPluginOptions?: Options;
15
+ };
16
+ declare const PLUGIN_ESLINT_NAME = "rsbuild:eslint";
17
+ declare const pluginEslint: (options?: PluginEslintOptions) => RsbuildPlugin;
18
+
19
+ export { PLUGIN_ESLINT_NAME, type PluginEslintOptions, pluginEslint };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { Options } from 'eslint-webpack-plugin';
3
- export type PluginEslintOptions = {
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
+ import { Options } from 'eslint-webpack-plugin';
3
+
4
+ type PluginEslintOptions = {
4
5
  /**
5
6
  * Whether to enable ESLint checking.
6
7
  * @default true
@@ -12,5 +13,7 @@ export type PluginEslintOptions = {
12
13
  */
13
14
  eslintPluginOptions?: Options;
14
15
  };
15
- export declare const PLUGIN_ESLINT_NAME = "rsbuild:eslint";
16
- export declare const pluginEslint: (options?: PluginEslintOptions) => RsbuildPlugin;
16
+ declare const PLUGIN_ESLINT_NAME = "rsbuild:eslint";
17
+ declare const pluginEslint: (options?: PluginEslintOptions) => RsbuildPlugin;
18
+
19
+ export { PLUGIN_ESLINT_NAME, type PluginEslintOptions, pluginEslint };
package/dist/index.js CHANGED
@@ -1,13 +1,5 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
-
5
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
6
- import { fileURLToPath } from "url";
7
- import path from "path";
8
-
9
1
  // src/index.ts
10
- import path2 from "path";
2
+ import path from "node:path";
11
3
  var PLUGIN_ESLINT_NAME = "rsbuild:eslint";
12
4
  var pluginEslint = (options = {}) => ({
13
5
  name: PLUGIN_ESLINT_NAME,
@@ -26,7 +18,7 @@ var pluginEslint = (options = {}) => ({
26
18
  extensions: ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts"],
27
19
  exclude: [
28
20
  "node_modules",
29
- path2.relative(api.context.rootPath, distPath)
21
+ path.relative(api.context.rootPath, distPath)
30
22
  ]
31
23
  };
32
24
  chain.plugin(CHAIN_ID.PLUGIN.ESLINT).use(ESLintPlugin, [
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-eslint",
3
- "version": "1.0.0-alpha.2",
4
- "description": "ESLint plugin for Rsbuild",
5
- "homepage": "https://rsbuild.dev",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/web-infra-dev/rsbuild",
9
- "directory": "packages/plugin-eslint"
10
- },
3
+ "version": "1.0.0",
4
+ "repository": "https://github.com/rspack-contrib/rsbuild-plugin-eslint",
11
5
  "license": "MIT",
12
6
  "type": "module",
13
7
  "exports": {
@@ -17,32 +11,54 @@
17
11
  "require": "./dist/index.cjs"
18
12
  }
19
13
  },
20
- "main": "./dist/index.cjs",
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
21
16
  "types": "./dist/index.d.ts",
22
17
  "files": [
23
18
  "dist"
24
19
  ],
20
+ "simple-git-hooks": {
21
+ "pre-commit": "npx nano-staged"
22
+ },
23
+ "nano-staged": {
24
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
25
+ "biome check --write --no-errors-on-unmatched"
26
+ ]
27
+ },
25
28
  "dependencies": {
26
29
  "eslint-webpack-plugin": "^4.2.0",
27
30
  "webpack": "^5.92.1"
28
31
  },
29
32
  "devDependencies": {
33
+ "@biomejs/biome": "^1.8.3",
34
+ "@playwright/test": "^1.44.1",
35
+ "@rsbuild/core": "1.0.0-alpha.3",
36
+ "@types/node": "^20.14.1",
30
37
  "eslint": "^9.6.0",
31
- "typescript": "^5.5.2",
32
- "@rsbuild/core": "1.0.0-alpha.2",
33
- "@scripts/test-helper": "1.0.0-alpha.2"
38
+ "nano-staged": "^0.8.0",
39
+ "playwright": "^1.44.1",
40
+ "simple-git-hooks": "^2.11.1",
41
+ "tsup": "^8.0.2",
42
+ "typescript": "^5.5.2"
34
43
  },
35
44
  "peerDependencies": {
36
- "@rsbuild/core": "^1.0.0-alpha.2",
45
+ "@rsbuild/core": "1.x",
37
46
  "eslint": "^8.0.0 || ^9.0.0"
38
47
  },
48
+ "peerDependenciesMeta": {
49
+ "@rsbuild/core": {
50
+ "optional": true
51
+ }
52
+ },
39
53
  "publishConfig": {
40
54
  "access": "public",
41
- "provenance": true,
42
55
  "registry": "https://registry.npmjs.org/"
43
56
  },
44
57
  "scripts": {
45
- "build": "modern build",
46
- "dev": "modern build --watch"
58
+ "build": "tsup",
59
+ "dev": "tsup --watch",
60
+ "lint": "biome check .",
61
+ "lint:write": "biome check . --write",
62
+ "test": "playwright test"
47
63
  }
48
64
  }