Skip to content

Fix sort requires moving requires above local require = require(...) - #1185

Open
mkantautas wants to merge 1 commit into
JohnnyMorganz:mainfrom
mkantautas:fix/sort-requires-rebound-require
Open

mkantautas wants to merge 1 commit into
JohnnyMorganz:mainfrom
mkantautas:fix/sort-requires-rebound-require

Conversation

@mkantautas

Copy link
Copy Markdown

With sort requires enabled, local require = require(...) was sorted like any other require, by its name. In the example from #993 it moved below the six requires that call the new require, so those requires would run with the original require.

A require that rebinds require itself is now not sortable. It stays in place and splits its block, the same as any other local between requires. Requires before it are sorted above it, and requires after it are sorted below it.

  • Unit test for the rebinding case in sort_requires.rs
  • Snapshot test with the input from the issue
  • Luau test for const require = require(...) :: any with requires on both sides
  • CHANGELOG entry, and a note in the README's Requires Sorting section

cargo test (default, no default features, each dialect feature and all features), cargo fmt -- --check and cargo clippy --all-features -- -D warnings pass.

This covers the case where the rebound variable is require itself. Requires that depend on a variable bound by another require are still sorted by name: local Util = require(script.Util) followed by local A = require(Util.A) still puts A first. That case needs the reference analysis suggested in the issue.

Addresses the case reported in #993.

A require that rebinds `require` itself is no longer sortable, so it stays in place and splits its block. The requires after it, which call the new `require`, stay below it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant