ESLint 달러 ($)가 정의되지 않았습니다. (no-undef)
$("#ID").hide();
내 프로젝트에 ESLint를 추가합니다.
symbol을 제외한 모든 것이 괜찮습니다 $
.
오류가 발생합니다. [eslint] '$' is not defined. (no-undef)
내 .eslintrc.json
(참고 : 동등한 자바 스크립트가있을 때 jquery 함수를 허용하지 않도록 설정된 추가 규칙 이 있습니다) :
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": [
"eslint:recommended"
],
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"dollar-sign",
"jquery"
],
"rules": {
"indent": [
"error" ,
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"jquery/no-ajax": 2,
"jquery/no-animate": 2,
"jquery/no-attr": 2,
"jquery/no-bind": 2,
"jquery/no-class": 2,
"jquery/no-clone": 2,
"jquery/no-closest": 2,
"jquery/no-css": 2,
"jquery/no-data": 2,
"jquery/no-deferred": 2,
"jquery/no-delegate": 2,
"jquery/no-each": 2,
"jquery/no-fade": 2,
"jquery/no-filter": 2,
"jquery/no-find": 2,
"jquery/no-global-eval": 2,
"jquery/no-has": 2,
"jquery/no-hide": 2,
"jquery/no-html": 2,
"jquery/no-in-array": 2,
"jquery/no-is": 2,
"jquery/no-map": 2,
"jquery/no-merge": 2,
"jquery/no-param": 2,
"jquery/no-parent": 2,
"jquery/no-parents": 2,
"jquery/no-parse-html": 2,
"jquery/no-prop": 2,
"jquery/no-proxy": 2,
"jquery/no-serialize": 2,
"jquery/no-show": 2,
"jquery/no-sizzle": 2,
"jquery/no-slide": 2,
"jquery/no-text": 2,
"jquery/no-toggle": 2,
"jquery/no-trigger": 2,
"jquery/no-trim": 2,
"jquery/no-val": 2,
"jquery/no-wrap": 2,
"dollar-sign/dollar-sign": [
2,
"ignoreProperties"
]
}
eslint-plugin-dollar-sign 및 eslint-plugin-jquery의 두 가지 플러그인을 추가 한 것을 볼 수 있습니다 .
이 규칙이 작동하지 않는 이유는 무엇입니까?
"dollar-sign/dollar-sign": [ 2, "ignoreProperties" ]
너는 그리워하고있다
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"jquery": true
},
$
jquery
환경이 활성화 되지 않은 전역으로 선언되지 않습니다 . 그 때문에 no-undef
선언되지 않은 변수를 사용하고 있다는 오류 가 발생합니다 .
https://eslint.org/docs/user-guide/configuring#specifying-environments
JavaScript 파일 내부의 주석을 사용하여 환경을 지정할 수 있습니다. 다음 형식을 사용하십시오.
Add the line below as a comment at the beginning of your JavaScript file.
/*eslint-env jquery*/
The eslinter will stop throwing undefined on '$' because it will know you are working with jQuery.
You can also add this line to the top of your js file:
/* global $ */
To prevent warning over "$", or for any other global like "varName":
/* global varName */
In .eslintrc.js
Add
{
"globals": {
"$": true
}
}
See https://eslint.org/docs/user-guide/configuring#specifying-globals
참고URL : https://stackoverflow.com/questions/39510736/eslint-dollar-is-not-defined-no-undef
'Development Tip' 카테고리의 다른 글
파이썬에서 numpy.linalg.eig를 사용한 후 고유 값 및 관련 고유 벡터 정렬 (0) | 2020.10.29 |
---|---|
DOM 객체에 속성을 설정할 때 매개 변수 재 할당을 방지하는 방법 (0) | 2020.10.28 |
ArrayList에 Java의 객체가 포함되어 있는지 확인하는 가장 효율적인 방법 (0) | 2020.10.28 |
Java-문자열을 유효한 URI 객체로 변환 (0) | 2020.10.28 |
앵커 링크 내부의 버튼은 Firefox에서 작동하지만 Internet Explorer에서는 작동하지 않습니까? (0) | 2020.10.28 |