A Pennsylvania judge said Friday the state’s Congressional districts were drawn to give Republicans an advantage, but they did not violate the state Constitution, ruling in a high-profile gerrymandering case with the potential to have major consequences on the 2018 midterm elections.

Judge P. Kevin Brobson of Commonwealth Court in Harrisburg noted that Republicans hold 13 out of 18 Congressional seats in Pennsylvania, a perennial swing state that has one of the most extensively gerrymandered maps in the country. Nonetheless, the judge said that Democrats who brought suit had failed to articulate a legal “standard” for creating nonpartisan maps.

The case now goes to the Pennsylvania Supreme Court, which has agreed to fast-track it. If the court rejects Judge Brobson’s conclusion, it could order new maps drawn in time for the 2018 midterm elections. Pennsylvania is expected to be fiercely fought terrain next year in elections turning on President Trump’s popularity. Mr. Trump’s 2016 victory in the state was the first for a Republican presidential candidate since 1988, but Republicans are already worried about losing Congressional seats even without new maps.

In practical terms, Judge Brobson’s determination — in the form of a finding ordered by the State Supreme Court — is a recommendation, which the high court may affirm or reject. Five of the court’s seven justices are Democrats.