eslint-plugin-prettier: error Delete `··` prettier/prettier
What version of eslint
are you using?
No use
What version of prettier
are you using?
“prettier”: “^1.18.2”
What version of eslint-plugin-prettier
are you using?
“eslint-plugin-prettier”: “^3.1.0”
Please paste any applicable config files that you’re using (e.g. .prettierrc
or .eslintrc
files)
{
"printWidth": 80,
"eslintIntegration": true,
"stylelintIntegration": true,
"tabWidth": 2,
"singleQuote": true,
"semi": false
}
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"wx": "readonly",
"getCurrentPages": "readonly",
"getApp": "readonly",
"Page": "readonly",
"Component": "readonly",
"App": "readonly"
},
"root": true,
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"prettier/prettier": "error",
"@typescript-eslint/member-delimiter-style": "off",
"@typescript-eslint/interface-name-prefix": ["warn", "always"],
"@typescript-eslint/explicit-function-return-type": ["error", {
"allowExpressions": true,
"allowTypedFunctionExpressions": true,
"allowHigherOrderFunctions": true
}],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/indent": ["error", 2]
}
}
What source code are you linting?
/**
* 小程序配置文件
*/
const isProd = false
const isMock = false
const config: IConfig = {
version: '1.5.7',
versionDesc: `xxxxxx`,
isProd,
env: isProd ? 'pro' : 'dev',
rootUrl: isProd
? 'https://xxx.funxi.cn'
: isMock
? 'http://xxx:8017'
: 'https://xxx.cn',
tabBarUrlList: []
}
export default config
What did you expect to happen?
fix error
What actually happened?
Here’s a error message:
Here’s a hint from gulp-eslint: As you can see, “fixed” is true, and the error indicates that it has been fixed, but the actual situation is not fixed. This misleads me into a constant cycle of error reporting and fixing.
{ filePath:
'/Users/april/myfile/www/gitstore/wechat_cabinet/src/config.ts',
messages:
[ { ruleId: 'prettier/prettier',
severity: 2,
message: 'Delete `··`',
line: 16,
column: 5,
nodeType: null,
endLine: 16,
endColumn: 7,
fix: [Object] },
{ ruleId: 'prettier/prettier',
severity: 2,
message: 'Delete `··`',
line: 17,
column: 1,
nodeType: null,
endLine: 17,
endColumn: 3,
fix: [Object] } ],
errorCount: 2,
warningCount: 0,
fixableErrorCount: 2,
fixableWarningCount: 0,
output:
'/**\n * 小程序配置文件\n */\n\nconst isProd = false\nconst isMock = false\n\nconst config: IConfig = {\n version: \'1.5.7\',\n versionDesc: `xxxxxx`,\n isProd,\n env: isProd ? \'pro\' : \'dev\',\n rootUrl: isProd\n ? \'https://xxx.funxi.cn\'\n : isMock\n ? \'http://xxx:8017\'\n : \'https://xxx.cn\',\n tabBarUrlList: []\n}\n\nexport default config\n',
fixed: true }
However, if I change ‘printWidth’ to 400, then ‘rootUrl’ will not prompt error messages and will not format line breaks, so the above problem will not occur, but it will not solve the root problem.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 43 (4 by maintainers)
Commits related to this issue
- fix: change prettier endOfLine to crlf - https://github.com/prettier/eslint-plugin-prettier/issues/219#issuecomment-610262026 — committed to lbwa/ts-monorepo-boilerplate by lbwa 4 years ago
- Issue with EOL? https://github.com/prettier/eslint-plugin-prettier/issues/219 — committed to shahradelahi/telegraf by shahradelahi 4 months ago
@mutaimwiti or, you can add this line to your
.prettierrc
"endOfLine": "auto"
put this in eslint file, worked for me:
"prettier/prettier": ["error", { "endOfLine": "off" }]
None of this helped me actually
Prettier belives you’ve got too many spaces on lines 16 and 17. As such we seem to be reporting the error from prettier correctly.
If running eslint with the
--fix
flag does not cause this to be fixed then I expect you have some other eslint rule conflicting with prettier’s fix that is putting the spacing back.I note that you are not extending the eslint-config-prettier configuration. You should configure that there are no eslint rules that conflict with prettier’s formatting.
For me it was indentation problem. You can run
npx eslint folder/file.js --fix
.make sure add rules: {‘prettier/prettier’: [‘error’, {endOfLine: ‘auto’}]}, line in .eslintrc.js and also enable prettier plugin in vs code.
None of this is helpful
Check and make sure you don’t have the
indent
eslint rule.Like:
"indent": [ "error", 2 ]
Run
This fixed the issues for me
this worked for me
.vscode/settings.json
There is a setting in Visual Studio Code “Javascript > Format: Enable” that can potentially conflict with the Prettier formatting. After disabling this setting, Prettier was able to take full control and fixed this problem for me.
here is my solution. Pay attention on line with rules for prettier. Just add {“endOfLine”: “auto”} for prettier rules.
.eslintrc:
.prettierrc:
dependencies:
disable your default formatter, only use eslint as code formatter
“prettier/prettier”: [ “warn”, { “singleQuote”: true, “endOfLine”: “auto”, “tabWidth”: 4 } ],
Not sure this will help anyone else, but errors didn’t go away for me until I restarted vscode.
Here I’m using npm and so I run the equivalent command:
Solved here !
it works for me, thx
Restarting vscode helped. It has some issue with detecting changes in prettier config
@v-radev 's solution:
worked for me.
In my file, I had many lines like:
I inserted one linear line like:
Which broke the eslint rule. After running the solution, I see that it got restructured like the rest:
for those confused still, you may want to check this vid for context. https://www.youtube.com/watch?v=St1YSNoB36Y&t=121s
I was able to eventually solve my issue. I added a script under “scripts” in the package.json===> “lintfix”: “eslint ./src --fix --ext .js” <===then a ran ===> npm run lintfix
As @Dozorengel described, problem is probably related with your line ending file format. Try to setup
.editorconfg
file https://editorconfig.org/ or try to change line ending in your editor.@tomleo It did! I changed my
tabWidth
property in my.prettierrc
file and I believe the VS Code Prettier extension did not immediately pickup the change. I saved a file and saw the tab width change to the new setting and then straight back to the original one while having eslint yelling at me that my indentation was incorrect. Reloading VS Code seems to have forced the Prettier extension to pick up the new config and now when I save a file my code indentation matches the newly set config without issues. Therefore thanks for your comment, it helped out! 😅I am using VSCode, and adding the following additional setting option worked for me.
I need to run prettier and auto fix everything afterwards though.
This works:
But i’m pretty sure it’s just a workaround and not the actual fix.
it helps me!!!
Not sure who may find this useful, but I realised this happened because I was declaring an anonymous function which somehow affected formatting of prettier. Rewriting the function declaration to be a named function helped. Also it’s a benefit because tracing named functions give you the name, while anonymous functions may be harder to trace.
This is not a good practice IMO.