Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public Space visitSpace(Space space, Space.Location loc, P p) {
String whitespace = s.getWhitespace();
int lastNewline = whitespace.lastIndexOf('\n');
// Skip import prefixes, leave those up to OrderImports which better understands that domain
if (lastNewline > 0 && loc != Space.Location.IMPORT_PREFIX) {
// Skip compilation unit prefix to preserve shebangs and other file-level prefixes
if (lastNewline > 0 && loc != Space.Location.IMPORT_PREFIX && loc != Space.Location.COMPILATION_UNIT_PREFIX) {
StringBuilder ws = new StringBuilder();
for (int i = 0; i < whitespace.length(); i++) {
char c = whitespace.charAt(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2025 the original author or authors.
* <p>
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://docs.moderne.io/licensing/moderne-source-available-license
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.javascript;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.openrewrite.Issue;
import org.openrewrite.java.format.RemoveTrailingWhitespace;
import org.openrewrite.javascript.rpc.JavaScriptRewriteRpc;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import static org.openrewrite.javascript.Assertions.javascript;

class RemoveTrailingWhitespaceTest implements RewriteTest {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been told these tests might not execute in CI, and locally I'm getting IllegalStateException: JavaScript RPC process shut down early with exit code 1. Do you think we still need this following #6349 @greg-at-moderne ?


@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new RemoveTrailingWhitespace());
}

@AfterEach
void after() {
JavaScriptRewriteRpc.shutdownCurrent();
}

@Issue("https://github.com/openrewrite/rewrite/issues/6274")
@Test
void doNotRemoveShebang() {
rewriteRun(
javascript(
"""
#!/usr/bin/env node

/**
* Generate llms.txt and llms-full.txt for OpenRewrite documentation
*/
"""
)
);
}
}