gen-jhipster
Version:
VHipster - Spring Boot + Angular/React/Vue in one handy generator
26 lines (25 loc) • 1.14 kB
JavaScript
import { extname } from 'node:path';
import { isFileStateModified } from 'mem-fs-editor/state';
import { passthrough } from 'p-transform';
import { addLineNumbers } from "../internal/transform-utils.js";
import javaLintWorker from "./java-lint-worker.js";
export const createRemoveUnusedImportsTransform = async function (options = {}) {
const { ignoreErrors } = options;
return passthrough(async (file) => {
if (extname(file.path) === '.java' && isFileStateModified(file) && file.contents) {
const fileContents = file.contents.toString('utf8');
const result = await javaLintWorker({ fileContents });
if ('result' in result) {
file.contents = Buffer.from(result.result);
}
if ('error' in result) {
const errorMessage = `Error parsing file ${file.relative}: ${result.error} at ${addLineNumbers(fileContents)}`;
if (ignoreErrors) {
this?.log?.warn?.(errorMessage);
return;
}
throw new Error(errorMessage);
}
}
});
};