forked from stkb/Rewrap
-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Hi @dnut, thanks again for creating this fork and maintaining it, amazing! 🙌
Rewrap breaks single-line ESLint configuration comments into multiple lines, breaking their functionality:
Before formatting (no warning)
After formatting (warning)
Warnings:
'nextLoad(url).source' may use Object's default stringification format ('[object Object]') when stringified. eslint [@typescript-eslint/no-base-to-string](https://typescript-eslint.io/rules/no-base-to-string)
Unused eslint-disable directive (no problems were reported). eslint
Full code (TypeScript):
import { registerHooks, stripTypeScriptTypes } from 'node:module';
const tsRegex = /^file:.*(?<!\.d)\.m?ts$/;
// Intercept .ts / .mts files (skipping .d.ts files) and
// transpile to JS, returning ES module
registerHooks({
load(url, context, nextLoad) {
if (tsRegex.test(url)) {
return {
format: 'module',
source: stripTypeScriptTypes(
/** @type {import('node:module').ModuleSource} */ (
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- ModuleSource returns useful information from .toString()
nextLoad(url).source
).toString(),
{
mode: 'transform',
sourceUrl: url,
},
),
shortCircuit: true,
};
}
return nextLoad(url, context);
},
});
// Path to entry point
await import('../src/index.ts');Implementation Suggestion
Ignore lines starting with eslint-disable-next-line and eslint-disable-line (maybe also eslint-disable and eslint-enable)
Metadata
Metadata
Assignees
Labels
No labels