In one of her Peter Wimsey novels Dorothy Sayers has someone remark that detective stories are extremely moral despite the murder and mayhem, because good triumphs over evil when the case is solved and the murderer brought to justice. In this way detective stories are also hopeful, because they imagine a world in which good does triumph, and the wicked get punished, or at least halted in their forward momentum and kept from doing more harm.
Sayers was writing from the 1920s into the 1940s, and detective stories have changed a lot (and even then Dashiell Hammett was writing fiction based on his own experiences as a Pinkerton’s detective, for one thing; Patricia Highsmith’s Mr. Ripley happened, for another), but the theory still holds. Even the recent (2014) season 1 of True Detective, which is about as noir as you can get, has that ground note of hopefulness, without which the story would be unbearable.* As Nic Pizzolatto, the writer/creator of the show, said in the DVD interview, he wanted that hope; he wanted to show that “optimism is no more of an illusion than pessimism.”
*A real life illustration of how a hopeful story can make something bearable: a librarian friend told me about a patron who took out DVDs of Law and Order: The Special Victims Unit because of her work — in a special victims unit. The crimes she investigated were so much worse than those on the TV show, and often unresolved even when the criminals were known, that watching the show was a way to restore her hope, and keep on keeping on.