What is the literary device of writing exactly as a character speaks, even if words are misspelled and the grammar is non-standard?

Misspellings and non-standard grammar are elements of a literary device called (surprise!) voice. A character's voice clearly identifies the speaker's personality, beliefs, education, economic class, and more. For example, take a look at the opening sentences of Mark Twain's The Adventures of Huckleberry Finn:
You don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. . . .

The text notifies you that Huck Finn is the narrator and will tell his story in his own words, in his own language and dialect (complete with grammatical errors and misspellings), and from his own point of view. By using the first-person narrative point of view, Twain carries on the southwestern humor tradition of vernacular language; that is, Huck sounds like a young, uneducated boy from Missouri probably would sound.