A federal judge has declared President Donald Trump's executive order denying federal funding to so-called sanctuary cities to be unconstitutional. The judge got it right.

In his opinion this week in County of Santa Clara v. Trump, and the related case of City and County of San Francisco v. Trump, Judge William Orrick of the U.S. District Court for the Northern District of California found the president's order to be in violation of the 10th Amendment, the Fifth Amendment, and the constitutional separation of powers.

"The Constitution vests the spending powers in Congress, not the President, so the Executive Order cannot constitutionally place new conditions on federal funds," Judge Orrick wrote. "Further, the Tenth Amendment requires that conditions on federal funds be unambiguous and timely made; that they bear some relation to the funds at issue; and that they not be unduly coercive. Federal funding that bears no meaningful relationship to immigration enforcement cannot be threatened merely because a jurisdiction chooses an immigration enforcement strategy of which the President disapproves."

I've said it before and I'll say it again: Sanctuary cities are protected by both the Constitution and Supreme Court precedent. For starters, as the late Justice Antonin Scalia explained in Printz v. United States (1997), "the Federal Government may neither issue directives requiring the States to address particular problems, nor command the States' officers, or those of their political subdivisions, to administer or enforce a federal regulatory program." Put simply, Trump's executive order flunks the 10th Amendment test that Scalia spelled out in Printz.

Trump's executive order also flunks the test set forth by the Supreme Court in National Federation of Independent Business v. Sebelius (2012), which held that the federal government may not threaten to withhold existing funding from a state in an attempt to coerce that state into doing the feds' bidding. Such an effort would be an unconstitutional act of "economic dragooning."

Finally, Trump's executive order flunks the text of the Constitution itself, which, as Judge Orrick points out, "vests the spending powers in Congress, not the President." The limited and enumerated powers of the executive branch are spelled out in Article II; the federal spending power is located in Article I.

Related: Will Liberals Learn to Love the 10th Amendment?