JS(期望换行符为'LF',但发现为'CRLF'。eslintlinebreak-style)问题

3

我是新手,学习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。

3个回答

9
点击右下角的LF / CLRF图标,将其更改为您需要的内容。 bottom right icon select panel 或者您可以更改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

在右下角,您可以更改行尾字符:

enter image description here

只需从CRLF更改为LF即可。

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


0
感谢我的一位资深同事提供了这个解决方案:
您还可以在 package.json 的 "rules" 部分中添加 ""linebreak-style": 0,",这基本上意味着告诉 eslint 忽略换行符样式(0 表示忽略)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接