【问题标题】:JS (Expected linebreaks to be 'LF' but found 'CRLF'.eslintlinebreak-style) issueJS(预期换行符为“LF”但发现“CRLF”.eslint linebreak-style)问题
【发布时间】:2020-10-06 08:57:41
【问题描述】:

我是 JS 新手。我创建了带有复选框行的表格。现在我想测试一下。但我的 index.js 文件出现错误。

我的代码

import React from 'react';
import { Spin, Table } from 'antd';
import { useFetch } from 'innroad.common.ui';
import * as apiService from 'services/ApiService';

const AccountType = (onSelectingItems) => {
  const [data, isLoading] = useFetch(apiService.accountType);

  return (
    <Spin spinning={isLoading}>
      <Table
        key="id"
        bordered="true"
        rowKey="id"
        dataSource={data}
        rowSelection={{ onChange: onSelectingItems }}
        pagination={false}
      >
        <Table.Column title="Account Type" dataIndex="accountType" />
      </Table>

    </Spin>
  );
};

/* AccountType.propTypes = {
  selectionType: PropTypes.string,
  onSelectingLineItems: PropTypes.func,
}; */

AccountType.defaultProps = {
  selectionType: 'checkbox',
  onSelectingLineItems: () => { },
};

export default AccountType;

还有一个问题:我应该使用 AccountType.propTypes - 注释块吗?如果是,我需要如何更改它?因为现在我在这个块中遇到错误 - 我声明但没有使用。

Index.JS(这里有错误)

export { default } from './AccountType';

预期的换行符是 'LF',但在 ";" 之后发现了 'CRLF'.eslintlinebreak-style

【问题讨论】:

    标签: javascript html css visual-studio-code frontend


    【解决方案1】:

    单击右下角的 LF / CLRF 图标并将其更改为您需要的。

    或者你可以在 eslint 中更改规则

    "linebreak-style": ["error", "windows"]
    or
    "linebreak-style": ["error", "unix"]
    

    https://eslint.org/docs/rules/linebreak-style

    您还可以将 git 配置为使用选定的行尾样式结帐。这往往是“问题”再次出现的原因。

    例如

    $ git config --global core.autocrlf true
    # Configure Git to ensure line endings in files you checkout are correct for Windows.
    # For compatibility, line endings are converted to Unix style when you commit files.
    

    https://docs.github.com/en/free-pro-team@latest/github/using-git/configuring-git-to-handle-line-endings

    【讨论】:

      【解决方案2】:

      右下角可以更改换行符:

      只需从 CRLF 更改为 LF。

      如果您使用 Git,您可以通过配置自动更改此设置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-16
        • 2020-11-03
        • 2014-10-30
        • 1970-01-01
        • 2018-06-20
        • 1970-01-01
        • 2015-04-23
        相关资源
        最近更新 更多