From d8055feb0118ba82acc0a76ce9f05c12d6fd586e Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 6 Feb 2026 12:57:05 +0000 Subject: [PATCH] test(linter/plugins): test fixes and suggestions at very end of file (#19054) Alter test fixtures for fixes and suggestions. Remove trailing newline from end of fixture files, so that the last fix the plugin makes is at very end of file - makes sure fixes in this position still work. Add checks to these tests and also the BOM test to catch if these fixture files accidentally get formatted, which would add a trailing newline and prevent the tests testing what they should do. --- apps/oxlint/test/fixtures/bom/plugin.ts | 9 ++++++++- apps/oxlint/test/fixtures/fixes/files/index.js | 2 +- apps/oxlint/test/fixtures/fixes/fix.snap.md | 1 - apps/oxlint/test/fixtures/fixes/plugin.ts | 7 +++++++ apps/oxlint/test/fixtures/suggestions/files/index.js | 2 +- .../test/fixtures/suggestions/fix-suggestions.snap.md | 1 - apps/oxlint/test/fixtures/suggestions/plugin.ts | 7 +++++++ oxfmtrc.jsonc | 2 ++ 8 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/oxlint/test/fixtures/bom/plugin.ts b/apps/oxlint/test/fixtures/bom/plugin.ts index a3b903281ccff..1f3c43dd7a5c7 100644 --- a/apps/oxlint/test/fixtures/bom/plugin.ts +++ b/apps/oxlint/test/fixtures/bom/plugin.ts @@ -1,3 +1,5 @@ +import assert from "node:assert"; + import type { Plugin } from "#oxlint/plugins"; const plugin: Plugin = { @@ -7,13 +9,18 @@ const plugin: Plugin = { rules: { bom: { create(context) { + // Check file has not been formatted by accident. + // We want the fixture files not to have trailing whitespace to check diagnostics at very end of file. + const sourceText = context.sourceCode.text; + assert(sourceText.endsWith(";"), "Fixture file has been formatted"); + return { Program(node) { context.report({ message: "\n" + `hasBOM: ${context.sourceCode.hasBOM}\n` + - `sourceText: ${JSON.stringify(context.sourceCode.text)}\n` + + `sourceText: ${JSON.stringify(sourceText)}\n` + `Program span: ${node.start}-${node.end}`, node, }); diff --git a/apps/oxlint/test/fixtures/fixes/files/index.js b/apps/oxlint/test/fixtures/fixes/files/index.js index 2a6f6bfaeb243..776d00a9806c5 100644 --- a/apps/oxlint/test/fixtures/fixes/files/index.js +++ b/apps/oxlint/test/fixtures/fixes/files/index.js @@ -11,4 +11,4 @@ let h = 8; let i = 9; let j = 10; -debugger; +debugger; \ No newline at end of file diff --git a/apps/oxlint/test/fixtures/fixes/fix.snap.md b/apps/oxlint/test/fixtures/fixes/fix.snap.md index 7ab316deab6bd..a533c9dfb894b 100644 --- a/apps/oxlint/test/fixtures/fixes/fix.snap.md +++ b/apps/oxlint/test/fixtures/fixes/fix.snap.md @@ -27,5 +27,4 @@ let granular = 9; let cowabunga = 10; - ``` diff --git a/apps/oxlint/test/fixtures/fixes/plugin.ts b/apps/oxlint/test/fixtures/fixes/plugin.ts index 9ea944694d0c6..389b6bf30ec23 100644 --- a/apps/oxlint/test/fixtures/fixes/plugin.ts +++ b/apps/oxlint/test/fixtures/fixes/plugin.ts @@ -1,3 +1,5 @@ +import assert from "node:assert"; + import type { Diagnostic, Node, Plugin, Rule } from "#oxlint/plugins"; const rule: Rule = { @@ -5,6 +7,11 @@ const rule: Rule = { fixable: "code", }, create(context) { + // Check file has not been formatted by accident. + // We want the fixture files not to have trailing whitespace to check fixes at very end of file. + const sourceText = context.sourceCode.text; + assert(!sourceText.endsWith("\n"), "Fixture file has been formatted"); + let debuggerCount = 0; return { DebuggerStatement(node) { diff --git a/apps/oxlint/test/fixtures/suggestions/files/index.js b/apps/oxlint/test/fixtures/suggestions/files/index.js index 07d7b51b966f3..14e5b4e58a111 100644 --- a/apps/oxlint/test/fixtures/suggestions/files/index.js +++ b/apps/oxlint/test/fixtures/suggestions/files/index.js @@ -12,4 +12,4 @@ let i = 9; let j = 10; let k = 11; -debugger; +debugger; \ No newline at end of file diff --git a/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md b/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md index fb2e98a236c82..e4fc8c283701b 100644 --- a/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md +++ b/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md @@ -28,5 +28,4 @@ let cowabunga = 10; let kaboom = 11; - ``` diff --git a/apps/oxlint/test/fixtures/suggestions/plugin.ts b/apps/oxlint/test/fixtures/suggestions/plugin.ts index 6dec236aaad52..ef5fcc50417aa 100644 --- a/apps/oxlint/test/fixtures/suggestions/plugin.ts +++ b/apps/oxlint/test/fixtures/suggestions/plugin.ts @@ -1,3 +1,5 @@ +import assert from "node:assert"; + import type { Node, Plugin, Rule, Suggestion } from "#oxlint/plugins"; const rule: Rule = { @@ -5,6 +7,11 @@ const rule: Rule = { hasSuggestions: true, }, create(context) { + // Check file has not been formatted by accident. + // We want the fixture files not to have trailing whitespace to check suggestions at very end of file. + const sourceText = context.sourceCode.text; + assert(!sourceText.endsWith("\n"), "Fixture has been formatted"); + let debuggerCount = 0; return { DebuggerStatement(node) { diff --git a/oxfmtrc.jsonc b/oxfmtrc.jsonc index 827ae6194701e..b949f46c6ee23 100644 --- a/oxfmtrc.jsonc +++ b/oxfmtrc.jsonc @@ -6,6 +6,8 @@ "**/fixtures/**", "!apps/oxlint/test/fixtures/**", "apps/oxlint/test/fixtures/bom/files/**", + "apps/oxlint/test/fixtures/fixes/files/**", + "apps/oxlint/test/fixtures/suggestions/files/**", "**/dist/**", "**/generated/**", "**/CHANGELOG.md",