2017-09-04 112 views
4

我不斷收到ESLint錯誤'define' is not defined. (no-undef)。我相信,我可以在全球範圍內定義define,但是不應該在本地支持?定義未定義(ESLint)

使用一個代碼示例定義:

define([], function() { // Error here! 
    'use strict'; 
    .... 

這是我eslintrc.json:

{ 
    "env": { 
     "shared-node-browser": true, 
     "commonjs": true 
    }, 
    "plugins": ["requirejs"], 
    "extends": ["eslint:recommended"], 
    "rules": { 
     "indent": [ 
      "error", 
      "tab" 
     ], 
     "linebreak-style": [ 
      "error", 
      "windows" 
     ], 
     "quotes": [ 
      "error", 
      "single" 
     ], 
     "semi": [ 
      "error", 
      "always" 
     ], 
     "requirejs/no-invalid-define": 2, 
     "requirejs/no-multiple-define": 2, 
     "requirejs/no-named-define": 2, 
     "requirejs/no-commonjs-wrapper": 2, 
     "requirejs/no-object-define": 1 
    } 
} 
+0

它不會在本地定義,因爲每個人都有不同的期望和要求。這就是爲什麼有一個'.rc'文件,所以每個人都可以指定他們自己的全局要求。所以,是的,只需要在你的配置文件中添加全局部分即可。 – Andy

回答

8

在你.eslintrc.json集:

"env": { 
    "amd": true 
}, 

當 「AMD」 環境打開,eslint註冊全局變量爲definerequire

我也會關閉"commonjs"環境,除非你真的在同一個代碼庫中混合AMD和CommonJS。

+0

謝謝,它工作。也刪除commonjs :) –