简体   繁体   中英

Error " prettier/prettier: Delete `·· ` " while setting up prettier on vim

I created a NextJs project and I wanted to integrate Prettier ans Eslint to help me out. Here's my config files:

.prettierrc

{                                                                               
     "trailingComma": "es5",                                                       
    "semi": true,                                                                 
    "singleQuote": true,                                                          
    "tabWidth": 2,                                                                
    "endOfLine": "auto"        
}    

.eslintrc

   {                                                                               
     "plugins": ["prettier"],                                                      
     "extends": ["prettier"],                                                      
     "rules": {                                                                    
       "prettier/prettier": "error"                                                
     },                                                                            
   "parserOptions": {                                                              
         "ecmaVersion": 7,                                                         
        "sourceType": "module",                                                   
        "ecmaFeatures": {                                                         
            "jsx": true,                                                          
        }                                                                         
    }                                                                             
  }  

I also have a .editor config file

# EditorConfig is awesome: http://EditorConfig.org                              
  2                                                                                 
  3 # top-most EditorConfig file                                                    
  4 root = true                                                                     
  5                                                                                 
  6 # Unix-style newlines with a newline ending every file                          
  7 [*]                                                                             
  8 end_of_line = lf                                                                
  9 insert_final_newline = true                                                     
 10 indent_style = space                                                            
 11 indent_size = 4                                                                 
 12 charset = utf-8                                                                 
 13                                                                                 
 14 [*.{js,json}]                                                                   
 15 indent_size = 2                                                                 
 16                                                                                                                
 17 [*.sql]                                                                                                        
 18 indent_size = 8 

When save my files, I get the error

prettier/prettier: Delete `··`

Can someone help me out?

there is a conflict between .prettierrc and .editorconfig . ESLint will only follow what is in the .prettierrc . In your case, your file is following .editorconfig rule (that overwrites what is in .prettierrc ) but your ESLint is following .prettierrc rule.

in your .prettierrc ,

"tabWidth": 2

in your .editorconfig ,

indent_size = 4

you can either set "tabWidth": 4 or remove indent_size = 4 to resolve the problem (depends on whether you prefer 2 or 4).

in fact these parameters in .editorconfig

end_of_line
indent_style
indent_size/tab_width
max_line_length

will conflict with these in .prettierrc

"endOfLine"
"useTabs"
"tabWidth"
"printWidth"

you can either let .editorconfig to follow .prettierrc default or sync both .editorconfig and .prettierrc for things to work properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM