ESLint - 不修改文件

lon*_*aft 9 javascript lint eslint

我正在尝试使用ESLint来修改和修复我的代码.当我使用我的配置文件运行ESLint并且没有修复标志时,它运行正常,这就是它输出的内容.

eslint -c .eslintrc.json ./src/aura/SearchAvailableNumbers

/home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js
    8:9   error  Unexpected blank line after variable declarations  newline-after-var
   15:13  error  'hlp' is defined but never used                    no-unused-vars
   50:30  error  'helper' is defined but never used                 no-unused-vars
   55:32  error  'helper' is defined but never used                 no-unused-vars
   59:42  error  'helper' is defined but never used                 no-unused-vars
   69:7   error  Expected { after 'if' condition                    curly
   69:22  error  Expected '===' and instead saw '=='                eqeqeq
   71:22  error  Expected '===' and instead saw '=='                eqeqeq
   76:22  error  Expected '===' and instead saw '=='                eqeqeq
   84:50  error  Object properties must go on a new line            object-property-newline
   89:21  error  Expected '===' and instead saw '=='                eqeqeq
  113:27  error  'appEvent' is already defined                      no-redeclare

/home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js
  14:17  error  Gratuitous parentheses around expression  no-extra-parens
  23:17  error  'appEvent' is defined but never used      no-unused-vars
  24:28  error  Expected '===' and instead saw '=='       eqeqeq
  28:28  error  Expected '===' and instead saw '=='       eqeqeq
  32:28  error  Expected '===' and instead saw '=='       eqeqeq
Run Code Online (Sandbox Code Playgroud)

所有这些信息都是正确的,并且是必须在代码中修复的问题.所以我再次运行它,这一次

eslint --fix --debug -c .eslintrc.json ./src/aura/SearchAvailableNumbers

现在输出是

eslint:cli Running on files +0ms
  eslint:config Using command line config .eslintrc.json +70ms
  eslint:config-file Loading JSON config file: /home/jason/sfa/testproj/.eslintrc.json +5ms
  eslint:config-file Loading /usr/local/lib/node_modules/eslint/conf/eslint.json +292ms
  eslint:config-file Loading JSON config file: /usr/local/lib/node_modules/eslint/conf/eslint.json +0ms
  eslint:ignored-paths Looking for ignore file in /home/jason/sfa/testproj +40ms
  eslint:ignored-paths Could not find ignore file in cwd +0ms
  eslint:glob-util Creating list of files to process. +1ms
  eslint:cli-engine Processing /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js +6ms
  eslint:cli-engine Linting /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js +1ms
  eslint:config Constructing config for /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js +0ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /home/jason/sfa/testproj/.eslintrc.yml +2ms
  eslint:config-file Loading YAML config file: /home/jason/sfa/testproj/.eslintrc.yml +1ms
  eslint:config-file Loading /usr/local/lib/node_modules/eslint/conf/eslint.json +63ms
  eslint:config-file Loading JSON config file: /usr/local/lib/node_modules/eslint/conf/eslint.json +0ms
  eslint:config Using /home/jason/sfa/testproj/.eslintrc.yml +5ms
  eslint:config Merging command line config file +0ms
  eslint:config Merging command line environment settings +0ms
  eslint:config-ops Apply environment settings to config +1ms
  eslint:config-ops Creating config for environment browser +0ms
  eslint:cli-engine Linting code for /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js (pass 1) +3ms
  eslint:cli-engine Generating fixed text for /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js (pass 1) +147ms
  eslint:text-fixer Applying fixes +0ms
  eslint:text-fixer No fixes to apply +0ms
  eslint:cli-engine Processing /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js +0ms
  eslint:cli-engine Linting /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js +1ms
  eslint:config Constructing config for /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js +0ms
  eslint:config Using config from cache +0ms
  eslint:cli-engine Linting code for /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js (pass 1) +0ms
  eslint:cli-engine Generating fixed text for /home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js (pass 1) +56ms
  eslint:text-fixer Applying fixes +0ms
  eslint:text-fixer No fixes to apply +0ms
  eslint:cli-engine Linting complete in: 291ms +1ms
  eslint:cli Fix mode enabled - applying fixes +0ms

/home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersController.js
    8:9   error  Unexpected blank line after variable declarations  newline-after-var
   15:13  error  'hlp' is defined but never used                    no-unused-vars
   50:30  error  'helper' is defined but never used                 no-unused-vars
   55:32  error  'helper' is defined but never used                 no-unused-vars
   59:42  error  'helper' is defined but never used                 no-unused-vars
   69:7   error  Expected { after 'if' condition                    curly
   69:22  error  Expected '===' and instead saw '=='                eqeqeq
   71:22  error  Expected '===' and instead saw '=='                eqeqeq
   76:22  error  Expected '===' and instead saw '=='                eqeqeq
   84:50  error  Object properties must go on a new line            object-property-newline
   89:21  error  Expected '===' and instead saw '=='                eqeqeq
  113:27  error  'appEvent' is already defined                      no-redeclare

/home/jason/sfa/testproj/src/aura/SearchAvailableNumbers/SearchAvailableNumbersHelper.js
  14:17  error  Gratuitous parentheses around expression  no-extra-parens
  23:17  error  'appEvent' is defined but never used      no-unused-vars
  24:28  error  Expected '===' and instead saw '=='       eqeqeq
  28:28  error  Expected '===' and instead saw '=='       eqeqeq
  32:28  error  Expected '===' and instead saw '=='       eqeqeq

? 17 problems (17 errors, 0 warnings)
Run Code Online (Sandbox Code Playgroud)

当我打开实际代码时,没有任何改变.当我再次运行linter时,它输出相同的东西.

它清楚地说"生成固定文本",但随后输出"无需修复".我找不到关于修复标志如何在线运行的任何内容,所以我转向stackoverflow寻求帮助..在此先感谢.

Ily*_*din 11

并非所有ESLint规则都是可修复的(实际上大多数规则尚不可修复).您可以通过在此页面上查找扳手字形找出可以自动固定的规则:http://eslint.org/docs/rules/

您有任何错误的规则目前都不可自动修复.有些是因为ESLint团队还没有得到它们(比如newline-after-var),有些,因为它很可能创建一个不同的逻辑然后用于原始代码(如eqeqeq)和一些,因为它不可能找到正确的方法自动修复它(像no-unused-varsno-redeclare)

  • 因为使用静态分析不可能完全确定变量没有被使用。在 JavaScript 中使用变量的方法太多了。另外,如果您在使用变量名称的地方输错了变量名称怎么办?ESLint 自动修复遵循“不造成伤害”的原则。仅当 100% 确定更改不会导致不同的行为时,它才会更改代码。 (8认同)
  • eslint 无法修复例如 unsed 参数错误,这有点蹩脚 (2认同)