0

很抱歉重复这个问题,但我是一个菜鸟,不明白如何解决这个问题。如果不难,请更详细地描述如何解决这个问题。

我正在使用 2017 教科书创建我的学习项目,并且该代码中没有此类错误。由于我对如此复杂的项目缺乏经验,我无法自己找到问题。

在此处输入图像描述 吞咽文件

const gulp = require ('gulp') ;
const babel = require('gulp-babel');
const eslint = require('gulp-eslint');

// Задание для gulp - инструмент сборки.
gulp.task('default', async function ()
{
    // Запуск ESLint
    gulp.src(["es6/**/*.js", "public/es6/**/*.js"])
        .pipe(eslint())
        .pipe(eslint.format());
    // Указание для node.js
    // Указание кода источника для сборки.
    gulp.src("es6/**/*.js")
        // Транспортировка(pipe) файлов исходного кода в Babel, который преобразует их из ЕSб в ES5.
        .pipe(babel())
        // На завершающем этапе откомпилированный код ES5 транспортируется по назначению, в каталог dist.
        .pipe(gulp.dest("dist"));

    // Указание для браузера.
    // Указание кода источника для сборки.
    gulp.src("public/es6/**/*.js")
        // Вызов транскриптора для кода.
        .pipe(babel())
        //На завершающем этапе откомпилированный код ESS транспортируется по назначению, в каталог dist.
        .pipe(gulp.dest("public/dist"));
});

包裹:

{
      "name": "javascriptproject",
      "version": "1.0.0",
      "description": "myProject",
      "main": "main.js",
      "directories": {
        "test": "test"
      },
      "dependencies": {
        "gulp-eslint": "^6.0.0",
        "save-dev": "0.0.1-security",
        "underscore": "^1.13.1"
      },
      "devDependencies": {
        "@babel/core": "^7.14.6",
        "@babel/preset-env": "^7.14.7",
        "@babel/preset-react": "^7.14.5",
        "babel-preset-es2015": "^6.24.1",
        "eslint": "^7.29.0",
        "eslint-plugin-react": "^7.24.0",
        "gulp": "^4.0.2",
        "gulp-babel": "^8.0.0"
      },
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "repository": {
        "type": "git",
        "url": "D:\\JavaScriptProject"
      },
      "keywords": [
        "my",
        "first",
        "project"
      ],
      "author": "me",
      "license": "ISC"
    }

.eslintrc:

module.exports = {
    "env": {
        "browser": true,
        "es2021": true,
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
};
4

1 回答 1

-1

经过一些更改后我得到了它

.eslintrc

  1. 我变了 "es2021": true, into "es2020": true,
  2. 在我得到错误后,Parsing error: Invalid ecmaVersion我改变了 "ecmaVersion": 12,,into "ecmaVersion": 11
  3. 最后一个我检查了https://github.com/yannickcr/eslint-plugin-react#recommend并找到了如何“启用”包含此部分中所有可用规则的​​所有配置的解决方案:
 "extends": [
        "eslint:recommended",
        "plugin:react/recommended",
        "eslint:all", // just added this line
        "plugin:react/all" // and this line
    ],

我不确定这是否真的有效,但看起来像这样:

D:\JavaScriptProject\public\es6\test.js
   1:1   error  'use strict' is unnecessary inside of modules                                    strict
   1:1   error  Strings must use doublequote                                                     quotes
   1:14  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   2:1   error  Expected space or tab after '//' in comment                                      spaced-comment
   2:40  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   3:18  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   4:6   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   5:10  error  Extra space after key 'subject'                                                  key-spacing
   5:10  error  Unquoted property 'subject' found                                                quote-props
   5:20  error  Strings must use doublequote                                                     quotes
   5:34  error  Object properties must go on a new line                                          object-property-newline
   5:34  error  Unquoted property 'verb' found                                                   quote-props
   5:40  error  Strings must use doublequote                                                     quotes
   5:46  error  Object properties must go on a new line                                          object-property-newline
   5:46  error  Unquoted property 'object' found                                                 quote-props
   5:46  error  Expected object keys to be in ascending order. 'object' should be before 'verb'  sort-keys
   5:54  error  Strings must use doublequote                                                     quotes
   5:63  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   6:10  error  Extra space after key 'subject'                                                  key-spacing
   6:10  error  Unquoted property 'subject' found                                                quote-props
   6:20  error  Strings must use doublequote                                                     quotes
   6:33  error  Object properties must go on a new line                                          object-property-newline
   6:33  error  Unquoted property 'verb' found                                                   quote-props
   6:39  error  Strings must use doublequote                                                     quotes
   6:47  error  Object properties must go on a new line                                          object-property-newline
   6:47  error  Unquoted property 'object' found                                                 quote-props
   6:47  error  Expected object keys to be in ascending order. 'object' should be before 'verb'  sort-keys
   6:55  error  Strings must use doublequote                                                     quotes
   6:63  error  Unexpected trailing comma                                                        comma-dangle
   6:64  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   7:7   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   8:1   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
   9:42  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  10:1   error  Expected a function expression                                                   func-style
  10:13  error  Missing space before function parentheses                                        space-before-function-paren
  10:38  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  11:1   error  Opening curly brace does not appear on the same line as controlling statement    brace-style
  11:1   error  Block must be padded by blank lines                                              padded-blocks
  11:2   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  12:5   error  Unexpected console statement                                                     no-console
  12:51  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  13:1   error  Block must be padded by blank lines                                              padded-blocks
  13:2   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  14:1   error  Comments should not begin with a lowercase character                             capitalized-comments
  14:26  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  15:1   error  Expected space(s) after "for"                                                    keyword-spacing
  15:9   error  Identifier name 's' is too short (< 2)                                           id-length
  15:9   error  's' is never reassigned. Use 'const' instead                                     prefer-const
  15:24  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  16:1   error  Opening curly brace does not appear on the same line as controlling statement    brace-style
  16:1   error  Block must be padded by blank lines                                              padded-blocks
  16:2   error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  17:12  error  Expected linebreaks to be 'LF' but found 'CRLF'                                  linebreak-style
  18:1   error  Block must be padded by blank lines                                              padded-blocks
  18:2   error  Newline required at end of file but not found                                    eol-last

✖ 110 problems (110 errors, 0 warnings)
  100 errors and 0 warnings potentially fixable with the `--fix` option.
于 2021-06-24T22:13:04.670 回答