0

In the following code, if I remove // prettier-ignore, then prettier will transform

'Accept'

into

Accept

Which will generate a compilation error. Prettier doesn't do that on my other headers.

Is there a better solution to this than asking prettier to ignore the next line?

export default function({ $axios, redirect }, inject) {
// Create a custom axios instance
const api = $axios.create({
    headers: {
        common: {
            // prettier-ignore
            'Accept': 'application/json; charset=utf-8',
            'Content-Type': 'application/json; charset=utf-8'
        }
    }
})

api.setBaseURL('http://10.10.10.5:8088')

// Inject to context as $api
inject('api', api)

}

The Vue2 error if I do not enclose the headers names with single quotes:

Syntax Error: Unexpected token, expected "," (9:11)

common: {
Accept: 'application/json; charset=utf-8',
Content-Type: 'application/json; charset=utf-8'
       ^
}

.prettierrc.json:

{
"tabWidth": 4,
"useTabs": true,
"semi": false,
"singleQuote": true
}
stKKd
  • 444
  • 1
  • 5
  • 11
  • 2
    It doesnt have to raise a compilation error , because it's a correct syntax. what is your error? – Alireza HI Apr 27 '20 at 11:31
  • @AlirezaHI Question updated to include error – stKKd Apr 27 '20 at 13:24
  • do you have a `.pretiierrc` file ? If you have can you add the content to the question? – Alireza HI Apr 27 '20 at 15:12
  • 1
    @AlirezaHI Updated. By the way maybe it doesn't make sense to have Content-Type as a common rule because Content-Type should be used only for PUT and POST and thus set accordingly when calling a specific .put or .post method in that Axios instance? Maybe prettier has a ruling about not having Content-Type as a global header for ALL type of requests?. – stKKd Apr 28 '20 at 01:57

0 Answers0