ESLint/Prettier报错:部分场景需将··替换为↹的问题排查
ESLint/Prettier 缩进冲突问题:空格需替换为制表符(仅部分场景出现)
我遇到ESLint/Prettier报错:要求将··(两个空格)替换为↹(制表符),但该报错仅在部分代码场景中出现,例如以下代码:
export const getTotalHabitableArea = ( checklist: FormattedChecklistType, isFullChecklist: boolean, ) => { if (!checklist) return null return isFullChecklist ? checklist?.indoorSpaces.floors.reduce( (acc, current) => Number(acc) + Number(current.floorHabitableArea || 0), 0, ) : checklist?.indoorSpaces.totalHabitableArea }
(报错截图:
)
我的.prettierrc配置如下:
{ "tabWidth": 2, "endOfLine": "auto", "proseWrap": "never", "semi": false, "singleQuote": true, "useTabs": true, "trailingComma": "all", "printWidth": 80 }
ESLint配置如下:
module.exports = { settings: { 'import/resolver': { typescript: {}, // load alias settings from tsconfig.json into ESLint node: { extensions: ['.js', '.jsx', '.ts', '.tsx'], moduleDirectory: ['node_modules', 'src/'], }, }, }, extends: [ 'eslint:recommended', 'next', 'prettier', 'turbo', 'plugin:import/recommended', 'plugin:import/typescript', 'plugin:prettier/recommended', ], plugins: [ '@typescript-eslint', 'formatjs', 'prettier', 'react', 'simple-import-sort', ], rules: { '@next/next/no-html-link-for-pages': 'off', 'no-case-declarations': 'off', 'no-prototype-builtins': 'off', 'no-unused-vars': 'off', // in favor of @typescript-eslint/no-unused-vars 'react-hooks/exhaustive-deps': 'off', 'react/jsx-key': 'off', '@typescript-eslint/no-unused-vars': 'error', 'formatjs/no-offset': 'error', 'simple-import-sort/exports': 'error', 'simple-import-sort/imports': 'error', 'arrow-body-style': ['error', 'as-needed'], 'formatjs/enforce-id': [ 'error', { idInterpolationPattern: '[sha512:contenthash:base64:6]', //i18n }, ], 'no-console': ['error', { allow: ['warn', 'error', 'info', 'debug'] }], 'react/self-closing-comp': ['error', { component: true, html: true }], 'simple-import-sort/imports': [ 'error', { groups: [ // `react` first, `next` second ['^react$', '^react-intl', '^next'], // packages starting with a character ['^[a-z]'], // 'common' packages ['^common'], // UI packages ['^ui'], // modules ['^modules'], // store ['^store'], // store ['^hooks'], // Packages starting with `@` ['^@'], // Packages starting with `~` ['^~'], // Imports starting with `../` ['^\.\.(?!/?$)', '^\.\./?$'], // Imports starting with `./` ['^\./(?=.*/)(?!/?$)', '^\.(?!/?$)', '^\./?$'], // Style imports ['^.+\.s?css$'], // Side effect imports ['^\u0000'], ], }, ], }, }
我尝试过将useTabs改为false,也调整过ESLint配置中的部分选项,但都没有效果,不清楚具体冲突点。已开启自动格式化,保存时错误会短暂消失但很快重现。
内容的提问来源于stack exchange,提问作者Andrik Dizhak
相关产品推荐
相关产品推荐

