gpt4 book ai didi

javascript - 保存文件时 JS/JSX 自动缩进错误

转载 作者:行者123 更新时间:2023-11-29 20:49:16 25 4
gpt4 key购买 nike

我在保存 JSX 或 JS 文件时遇到自动缩进问题。当我保存文件时,它缩进不正确并导致 linting 错误。

这是原始的js文件。

问题_4.js

import React from 'react';

import './Question_4.scss';

class Question_4 extends React.Component {
constructor(props) {
super(props);

}

handleClick = () => {
console.log('this is question 4 clicked:', this);

}

render() {
return (
<button className="button-redirect" onClick={this.handleClick}>
<div className="home-cta-image home-cta-image--neighborhood"></div>
</button>
);
}
}

export default Question_4;

然后当我保存时 (ctrl+s)。它在渲染函数的下方显示了不正确的缩进。

import React from 'react';

import './Question_4.scss';

class Question_4 extends React.Component {
constructor(props) {
super(props);

}

handleClick = () => {
console.log('this is question 4 clicked:', this);

}

render() {
return ( <
button className = "button-redirect"
onClick = { this.handleClick } >
<
div className = "home-cta-image home-cta-image--neighborhood" > < /div> <
/button>
);
}
}

export default Question_4;

我不确定是我的 eslint 文件还是其他地方导致了问题。

.eslintrc.json文件

{
"extends": [
"airbnb"
],
"parser": "babel-eslint",
"env": {
"browser": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"react/prefer-stateless-function": 0,
"react/jsx-indent": ["error", 4],
"react/jsx-indent-props": ["error", 4],
"react/jsx-no-undef": ["2", { "allowGlobals": true }],
"indent": ["error", 4],
"comma-dangle": 0,
"no-tabs": 0,
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"function-paren-newline": 0,
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
}
}

最佳答案

禁用 Beautify VS Code 的扩展选项卡中的扩展。

我通过与我的比较检查了你的工作区设置,我在列表中看到了这个扩展的名称。然后我安装并验证了我的假设,这个扩展导致格式不正确。

关于javascript - 保存文件时 JS/JSX 自动缩进错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52727960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com