【问题标题】:eslint watch task running repeatedlyeslint 监视任务重复运行
【发布时间】:2016-07-24 14:17:26
【问题描述】:

我正在尝试使用 npm scripts 在文件更改时使用 eslint 对我的文件进行 lint:

"scripts": {                                                                   
  "lint": "eslint ./* lib",                                                    
  "lint:watch":"watch 'npm run lint' .",                                       
  "test": "echo \"Error: no test specified\" && exit 1"                        
}

我使用watch 包来完成此操作。

我发现watch任务无限循环运行。 eslint 是否写入应用程序根目录中的文件。如果是这样,我怎样才能教手表忽略eslint所做的更改。

我的.eslintrc,如果需要的话:

{                                                                                
   "parser":"babel-eslint",                                                        
   "extends":"eslint:recommended",                                                 
   "rules":{                                                                       
      "strict":2,                                                                  
      "no-var":2,                                                                  
      "prefer-template":2,                                                         
      "prefer-arrow-callback":1,                                                   
      "prefer-rest-params":2,                                                      
      "prefer-spread":2,                                                           
      "object-shorthand":1,                                                        
      "no-duplicate-imports":2,                                                    
      "no-confusing-arrow":2,                                                      
      "comma-dangle":0                                                             
    }                                                                              
 }        

【问题讨论】:

  • 要快速禁用文件,只需将此行放在顶部:/* eslint-disable */
  • @Omarjmh 我认为有误传,我在eslint 上运行了一个名为watch 的包,该包正在监视项目根目录中的文件,当eslint 运行时它似乎写入root directory 上的一个文件夹导致 watch 检测到再次运行 eslint 的更改。如果我知道哪个文件,我可以要求watch 忽略它。

标签: javascript node.js watch eslint package.json


【解决方案1】:

您可以通过在项目的根目录中创建一个.eslintignore 文件来告诉 ESLint 忽略特定的文件和目录。这是一个样子:

它是纯文本,只需在您的项目中添加一个.eslintignore 文件并写入您不想“观看”的文件

下面会忽略所有的JS文件:

**/*.js

您可以获取特定或使用上述 glob 模式来忽略特定类型的所有文件。

Relevant Docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 2019-02-16
    • 1970-01-01
    相关资源
    最近更新 更多