Scotland's First Minster, Nicola Sturgeon, has survived the first of three big challenges this week. Arguably she is already past the worst of them. And that is bad news for Scotland's unionist parties.

Today the independent expert on the Ministerial Code, James Hamilton QC, ruled that Ms Sturgeon did not break the ministerial code - the rules government ministers operate under.

The key finding in Mr Hamilton's report was: "I am of the opinion that the First Minister did not breach the provisions of the Ministerial Code in respect of any of these matters."

Nicola Sturgeon immediately responded: "Mr Hamilton has considered all of the allegations against me, and I am happy that his report's findings clear me of any breach of the ministerial code."

Nicola Sturgeon

The charge of breaching the ministerial code is usually - though not always a resigning matter. For weeks the opposition parties in Holyrood - the Conservatives, Labour and the Liberal Democrats - and their Westminster colleagues, have kept up a drumbeat against Sturgeon, alleging she had broken the ministerial code over the accounts to parliament of her role in the Alex Salmond affair, and must resign.

Another report - by a parliamentary committee - will be published tomorrow. Its key finding, that Ms Sturgeon did not give an accurate account to the committee, can be (and indeed has been) dismissed by her as partisan - especially as that finding was leaked to the media last week. 

That decision was reached by a 5-4 majority vote. There are four SNP members on the committee, two conservatives, one each from Labour and the Lib Dems, and one Independent.

She is also likely to face a motion of no-confidence from the opposition parties. The SNP is a minority government in Scotland, kept in power by the votes of the Green Party. 

But the Greens want another referendum on independence, and today the Scottish government published legislation setting out its intention to hold a second referendum - at a time to be determined by the Scottish parliament - during the first half of the next parliamentary term. The Hamilton report makes it easier for the Greens to keep supporting Ms Sturgeon as their best chance of another independence vote.

With the findings of the Independent Hamilton inquiry in her hand, she now has the means to face down those demands, and lead the SNP into elections for the Scottish parliament in May. And that election may well be crucial for the future of the United Kingdom.

The efforts to pile the pressure on the best known figure in Scottish politics has to be seen against the background of those Scottish parliament elections - and their consequent impact on the campaign for a second Independence referendum, a campaign that is led by Ms Sturgeon.

The success or otherwise of that renewed push for an independence referendum depends on how the Scottish National Party does in those Holyrood elections. 

The SNP case is that if they emerge as the biggest party in Scotland for the fifth election in a row, the demand for a referendum will have to be seen as the settled will of the Scottish people and the government in London will have no option but to give in and allow one to take place.

And the difference between emerging once again as the biggest force in Scottish politics, or not, could be the public's perception of Nicola Sturgeon. Which is why the main opposition Conservative Party has every interest in hitting her hard over the Salmond affair. As do the other unionist parties, Labour and the Liberal Democrats.

Put crudely - stop Sturgeon, stop the referendum.

Yes, she has questions to answer over the Salmond affair, yes the parliament has every right (indeed duty) to hold minsters to account, and one of the yardsticks for doing that is the ministerial code, the set of standards minsters are expected to adhere to. One of the big sins in the ministerial code is misleading parliament.

But down in London the opposition Labour Party has claimed that Prime Minister Boris Johnson has misled the house three times this month already (the Unison trade union cites seven examples since the start of the year). 

Boris Johnson

Home Secretary Priti Patel was also found to have breached the ministerial code by an independent investigator, who ruled she had bullied staff in her department. But Boris Johnson decided it did not warrant her resignation. The independent investigator resigned instead.

Being cleared by James Hamilton is a big deal for Nicola Sturgeon because Mr Hamilton is an independent figure, not connected to Scottish politics (indeed not even Scottish) - unlike the inquiry conducted by a committee of the Scottish parliament, which is by nature partisan. 

While Ms Sturgeon, in the midst of an election campaign, can try and tough out a committee report she has already dismissed as flawed by partisanship, she could not have so easily dismissed an adverse finding by James Hamilton.

Mr Hamilton will be familiar to Irish readers as the former director of public prosecutions, a role in which skillfully skirting controversy and resisting political pressure is always required. 

But Mr Hamilton has direct personal experience of being involved in parliamentary inquiries. He featured in the dramatic 1994 committee investigation into the collapse of Albert Reynold's government, where he was referred to as "Official B". 

Part of its remit meant the committee was investigating the delays in the extradition of the paedophile priest Fr Brendan Smyth to Northern Ireland. Mr Hamilton emerged one of the winners from that inquiry, and went on to successfully lead the DPP's office from 1999 to 2011.

IN 2013 he was appointed by Alex Salmond to be the independent expert to examine potential breaches of the ministerial code. He investigated six claims against Alex Salmond, ruling in favour of the first minister in all of them.

In 2017, he was asked by the Welsh government to investigate if its then first minister, Carwyn Jones, had lied to the Welsh Assembly about allegations of bullying within government. Mr Hamilton cleared Mr Jones of breaching the ministerial code and said his account to the assembly was "accurate and truthful, and not misleading".

The two sets of inquiries into Nicola Sturgeon arise from her handling - as First Minster and leader of the SNP - of allegations of sexual misconduct by her predecessor Alex Salmond.

The row began when allegations of sexual harassment - strongly denied - were made against Mr Salmond by two female civil servants in 2018.

Alex Salmond

The complaints were made after Ms Sturgeon asked for new government policies on sexual harassment to be put in place in the wake of the #MeToo movement. Mr Salmond believed the policy was aimed at him.

The Scottish government eventually admitted it had botched its investigation. It had to pay Mr Salmond's legal fees of more than £500,000 after it admitted it had acted unlawfully.

Mr Salmond has accused officials close to Ms Sturgeon - including her husband Peter Murrell, the SNP's chief executive - of plotting against him. They all deny these claims.

Then, in January 2019, Mr Salmond was arrested and charged with multiple counts of sexual assault, including attempted rape.

Mr Salmond was cleared of all 13 charges - which were alleged to have happened while he was first minister - after a trial last March.

The nine women who made the allegations included an SNP politician, a party worker and several current and former Scottish government civil servants and officials.

In court, Mr Salmond said the claims made about his alleged conduct were "deliberate fabrications for a political purpose", or "exaggerations".

He has since claimed there was a "deliberate, prolonged, malicious and concerted effort" from some in the Scottish government and leading SNP figures to damage him and even have him sent to prison.

Ms Sturgeon has accused him of peddling false conspiracy theories and suggested her predecessor is angry because she "did not collude with him" to make the sexual harassment allegations "go away".

It was a nasty piece of party infighting, with factions of the SNP supporting the leader and her predecessor turning on each other, gleefully watched by the opposition unionist parties, who badly needed something to attack Ms Sturgeon and the SNP with. Their best shot was getting her on a breach of the ministerial code, and forcing her resignation.

Now she lives to fight another day, with momentum starting to swing in her direction. The mud will continue to be thrown as the Scottish parliament heads towards its dissolution on Thursday. And no doubt will continue during the election campaign.

But it looks like Nicola Sturgeon will lead the SNP in that campaign, during which the full weight of the pro-union parties in London will be brought to bear to try and stop another Independence referendum.

The SNP today applied for the right to add the phrase "Indyref2" to the ballot paper for May's election. Survive tomorrow's challenges, and it will be game on for Ms Sturgeon in what promises to be one almighty election campaign, where the future of the union is the one big issue.