Skip to content

Commit

Permalink
feat!: remove chokidar option
Browse files Browse the repository at this point in the history
  • Loading branch information
ModyQyW committed Sep 30, 2024
1 parent 0a1a781 commit e33e7f0
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 60 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export const ESLINT_SEVERITY = {
WARNING: 1,
} as const;

export const CWD = process.cwd();

export const PLUGIN_NAME = "vite:eslint2";

export const COLOR_MAPPING: Record<
Expand Down
42 changes: 1 addition & 41 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { dirname, extname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { Worker } from "node:worker_threads";
import type { FSWatcher } from "chokidar";
import chokidar from "chokidar";
import debugWrap from "debug";
import type * as Vite from "vite";
import { CWD, PLUGIN_NAME } from "./constants";
import { PLUGIN_NAME } from "./constants";
import type {
ESLintFormatter,
ESLintInstance,
Expand All @@ -32,7 +30,6 @@ export default function ESLintPlugin(
const options = getOptions(userOptions);

let worker: Worker;
let watcher: FSWatcher;

const filter = getFilter(options);
let eslintInstance: ESLintInstance;
Expand Down Expand Up @@ -84,39 +81,6 @@ export default function ESLintPlugin(
},
async transform(_, id) {
debug("==== transform hook ====");
// initialize watcher
if (options.chokidar) {
if (watcher) return;
debug("Initialize watcher");
watcher = chokidar
.watch(options.include, { ignored: options.exclude })
.on("change", async (path) => {
debug("==== change event ====");
const fullPath = resolve(CWD, path);
// worker + watcher
if (worker) return worker.postMessage(fullPath);
// watcher only
const shouldIgnore = await shouldIgnoreModule(
fullPath,
filter,
eslintInstance,
);
debug(`should ignore: ${shouldIgnore}`);
if (shouldIgnore) return;
return await lintFiles(
{
files: options.lintDirtyOnly ? fullPath : options.include,
eslintInstance,
formatter,
outputFixes,
options,
},
// this, // TODO: use transform hook context will breaks build
);
});
return;
}
// no watcher
debug(`id: ${id}`);
const filePath = getFilePath(id);
debug(`filePath: ${filePath}`);
Expand All @@ -137,10 +101,6 @@ export default function ESLintPlugin(
this, // use transform hook context
);
},
async buildEnd() {
debug("==== buildEnd ====");
if (watcher?.close) await watcher.close();
},
};
}

Expand Down
14 changes: 0 additions & 14 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,6 @@ export interface ESLintPluginOptions extends ESLint.ESLint.Options {
* @default true
*/
lintDirtyOnly: boolean;
/**
* Run ESLint in Chokidar `change` event instead of `transform` hook. This is disabled by default.
*
* Recommend to enable `lintOnStart` if you enable this one.
*
* 在 Chokidar `change` 事件中而不是在 `transform` 生命周期中运行 ESLint。默认禁用。
*
* 如果你启用这个选项,建议也启用 `lintOnStart`。
*
* @default false
*
* @deprecated
*/
chokidar: boolean;
/**
* Emit found errors. This is enabled by default.
*
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const getOptions = ({
lintInWorker,
lintOnStart,
lintDirtyOnly,
chokidar,
emitError,
emitErrorAsWarning,
emitWarning,
Expand All @@ -50,7 +49,6 @@ export const getOptions = ({
lintInWorker: lintInWorker ?? false,
lintOnStart: lintOnStart ?? false,
lintDirtyOnly: lintDirtyOnly ?? true,
chokidar: chokidar ?? false,
emitError: emitError ?? true,
emitErrorAsWarning: emitErrorAsWarning ?? false,
emitWarning: emitWarning ?? true,
Expand Down Expand Up @@ -78,7 +76,6 @@ export const getESLintConstructorOptions = (
"lintInWorker",
"lintOnStart",
"lintDirtyOnly",
"chokidar",
"emitError",
"emitErrorAsWarning",
"emitWarning",
Expand Down

0 comments on commit e33e7f0

Please sign in to comment.