eslint --fix 在发生无重复导入时会破坏​​代码

发布于 2025-01-11 00:17:27 字数 1984 浏览 4 评论 0原文

例如,在经过 eslint init 过程的新 React Native 应用程序上运行 npx eslint ./App.js --fix 将导致代码格式从:

App.js:

import {
  StyleSheet,
  View,
  TextInput,
  ImageBackground,
  Image,
  TouchableOpacity,
  SafeAreaView
} from 'react-native';
import { I18nManager } from 'react-native'

变为:

import {
  StyleSheet,
  View,
  TextInput,
  ImageBackground,
  Image,
  TouchableOpacity,
  SafeAreaView, // <<< LOOK HERE
, I18nManager } from 'react-native';

注意SafeAreaView 之后的双逗号

知道是什么原因导致双逗号以及如何修复它?感谢您。 ...................................................... ...

我的 .eslintrc.json 文件:

{
    "env": {
        "es2021": true,
        "node": true
    },
    "extends": [
        "plugin:react/recommended",
        "airbnb"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
}

package.json:

{
  "name": "AwesomeProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.67.3"
  },
  "devDependencies": {
    "@babel/core": "^7.17.5",
    "@babel/runtime": "^7.17.2",
    "@react-native-community/eslint-config": "^3.0.1",
    "babel-jest": "^27.5.1",
    "eslint": "^8.10.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.29.2",
    "eslint-plugin-react-hooks": "^4.3.0",
    "jest": "^27.5.1",
    "metro-react-native-babel-preset": "^0.69.0",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

for example, running npx eslint ./App.js --fix on a fresh react native app that went through the eslint init process will cause the code to format from:

App.js:

import {
  StyleSheet,
  View,
  TextInput,
  ImageBackground,
  Image,
  TouchableOpacity,
  SafeAreaView
} from 'react-native';
import { I18nManager } from 'react-native'

to:

import {
  StyleSheet,
  View,
  TextInput,
  ImageBackground,
  Image,
  TouchableOpacity,
  SafeAreaView, // <<< LOOK HERE
, I18nManager } from 'react-native';

notice the double comma after SafeAreaView

any idea what causes the double commas and how to fix it? thanks you.
.....................................................

my .eslintrc.json file:

{
    "env": {
        "es2021": true,
        "node": true
    },
    "extends": [
        "plugin:react/recommended",
        "airbnb"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": "latest",
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
}

package.json:

{
  "name": "AwesomeProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.67.3"
  },
  "devDependencies": {
    "@babel/core": "^7.17.5",
    "@babel/runtime": "^7.17.2",
    "@react-native-community/eslint-config": "^3.0.1",
    "babel-jest": "^27.5.1",
    "eslint": "^8.10.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.29.2",
    "eslint-plugin-react-hooks": "^4.3.0",
    "jest": "^27.5.1",
    "metro-react-native-babel-preset": "^0.69.0",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2025-01-18 00:17:27

该问题已解决,这是 eslint 本身的错误,最新版本(8.11.0)已应用修复。

https://github.com/eslint/eslint/pull/15669

The issue has been resolved, it was a bug with eslint itself and the latest version (8.11.0) has applied a fix.

https://github.com/eslint/eslint/pull/15669

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文