Skip to content

eslint-disable-next-line and eslint-disable-line line comments break when formatted #33

@karlhorky

Description

@karlhorky

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)

Image

After formatting (warning)

Image

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions