【问题标题】:How to fix eslint/prettier "Parsing error: ';' expected" for .css file?如何修复 eslint/prettier “解析错误:';' .css 文件的“预期”?
【发布时间】:2019-12-24 20:21:59
【问题描述】:

这是我收到的错误示例,我不知道如何解决:

// example.css

body {
  height: 100%;
}

这会在运行 eslint 时在终端返回如下错误:

1:5 错误解析错误:';'预计

这是我的 eslintrc 和 prettierrc 配置, 感谢您的帮助:

// eslintrc.js

module.exports = {
    env: {
        browser: true,
        jest: true,
        node: true,
        es6: true,
    },
    parser: '@typescript-eslint/parser',
    plugins: ['@typescript-eslint'],
    extends: [
        'airbnb',
        'prettier',
        'prettier/react',
        'prettier/@typescript-eslint',
        'plugin:@typescript-eslint/recommended',
    ],
    parserOptions: {
        ecmaVersion: 2018,
        sourceType: 'module',
        ecmaFeatures: {
            jsx: true,
        },
    },
    rules: {
        'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
        'react/jsx-filename-extension': ['warn', { extensions: ['.tsx', '.jsx'] }],
        '@typescript-eslint/interface-name-prefix': ['error', { prefixWithI: 'always' }]
    },
    settings: {
        react: {
            version: 'detect',
        },
        'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],
        'import/parsers': {
            '@typescript-eslint/parser': ['.ts', '.tsx'],
        },
        'import/resolver': {
            node: {
                extensions: ['.js', '.jsx', '.ts', '.tsx'],
                moduleDirectory: ['node_modules', 'src'],
            },
        },
    },
};
// prettierrc.js

module.exports =  {
    semi:  true,
    trailingComma:  'all',
    singleQuote:  true,
    printWidth:  120,
    tabWidth:  2,
};

【问题讨论】:

    标签: css eslint prettier


    【解决方案1】:

    经过一番研究,我发现我的 eslint 命令是问题所在:

    yarn eslint src/**

    这包括 .css、.json 等文件,即使我的 eslintrc 配置正确。通过切换到此功能,问题不再出现:

    yarn eslint --ext js,jsx,ts,tsx src

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-03
      • 2020-08-02
      • 2021-06-05
      • 2019-12-12
      • 1970-01-01
      • 2021-11-18
      • 2018-09-18
      • 1970-01-01
      相关资源
      最近更新 更多